golibby: github.com/danrl/golibby/queensboard Index | Files

package queensboard

import "github.com/danrl/golibby/queensboard"

Package queensboard provides a data structure and method similar to a chess board. Queens can be placed on the board, but not within the attack range of another queen. The purpose of this package is to provide the underlying tools for demonstrating simple backtracking algorithms.

Index

Package Files

queensboard.go

Variables

var (
    // ErrorOperationNotPermitted indicates that an operation is not permitted
    // on a particular field. E.g. placing a queen on an attacked field or
    // removing a queen from a field that holds no queen
    ErrorOperationNotPermitted = fmt.Errorf("operation not permitted")
    // ErrorOutOfBounds is returned when coordinates point to a field outside
    // of the board
    ErrorOutOfBounds = fmt.Errorf("out of bounds coordinates")
    // ErrorInvalidBoardDimensions is returned in case of invalid width or
    // height values for creating a new board
    ErrorInvalidBoardDimensions = fmt.Errorf("invalid board dimensions")
)

type Board Uses

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

Board holds a concurrency-safe Queens Board

func New Uses

func New() *Board

New returns an empty standard-sized (8x8) fields board

func NewCustom Uses

func NewCustom(width, height int) (*Board, error)

NewCustom returns a board with custom width and height

func (*Board) AvailableFields Uses

func (b *Board) AvailableFields() []Coordinates

AvailableFields returns a list of fields available for queen placement

func (*Board) PlaceQueen Uses

func (b *Board) PlaceQueen(c Coordinates) error

PlaceQueen places a queen on the board and updates the attack counters of all affected fields.

func (*Board) Print Uses

func (b *Board) Print(w io.Writer) error

Print writes a human readable representation of the current board state to the given writer

func (*Board) Queens Uses

func (b *Board) Queens() int

Queens returns the number of queens on the board

func (*Board) RemoveQueen Uses

func (b *Board) RemoveQueen(c Coordinates) error

RemoveQueen removes a queen from the board and updates the attack counters of all affected fields.

type Coordinates Uses

type Coordinates struct {
    X, Y int
}

Coordinates holds the x and y values for addressing a field on the board

Package queensboard imports 4 packages (graph). Updated 2018-04-15. Refresh now. Tools for package owners.