sudoku

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render added in v0.0.2

func Render(g *Grid) string

Render renders the given Sudoku Grid in a pretty ASCII table.

func RenderDiff added in v0.0.2

func RenderDiff(g, og *Grid) string

RenderDiff renders the given Sudoku Grid in a pretty ASCII table and highlights the differences compared to Grid 'og'.

Types

type Block

type Block struct {
	// contains filtered or unexported fields
}

Block defines one individual slot in the 9x9 grid.

func (*Block) Value

func (b *Block) Value() int

Value returns the currently set value.

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

Grid is a 3x3 matrix of Grids - basically a 9x9 matrix of integers.

func NewGrid

func NewGrid(opts ...Option) *Grid

NewGrid returns a new Grid object with sane defaults.

func (*Grid) ApplyDifficulty

func (g *Grid) ApplyDifficulty(d difficulty.Difficulty)

ApplyDifficulty applies the difficulty level on the current grid.

func (*Grid) ApplyPattern

func (g *Grid) ApplyPattern(p *pattern.Pattern)

ApplyPattern applies the pattern on the current grid.

func (Grid) Checksum

func (g Grid) Checksum() string

Checksum returns a unique identifier for the Grid.

func (Grid) Clone

func (g Grid) Clone() *Grid

Clone returns a cloned copy of Grid.

func (*Grid) CopySubGrid

func (g *Grid) CopySubGrid(srcGrid *Grid, srcLoc, dstLoc Location) error

CopySubGrid copies the values from the SubGrid that contains the source Location into the SubGrid that contains the target Location.

func (Grid) Count

func (g Grid) Count() int

Count returns the number of Blocks that are filled and has a value.

func (Grid) CountToDo

func (g Grid) CountToDo() int

CountToDo returns the number of blocks that are not filled and has 0 value.

func (Grid) CountValue added in v0.0.2

func (g Grid) CountValue(n int) int

CountValue returns the number of Blocks that are filled with the given value.

func (Grid) Done

func (g Grid) Done() bool

Done returns true if all Blocks are filled.

func (Grid) Empty

func (g Grid) Empty() bool

Empty returns true if all Blocks are empty.

func (Grid) Get

func (g Grid) Get(row, col int) int

Get returns the value stored in the Block at row 'row' and column 'col'.

func (Grid) GetMetadata

func (g Grid) GetMetadata(key string) string

GetMetadata returns metadata stored against a key.

func (Grid) HasInColumn

func (g Grid) HasInColumn(col, n int) bool

HasInColumn returns true if the column 'col' contains the number 'n',

func (Grid) HasInRow

func (g Grid) HasInRow(row, n int) bool

HasInRow returns true if the row 'row' contains the number 'n',

func (Grid) IsSet

func (g Grid) IsSet(row, col int) bool

IsSet returns true if there is a value in the row 'row' and column 'col'.

func (*Grid) MarshalArray

func (g *Grid) MarshalArray() [][]int

MarshalArray returns the Grid in a simple 2-dimensional array.

func (*Grid) MarshalCSV

func (g *Grid) MarshalCSV() string

MarshalCSV returns the Grid in a simple CSV string.

func (Grid) Possibilities

func (g Grid) Possibilities(row, col int) *Possibilities

Possibilities returns the Possibilities for the given block at row 'row' and column 'col'.

func (*Grid) Reset

func (g *Grid) Reset(row, col int)

Reset resets the block corresponding to the row 'row' and column 'col'.

func (*Grid) Set

func (g *Grid) Set(row, col, n int) bool

Set sets the number 'n' in the row 'row' and column 'col' if it is a valid value to set there.

func (*Grid) SetMetadata

func (g *Grid) SetMetadata(key, val string)

SetMetadata stores metadata stored against a key.

func (*Grid) SetRNG

func (g *Grid) SetRNG(rng *rand.Rand)

SetRNG sets the RNG to be used by the Grid when needed.

func (Grid) String

func (g Grid) String() string

String returns the Grid in a human-readable CSV form.

func (*Grid) SubGrid

func (g *Grid) SubGrid(row, col int) *SubGrid

SubGrid returns the SubGrid corresponding to the given location.

func (*Grid) SubGrids

func (g *Grid) SubGrids() SubGrids

SubGrids returns all the registered SubGrids.

func (*Grid) UnmarshalArray

func (g *Grid) UnmarshalArray(arr [][]int) error

UnmarshalArray unmarshals a 2-dimensional array into the Grid.

func (*Grid) UnmarshalCSV

func (g *Grid) UnmarshalCSV(csvString string) error

UnmarshalCSV unmarshals a CSV string into the Grid.

func (*Grid) Validate

func (g *Grid) Validate() (bool, error)

Validate validates the Grid and returns if all the values are valid.

type Location

type Location struct {
	X int
	Y int
}

Location points to a specific location on the Grid (x, y).

func (Location) IsValid

func (l Location) IsValid() bool

IsValid returns true is the Location points to a location within a 9x9 Grid.

type Option

type Option func(g *Grid)

Option helps customize the Grid.

func WithRNG

func WithRNG(rng *rand.Rand) Option

WithRNG customizes the Random Number Generator used by the Grid.

func WithSubGrids

func WithSubGrids(sgs []SubGrid) Option

WithSubGrids customizes the way Sub-Grids are defined in the Grid.

type Possibilities

type Possibilities struct {
	// contains filtered or unexported fields
}

Possibilities keep track of possible values for a single Block.

func NewPossibilitiesFromMap

func NewPossibilitiesFromMap(data map[int]bool, rng *rand.Rand) *Possibilities

NewPossibilitiesFromMap returns a Possibilities object based on the given map. Key being the number (1-9) and the value being whether it is possible or not.

func (Possibilities) Available

func (p Possibilities) Available() []int

Available returns the available values.

func (Possibilities) AvailableLen

func (p Possibilities) AvailableLen() int

AvailableLen returns the number of available values.

func (Possibilities) AvailableMap added in v0.0.2

func (p Possibilities) AvailableMap() map[int]bool

AvailableMap returns the available values in a map for quick look-ups.

func (*Possibilities) Get

func (p *Possibilities) Get() int

Get returns the first possible number and takes it out of available numbers list.

func (*Possibilities) ResetAvailable

func (p *Possibilities) ResetAvailable()

ResetAvailable resets the list of available numbers.

type SubGrid

type SubGrid struct {
	Locations []Location
	// contains filtered or unexported fields
}

SubGrid is a 3x3 matrix of integers.

func (SubGrid) Count

func (s SubGrid) Count() int

Count returns the number of Blocks that are filled and has a value.

func (SubGrid) Done

func (s SubGrid) Done() bool

Done returns true if all Blocks are filled.

func (SubGrid) Empty

func (s SubGrid) Empty() bool

Empty returns true if all Blocks are empty.

func (SubGrid) Has

func (s SubGrid) Has(n int) bool

Has returns true if the SubGrid has the given number in some location.

func (SubGrid) HasLocation

func (s SubGrid) HasLocation(x, y int) bool

HasLocation returns true if the SubGrid has the given location.

func (SubGrid) String

func (s SubGrid) String() string

String returns the SubGrid in a human-readable CSV form.

func (SubGrid) Validate

func (s SubGrid) Validate() (bool, error)

Validate validates the SubGrid and returns if all the values are valid.

type SubGrids

type SubGrids []SubGrid

SubGrids represent a list of WithSubGrids in a 9x9 Grid

func (SubGrids) String

func (sgs SubGrids) String() string

String returns the WithSubGrids in a human-readable format.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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