first successful run to solve a simple puzzle
This commit is contained in:
+26
-6
@@ -11,6 +11,8 @@ import (
|
||||
|
||||
type Solver struct {
|
||||
strategies []strategies.Strategy
|
||||
returnTo int
|
||||
field *board.Field
|
||||
conf struct {
|
||||
all bool
|
||||
repeat bool
|
||||
@@ -22,19 +24,37 @@ func (s *Solver) Add(strategy 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 {
|
||||
//TODO: clean und Fehlerauffangen
|
||||
s.strategies[i].SearchProgressableCells()
|
||||
numberOfChanges := s.strategies[i].ApplyAll()
|
||||
if numberOfChanges == 0 {
|
||||
return false
|
||||
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
|
||||
}
|
||||
return true
|
||||
|
||||
if s.field.IsSolved() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Solver) Search() {
|
||||
|
||||
Reference in New Issue
Block a user