Refactor Sudoku field and solver implementation
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package strategies
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"git.kleiax.de/homepage/field"
|
||||
)
|
||||
|
||||
@@ -15,11 +17,12 @@ type Notes struct {
|
||||
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())
|
||||
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.Notes.Has(note) || cell.GetNumber() != 0 {
|
||||
if cell.GetNotes().Has(note) || cell.GetNumber() != 0 {
|
||||
continue
|
||||
}
|
||||
ch := field.ExternalChange{
|
||||
@@ -30,7 +33,7 @@ func (n *Notes) SearchProgressableCells() int {
|
||||
Marks: nil,
|
||||
From: 0,
|
||||
}
|
||||
n.changes = append(n.changes, ch)
|
||||
n.queue(ch)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -41,6 +44,10 @@ 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)
|
||||
|
||||
@@ -76,6 +83,7 @@ func intersection3(a, b, c []int) []int {
|
||||
for v := range set {
|
||||
result = append(result, v)
|
||||
}
|
||||
sort.Ints(result)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user