Documentation ¶
Index ¶
- Variables
- func AbsInt(x int) int
- func Max[T constraints.Ordered](x T, y T) T
- func Min[T constraints.Ordered](x T, y T) T
- func Random() *rand.Rand
- func RandomSeed() int64
- func RandomSeeded(seed int64) *rand.Rand
- type Bitset
- func (bits *Bitset) And(and Bitset) int
- func (bits *Bitset) Clear()
- func (bits *Bitset) Differences(other Bitset) bool
- func (bits *Bitset) Fill(n int)
- func (bits *Bitset) First() int
- func (bits *Bitset) Has(i int) bool
- func (bits *Bitset) Last() int
- func (bits *Bitset) Or(or Bitset) int
- func (bits *Bitset) Overlaps(other Bitset) bool
- func (bits *Bitset) Remove(remove Bitset) int
- func (bits *Bitset) Set(i int, on bool) bool
- func (bits *Bitset) ToSlice() []int
- func (bits *Bitset) UpdateCount()
- type Candidates
- func (cand *Candidates) And(and Candidates) int
- func (cand *Candidates) Differences(other Candidates) bool
- func (cand *Candidates) First() int
- func (cand *Candidates) Has(i int) bool
- func (cand *Candidates) Last() int
- func (cand *Candidates) Or(or Candidates) int
- func (cand *Candidates) Overlaps(other Candidates) bool
- func (cand *Candidates) Remove(remove Candidates) int
- func (cand *Candidates) Set(i int, on bool) bool
- func (cand *Candidates) ToSlice() []int
- type Cell
- func (cell *Cell) Candidates() []int
- func (cell *Cell) Empty() bool
- func (cell *Cell) FirstCandidate() int
- func (cell *Cell) GetGroup(groupIndex Group) int
- func (cell *Cell) HasCandidate(value int) bool
- func (cell *Cell) HasValue() bool
- func (cell *Cell) InBox(other *Cell) bool
- func (cell *Cell) InColumn(other *Cell) bool
- func (cell *Cell) InGroup(other *Cell) bool
- func (cell *Cell) InRow(other *Cell) bool
- func (cell *Cell) LastCandidate() int
- func (cell *Cell) MaxValue() int
- func (cell *Cell) MinValue() int
- func (cell *Cell) RemoveCandidate(value int) bool
- func (cell *Cell) SetValue(value int) bool
- func (cell *Cell) ToConsoleString() string
- func (cell *Cell) Valid() bool
- type ClearLimit
- type Color
- type Constraint
- type ConstraintDifference
- type ConstraintDivisible
- type ConstraintMagic
- type ConstraintOrder
- type ConstraintScalePair
- type ConstraintSum
- type ConstraintSumProvider
- type ConstraintUnique
- type Generator
- func (gen *Generator) Attempt() *Puzzle
- func (gen *Generator) Attempts(tries int) (*Puzzle, int)
- func (gen *Generator) ClearCells(puzzle *Puzzle, limits ClearLimit) (*Puzzle, int)
- func (gen *Generator) Generate() (*Puzzle, int)
- func (gen *Generator) GetRandomUnsolved() *Cell
- func (gen *Generator) GetUnsolved() *Cell
- func (gen *Generator) IsComplete() bool
- func (gen *Generator) Puzzle() *Puzzle
- func (gen *Generator) Reset()
- func (gen *Generator) Solver() *Solver
- type Group
- type Kind
- func (kind *Kind) Area() int
- func (kind *Kind) BoxesHigh() int
- func (kind *Kind) BoxesWide() int
- func (kind *Kind) Clone() *Kind
- func (kind *Kind) ConstraintsFor(cell *Cell) []Constraint
- func (kind *Kind) Create(values [][]int) Puzzle
- func (kind *Kind) Digits() int
- func (kind *Kind) DigitsSize() int
- func (kind *Kind) Empty() Puzzle
- func (kind *Kind) Generator() Generator
- func (kind *Kind) GetDimensions() (boxsWide int, boxsHigh int, boxWidth int, boxHeight int, size int)
- func (kind *Kind) Size() int
- type Position
- type Puzzle
- func (puzzle *Puzzle) Clear()
- func (puzzle *Puzzle) Clone() Puzzle
- func (puzzle *Puzzle) Contains(col int, row int) bool
- func (puzzle *Puzzle) EncodedString() string
- func (puzzle *Puzzle) Get(col int, row int) *Cell
- func (puzzle *Puzzle) GetAll() [][]int
- func (puzzle *Puzzle) GetCandidates() [][][]int
- func (puzzle *Puzzle) GetCandidatesFor(cell *Cell) Candidates
- func (puzzle *Puzzle) GetColumn(columnIndex int) []int
- func (puzzle *Puzzle) GetColumnCells(columnIndex int) []*Cell
- func (puzzle *Puzzle) GetRow(rowIndex int) []int
- func (puzzle *Puzzle) GetRowCells(rowIndex int) []*Cell
- func (puzzle *Puzzle) GetSolutions(limit SolutionsLimit) []*Solver
- func (puzzle *Puzzle) GetSymmetric(cell *Cell) *Cell
- func (puzzle *Puzzle) HasUniqueSolution() bool
- func (puzzle *Puzzle) IsCandidate(value int) bool
- func (puzzle *Puzzle) IsSolved() bool
- func (puzzle *Puzzle) IsValid() bool
- func (puzzle *Puzzle) MaxCandidate() int
- func (puzzle *Puzzle) MinCandidate() int
- func (puzzle *Puzzle) PrintConsole()
- func (puzzle *Puzzle) PrintConsoleCandidates()
- func (instance *Puzzle) PrintConsoleCells()
- func (puzzle *Puzzle) Remove(col int, row int) bool
- func (puzzle *Puzzle) RemoveCell(cell *Cell) bool
- func (puzzle *Puzzle) Set(col int, row int, value int) bool
- func (puzzle *Puzzle) SetAll(values [][]int) int
- func (puzzle *Puzzle) SetCell(cell *Cell, value int) bool
- func (puzzle *Puzzle) Solver() Solver
- func (puzzle *Puzzle) String() string
- func (puzzle *Puzzle) ToConsoleCandidatesString() string
- func (instance *Puzzle) ToConsoleCellsString() string
- func (puzzle *Puzzle) ToConsoleString() string
- func (puzzle *Puzzle) ToStateString(includeKind bool, emptyValue string) string
- func (puzzle *Puzzle) UniqueId() string
- func (puzzle *Puzzle) WriteConsole(out io.Writer)
- func (puzzle *Puzzle) WriteConsoleCandidates(out io.Writer)
- type PuzzlePDF
- func (pdf *PuzzlePDF) Add(puzzle *Puzzle, candidates bool, stateString bool, solutionString bool)
- func (pdf *PuzzlePDF) Download(w http.ResponseWriter, filename string, direct bool) (any, int)
- func (pdf *PuzzlePDF) Generate() *gofpdf.Fpdf
- func (pdf *PuzzlePDF) Send(w http.ResponseWriter, direct bool) (any, int)
- func (pdf *PuzzlePDF) Write(writer io.Writer, direct bool)
- func (pdf *PuzzlePDF) WriteFile(path string)
- type PuzzlePDFItem
- type Queue
- type QueueNode
- type Size
- type SolutionsLimit
- type SolveLimit
- type SolveStep
- func CreateStepBasicFish(setSize int, technique string, firstCost int, subsequentCost int) *SolveStep
- func CreateStepHiddenSubsets(subsetSize int, technique string, firstCost int, subsequentCost int) *SolveStep
- func CreateStepNakedSubsets(subsetSize int, technique string, firstCost int, subsequentCost int) *SolveStep
- type SolveStepLogic
- type Solver
- func (solver *Solver) Box(box int) []*Cell
- func (solver *Solver) CanContinue(limits SolveLimit, cost int) bool
- func (solver *Solver) CanContinueStep(limits SolveLimit, step *SolveStep) bool
- func (solver *Solver) Col(col int) []*Cell
- func (solver *Solver) GetCellWhere(where func(cell *Cell) bool) *Cell
- func (solver *Solver) GetCost(step *SolveStep) int
- func (solver *Solver) GetLastLog() *SolverLog
- func (solver *Solver) GetMinCandidateCount() int
- func (solver *Solver) Group(groupIndex Group, cell *Cell) []*Cell
- func (solver *Solver) LogAfter(after *Cell)
- func (solver *Solver) LogBefore(before *Cell)
- func (solver *Solver) LogPlacement(after *Cell)
- func (solver *Solver) LogStep(step *SolveStep)
- func (solver *Solver) Row(row int) []*Cell
- func (solver *Solver) Set(col int, row int, value int) bool
- func (solver *Solver) SetCell(cell *Cell, value int) bool
- func (solver *Solver) Solve(limits SolveLimit) (*Puzzle, bool)
- func (solver *Solver) Solved() bool
- type SolverLog
- type Stack
Constants ¶
This section is empty.
Variables ¶
var ( ColorWhite = Color{255, 255, 255} ColorBlack = Color{0, 0, 0} ColorGreen = Color{0, 255, 0} ColorRed = Color{255, 0, 0} ColorBlue = Color{0, 0, 255} ColorGray = Color{127, 127, 127} )
var Classic = &Kind{ BoxSize: Size{3, 3}, }
The classic 9x9 puzzle with 9 boxes of 3x3 and digits 1-9.
var DifficultyBeginner = ClearLimit{ SolveLimit: SolveLimit{MinCost: 3600, MaxCost: 4500}, Symmetric: true, }
var DifficultyDiabolical = ClearLimit{ SolveLimit: SolveLimit{MinCost: 11000, MaxCost: 25000}, Symmetric: false, }
var DifficultyEasy = ClearLimit{ SolveLimit: SolveLimit{MinCost: 4300, MaxCost: 5500}, Symmetric: true, }
var DifficultyFiendish = ClearLimit{ SolveLimit: SolveLimit{MinCost: 8300, MaxCost: 14000}, Symmetric: false, }
var DifficultyHard = ClearLimit{ SolveLimit: SolveLimit{MinCost: 6000, MaxCost: 7200}, Symmetric: false, }
var DifficultyMedium = ClearLimit{ SolveLimit: SolveLimit{MinCost: 5300, MaxCost: 6900}, Symmetric: true, }
var DifficultyTricky = ClearLimit{ SolveLimit: SolveLimit{MinCost: 6500, MaxCost: 9300}, Symmetric: false, }
var GenerateSolveSteps = []*SolveStep{ StepNakedSingle, StepHiddenSingle, StepPointingCandidates, StepClaimingCandidates, StepConstraints, StepNakedSubsets2, StepNakedSubsets3, }
var Kind2x2 = &Kind{ BoxSize: Size{2, 2}, }
A 4x4 puzzle with 4 boxes of 2x2 and digits 1-4.
var Kind3x2 = &Kind{ BoxSize: Size{3, 2}, }
A 6x6 puzzle with 6 boxes of 3x2 and digits 1-6.
var Kind4x3 = &Kind{ BoxSize: Size{4, 3}, }
A 12x12 puzzle with 12 boxes of 4x3 and digits 1-12.
var Kind4x4 = &Kind{ BoxSize: Size{4, 4}, }
A 16x16 puzzle with 16 boxes of 4x4 and digits 1-16.
var StandardSolveSteps = []*SolveStep{ StepNakedSingle, StepHiddenSingle, StepPointingCandidates, StepClaimingCandidates, StepConstraints, StepSkyscraper, Step2StringKite, StepNakedSubsets2, StepHiddenSubsets2, StepEmptyRectangle, StepXWing, StepNakedSubsets3, StepHiddenSubsets3, StepSwordfish, StepNakedSubsets4, StepHiddenSubsets4, StepJellyfish, }
var Step2StringKite = &SolveStep{ Technique: "2-String Kite", FirstCost: 2800, SubsequentCost: 1600, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { return 0, do2StringKite(solver, limits, step) > 0 }, }
var StepBruteForce = &SolveStep{ Technique: "Brute Force", FirstCost: 0, SubsequentCost: 0, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { return 0, false }, }
================================================== Step: Brute Force ==================================================
var StepClaimingCandidates = &SolveStep{ Technique: "Claiming Candidates", FirstCost: 350, SubsequentCost: 200, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { removed := false if solver.CanContinueStep(limits, step) { removed = doRemoveClaimingCandidates(solver, limits, step) > 0 } return 0, removed }, }
================================================== Step: Claiming Candidates
http://hodoku.sourceforge.net/en/tech_intersections.php
==================================================
var StepConstraints = &SolveStep{ Technique: "Constraints", FirstCost: 0, SubsequentCost: 0, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { removed := 0 for _, cell := range solver.Unsolved { if len(cell.Constraints) == 0 { continue } candidates := cell.candidates for _, constraint := range cell.Constraints { constraint.RemoveCandidates(cell, &solver.Puzzle, &candidates) } if candidates.Value != cell.candidates.Value { solver.LogStep(step) solver.LogBefore(cell) removed += cell.candidates.Count - candidates.Count cell.candidates = candidates solver.LogPlacement(cell) if !solver.CanContinueStep(limits, step) { break } } } return 0, removed > 0 }, }
================================================== Step: Constraints ==================================================
var StepEmptyRectangle = &SolveStep{ Technique: "Empty Rectangle", FirstCost: 2800, SubsequentCost: 1600, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { return 0, doEmptyRectangle(solver, limits, step) > 0 }, }
var StepHiddenSingle = &SolveStep{ Technique: "Hidden Single", FirstCost: 100, SubsequentCost: 100, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { placements := 0 for solver.CanContinueStep(limits, step) { cell, cellValue := getHiddenSingle(solver) if cell != nil { solver.LogStep(step) solver.LogBefore(cell) solver.SetCell(cell, cellValue) solver.LogPlacement(cell) placements++ } else { break } } return placements, placements > 0 }, }
================================================== Step: Hidden Single
http://hodoku.sourceforge.net/en/tech_singles.php
==================================================
var StepHiddenSubsets2 = CreateStepHiddenSubsets(2, "Hidden Pair", 1500, 1200)
var StepHiddenSubsets3 = CreateStepHiddenSubsets(3, "Hidden Triplet", 2400, 1600)
var StepHiddenSubsets4 = CreateStepHiddenSubsets(4, "Hidden Quad", 7000, 5000)
var StepJellyfish = CreateStepBasicFish(4, "Jellyfish", 10000, 8000)
var StepNakedSingle = &SolveStep{ Technique: "Naked Single", FirstCost: 100, SubsequentCost: 100, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { placements := 0 for solver.CanContinueStep(limits, step) { cell, cellValue := getNakedSingle(solver) if cell != nil { solver.LogStep(step) solver.LogBefore(cell) solver.SetCell(cell, cellValue) solver.LogPlacement(cell) placements++ } else { break } } return placements, false }, }
================================================== Step: Naked Single
http://hodoku.sourceforge.net/en/tech_singles.php
==================================================
var StepNakedSubsets2 = CreateStepNakedSubsets(2, "Naked Pair", 750, 500)
var StepNakedSubsets3 = CreateStepNakedSubsets(3, "Naked Triplet", 2000, 1400)
var StepNakedSubsets4 = CreateStepNakedSubsets(4, "Naked Quad", 5000, 4000)
var StepPointingCandidates = &SolveStep{ Technique: "Pointing Candidates", FirstCost: 350, SubsequentCost: 200, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { removed := false if solver.CanContinueStep(limits, step) { removed = doRemovePointingCandidates(solver, limits, step) > 0 } return 0, removed }, }
================================================== Step: Pointing Candidates
http://hodoku.sourceforge.net/en/tech_intersections.php
==================================================
var StepSkyscraper = &SolveStep{ Technique: "Skyscraper", FirstCost: 2800, SubsequentCost: 1600, Logic: func(solver *Solver, limits SolveLimit, step *SolveStep) (int, bool) { return 0, doSkyscraper(solver, limits, step) > 0 }, }
var StepSwordfish = CreateStepBasicFish(3, "Swordfish", 8000, 6000)
var StepXWing = CreateStepBasicFish(2, "X-Wing", 2800, 1600)
Functions ¶
func Max ¶
func Max[T constraints.Ordered](x T, y T) T
func Min ¶
func Min[T constraints.Ordered](x T, y T) T
func RandomSeed ¶
func RandomSeed() int64
func RandomSeeded ¶
Types ¶
type Bitset ¶
A set of integers from 0 to 63 with O(1) add, remove, search, and union/substraction/intersection set operations.
func (*Bitset) And ¶
Removes any integers from this set that also don't exist in the given set (intersection).
func (*Bitset) Differences ¶
Returns whether this set and the other don't share one or more integers.
func (*Bitset) Set ¶
Adds or removes the integer from the set and returns true if the set has changed as a result of this call.
func (*Bitset) UpdateCount ¶
func (bits *Bitset) UpdateCount()
Updates the number of integers in the set based on the Value.
type Candidates ¶
type Candidates struct {
Bitset
}
A set of possible values for a cell. This is similar to a Bitset but is 1 based.
func (*Candidates) And ¶
func (cand *Candidates) And(and Candidates) int
Removes any candidates from this set that also don't exist in the given set (intersection).
func (*Candidates) Differences ¶
func (cand *Candidates) Differences(other Candidates) bool
Returns whether this set and the other don't share one or more candidates.
func (*Candidates) First ¶
func (cand *Candidates) First() int
The smallest candidate in the set or 64 if the set is empty
func (*Candidates) Has ¶
func (cand *Candidates) Has(i int) bool
Returns whether the candidate exists in the set.
func (*Candidates) Last ¶
func (cand *Candidates) Last() int
The largest candidate in the set or 0 if the set is empty
func (*Candidates) Or ¶
func (cand *Candidates) Or(or Candidates) int
Adds all candidates in the given set to this set (union).
func (*Candidates) Overlaps ¶
func (cand *Candidates) Overlaps(other Candidates) bool
Returns whether this set and the other share any candidates.
func (*Candidates) Remove ¶
func (cand *Candidates) Remove(remove Candidates) int
Removes all candidates in the given set from this set.
func (*Candidates) Set ¶
func (cand *Candidates) Set(i int, on bool) bool
Adds or removes the candidate from the set and returns true if the set has changed as a result of this call.
func (*Candidates) ToSlice ¶
func (cand *Candidates) ToSlice() []int
Creates a slice of all candidates in this set.
type Cell ¶
type Cell struct { // The Value in the cell or 0 if a no Value exists yet. Value int // The unique Id of the cell. This is also the index of this cell in the puzzle's cells slice. Id int // The zero-based Row this cell is in. Row int // The zero-based column this cell is in. Col int // The zero-based Box this cell is in which starts in the top left of the puzzle and goes right and then restarts on the left side for the next row. Box int // The constrains applicable for this cell. Constraints []Constraint // contains filtered or unexported fields }
A cell holds a value or possible values in a Sudoku puzzle.
func (*Cell) Candidates ¶
Returns the candidates that exists in this cell as a slice of ints.
func (*Cell) FirstCandidate ¶
Returns the smallest candidate available in this cell. If none exist then 64 is returned.
func (*Cell) GetGroup ¶
Returns the group given its index. The group order starting with zero is Col, Row, Box.
func (*Cell) HasCandidate ¶
Determines if this cell has the given candidate.
func (*Cell) InGroup ¶
Returns whether this cell and the given cell are in the same group (box, column, or row).
func (*Cell) LastCandidate ¶
Returns the largest candidate available in this cell. If none exist then 0 is returned.
func (*Cell) MaxValue ¶
The maximum value this cell can possibly be, taking into account it might already have a value and therefore no candidates.
func (*Cell) MinValue ¶
The minimum value this cell can possibly be, taking into account it might already have a value and therefore no candidates.
func (*Cell) RemoveCandidate ¶
Removes the given candidate from this cell and returns whether it existed in the first place.
func (*Cell) SetValue ¶
Attempts to set the value of this cell. If this cell already has a value or doesn't have the given value as a candidate then false will be returned. Otherwise if the value is applied then true is returned.
func (*Cell) ToConsoleString ¶
type ClearLimit ¶
type ClearLimit struct { SolveLimit Symmetric bool MaxStates int Fast bool }
func (ClearLimit) Extend ¶
func (limits ClearLimit) Extend(extend ClearLimit) ClearLimit
type Constraint ¶
type Constraint interface { Affects(cell *Cell) bool RemoveCandidates(cell *Cell, puzzle *Puzzle, remove *Candidates) }
A constraint is an added rule for solving the puzzle. This enables more complex puzzles with fewer givens. The following basic constraints are supported - A collection of cells sum up to a value
- Diagonal lines: https://www.youtube.com/watch?v=Vc-FYo_nur4
- Groups/cages: https://www.youtube.com/watch?v=2v6Lf3Q5AEo&t=885s
- X/V: https://www.youtube.com/watch?v=9ATC_uBF8ow
- Squares: https://www.youtube.com/watch?v=u6Le6f9d0KU&t=602s
- Knights move: https://www.youtube.com/watch?v=3FMNh-_FNlk
- Magic square: https://www.youtube.com/watch?v=La7Yg_rav24
- A collection of cells sum up to the value of another cell
- A collection of cells go from increasing to decreasing order (known direction or not)
- Thermo(meter): https://www.youtube.com/watch?v=KTth49YrQVU
- Circled ends: https://www.youtube.com/watch?v=Tpk3ga2T9Ps&t=159s
- A collection of cells even & odd digits sum to same value - A cell cannot have the same value as a collection of cells
- Kings move
- Knights move: https://www.youtube.com/watch?v=hAyZ9K2EBF0
- No repeats in group/age: https://www.youtube.com/watch?v=u6Le6f9d0KU&t=602s, https://www.youtube.com/watch?v=hAyZ9K2EBF0
- Or constraint (multiple constraints can dictate which candidates are available)
- Sum is square: https://www.youtube.com/watch?v=u6Le6f9d0KU&t=602s
- And constraint
- Circled ends & no duplicates: https://www.youtube.com/watch?v=Tpk3ga2T9Ps&t=159s
type ConstraintDifference ¶
type ConstraintDifference struct { // The minimum difference that should exist between the given cells. // If the cells are in the same groups then the minimum is already technically 1 // since the same value can't exist in the same group. A value of 2 means all // cells will need to be atleast 2 apart. Min int // The maximum difference that should exist between the given cells. // For example if the Max is 4 and one of the cells is 2 then the other cells // are constrained to 1, 2, 3, 4, 5, and 6. Max int // The cells which are affected by this constaint. If nil all cells in the puzzle // are affected (minus what's given in Exclude). Cells *[]Position // The cells which are looked at by the constraint. If nil the cells involved in // the logic are the Cells given. Relative *[]Position // The cells to exclude from being constrained when Cells is nil // (meaning all cells are constrained int he puzzle). Exclude *[]Position }
================================================== Constraint: Difference ==================================================
func (*ConstraintDifference) Affects ¶
func (c *ConstraintDifference) Affects(cell *Cell) bool
func (*ConstraintDifference) RemoveCandidates ¶
func (c *ConstraintDifference) RemoveCandidates(cell *Cell, puzzle *Puzzle, remove *Candidates)
type ConstraintDivisible ¶
================================================== Constraint: Divisible ==================================================
func ConstraintEven ¶
func ConstraintEven(cells []Position) ConstraintDivisible
func ConstraintOdd ¶
func ConstraintOdd(cells []Position) ConstraintDivisible
func (*ConstraintDivisible) Affects ¶
func (c *ConstraintDivisible) Affects(cell *Cell) bool
func (*ConstraintDivisible) RemoveCandidates ¶
func (c *ConstraintDivisible) RemoveCandidates(cell *Cell, puzzle *Puzzle, remove *Candidates)
type ConstraintMagic ¶
type ConstraintMagic struct {
Center Position
}
================================================== Constraint: Magic Square ==================================================
func (*ConstraintMagic) Affects ¶
func (c *ConstraintMagic) Affects(cell *Cell) bool
func (*ConstraintMagic) RemoveCandidates ¶
func (c *ConstraintMagic) RemoveCandidates(cell *Cell, puzzle *Puzzle, remove *Candidates)
type ConstraintOrder ¶
================================================== Constraint: Uniqueness ==================================================
func (*ConstraintOrder) Affects ¶
func (c *ConstraintOrder) Affects(cell *Cell) bool
func (*ConstraintOrder) RemoveCandidates ¶
func (c *ConstraintOrder) RemoveCandidates(cell *Cell, puzzle *Puzzle, remove *Candidates)
type ConstraintScalePair ¶
================================================== Constraint: Scale ==================================================
func ConstraintScalePairs ¶
func ConstraintScalePairs(scale int, pairs [][2]Position) []ConstraintScalePair
func (*ConstraintScalePair) Affects ¶
func (c *ConstraintScalePair) Affects(cell *Cell) bool
func (*ConstraintScalePair) RemoveCandidates ¶
func (c *ConstraintScalePair) RemoveCandidates(cell *Cell, puzzle *Puzzle, remove *Candidates)
type ConstraintSum ¶
type ConstraintSum struct { // The function which returns a value the cells need to sum to. Sum ConstraintSumProvider // The list of cells that are constrained to some sum. If this is nil then // all cells will be a part of the constraint. Cells *[]Position Relative *[]Position }
A constraint on a set of cells that states that set or relative cells should sum to a value.
func (*ConstraintSum) Affects ¶
func (c *ConstraintSum) Affects(cell *Cell) bool
func (*ConstraintSum) RemoveCandidates ¶
func (c *ConstraintSum) RemoveCandidates(cell *Cell, puzzle *Puzzle, remove *Candidates)
type ConstraintSumProvider ¶
A function which returns a value other cells should sum to given the cell being constrained and the puzzle. If there is no sum to constrain then 0 should be returned.
func SumCell ¶
func SumCell(pos Position, relative bool) ConstraintSumProvider
A sum provider which returns the value (or largest candidate) of a cell at the given position
func SumCells ¶
func SumCells(positions []Position, relative bool) ConstraintSumProvider
A sum provider which returns the value (or largest candidate) of a cell at the given position
func SumConstant ¶
func SumConstant(value int) ConstraintSumProvider
A sum provider which returns a constant value
type ConstraintUnique ¶
A constraint on a set of cells where they can't have the same value OR they all need to have the same value.
func (*ConstraintUnique) Affects ¶
func (c *ConstraintUnique) Affects(cell *Cell) bool
func (*ConstraintUnique) RemoveCandidates ¶
func (c *ConstraintUnique) RemoveCandidates(cell *Cell, puzzle *Puzzle, remove *Candidates)
type Generator ¶
Generates puzzles of the given kind using a particular random number generator.
func NewGenerator ¶
func NewSeededGenerator ¶
func (*Generator) ClearCells ¶
func (gen *Generator) ClearCells(puzzle *Puzzle, limits ClearLimit) (*Puzzle, int)
func (*Generator) GetRandomUnsolved ¶
func (*Generator) GetUnsolved ¶
func (*Generator) IsComplete ¶
type Kind ¶
type Kind struct { BoxSize Size Constraints []Constraint }
func (*Kind) ConstraintsFor ¶
func (kind *Kind) ConstraintsFor(cell *Cell) []Constraint
func (*Kind) DigitsSize ¶
How many characters it could take to print out the largest digit of a value in this puzzle kind.
type Puzzle ¶
func FromEncoded ¶
func FromString ¶
func (*Puzzle) EncodedString ¶
func (*Puzzle) GetCandidates ¶
func (*Puzzle) GetCandidatesFor ¶
func (puzzle *Puzzle) GetCandidatesFor(cell *Cell) Candidates
func (*Puzzle) GetColumnCells ¶
func (*Puzzle) GetRowCells ¶
func (*Puzzle) GetSolutions ¶
func (puzzle *Puzzle) GetSolutions(limit SolutionsLimit) []*Solver
func (*Puzzle) GetSymmetric ¶
func (*Puzzle) HasUniqueSolution ¶
func (*Puzzle) IsCandidate ¶
func (*Puzzle) MaxCandidate ¶
func (*Puzzle) MinCandidate ¶
func (*Puzzle) PrintConsole ¶
func (puzzle *Puzzle) PrintConsole()
func (*Puzzle) PrintConsoleCandidates ¶
func (puzzle *Puzzle) PrintConsoleCandidates()
func (*Puzzle) PrintConsoleCells ¶
func (instance *Puzzle) PrintConsoleCells()
func (*Puzzle) RemoveCell ¶
func (*Puzzle) ToConsoleCandidatesString ¶
func (*Puzzle) ToConsoleCellsString ¶
func (*Puzzle) ToConsoleString ¶
func (*Puzzle) ToStateString ¶
func (*Puzzle) WriteConsole ¶
func (*Puzzle) WriteConsoleCandidates ¶
type PuzzlePDF ¶
type PuzzlePDF struct { Puzzles []PuzzlePDFItem PuzzlesWide int PuzzlesHigh int PuzzleSpacing float64 MarginLeft float64 MarginRight float64 MarginTop float64 MarginBottom float64 Landscape bool PageSize string Font string ValueFontColor Color ValueBackColor Color ValueFontScale float64 CandidateColor Color CandidateScale float64 BorderThickColor Color BorderThickWidth float64 BorderThinColor Color BorderThinWidth float64 StateColor Color SolutionColor Color }
type PuzzlePDFItem ¶
type SolutionsLimit ¶
type SolutionsLimit struct { SolveLimit MaxSolutions int LogEnabled bool LogState bool }
type SolveLimit ¶
type SolveStep ¶
type SolveStep struct { Technique string FirstCost int SubsequentCost int Logic SolveStepLogic }
func CreateStepBasicFish ¶
func CreateStepBasicFish(setSize int, technique string, firstCost int, subsequentCost int) *SolveStep
================================================== Step: Remove Naked Subset Candidates
http://hodoku.sourceforge.net/en/tech_naked.php
==================================================
func CreateStepHiddenSubsets ¶
func CreateStepHiddenSubsets(subsetSize int, technique string, firstCost int, subsequentCost int) *SolveStep
================================================== Step: Remove Hidden Subset Candidates
http://hodoku.sourceforge.net/en/tech_hidden.php
==================================================
func CreateStepNakedSubsets ¶
func CreateStepNakedSubsets(subsetSize int, technique string, firstCost int, subsequentCost int) *SolveStep
================================================== Step: Remove Naked Subset Candidates
http://hodoku.sourceforge.net/en/tech_naked.php
==================================================
type SolveStepLogic ¶
type SolveStepLogic func(solver *Solver, limits SolveLimit, step *SolveStep) (placements int, restart bool)
type Solver ¶
type Solver struct { Puzzle Puzzle Steps []*SolveStep Unsolved []*Cell Boxs [][]*Cell Rows [][]*Cell Cols [][]*Cell LogEnabled bool LogState bool LogTechniques map[string]int Logs []SolverLog // contains filtered or unexported fields }
func (*Solver) CanContinue ¶
func (solver *Solver) CanContinue(limits SolveLimit, cost int) bool
func (*Solver) CanContinueStep ¶
func (solver *Solver) CanContinueStep(limits SolveLimit, step *SolveStep) bool