Documentation
¶
Overview ¶
Package chess provides basic chess constants and functions.
Index ¶
- func IsValidCoords(f File, r Rank) bool
- type Bitboard
- func (b *Bitboard) Assign(s Square, cond bool)
- func (b *Bitboard) Clear(s Square)
- func (b *Bitboard) ClearIf(s Square, cond bool)
- func (b *Bitboard) DebugString() string
- func (b *Bitboard) Get(s Square) bool
- func (b *Bitboard) Intersects(other Bitboard) bool
- func (b *Bitboard) IsEmpty() bool
- func (b *Bitboard) Mirror()
- func (b *Bitboard) Set(s Square)
- func (b *Bitboard) SetIf(s Square, cond bool)
- func (b *Bitboard) Toggle(s Square)
- type CastleRight
- type CastleRights
- type Color
- type EnPassantRight
- type File
- type Move
- type Piece
- type Position
- type Rank
- type Role
- type Square
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidCoords ¶
IsValidCoords returns true if the given coordinates reference a valid square.
Types ¶
type Bitboard ¶
type Bitboard uint64
Bitboard is an integer where each bit represents one square. From LSB to MSB, the bits represent a1, b1, ..., h1, a2, ..., h8.
func BishopAttacks ¶
BishopAttacks returns the squares a bishop can attack from a given square, accounting for occupied squares.
func QueenAttacks ¶
QueenAttacks returns the squares a queen can attack from a given square, accounting for occupied squares.
func RookAttacks ¶
RookAttacks returns the squares a rook can attack from a given square, accounting for occupied squares.
func Targets ¶
Targets returns the squares a piece can target from a given square. For example, Targets(WhitePawn, A2) returns a bitboard with A3, B3, and A4 set.
func (*Bitboard) ClearIf ¶
ClearIf clears the bit at s to 0 if cond is true. If cond is false, the bit is left unchanged.
func (*Bitboard) DebugString ¶
DebugString returns a multi-line string representation of the bitboard.
func (*Bitboard) Intersects ¶
Intersects returns true if two bitboards have any bits in common.
func (*Bitboard) Mirror ¶
func (b *Bitboard) Mirror()
Mirror mirrors the represented board vertically. For example, the bit at A1 is now at A8.
type CastleRight ¶
type CastleRight uint8
CastleRight represents a single castle right.
const ( WhiteShortCastleRight CastleRight = 1 << iota WhiteLongCastleRight BlackShortCastleRight BlackLongCastleRight )
func (CastleRight) String ¶
func (c CastleRight) String() string
type CastleRights ¶
type CastleRights uint8
CastleRights represents the available castle rights of both players.
const ( // NoCastleRights represents the state where no castle rights are available. NoCastleRights CastleRights = 0 // AllCastleRights represents the state where all castle rights are available to both players. AllCastleRights CastleRights = 0xF )
func (*CastleRights) Disable ¶
func (c *CastleRights) Disable(r CastleRight)
Disable disables a castle right.
func (*CastleRights) Enable ¶
func (c *CastleRights) Enable(r CastleRight)
Enable enables a castle right.
func (*CastleRights) Get ¶
func (c *CastleRights) Get(r CastleRight) bool
Get returns true if a castle right is available.
type EnPassantRight ¶
type EnPassantRight uint8
EnPassantRight represents an en passant right.
A Square can be cast directly to this type, like EnPassantRight(D6).
To represent the lack of an en passant right, use NoEnPasssantRight.
const NoEnPassantRight EnPassantRight = 0xFF
NoEnPassantRight represents the lack of an en passant right.
type File ¶
type File uint8
File represents a board file.
type Move ¶
type Move uint16
Move represents an engine move, or equivalently, a transition between two positions. In chess terminology, this would be a ply.
func NewMove ¶
NewMove returns a new Move.
To represent promotion moves, use NewPromotionMove instead.
To represent castling moves, use the king's original and destination squares as the from and to squares respectively.
func NewPromotionMove ¶
NewPromotionMove returns a new Move that records the given promotion.
func (Move) From ¶
From returns the square at which the move starts.
If the move is castling, the from square is the king's original square.
type Position ¶
type Position struct { Board []Bitboard // Board describes which pieces are on the board and where. CastleRights CastleRights EnPassantRight EnPassantRight SideToMove Color HalfMoves uint8 // HalfMoves is the number of half moves since the last capture or pawn move. FullMoves uint16 // FullMoves starts at 1 and is incremented after Black moves. }
Position represents a game position. Three-fold repetition is not tracked here.
func NewPosition ¶
func NewPosition() Position
NewPosition returns a new position, pre-populated with all starting pieces.
func (*Position) BlackPieces ¶
BlackPieces returns a bitboard of all black piece locations.
func (*Position) Get ¶
Get returns the piece on the given square. If there's no piece there, ok is false.
func (*Position) Reset ¶
func (p *Position) Reset()
Reset resets the position to the starting position.
func (*Position) WhitePieces ¶
WhitePieces returns a bitboard of all white piece locations.
type Rank ¶
type Rank uint8
Rank represents a board rank. Note that Rank1 is represented by 0.