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 ¶
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 (*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 ¶
Print writes a human readable representation of the current board state to the given writer
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