Documentation
¶
Overview ¶
Package state implements a representation of Amazons board states and provides the means to construct a game tree.
Index ¶
- func KFrontier(occupancy bb.BitBoard, territory bb.BitBoard) bb.BitBoard
- func KNeighbors(occupancy bb.BitBoard, position bb.Position) bb.BitBoard
- func QFrontier(occupancy bb.BitBoard, territory bb.BitBoard) bb.BitBoard
- func QNeighbors(occupancy bb.BitBoard, position bb.Position) bb.BitBoard
- type Board
- type Move
- type PlayerColor
- type PositionStatus
- type SuccessorSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KFrontier ¶
Returns the frontier of a given territory. A territory is a set of positions on the board, and the frontier of a territory is defined to be the set of positions that are adjacent to some position in the territory, excluding any positions that are already in the territory. Two positions p and q are adjacent if and only if a chess king could move from p to q in a single move, accounting for any arrows or queens that could obstruct such a move.
func KNeighbors ¶
Returns a bitboard where each neighbor of a given position is flagged, where two squares p and q are neighbors if and only if a chess king could move from p to q (accounting for squares that are already occupied by arrows or queens).
func QFrontier ¶
Returns the frontier of a given territory. A territory is a set of positions on the board, and the frontier of a territory is defined to be the set of positions that are adjacent to some position in the territory, excluding any positions that are already in the territory. Two positions p and q are adjacent if and only if a chess queen could move from p to q in a single move, accounting for any arrows or queens that could obstruct such a move.
func QNeighbors ¶
Returns a bitboard where each neighbor of a given position is flagged, where two squares p and q are neighbors if and only if a chess queen could move from p to q (accounting for squares that are already occupied by arrows or queens).
Types ¶
type Board ¶
type Board struct {
// The occupied squares on the board. An occupied square is one that has
// either a queen or an arrow on it.
Occupancy bb.BitBoard
// The positions of the black queens on the board.
Black [4]bb.Position
// The positions of the white queens on the board.
White [4]bb.Position
// The most recent move made.
Move Move
// The player who can make the next move.
Player PlayerColor
}
Represents a board state.
func Apply ¶ added in v0.0.3
Applies a move to the board, returning a new board with the updated state. If the move is illegal, then an error is returned.
func Initial ¶ added in v0.0.6
func Initial() Board
Represents the starting position for an Amazons game.
func RandomBoard ¶ added in v0.0.3
Returns a random board state after some number of turns by simulating a game where each player randomly picks moves. Note that the number of turns is the same as the number of arrows, and getting the zeroth turn will always yield the initial board state.
func (*Board) IsTerminal ¶ added in v0.0.5
Returns true if and only if the board state is terminal.
func (*Board) Status ¶ added in v0.0.5
func (b *Board) Status(pos bb.Position) PositionStatus
Returns StatusVacant, StatusWhiteQueen, StatusBlackQueen, or StatusArrow, depending on what the status of the position is on the board. This function is not optimal and is only provided for convenience.
func (Board) Successors ¶
func (board Board) Successors(dst *SuccessorSlice)
Computes the successors of a state and stores them in the specified array. The number of computed successors is returned.
type Move ¶
type Move struct {
// The original position of the queen being moved.
From bb.Position
// The new position of the queen being moved.
To bb.Position
// The position where the queen fired her arrow.
Arrow bb.Position
}
Represents a move.
type PlayerColor ¶
type PlayerColor byte
Represents a player color.
const ( White PlayerColor = 0 // Represents the player on White Black PlayerColor = 1 // Represents the player on Black )
type PositionStatus ¶ added in v0.0.5
type PositionStatus uint8
Represents the status of a given position on the board. That is, whether it is vacant, covered by an arrow, or occupied by a queen.
const ( StatusVacant PositionStatus = iota StatusWhiteQueen StatusBlackQueen StatusArrow )