Documentation
¶
Overview ¶
Package core implements basic chess functionality.
Index ¶
- type Bitboard
- func (b *Bitboard) Clear(s Square)
- func (b *Bitboard) Count() int
- func (b *Bitboard) Debug() string
- func (b *Bitboard) First() Square
- func (b *Bitboard) FlipV()
- func (b *Bitboard) Get(s Square) bool
- func (b *Bitboard) Intersects(other Bitboard) bool
- func (b *Bitboard) Set(s Square)
- func (b *Bitboard) With(other Bitboard)
- type Board
- func (b *Board) AllEmpty(bb Bitboard) bool
- func (b *Board) BlackKing() Square
- func (b *Board) BlackPieces() Bitboard
- func (b *Board) Clear(s Square)
- func (b *Board) Get(s Square) (Piece, bool)
- func (b *Board) IsEmpty(s Square) bool
- func (b *Board) IsOccupied(s Square) bool
- func (b *Board) Move(p Piece, from, to Square)
- func (b *Board) MoveToEmpty(p Piece, from, to Square)
- func (b *Board) Promote(from, to Square, p PieceType)
- func (b *Board) Set(p Piece, s Square)
- func (b *Board) SetOnEmpty(p Piece, s Square)
- func (b *Board) WhiteKing() Square
- func (b *Board) WhitePieces() Bitboard
- type Color
- type File
- type Move
- type Piece
- type PieceType
- type Position
- type Rank
- type Square
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bitboard ¶
type Bitboard uint64
A Bitboard represents each square on the board as a bit. The LSB is a1, and the MSB is h8.
func NewBitboard ¶
NewBitboard returns a new bitboard with the given squares set.
func (*Bitboard) Clear ¶
Clear clears the given square to 0.
Example ¶
b := NewBitboard(A1, H8) b.Clear(H8) fmt.Println(b.Debug())
Output: ........ ........ ........ ........ ........ ........ ........ X.......
func (*Bitboard) Count ¶
Count returns the number of squares set to 1.
Example ¶
b := NewBitboard(A1, H8) fmt.Println(b.Count())
Output: 2
func (*Bitboard) First ¶
First returns the first square set to 1. If the bitboard is empty, it returns an invalid square.
Example ¶
b := NewBitboard(E5, D4, C3) fmt.Println(b.First())
Output: C3
func (*Bitboard) FlipV ¶
func (b *Bitboard) FlipV()
FlipV flips the bitboard horizontally.
Example ¶
b := NewBitboard(C2, D2, E2, F2) b.FlipV() fmt.Println(b.Debug())
Output: ........ ..XXXX.. ........ ........ ........ ........ ........ ........
func (*Bitboard) Get ¶
Get returns true if the given square is set to 1.
Example ¶
b := NewBitboard(A1, H8) fmt.Println(b.Get(A1)) fmt.Println(b.Get(A2))
Output: true false
func (*Bitboard) Intersects ¶
Intersects returns true if the bitboards have any squares in common.
Example ¶
a := NewBitboard(A1, H8) b := NewBitboard(A2, H7) c := NewBitboard(A1, H7) fmt.Println(a.Intersects(b)) fmt.Println(a.Intersects(c))
Output: false true
type Board ¶
type Board [12]Bitboard
Board contains piece placements.
func (*Board) BlackPieces ¶
BlackPieces returns the location of all black pieces.
func (*Board) IsOccupied ¶
IsOccupied returns true if the square is occupied.
func (*Board) Move ¶
Move moves a piece to a square. If there is already a piece at the destination, that piece is removed. If the destination is known to be empty, MoveToEmpty is faster.
func (*Board) MoveToEmpty ¶
MoveToEmpty moves a piece to an empty square.
func (*Board) Set ¶
Set places a piece on a square. If there is already a piece on the square, that piece is removed. If the square is known to be empty, SetOnEmpty is faster.
func (*Board) SetOnEmpty ¶
SetOnEmpty places a piece on an empty square.
func (*Board) WhitePieces ¶
WhitePieces returns the location of all white pieces.
type File ¶
type File uint64
A File is a column on the chess board.
type Piece ¶
type Piece uint64
A Piece represents a chess piece.
type Position ¶
type Position struct { Board Board SideToMove Color EnPassant Square // The zero value indicates no en passant square. WhiteOO, WhiteOOO bool BlackOO, BlackOOO bool HalfMoveClock int FullMoveNumber int // Starts at 1. }
Position represents a chess position.
func (*Position) FriendlyKing ¶
FriendlyKing returns the location of the side to move's king.
type Rank ¶
type Rank uint64
A Rank is a row on the chess board.
type Square ¶
type Square uint64
A Square is a location on the chess board.
const ( A1 Square = iota B1 C1 D1 E1 F1 G1 H1 A2 B2 C2 D2 E2 F2 G2 H2 A3 B3 C3 D3 E3 F3 G3 H3 A4 B4 C4 D4 E4 F4 G4 H4 A5 B5 C5 D5 E5 F5 G5 H5 A6 B6 C6 D6 E6 F6 G6 H6 A7 B7 C7 D7 E7 F7 G7 H7 A8 B8 C8 D8 E8 F8 G8 H8 )
Square constants.