Files
Sudoku/logic/strategies/strategy.go
T
2026-07-17 22:35:11 +02:00

68 lines
2.1 KiB
Go

package strategies
import (
"fmt"
"git.kleiax.de/homepage/libs/sudoku/board"
)
// ────────────────────────────────────────────────────────────────────────────── //
// STRATEGY INTERFACE //
// ────────────────────────────────────────────────────────────────────────────── //
type Strategy interface {
Init(f *board.Field)
ApplyAll() int
ApplyNext() bool
ApplyOne(n int) bool
Name() string
SearchProgressableCells() int
}
// ────────────────────────────────────────────────────────────────────────────── //
// BASE STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type Base struct {
name string
field *board.Field
changes []board.Change //eigener Typ muss her
}
func (b *Base) Init(f *board.Field) {
b.field = f
}
func (b *Base) ApplyAll() int {
// for _, change := range sb.changes {
// //change.do()
// }
return len(b.changes)
}
func (b *Base) ApplyNext() bool {
if len(b.changes) < 1 {
return false
}
//sb.changes[0].do()
b.changes = b.changes[1:]
return true
}
func (b *Base) ApplyOne(n int) bool {
if len(b.changes) <= n || n < 0 {
return false
}
//sb.changes[n].do()
b.changes = append(b.changes[:n], b.changes[n+1:]...)
return true
}
func (b *Base) getName() string {
return "Unkown"
}
func (b *Base) Name() string {
return fmt.Sprintf("Die Strategie heißt: %s", b.getName())
}