sudogo

package
v0.0.0-...-e89bacc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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}
)
View Source
var Classic = &Kind{
	BoxSize: Size{3, 3},
}

The classic 9x9 puzzle with 9 boxes of 3x3 and digits 1-9.

View Source
var DifficultyBeginner = ClearLimit{
	SolveLimit: SolveLimit{MinCost: 3600, MaxCost: 4500},
	Symmetric:  true,
}
View Source
var DifficultyDiabolical = ClearLimit{
	SolveLimit: SolveLimit{MinCost: 11000, MaxCost: 25000},
	Symmetric:  false,
}
View Source
var DifficultyEasy = ClearLimit{
	SolveLimit: SolveLimit{MinCost: 4300, MaxCost: 5500},
	Symmetric:  true,
}
View Source
var DifficultyFiendish = ClearLimit{
	SolveLimit: SolveLimit{MinCost: 8300, MaxCost: 14000},
	Symmetric:  false,
}
View Source
var DifficultyHard = ClearLimit{
	SolveLimit: SolveLimit{MinCost: 6000, MaxCost: 7200},
	Symmetric:  false,
}
View Source
var DifficultyMedium = ClearLimit{
	SolveLimit: SolveLimit{MinCost: 5300, MaxCost: 6900},
	Symmetric:  true,
}
View Source
var DifficultyTricky = ClearLimit{
	SolveLimit: SolveLimit{MinCost: 6500, MaxCost: 9300},
	Symmetric:  false,
}
View Source
var Kind2x2 = &Kind{
	BoxSize: Size{2, 2},
}

A 4x4 puzzle with 4 boxes of 2x2 and digits 1-4.

View Source
var Kind3x2 = &Kind{
	BoxSize: Size{3, 2},
}

A 6x6 puzzle with 6 boxes of 3x2 and digits 1-6.

View Source
var Kind4x3 = &Kind{
	BoxSize: Size{4, 3},
}

A 12x12 puzzle with 12 boxes of 4x3 and digits 1-12.

View Source
var Kind4x4 = &Kind{
	BoxSize: Size{4, 4},
}

A 16x16 puzzle with 16 boxes of 4x4 and digits 1-16.

View Source
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
	},
}
View Source
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 ==================================================

View Source
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

==================================================

View Source
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 ==================================================

View Source
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
	},
}
View Source
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

==================================================

View Source
var StepHiddenSubsets2 = CreateStepHiddenSubsets(2, "Hidden Pair", 1500, 1200)
View Source
var StepHiddenSubsets3 = CreateStepHiddenSubsets(3, "Hidden Triplet", 2400, 1600)
View Source
var StepHiddenSubsets4 = CreateStepHiddenSubsets(4, "Hidden Quad", 7000, 5000)
View Source
var StepJellyfish = CreateStepBasicFish(4, "Jellyfish", 10000, 8000)
View Source
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

==================================================

View Source
var StepNakedSubsets2 = CreateStepNakedSubsets(2, "Naked Pair", 750, 500)
View Source
var StepNakedSubsets3 = CreateStepNakedSubsets(3, "Naked Triplet", 2000, 1400)
View Source
var StepNakedSubsets4 = CreateStepNakedSubsets(4, "Naked Quad", 5000, 4000)
View Source
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

==================================================

View Source
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
	},
}
View Source
var StepSwordfish = CreateStepBasicFish(3, "Swordfish", 8000, 6000)
View Source
var StepXWing = CreateStepBasicFish(2, "X-Wing", 2800, 1600)

Functions

func AbsInt

func AbsInt(x int) int

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 Random

func Random() *rand.Rand

func RandomSeed

func RandomSeed() int64

func RandomSeeded

func RandomSeeded(seed int64) *rand.Rand

Types

type Bitset

type Bitset struct {
	Value uint64
	Count int
}

A set of integers from 0 to 63 with O(1) add, remove, search, and union/substraction/intersection set operations.

func (*Bitset) And

func (bits *Bitset) And(and Bitset) int

Removes any integers from this set that also don't exist in the given set (intersection).

func (*Bitset) Clear

func (bits *Bitset) Clear()

Removes all integers from the set

func (*Bitset) Differences

func (bits *Bitset) Differences(other Bitset) bool

Returns whether this set and the other don't share one or more integers.

func (*Bitset) Fill

func (bits *Bitset) Fill(n int)

Sets the set to the first N integers starting with 0.

func (*Bitset) First

func (bits *Bitset) First() int

The smallest integer in the set or 64 if the set is empty.

func (*Bitset) Has

func (bits *Bitset) Has(i int) bool

Returns whether the integer exists in the set

func (*Bitset) Last

func (bits *Bitset) Last() int

The largest integer in the set or -1 if the set is empty.

func (*Bitset) Or

func (bits *Bitset) Or(or Bitset) int

Adds all integers in the given set to this set (union).

func (*Bitset) Overlaps

func (bits *Bitset) Overlaps(other Bitset) bool

Returns whether this set and the other share any integers.

func (*Bitset) Remove

func (bits *Bitset) Remove(remove Bitset) int

Removes all integers in the given set from this set.

func (*Bitset) Set

func (bits *Bitset) Set(i int, on bool) bool

Adds or removes the integer from the set and returns true if the set has changed as a result of this call.

func (*Bitset) ToSlice

func (bits *Bitset) ToSlice() []int

Creates a slice of all integers in this set.

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

func (cell *Cell) Candidates() []int

Returns the candidates that exists in this cell as a slice of ints.

func (*Cell) Empty

func (cell *Cell) Empty() bool

Returns this cell is empty (does not have a value in it).

func (*Cell) FirstCandidate

func (cell *Cell) FirstCandidate() int

Returns the smallest candidate available in this cell. If none exist then 64 is returned.

func (*Cell) GetGroup

func (cell *Cell) GetGroup(groupIndex Group) int

Returns the group given its index. The group order starting with zero is Col, Row, Box.

func (*Cell) HasCandidate

func (cell *Cell) HasCandidate(value int) bool

Determines if this cell has the given candidate.

func (*Cell) HasValue

func (cell *Cell) HasValue() bool

Returns whether this cell has a value in it.

func (*Cell) InBox

func (cell *Cell) InBox(other *Cell) bool

Returns whether this cell and the given cell are in the same box.

func (*Cell) InColumn

func (cell *Cell) InColumn(other *Cell) bool

Returns whether this cell and the given cell are in the same column.

func (*Cell) InGroup

func (cell *Cell) InGroup(other *Cell) bool

Returns whether this cell and the given cell are in the same group (box, column, or row).

func (*Cell) InRow

func (cell *Cell) InRow(other *Cell) bool

Returns whether this cell and the given cell are in the same row.

func (*Cell) LastCandidate

func (cell *Cell) LastCandidate() int

Returns the largest candidate available in this cell. If none exist then 0 is returned.

func (*Cell) MaxValue

func (cell *Cell) MaxValue() int

The maximum value this cell can possibly be, taking into account it might already have a value and therefore no candidates.

func (*Cell) MinValue

func (cell *Cell) MinValue() int

The minimum value this cell can possibly be, taking into account it might already have a value and therefore no candidates.

func (*Cell) RemoveCandidate

func (cell *Cell) RemoveCandidate(value int) bool

Removes the given candidate from this cell and returns whether it existed in the first place.

func (*Cell) SetValue

func (cell *Cell) SetValue(value int) bool

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

func (cell *Cell) ToConsoleString() string

func (*Cell) Valid

func (cell *Cell) Valid() bool

Returns if this cell is valid, meaning the value and candidates it has match. If this returns false then there is a logical error in the software.

type ClearLimit

type ClearLimit struct {
	SolveLimit
	Symmetric bool
	MaxStates int
	Fast      bool
}

func (ClearLimit) Extend

func (limits ClearLimit) Extend(extend ClearLimit) ClearLimit

type Color

type Color struct {
	R int
	G int
	B int
}

func (Color) Is

func (c Color) Is(other Color) bool

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

- 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)

- A collection of cells even & odd digits sum to same value - A cell cannot have the same value as a collection of cells

- Or constraint (multiple constraints can dictate which candidates are available)

- And constraint

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

type ConstraintDivisible struct {
	By        int
	Remainder int
	Cells     []Position
}

================================================== 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

type ConstraintOrder struct {
	Cells     *[]Position
	Relative  *[]Position
	Direction int
}

================================================== 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

type ConstraintScalePair struct {
	Scale  int
	First  Position
	Second Position
}

================================================== 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

type ConstraintSumProvider func(cell *Cell, puzzle *Puzzle) int

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

type ConstraintUnique struct {
	Cells    *[]Position
	Relative *[]Position
	Same     bool
}

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

type Generator struct {
	Kind *Kind

	Random *rand.Rand
	// contains filtered or unexported fields
}

Generates puzzles of the given kind using a particular random number generator.

func NewGenerator

func NewGenerator(kind *Kind) Generator

func NewRandomGenerator

func NewRandomGenerator(kind *Kind, random *rand.Rand) Generator

func NewSeededGenerator

func NewSeededGenerator(kind *Kind, seed int64) Generator

func (*Generator) Attempt

func (gen *Generator) Attempt() *Puzzle

func (*Generator) Attempts

func (gen *Generator) Attempts(tries int) (*Puzzle, int)

func (*Generator) ClearCells

func (gen *Generator) ClearCells(puzzle *Puzzle, limits ClearLimit) (*Puzzle, int)

func (*Generator) Generate

func (gen *Generator) Generate() (*Puzzle, int)

func (*Generator) GetRandomUnsolved

func (gen *Generator) GetRandomUnsolved() *Cell

func (*Generator) GetUnsolved

func (gen *Generator) GetUnsolved() *Cell

func (*Generator) IsComplete

func (gen *Generator) IsComplete() bool

func (*Generator) Puzzle

func (gen *Generator) Puzzle() *Puzzle

func (*Generator) Reset

func (gen *Generator) Reset()

func (*Generator) Solver

func (gen *Generator) Solver() *Solver

type Group

type Group int
const (
	GroupCol Group = iota
	GroupRow
	GroupBox
)

type Kind

type Kind struct {
	BoxSize     Size
	Constraints []Constraint
}

func NewKind

func NewKind(boxWidth int, boxHeight int) *Kind

func (*Kind) Area

func (kind *Kind) Area() int

How many cells would be in the puzzle.

func (*Kind) BoxesHigh

func (kind *Kind) BoxesHigh() int

How many boxes high the puzzle would be.

func (*Kind) BoxesWide

func (kind *Kind) BoxesWide() int

How many boxes wide the puzzle would be.

func (*Kind) Clone

func (kind *Kind) Clone() *Kind

func (*Kind) ConstraintsFor

func (kind *Kind) ConstraintsFor(cell *Cell) []Constraint

func (*Kind) Create

func (kind *Kind) Create(values [][]int) Puzzle

Creates a puzzle with an initial set of values of this kind.

func (*Kind) Digits

func (kind *Kind) Digits() int

The number of unique digits in this puzzle kind.

func (*Kind) DigitsSize

func (kind *Kind) DigitsSize() int

How many characters it could take to print out the largest digit of a value in this puzzle kind.

func (*Kind) Empty

func (kind *Kind) Empty() Puzzle

Creates an empty puzzle of this kind.

func (*Kind) Generator

func (kind *Kind) Generator() Generator

Creates a generator for puzzles of this kind.

func (*Kind) GetDimensions

func (kind *Kind) GetDimensions() (boxsWide int, boxsHigh int, boxWidth int, boxHeight int, size int)

Returns the dimensions of a puzzle of this kind.

func (*Kind) Size

func (kind *Kind) Size() int

The width, height, and number of digits in this puzzle kind.

type Position

type Position struct {
	Col int
	Row int
}

A cell position on a puzzle.

type Puzzle

type Puzzle struct {
	Kind  *Kind
	Cells []Cell
}

func FromEncoded

func FromEncoded(input string) *Puzzle

func FromString

func FromString(input string) *Puzzle

func New

func New(kind *Kind) Puzzle

func (*Puzzle) Clear

func (puzzle *Puzzle) Clear()

func (*Puzzle) Clone

func (puzzle *Puzzle) Clone() Puzzle

func (*Puzzle) Contains

func (puzzle *Puzzle) Contains(col int, row int) bool

func (*Puzzle) EncodedString

func (puzzle *Puzzle) EncodedString() string

func (*Puzzle) Get

func (puzzle *Puzzle) Get(col int, row int) *Cell

func (*Puzzle) GetAll

func (puzzle *Puzzle) GetAll() [][]int

func (*Puzzle) GetCandidates

func (puzzle *Puzzle) GetCandidates() [][][]int

func (*Puzzle) GetCandidatesFor

func (puzzle *Puzzle) GetCandidatesFor(cell *Cell) Candidates

func (*Puzzle) GetColumn

func (puzzle *Puzzle) GetColumn(columnIndex int) []int

func (*Puzzle) GetColumnCells

func (puzzle *Puzzle) GetColumnCells(columnIndex int) []*Cell

func (*Puzzle) GetRow

func (puzzle *Puzzle) GetRow(rowIndex int) []int

func (*Puzzle) GetRowCells

func (puzzle *Puzzle) GetRowCells(rowIndex int) []*Cell

func (*Puzzle) GetSolutions

func (puzzle *Puzzle) GetSolutions(limit SolutionsLimit) []*Solver

func (*Puzzle) GetSymmetric

func (puzzle *Puzzle) GetSymmetric(cell *Cell) *Cell

func (*Puzzle) HasUniqueSolution

func (puzzle *Puzzle) HasUniqueSolution() bool

func (*Puzzle) IsCandidate

func (puzzle *Puzzle) IsCandidate(value int) bool

func (*Puzzle) IsSolved

func (puzzle *Puzzle) IsSolved() bool

func (*Puzzle) IsValid

func (puzzle *Puzzle) IsValid() bool

func (*Puzzle) MaxCandidate

func (puzzle *Puzzle) MaxCandidate() int

func (*Puzzle) MinCandidate

func (puzzle *Puzzle) MinCandidate() int

func (*Puzzle) PrintConsole

func (puzzle *Puzzle) PrintConsole()

func (*Puzzle) PrintConsoleCandidates

func (puzzle *Puzzle) PrintConsoleCandidates()

func (*Puzzle) PrintConsoleCells

func (instance *Puzzle) PrintConsoleCells()

func (*Puzzle) Remove

func (puzzle *Puzzle) Remove(col int, row int) bool

func (*Puzzle) RemoveCell

func (puzzle *Puzzle) RemoveCell(cell *Cell) bool

func (*Puzzle) Set

func (puzzle *Puzzle) Set(col int, row int, value int) bool

func (*Puzzle) SetAll

func (puzzle *Puzzle) SetAll(values [][]int) int

func (*Puzzle) SetCell

func (puzzle *Puzzle) SetCell(cell *Cell, value int) bool

func (*Puzzle) Solver

func (puzzle *Puzzle) Solver() Solver

func (*Puzzle) String

func (puzzle *Puzzle) String() string

func (*Puzzle) ToConsoleCandidatesString

func (puzzle *Puzzle) ToConsoleCandidatesString() string

func (*Puzzle) ToConsoleCellsString

func (instance *Puzzle) ToConsoleCellsString() string

func (*Puzzle) ToConsoleString

func (puzzle *Puzzle) ToConsoleString() string

func (*Puzzle) ToStateString

func (puzzle *Puzzle) ToStateString(includeKind bool, emptyValue string) string

func (*Puzzle) UniqueId

func (puzzle *Puzzle) UniqueId() string

func (*Puzzle) WriteConsole

func (puzzle *Puzzle) WriteConsole(out io.Writer)

func (*Puzzle) WriteConsoleCandidates

func (puzzle *Puzzle) WriteConsoleCandidates(out io.Writer)

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
}

func NewPDF

func NewPDF() PuzzlePDF

func (*PuzzlePDF) Add

func (pdf *PuzzlePDF) Add(puzzle *Puzzle, candidates bool, stateString bool, solutionString bool)

func (*PuzzlePDF) Download

func (pdf *PuzzlePDF) Download(w http.ResponseWriter, filename string, direct bool) (any, int)

func (*PuzzlePDF) Generate

func (pdf *PuzzlePDF) Generate() *gofpdf.Fpdf

func (*PuzzlePDF) Send

func (pdf *PuzzlePDF) Send(w http.ResponseWriter, direct bool) (any, int)

func (*PuzzlePDF) Write

func (pdf *PuzzlePDF) Write(writer io.Writer, direct bool)

func (*PuzzlePDF) WriteFile

func (pdf *PuzzlePDF) WriteFile(path string)

type PuzzlePDFItem

type PuzzlePDFItem struct {
	Puzzle         *Puzzle
	Candidates     bool
	StateString    bool
	SolutionString bool
}

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue[T any]() Queue[T]

func (*Queue[T]) Clear

func (queue *Queue[T]) Clear()

func (*Queue[T]) Empty

func (queue *Queue[T]) Empty() bool

func (*Queue[T]) Next

func (queue *Queue[T]) Next() *T

func (*Queue[T]) Offer

func (queue *Queue[T]) Offer(value T)

func (*Queue[T]) Peek

func (queue *Queue[T]) Peek() *T

func (*Queue[T]) Poll

func (queue *Queue[T]) Poll() *T

func (*Queue[T]) Size

func (queue *Queue[T]) Size() int

type QueueNode

type QueueNode[T any] struct {
	// contains filtered or unexported fields
}

type Size

type Size struct {
	Width  int
	Height int
}

func (Size) Area

func (size Size) Area() int

type SolutionsLimit

type SolutionsLimit struct {
	SolveLimit
	MaxSolutions int
	LogEnabled   bool
	LogState     bool
}

type SolveLimit

type SolveLimit struct {
	MinCost       int
	MaxCost       int
	MaxPlacements int
	MaxLogs       int
	MaxBatches    int
	Techniques    map[string]int
}

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 NewSolver

func NewSolver(starting Puzzle) Solver

func (*Solver) Box

func (solver *Solver) Box(box int) []*Cell

func (*Solver) CanContinue

func (solver *Solver) CanContinue(limits SolveLimit, cost int) bool

func (*Solver) CanContinueStep

func (solver *Solver) CanContinueStep(limits SolveLimit, step *SolveStep) bool

func (*Solver) Col

func (solver *Solver) Col(col int) []*Cell

func (*Solver) GetCellWhere

func (solver *Solver) GetCellWhere(where func(cell *Cell) bool) *Cell

func (*Solver) GetCost

func (solver *Solver) GetCost(step *SolveStep) int

func (*Solver) GetLastLog

func (solver *Solver) GetLastLog() *SolverLog

func (*Solver) GetMinCandidateCount

func (solver *Solver) GetMinCandidateCount() int

func (*Solver) Group

func (solver *Solver) Group(groupIndex Group, cell *Cell) []*Cell

func (*Solver) LogAfter

func (solver *Solver) LogAfter(after *Cell)

func (*Solver) LogBefore

func (solver *Solver) LogBefore(before *Cell)

func (*Solver) LogPlacement

func (solver *Solver) LogPlacement(after *Cell)

func (*Solver) LogStep

func (solver *Solver) LogStep(step *SolveStep)

func (*Solver) Row

func (solver *Solver) Row(row int) []*Cell

func (*Solver) Set

func (solver *Solver) Set(col int, row int, value int) bool

func (*Solver) SetCell

func (solver *Solver) SetCell(cell *Cell, value int) bool

func (*Solver) Solve

func (solver *Solver) Solve(limits SolveLimit) (*Puzzle, bool)

func (*Solver) Solved

func (solver *Solver) Solved() bool

type SolverLog

type SolverLog struct {
	Step              *SolveStep
	Index             int
	Batch             int
	Cost              int
	Placement         bool
	Before            Cell
	After             Cell
	State             *Puzzle
	RunningCost       int
	RunningPlacements int
}

func (SolverLog) String

func (log SolverLog) String() string

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

func NewStack

func NewStack[T any](initialCapacity int) Stack[T]

func (*Stack[T]) At

func (stack *Stack[T]) At(index int) *T

func (*Stack[T]) Clear

func (stack *Stack[T]) Clear()

func (*Stack[T]) Empty

func (stack *Stack[T]) Empty() bool

func (*Stack[T]) Next

func (stack *Stack[T]) Next() *T

func (*Stack[T]) Peek

func (stack *Stack[T]) Peek() *T

func (*Stack[T]) Pop

func (stack *Stack[T]) Pop() *T

func (*Stack[T]) Push

func (stack *Stack[T]) Push(value T)

func (*Stack[T]) Size

func (stack *Stack[T]) Size() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL