takuzu

package module
v0.0.0-...-37fd81b Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package takuzu provides functions to solve, build or validate takuzu puzzles.

Index

Constants

View Source
const (
	ErrorNil = iota
	ErrorDuplicate
	ErrorTooManyValues
	ErrorTooManyAdjacentValues
)

Variables

This section is empty.

Functions

func BoardsMatch

func BoardsMatch(t1, t2 *Takuzu, ignoreUndefined bool) (match bool, line, col int)

BoardsMatch compares a Takuzu board to another, optionally ignoring empty cells. Returns true if the two boards match.

func CheckRangeCounts

func CheckRangeCounts(cells []Cell) (full bool, n0, n1 int)

CheckRangeCounts returns true if all cells of the provided range are defined, as well as the number of 0s and the number of 1s in the range.

func Copy

func Copy(src, dst *Takuzu) error

Copy copies a Takuzu board to another existing board

func SetSchrodingerLevel

func SetSchrodingerLevel(level uint)

SetSchrodingerLevel initializes the "Schrödinger" level (0 means disabled) It must be called before any board generation or reduction.

func SetVerbosityLevel

func SetVerbosityLevel(level int)

SetVerbosityLevel initializes the verbosity level of the resolution routines.

Types

type Cell

type Cell struct {
	Defined bool
	Value   int
}

Cell is a single cell of a Takuzu game board

func (*Cell) Set

func (c *Cell) Set(value int)

Set sets the value of the cell; a value -1 will set the cell as undefined

type Takuzu

type Takuzu struct {
	Size  int
	Board [][]Cell
}

Takuzu is a Takuzu game board (Size x Size)

func New

func New(size int) Takuzu

New creates a new Takuzu board

func NewFromString

func NewFromString(s string) (*Takuzu, error)

NewFromString creates a new Takuzu board from a string definition

func NewRandomTakuzu

func NewRandomTakuzu(size int, simple bool, wid string, buildBoardTimeout, reduceBoardTimeout time.Duration, minRatio, maxRatio int) (*Takuzu, error)

NewRandomTakuzu creates a new Takuzu board with a given size

func (Takuzu) CheckColumn

func (b Takuzu) CheckColumn(i int) error

CheckColumn returns an error if the column i fails validation

func (Takuzu) CheckLine

func (b Takuzu) CheckLine(i int) error

CheckLine returns an error if the line i fails validation

func (Takuzu) Clone

func (b Takuzu) Clone() Takuzu

Clone returns a copy of the Takuzu board

func (Takuzu) DumpBoard

func (b Takuzu) DumpBoard()

DumpBoard displays the Takuzu board

func (Takuzu) DumpString

func (b Takuzu) DumpString()

DumpString writes the content of the board as a string

func (Takuzu) FillLineColumn

func (b Takuzu) FillLineColumn(l, c int)

FillLineColumn add missing 0s or 1s if all 1s or 0s are there. Note: This method can update b.

func (Takuzu) GetColumn

func (b Takuzu) GetColumn(i int) []Cell

GetColumn returns a slice of cells containing the ith column of the board

func (Takuzu) GetColumnPointers

func (b Takuzu) GetColumnPointers(i int) []*Cell

GetColumnPointers returns a slice of pointers to the cells of the ith column of the board

func (Takuzu) GetLine

func (b Takuzu) GetLine(i int) []Cell

GetLine returns a slice of cells containing the ith line of the board

func (Takuzu) GetLinePointers

func (b Takuzu) GetLinePointers(i int) []*Cell

GetLinePointers returns a slice of pointers to the cells of the ith line of the board

func (Takuzu) ReduceBoard

func (tak Takuzu) ReduceBoard(trivial bool, wid string, buildBoardTimeout, reduceBoardTimeout time.Duration) (*Takuzu, error)

ReduceBoard randomly removes as many numbers as possible from the takuzu board and returns a pointer to the new board. The initial takuzu might be modified.

func (Takuzu) Set

func (b Takuzu) Set(l, c, value int)

Set sets the value of a specific cell A value -1 will undefine the cell

func (Takuzu) ToString

func (b Takuzu) ToString() string

ToString converts a takuzu board to its string representation

func (Takuzu) TrivialHint

func (b Takuzu) TrivialHint() (line, col, value int)

TrivialHint returns the coordinates and the value of the first cell that can be guessed using trivial methods. It returns {-1, -1, -1} if none can be found.

func (Takuzu) TrySolveRecurse

func (b Takuzu) TrySolveRecurse(allSolutions *[]Takuzu, timeout time.Duration) (*Takuzu, error)

TrySolveRecurse tries to solve the takuzu recursively, using trivial method first and using guesses if it fails.

func (Takuzu) TrySolveTrivial

func (b Takuzu) TrySolveTrivial() (bool, error)

TrySolveTrivial tries to solve the takuzu using a loop over simple methods It returns true if all cells are defined, and an error if the grid breaks the rules.

func (Takuzu) Validate

func (b Takuzu) Validate() (bool, error)

Validate checks a whole board for errors (not completeness) Returns true if all cells are defined.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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