package strategies import ( "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) { column, _ := n.field.GetColumn(cell.Pos.GetColumn()) block, _ := n.field.GetBlock(cell.Pos.GetBlockRow(), cell.Pos.GetBlockColumn()) candidates := intersection3(row.GetMissingNumbers(), column.GetMissingNumbers(), block.GetMissingNumbers()) for _, note := range candidates { if cell.Notes.Has(note) || cell.GetNumber() != 0 { continue } ch := field.ExternalChange{ Cell: cell, Action: field.ActionSetNote, Value: note, TriggerdBy: n.getName(), Marks: nil, From: 0, } n.changes = append(n.changes, ch) } }) }) return len(n.changes) } func (n *Notes) getName() string { return "Make Notes" } 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) } return result }