Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseSolver ¶
type BaseSolver struct {
Key string // The unique key of the solver.
DisplayName string // The display name of the solver.
Description string // The description of the solver.
Reliable bool // If the solver is reliable, it will always solve a valid Sudoku board, otherwise, it may not be able to solve some boards.
}
Define the base solver embedding the key and other properties.
func (BaseSolver) CountSolutions ¶
func (solver BaseSolver) CountSolutions(board *core.SudokuBoard) int
Function to implement the default solution counting logic on the base solver.
func (BaseSolver) GetDescription ¶
func (solver BaseSolver) GetDescription() string
Function to get the description of the base solver.
func (BaseSolver) GetDisplayName ¶
func (solver BaseSolver) GetDisplayName() string
Function to get the display name of the base solver.
func (BaseSolver) GetKey ¶
func (solver BaseSolver) GetKey() string
Function to get the key of the base solver.
func (BaseSolver) IsReliable ¶
func (solver BaseSolver) IsReliable() bool
Function to check if the base solver is reliable.
type DefaultSolver ¶
type DefaultSolver struct {
BaseSolver
}
Define the default solver object.
func NewDefaultSolver ¶
func NewDefaultSolver() DefaultSolver
Constructor like function to create a default DefaultSolver object.
func (DefaultSolver) CountSolutions ¶
func (solver DefaultSolver) CountSolutions(board *core.SudokuBoard) int
Function to count the number of solutions for the Sudoku board. Note that if the board is already solved, we return 1 as doing nothing is also a solution.
func (DefaultSolver) Hint ¶
func (solver DefaultSolver) Hint(board *core.SudokuBoard) *core.Cell
Function to generate a hint for the Sudoku board without solving the board.
func (DefaultSolver) Solve ¶
func (solver DefaultSolver) Solve(board *core.SudokuBoard) bool
Function to solve the Sudoku board with random candidate values.
type ISudokuSolver ¶
type ISudokuSolver interface {
// Return the key of the solver.
GetKey() string
// Return the display name of the solver.
GetDisplayName() string
// Return the description of the solver.
GetDescription() string
// Return if the solver is reliable.
IsReliable() bool
// Solve the Sudoku board, return false if the solver cannot fully solve the board.
Solve(board *core.SudokuBoard) bool
// Give a hint for the next step of the board, return nil if the solver cannot give a hint.
Hint(board *core.SudokuBoard) *core.Cell
// Count the number of solutions of the board. Return 0 if the solver cannot solve the board; return 1 if the board is already solved.
CountSolutions(board *core.SudokuBoard) int
}
Define the interface of a Sudoku solver.
type SudokuSolverStore ¶
type SudokuSolverStore map[string]ISudokuSolver
Define the solver store type containing the list of solvers.
func NewSudokuSolverStore ¶
func NewSudokuSolverStore() SudokuSolverStore
Function to initialize the solver store.
func (SudokuSolverStore) GetDefaultSolver ¶
func (store SudokuSolverStore) GetDefaultSolver() ISudokuSolver
Function to get the default backtracking solver from the store.
func (SudokuSolverStore) GetSolverByKey ¶
func (store SudokuSolverStore) GetSolverByKey(key string) ISudokuSolver
Function to get the solver by key from the store.