bb

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

This package implements a 10x10 bitboard for Amazons.

Index

Constants

View Source
const (
	W  int = iota // West
	NW            // Northwest
	N             // North
	NE            // Northeast
	E             // East
	SE            // Southeast
	S             // South
	SW            // Southwest
)
View Source
const NUMBER_OF_DIRECTIONS = 8

If you want to iterate over all directions, you can iterate over range NUMBER_OF_DIRECTIONS.

Variables

View Source
var KAdj = [100]BitBoard{}

For each position index p, KAdj[p] stores a precomputed bitboard that has each square q flagged if and only if a chess king on p could get to q in a single move.

View Source
var RayExc = [100][8]BitBoard{}

For each position index p and each direction d, RayExc[p][d] stores a precomputed bitboard such that each position is flagged if and only if it lies on a ray projected from p in the direction of d. This ray will exclude p (see RayInc for one that includes it).

View Source
var RayInc = [100][8]BitBoard{}

For each position index p and each direction d, RayInc[p][d] stores a precomputed bitboard such that each position is flagged if and only if it lies on a ray projected from p in the direction of d. This ray will include p (see RayExc for one that excludes it).

Functions

func Coords

func Coords(pos Position) (row, col int)

Converts a position index into row and column coordinates

Types

type BitBoard

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

Represents a board where each position index (0-99, since Amazons is played on a 10x10 board) is either 0 or 1, which we refer to as "unflagged" and "flagged," respectively.

func (BitBoard) And

func (a BitBoard) And(b BitBoard) BitBoard

Performs a bitwise AND operation (a & b) and returns the result.

func (BitBoard) AndNot

func (a BitBoard) AndNot(b BitBoard) BitBoard

Performs a bitwise AND-NOT operation (a &^ b) and returns the result.

func (*BitBoard) AssignAnd

func (a *BitBoard) AssignAnd(b BitBoard)

Performs a bitwise AND operation (a & b) and assigns the result to a.

func (*BitBoard) AssignAndNot

func (a *BitBoard) AssignAndNot(b BitBoard)

Performs a bitwise AND-NOT operation (a &^ b) and assigns the result to a.

func (*BitBoard) AssignNot

func (a *BitBoard) AssignNot()

Performs a bitwise NOT operation (a ^ b) and assigns the result to a.

func (*BitBoard) AssignOr

func (a *BitBoard) AssignOr(b BitBoard)

Performs a bitwise OR operation (a | b) and assigns the result to a.

func (*BitBoard) AssignXor

func (a *BitBoard) AssignXor(b BitBoard)

Performs a bitwise XOR operation (a ^ b) and assigns the result to a.

func (BitBoard) Count

func (bb BitBoard) Count() int

Returns the number of flagged positions on this board.

func (*BitBoard) Empty

func (bb *BitBoard) Empty() bool

Returns true if and only if the bitboard has no flags.

func (*BitBoard) Flag

func (bb *BitBoard) Flag(pos Position)

Flags a bit in the bitboard.

func (*BitBoard) Flagged

func (bb *BitBoard) Flagged(pos Position) bool

Returns true if the bit in the board is flagged and false otherwise.

func (*BitBoard) Lsb

func (bb *BitBoard) Lsb() Position

Returns the greatest flagged position index on the board. If the board is empty, then the null position (NULL_POS) is returned.

func (*BitBoard) Msb

func (bb *BitBoard) Msb() Position

Returns the position index of the most-significant bit in the board. If the board is empty, then the null position (NULL_POS) is returned .

func (*BitBoard) Next

func (bb *BitBoard) Next() Position

Returns the "lowest" position on the board, meaning that which is the closest to the bottom-right corner, and unflags it. If the bitboard is empty, then NULL_POS is returned.

func (BitBoard) Not

func (a BitBoard) Not() BitBoard

Performs a bitwise NOT operation (a ^ b) and returns the result.

func (*BitBoard) NotEmpty

func (bb *BitBoard) NotEmpty() bool

Returns true if and only if the bitboard has at least one flag.

func (BitBoard) Or

func (a BitBoard) Or(b BitBoard) BitBoard

Performs a bitwise OR operation (a | b) and returns the result.

func (*BitBoard) Unflag

func (bb *BitBoard) Unflag(pos Position)

Unflags a bit in the bitboard.

func (BitBoard) Xor

func (a BitBoard) Xor(b BitBoard) BitBoard

Performs a bitwise XOR operation (a ^ b) and returns the result.

type Position

type Position uint8

Represents a position on the 10x10 Amazons board with an index from 0 to 99. We use row-major ordering, so you can get the row index with position / 10 and the column with position % 10.

const NULL_POS Position = 100

Represents a null position. I.e., for functions that return a position, the null position should be returned if no valid position exists.

func Pos

func Pos(row, col int) Position

Converts row and column indices into a position index.

Jump to

Keyboard shortcuts

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