queensboard

package
v0.0.0-...-95ee068 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Board

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

Board holds a concurrency-safe Queens Board

func New

func New() *Board

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

func NewCustom

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

NewCustom returns a board with custom width and height

func (*Board) AvailableFields

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

AvailableFields returns a list of fields available for queen placement

func (*Board) PlaceQueen

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

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

func (b *Board) Queens() int

Queens returns the number of queens on the board

func (*Board) RemoveQueen

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

type Coordinates struct {
	X, Y int
}

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

Jump to

Keyboard shortcuts

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