package strategies import ( "sort" "git.kleiax.de/homepage/field" ) // ────────────────────────────────────────────────────────────────────────────── // // NOTES STRUCTURE // // ────────────────────────────────────────────────────────────────────────────── // type Notes struct { Base } func (n *Notes) SearchProgressableCells() int { n.field.ForEachRow(func(row *field.Row) { row.ForEachCell(func(cell *field.Cell) { pos := cell.GetPosition() column, _ := n.field.GetColumn(pos.GetColumn()) block, _ := n.field.GetBlock(pos.GetBlockRow(), pos.GetBlockColumn()) candidates := intersection3(row.GetMissingNumbers(), column.GetMissingNumbers(), block.GetMissingNumbers()) for _, note := range candidates { if cell.GetNotes().Has(note) || cell.GetNumber() != 0 { continue } ch := field.ExternalChange{ Cell: cell, Action: field.ActionSetNote, Value: note, TriggerdBy: n.getName(), Marks: nil, From: 0, } n.queue(ch) } }) }) return len(n.changes) } func (n *Notes) getName() string { return "Make Notes" } func (n *Notes) Name() string { return n.getName() } func intersection3(a, b, c []int) []int { set := make(map[int]bool) for _, v := range a { set[v] = true } // Nur Werte behalten, die auch in b vorkommen inB := make(map[int]bool) for _, v := range b { inB[v] = true } for v := range set { if !inB[v] { delete(set, v) } } // Nur Werte behalten, die auch in c vorkommen inC := make(map[int]bool) for _, v := range c { inC[v] = true } for v := range set { if !inC[v] { delete(set, v) } } result := make([]int, 0, len(set)) for v := range set { result = append(result, v) } sort.Ints(result) return result }