Documentation
¶
Overview ¶
Package chess provides functionality to handle chess and chess960 board positions.
Index ¶
Constants ¶
const ( White = iota Black )
const ( NoPiece = iota << 1 Pawn Knight Bishop Rook Queen King )
Piece types
const ( WP = White | Pawn WN = White | Knight WB = White | Bishop WR = White | Rook WQ = White | Queen WK = White | King BP = Black | Pawn BN = Black | Knight BB = Black | Bishop BR = Black | Rook BQ = Black | Queen BK = Black | King )
Pieces
const ( FileA = iota FileB FileC FileD FileE FileF FileG FileH )
Files
const ( Rank1 = iota Rank2 Rank3 Rank4 Rank5 Rank6 Rank7 Rank8 )
Ranks
const ( WhiteOO = White | kingSide BlackOO = Black | kingSide WhiteOOO = White | queenSide BlackOOO = Black | queenSide )
Castling
Variables ¶
var Figurines = []rune{
'.', ',',
0x2659, 0x265F,
0x2658, 0x265E,
0x2657, 0x265D,
0x2656, 0x265C,
0x2655, 0x265B,
0x2654, 0x265A,
}
var NullMove = Move{}
var PieceLetters = []rune{
'.', ',',
'P', 'p',
'N', 'n',
'B', 'b',
'R', 'r',
'Q', 'q',
'K', 'k',
}
Functions ¶
This section is empty.
Types ¶
type Board ¶
type Board struct { Piece [64]Piece // piece placement (NoPiece, WP, BP, WN, BN, ...) SideToMove int // White or Black MoveNr int // fullmove counter (1-based) Rule50 int // halfmove counter for the 50-move rule (counts from 0-100) EpSquare Sq // en-passant square (behind capturable pawn) CastleSq [4]Sq // rooks that can castle; e.g. CastleSq[WhiteOO] // contains filtered or unexported fields }
Board represents a regular chess or chess960 position.
func MustParseFen ¶
MustParseFen is like ParseFen, but panics if fen cannot be parsed.
func ParseFen ¶
ParseFen initializes a board with the given FEN string. Fields omitted from fen will default to the value in the starting position of a regular chess game (e.g. 'w' for the side-to-move), so that ParseFen("") returns the starting position.
For castling rights both the conventional KkQq can be used as well as file letters, for example 'C' for a white rook on the c-file that can castle. The latter is sometimes needed for chess960 positions.
func (*Board) Hash ¶
Hash returns a 64-bit hash of the position. This is the Polyglot hash, that can be used to lookup positions in a Polyglot opening book. Relevant documentation: http://alpha.uhasselt.be/Research/Algebra/Toga/book_format.html
func (*Board) IsCheckOrMate ¶
IsCheckOrMate returns whether the side to move is in check and/or has been mated. Mate without check means stalemate.
func (*Board) LegalMoves ¶
LegalMoves returns the list of moves that can be played in this position.
func (*Board) ParseMove ¶
ParseMove parses a move in algebraic notation. The parser is forgiving and will accept varying forms of algebraic notation, including slightly incorrect notations (for instance with uncapitalized piece characters). Examples: e4, Bb5, cxd3, O-O, 0-0-0, Rae1+, f8=Q, f8/Q, e2-e4, Bf1-b5, e2e4, f1b5, e1g1 (castling), f7f8q.
type Sq ¶
type Sq int8
const (
A1, B1, C1, D1, E1, F1, G1, H1 Sq = 8*iota + 0, 8*iota + 1, 8*iota + 2,
8*iota + 3, 8*iota + 4, 8*iota + 5, 8*iota + 6, 8*iota + 7
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
NoSquare Sq = -1
)
func (Sq) RelativeRank ¶
RelativeRank returns the square's rank relative to the given player (0-7).
Directories
¶
Path | Synopsis |
---|---|
package engine defines a generic interface for communicating with chess engines.
|
package engine defines a generic interface for communicating with chess engines. |
uci
Package uci (partly) implements the UCI protocol for communicating with chess engines.
|
Package uci (partly) implements the UCI protocol for communicating with chess engines. |
Package pgn reads chess games from Portable Game Notation (PGN) files.
|
Package pgn reads chess games from Portable Game Notation (PGN) files. |