state

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 3 Imported by: 4

Documentation

Overview

Package state implements a representation of Amazons board states and provides the means to construct a game tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KFrontier

func KFrontier(occupancy bb.BitBoard, territory bb.BitBoard) bb.BitBoard

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

func KNeighbors(occupancy bb.BitBoard, position bb.Position) bb.BitBoard

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

func QFrontier(occupancy bb.BitBoard, territory bb.BitBoard) bb.BitBoard

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

func QNeighbors(occupancy bb.BitBoard, position bb.Position) bb.BitBoard

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

func Apply(board Board, move Move) (Board, error)

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

func RandomBoard(turns int) Board

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

func (b *Board) IsTerminal() bool

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.

func (Move) IsLegal added in v0.0.3

func (m Move) IsLegal(board Board) error

If the given move is legal on the current board, this returns nil. Otherwise, it returns an error that explains why the move isn't allowed.

func (Move) String added in v0.0.3

func (m Move) String() string

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
)

type SuccessorSlice added in v0.0.6

type SuccessorSlice struct {
	Array  [maxSuccessors]Board
	Length int
}

Jump to

Keyboard shortcuts

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