67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"git.kleiax.de/homepage/board"
|
|
"git.kleiax.de/homepage/logic/strategies"
|
|
)
|
|
|
|
// ────────────────────────────────────────────────────────────────────────────── //
|
|
// SOLVER STRUCTURE //
|
|
// ────────────────────────────────────────────────────────────────────────────── //
|
|
|
|
type Solver struct {
|
|
strategies []strategies.Strategy
|
|
returnTo int
|
|
field *board.Field
|
|
conf struct {
|
|
all bool
|
|
repeat bool
|
|
}
|
|
}
|
|
|
|
func (s *Solver) Add(strategy strategies.Strategy) {
|
|
s.strategies = append(s.strategies, strategy)
|
|
}
|
|
|
|
func (s *Solver) InitStragies(field *board.Field) {
|
|
s.returnTo = 1
|
|
s.field = field
|
|
for _, strategy := range s.strategies {
|
|
strategy.Init(field)
|
|
}
|
|
}
|
|
|
|
func (s *Solver) Run(i int) bool {
|
|
for j := 0; j < len(s.strategies); j++ {
|
|
if s.strategies[j].SearchProgressableCells() == 0 {
|
|
continue
|
|
}
|
|
|
|
for _, change := range s.strategies[j].ApplyAll() {
|
|
if change.Action != board.ActionSetNumber {
|
|
continue
|
|
}
|
|
s.field.ForEachPartAtPos(change.Cell.Pos, func(part board.Part) {
|
|
part.ForEachCell(func(cell *board.Cell) {
|
|
cell.Notes.Remove(s.field, cell, change.Value, "remove note after insert of a number", nil)
|
|
})
|
|
})
|
|
}
|
|
|
|
j = s.returnTo - 1
|
|
}
|
|
|
|
if s.field.IsSolved() {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (s *Solver) Search() {
|
|
|
|
}
|
|
|
|
func (s *Solver) GetSolutionPath() []board.ExternalChange {
|
|
return nil
|
|
}
|