first successful run to solve a simple puzzle

This commit is contained in:
2026-07-25 06:58:15 +02:00
parent 8e99087a30
commit 7bf4a8d725
15 changed files with 201 additions and 28 deletions
+16 -8
View File
@@ -12,8 +12,8 @@ import (
type Strategy interface {
Init(f *board.Field)
ApplyAll() int
ApplyNext() bool
ApplyAll() []board.ExternalChange
ApplyNext() board.ExternalChange
Name() string
SearchProgressableCells() int
}
@@ -40,23 +40,31 @@ func (b *Base) Init(f *board.Field) {
b.field = f
}
func (b *Base) ApplyAll() int {
func (b *Base) ApplyAll() []board.ExternalChange {
changesCopy := make([]board.ExternalChange, len(b.changes))
copy(changesCopy, b.changes)
for _, change := range b.changes {
b.field.AddChange(&change)
}
len := len(b.changes)
b.changes = b.changes[:0]
return len
return changesCopy
}
func (b *Base) ApplyNext() bool {
func (b *Base) ApplyNext() board.ExternalChange {
if len(b.changes) < 1 {
return false
return board.ExternalChange{}
}
changeCopy := b.changes[0]
b.field.AddChange(&b.changes[0])
b.changes = b.changes[1:]
return true
return changeCopy
}
func (b *Base) getName() string {