Files

67 lines
1.7 KiB
Go

package logic
import (
"git.kleiax.de/homepage/field"
"git.kleiax.de/homepage/logic/strategies"
)
// ────────────────────────────────────────────────────────────────────────────── //
// SOLVER STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type Solver struct {
strategies []strategies.Strategy
returnTo int
field *field.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 *field.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 != field.ActionSetNumber {
continue
}
s.field.ForEachPartAtPos(change.Cell.Pos, func(part field.Part) {
part.ForEachCell(func(cell *field.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() []field.ExternalChange {
return nil
}