refactore to new project structure
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package sudoku
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.kleiax.de/homepage/board"
|
||||
"git.kleiax.de/homepage/logic"
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
field *board.Field
|
||||
solver logic.Solver
|
||||
}
|
||||
|
||||
func New(parser board.Parser, solver logic.Solver, data []byte) (*Game, error) {
|
||||
err := parser.Parse(data)
|
||||
if err != nil {
|
||||
return &Game{}, fmt.Errorf("can not create game: %w", err)
|
||||
}
|
||||
return &Game{solver: solver, field: parser.GetField(0)}, nil
|
||||
}
|
||||
|
||||
func (g *Game) Solve() error {
|
||||
g.solver.InitStragies(g.field)
|
||||
for !g.isFinished() {
|
||||
if !g.nextSolveStep() {
|
||||
return errors.New("no strategy can solve the puzzle")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Game) nextSolveStep() bool {
|
||||
return g.solver.Run(0)
|
||||
}
|
||||
|
||||
func (g *Game) prevSolveStep() {
|
||||
// far far in the future
|
||||
}
|
||||
|
||||
func (g *Game) isFinished() bool {
|
||||
return g.field.IsSolved()
|
||||
}
|
||||
|
||||
func (g *Game) GetField() board.Field {
|
||||
return *g.field
|
||||
}
|
||||
Reference in New Issue
Block a user