Documentation ¶
Overview ¶
Package chess is a go library designed to accomplish the following:
- chess game / turn management
- move validation
- PGN encoding / decoding
- FEN encoding / decoding
Using Moves
game := chess.NewGame() moves := game.ValidMoves() game.Move(moves[0])
Using Algebraic Notation
game := chess.NewGame() game.MoveStr("e4")
Using PGN
pgn, _ := chess.PGN(pgnReader) game := chess.NewGame(pgn)
Using FEN
fen, _ := chess.FEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1") game := chess.NewGame(fen)
Random Game
package main import ( "fmt" "math/rand" "github.com/corentings/chess/v2" ) func main() { game := chess.NewGame() // generate moves until game is over for game.Outcome() == chess.NoOutcome { // select a random move moves := game.ValidMoves() move := moves[rand.Intn(len(moves))] game.Move(move) } // print outcome and game PGN fmt.Println(game.Position().Board().Draw()) fmt.Printf("Game completed. %s by %s.\n", game.Outcome(), game.Method()) fmt.Println(game.String()) }
Index ¶
- Variables
- func FEN(fen string) (func(*Game), error)
- func GetPolyglotHashes() []string
- func PGN(r io.Reader) (func(*Game), error)
- type AlgebraicNotation
- type Board
- func (b *Board) Draw() string
- func (b *Board) Flip(fd FlipDirection) *Board
- func (b *Board) MarshalBinary() ([]byte, error)
- func (b *Board) MarshalText() ([]byte, error)
- func (b *Board) Piece(sq Square) Piece
- func (b *Board) Rotate() *Board
- func (b *Board) SquareMap() map[Square]Piece
- func (b *Board) String() string
- func (b *Board) Transpose() *Board
- func (b *Board) UnmarshalBinary(data []byte) error
- func (b *Board) UnmarshalText(text []byte) error
- type BookSource
- type BytesBookSource
- type CastleRights
- type ChessHasher
- type Color
- type Decoder
- type Encoder
- type File
- type FileBookSource
- type FlipDirection
- type Game
- func (g *Game) AddTagPair(k, v string) bool
- func (g *Game) AddVariation(parent *Move, newMove *Move)
- func (g *Game) Clone() *Game
- func (g *Game) Comments() [][]string
- func (g *Game) CurrentPosition() *Position
- func (g *Game) Draw(method Method) error
- func (g *Game) EligibleDraws() []Method
- func (g *Game) FEN() string
- func (g *Game) GetTagPair(k string) string
- func (g *Game) GoBack() bool
- func (g *Game) GoForward() bool
- func (g *Game) IsAtEnd() bool
- func (g *Game) IsAtStart() bool
- func (g *Game) MarshalText() ([]byte, error)
- func (g *Game) Method() Method
- func (g *Game) Moves() []*Move
- func (g *Game) NavigateToMainLine()
- func (g *Game) Outcome() Outcome
- func (g *Game) Position() *Position
- func (g *Game) Positions() []*Position
- func (g *Game) PushMove(algebraicMove string, options *PushMoveOptions) error
- func (g *Game) RemoveTagPair(k string) bool
- func (g *Game) Resign(color Color)
- func (g *Game) String() string
- func (g *Game) UnmarshalText(_ []byte) error
- func (g *Game) ValidMoves() []Move
- func (g *Game) Variations(move *Move) []*Move
- type GameScanned
- type Hash
- type Lexer
- type LongAlgebraicNotation
- type Method
- type Move
- type MoveTag
- type Notation
- type Outcome
- type PGNError
- type Parser
- type ParserError
- type Piece
- type PieceType
- type PolyglotBook
- type PolyglotEntry
- type PolyglotMove
- type Position
- func (pos *Position) Board() *Board
- func (pos *Position) CastleRights() CastleRights
- func (pos *Position) ChangeTurn() *Position
- func (pos *Position) EnPassantSquare() Square
- func (pos *Position) HalfMoveClock() int
- func (pos *Position) Hash() [16]byte
- func (pos *Position) MarshalBinary() ([]byte, error)
- func (pos *Position) MarshalText() ([]byte, error)
- func (pos *Position) Status() Method
- func (pos *Position) String() string
- func (pos *Position) Turn() Color
- func (pos *Position) UnmarshalBinary(data []byte) error
- func (pos *Position) UnmarshalText(text []byte) error
- func (pos *Position) Update(m *Move) *Position
- func (pos *Position) ValidMoves() []Move
- type PushMoveOptions
- type Rank
- type ReaderBookSource
- type Scanner
- type Side
- type Square
- type TagPairs
- type Token
- type TokenType
- type UCINotation
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnterminatedComment = func(pos int) error { return &PGNError{"unterminated comment", pos} } ErrUnterminatedQuote = func(pos int) error { return &PGNError{"unterminated quote", pos} } ErrInvalidCommand = func(pos int) error { return &PGNError{"invalid command in comment", pos} } ErrInvalidPiece = func(pos int) error { return &PGNError{"invalid piece", pos} } ErrInvalidSquare = func(pos int) error { return &PGNError{"invalid square", pos} } ErrInvalidRank = func(pos int) error { return &PGNError{"invalid rank", pos} } ErrNoGameFound = errors.New("no game found in PGN data") )
Custom error types for different PGN errors
Functions ¶
func FEN ¶
FEN takes a string and returns a function that updates the game to reflect the FEN data. Since FEN doesn't encode prior moves, the move list will be empty. The returned function is designed to be used in the NewGame constructor. An error is returned if there is a problem parsing the FEN data.
func GetPolyglotHashes ¶
func GetPolyglotHashes() []string
Types ¶
type AlgebraicNotation ¶
type AlgebraicNotation struct{}
AlgebraicNotation (or Standard Algebraic Notation) is the official chess notation used by FIDE. Examples: e4, e5, O-O (short castling), e8=Q (promotion).
func (AlgebraicNotation) Decode ¶
func (AlgebraicNotation) Decode(pos *Position, s string) (*Move, error)
Decode implements the Decoder interface.
func (AlgebraicNotation) Encode ¶
func (AlgebraicNotation) Encode(pos *Position, m *Move) string
Encode implements the Encoder interface.
func (AlgebraicNotation) String ¶
func (AlgebraicNotation) String() string
String implements the fmt.Stringer interface and returns the notation's name.
type Board ¶
type Board struct {
// contains filtered or unexported fields
}
A Board represents a chess board and its relationship between squares and pieces.
func (*Board) Flip ¶
func (b *Board) Flip(fd FlipDirection) *Board
Flip flips the board over the vertical or hoizontal center line.
func (*Board) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface and returns the bitboard representations as a array of bytes. Bitboads are encoded in the following order: WhiteKing, WhiteQueen, WhiteRook, WhiteBishop, WhiteKnight WhitePawn, BlackKing, BlackQueen, BlackRook, BlackBishop, BlackKnight, BlackPawn.
func (*Board) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface and returns a string in the FEN board format: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR.
func (*Board) SquareMap ¶
SquareMap returns a mapping of squares to pieces. A square is only added to the map if it is occupied.
func (*Board) String ¶
String implements the fmt.Stringer interface and returns a string in the FEN board format: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR.
func (*Board) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface and parses the bitboard representations as a array of bytes. Bitboads are decoded in the following order: WhiteKing, WhiteQueen, WhiteRook, WhiteBishop, WhiteKnight WhitePawn, BlackKing, BlackQueen, BlackRook, BlackBishop, BlackKnight, BlackPawn.
func (*Board) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnarshaler interface and takes a string in the FEN board format: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR.
type BookSource ¶
type BookSource interface { // Read reads exactly len(p) bytes into p or returns an error Read(p []byte) (n int, err error) // Size returns the total size of the book data Size() (int64, error) }
BookSource defines the interface for reading polyglot book data. This interface allows for different source implementations (file, memory, etc.) while maintaining consistent access patterns.
type BytesBookSource ¶
type BytesBookSource struct {
// contains filtered or unexported fields
}
BytesBookSource implements BookSource for byte slices
func NewBytesBookSource ¶
func NewBytesBookSource(data []byte) *BytesBookSource
NewBytesBookSource creates a new memory-based book source
func (*BytesBookSource) Read ¶
func (b *BytesBookSource) Read(p []byte) (n int, err error)
Read implements BookSource for BytesBookSource
func (*BytesBookSource) Size ¶
func (b *BytesBookSource) Size() (int64, error)
Size implements BookSource for BytesBookSource
type CastleRights ¶
type CastleRights string
CastleRights holds the state of both sides castling abilities.
func (CastleRights) CanCastle ¶
func (cr CastleRights) CanCastle(c Color, side Side) bool
CanCastle returns true if the given color and side combination can castle, otherwise returns false.
func (CastleRights) String ¶
func (cr CastleRights) String() string
String implements the fmt.Stringer interface and returns a FEN compatible string. Ex. KQq.
type ChessHasher ¶
type ChessHasher struct {
// contains filtered or unexported fields
}
ChessHasher provides methods to generate Zobrist hashes for chess positions
func NewChessHasher ¶
func NewChessHasher() *ChessHasher
NewChessHasher creates a new instance of ChessHasher
func (*ChessHasher) HashPosition ¶
func (ch *ChessHasher) HashPosition(fen string) (string, error)
HashPosition computes a Zobrist hash for a chess position in FEN notation
type Decoder ¶
Decoder is the interface implemented by objects that can decode a string into a move given the position. It is not the decoders responsibility to validate the move. An error is returned if the string could not be decoded.
type Encoder ¶
Encoder is the interface implemented by objects that can encode a move into a string given the position. It is not the encoders responsibility to validate the move.
type FileBookSource ¶
type FileBookSource struct {
// contains filtered or unexported fields
}
FileBookSource implements BookSource for files
func NewFileBookSource ¶
func NewFileBookSource(path string) *FileBookSource
NewFileBookSource creates a new file-based book source
func (*FileBookSource) Read ¶
func (f *FileBookSource) Read(p []byte) (n int, err error)
Read implements BookSource for FileBookSource
func (*FileBookSource) Size ¶
func (f *FileBookSource) Size() (int64, error)
Size implements BookSource for FileBookSource
type FlipDirection ¶
type FlipDirection int
FlipDirection is the direction for the Board.Flip method.
const ( // UpDown flips the board's rank values. UpDown FlipDirection = iota // LeftRight flips the board's file values. LeftRight )
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
A Game represents a single chess game.
func NewGame ¶
NewGame defaults to returning a game in the standard opening position. Options can be given to configure the game's initial state.
func (*Game) AddTagPair ¶
AddTagPair adds or updates a tag pair with the given key and value and returns true if the value is overwritten.
func (*Game) AddVariation ¶
func (*Game) Comments ¶
Comments returns the comments for the game indexed by moves. Comments returns the comments for the game indexed by moves.
func (*Game) CurrentPosition ¶
CurrentPosition returns the game's current move position. This is the position at the current pointer in the move tree. This should be used to get the current position of the game instead of Position().
func (*Game) Draw ¶
Draw attempts to draw the game by the given method. If the method is valid, then the game is updated to a draw by that method. If the method isn't valid then an error is returned.
func (*Game) EligibleDraws ¶
EligibleDraws returns valid inputs for the Draw() method.
func (*Game) GetTagPair ¶
GetTagPair returns the tag pair for the given key or nil if it is not present.
func (*Game) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface and encodes the game's PGN.
func (*Game) NavigateToMainLine ¶
func (g *Game) NavigateToMainLine()
func (*Game) PushMove ¶
func (g *Game) PushMove(algebraicMove string, options *PushMoveOptions) error
PushMove updates the game with the given move in algebraic notation.
func (*Game) RemoveTagPair ¶
RemoveTagPair removes the tag pair for the given key and returns true if a tag pair was removed.
func (*Game) Resign ¶
Resign resigns the game for the given color. If the game has already been completed then the game is not updated.
func (*Game) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnarshaler interface and assumes the data is in the PGN format.
func (*Game) ValidMoves ¶
ValidMoves returns a list of valid moves in the current position.
func (*Game) Variations ¶
Variations returns all alternative moves at the given position.
type GameScanned ¶
type GameScanned struct {
Raw string
}
type LongAlgebraicNotation ¶
type LongAlgebraicNotation struct{}
LongAlgebraicNotation is a fully expanded version of algebraic notation in which the starting and ending squares are specified. Examples: e2e4, Rd3xd7, O-O (short castling), e7e8=Q (promotion).
func (LongAlgebraicNotation) Decode ¶
func (LongAlgebraicNotation) Decode(pos *Position, s string) (*Move, error)
Decode implements the Decoder interface.
func (LongAlgebraicNotation) Encode ¶
func (LongAlgebraicNotation) Encode(pos *Position, m *Move) string
Encode implements the Encoder interface.
func (LongAlgebraicNotation) String ¶
func (LongAlgebraicNotation) String() string
String implements the fmt.Stringer interface and returns the notation's name.
type Method ¶
type Method uint8
A Method is the method that generated the outcome.
const ( // NoMethod indicates that an outcome hasn't occurred or that the method can't be determined. NoMethod Method = iota // Checkmate indicates that the game was won checkmate. Checkmate // Resignation indicates that the game was won by resignation. Resignation // DrawOffer indicates that the game was drawn by a draw offer. DrawOffer // Stalemate indicates that the game was drawn by stalemate. Stalemate // ThreefoldRepetition indicates that the game was drawn when the game // state was repeated three times and a player requested a draw. ThreefoldRepetition // FivefoldRepetition indicates that the game was automatically drawn // by the game state being repeated five times. FivefoldRepetition // FiftyMoveRule indicates that the game was drawn by the half // move clock being one hundred or greater when a player requested a draw. FiftyMoveRule // SeventyFiveMoveRule indicates that the game was automatically drawn // when the half move clock was one hundred and fifty or greater. SeventyFiveMoveRule // InsufficientMaterial indicates that the game was automatically drawn // because there was insufficient material for checkmate. InsufficientMaterial )
type Move ¶
type Move struct {
// contains filtered or unexported fields
}
A Move is the movement of a piece from one square to another.
type MoveTag ¶
type MoveTag uint16
A MoveTag represents a notable consequence of a move.
const ( // KingSideCastle indicates that the move is a king side castle. KingSideCastle MoveTag = 1 << iota // QueenSideCastle indicates that the move is a queen side castle. QueenSideCastle // Capture indicates that the move captures a piece. Capture // EnPassant indicates that the move captures via en passant. EnPassant // Check indicates that the move puts the opposing player in check. Check )
type Outcome ¶
type Outcome string
A Outcome is the result of a game.
const ( // NoOutcome indicates that a game is in progress or ended without a result. NoOutcome Outcome = "*" // WhiteWon indicates that white won the game. WhiteWon Outcome = "1-0" // BlackWon indicates that black won the game. BlackWon Outcome = "0-1" // Draw indicates that game was a draw. Draw Outcome = "1/2-1/2" )
type PGNError ¶
type PGNError struct {
// contains filtered or unexported fields
}
PGNError custom error types for different PGN errors.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser holds the state needed during parsing.
type ParserError ¶
func (*ParserError) Error ¶
func (e *ParserError) Error() string
type Piece ¶
type Piece int8
Piece is a piece type with a color.
const ( // NoPiece represents no piece. NoPiece Piece = iota // WhiteKing is a white king. WhiteKing // WhiteQueen is a white queen. WhiteQueen // WhiteRook is a white rook. WhiteRook // WhiteBishop is a white bishop. WhiteBishop // WhiteKnight is a white knight. WhiteKnight // WhitePawn is a white pawn. WhitePawn // BlackKing is a black king. BlackKing // BlackQueen is a black queen. BlackQueen // BlackRook is a black rook. BlackRook // BlackBishop is a black bishop. BlackBishop // BlackKnight is a black knight. BlackKnight // BlackPawn is a black pawn. BlackPawn )
type PieceType ¶
type PieceType int8
PieceType is the type of a piece.
func PieceTypeFromByte ¶
func PieceTypeFromString ¶
type PolyglotBook ¶
type PolyglotBook struct {
// contains filtered or unexported fields
}
PolyglotBook represents a polyglot opening book with optimized lookup capabilities. A polyglot book is a binary file format widely used in chess engines to store opening moves. Each entry in the book contains a position hash, a move, and additional metadata.
Example usage:
// Load from file book, err := LoadBookFromFile("openings.bin") if err != nil { log.Fatal(err) } // Find moves for a position hash := uint64(0x463b96181691fc9c) // Starting position hash moves := book.FindMoves(hash) // Get a random move weighted by the stored weights randomMove := book.GetRandomMove(hash)
func LoadBookFromFile ¶
func LoadBookFromFile(filename string) (*PolyglotBook, error)
LoadBookFromFile loads a polyglot book from a file path. This is a convenience function for the common case of loading from a file.
Example:
book, err := LoadBookFromFile("openings.bin") if err != nil { log.Fatal(err) }
func LoadFromBytes ¶
func LoadFromBytes(data []byte) (*PolyglotBook, error)
LoadFromBytes loads a polyglot book from a byte slice. This is useful when the book data is already in memory.
Example:
data := // ... your book data ... book, err := LoadFromBytes(data) if err != nil { log.Fatal(err) }
func LoadFromReader ¶
func LoadFromReader(reader io.Reader) (*PolyglotBook, error)
LoadFromReader loads a polyglot book from an io.Reader. Note that this will read the entire input into memory.
Example:
file, err := os.Open("openings.bin") if err != nil { log.Fatal(err) } defer file.Close() book, err := LoadFromReader(file) if err != nil { log.Fatal(err) }
func LoadFromSource ¶
func LoadFromSource(source BookSource) (*PolyglotBook, error)
LoadFromSource loads a polyglot book from any BookSource
func (*PolyglotBook) FindMoves ¶
func (book *PolyglotBook) FindMoves(positionHash uint64) []PolyglotEntry
FindMoves looks up all moves for a given position hash. Returns moves sorted by weight (highest weight first). Returns nil if no moves are found.
Example:
hash := uint64(0x463b96181691fc9c) // Starting position moves := book.FindMoves(hash) if moves != nil { for _, move := range moves { decodedMove := DecodeMove(move.Move) fmt.Printf("Move: %v, Weight: %d\n", decodedMove, move.Weight) } }
func (*PolyglotBook) GetRandomMove ¶
func (book *PolyglotBook) GetRandomMove(positionHash uint64) *PolyglotEntry
GetRandomMove returns a weighted random move from the available moves for a position. The probability of selecting a move is proportional to its weight. Returns nil if no moves are available.
Example:
hash := uint64(0x463b96181691fc9c) // Starting position move := book.GetRandomMove(hash) if move != nil { decodedMove := DecodeMove(move.Move) fmt.Printf("Selected move: %v\n", decodedMove) }
type PolyglotEntry ¶
type PolyglotEntry struct { Key uint64 // Zobrist hash of the chess position Move uint16 // Encoded move (see DecodeMove for format) Weight uint16 // Relative weight for move selection Learn uint32 // Learning data (usually 0) }
PolyglotEntry represents a single entry in a polyglot opening book. Each entry is exactly 16 bytes and contains information about a chess position and a recommended move.
type PolyglotMove ¶
type PolyglotMove struct { FromFile int // Source file (0-7) FromRank int // Source rank (0-7) ToFile int // Target file (0-7) ToRank int // Target rank (0-7) Promotion int // Promotion piece type (0=none, 1=knight, 2=bishop, 3=rook, 4=queen) CastlingMove bool // True if this is a castling move }
PolyglotMove represents a decoded chess move from a polyglot entry. The coordinates use 0-based indices where: - Files go from 0 (a-file) to 7 (h-file) - Ranks go from 0 (1st rank) to 7 (8th rank)
func DecodeMove ¶
func DecodeMove(move uint16) PolyglotMove
DecodeMove converts a polyglot move encoding into a more usable format. The move encoding uses bit fields as follows:
- bits 0-2: to file
- bits 3-5: to rank
- bits 6-8: from file
- bits 9-11: from rank
- bits 12-14: promotion piece
Promotion pieces are encoded as:
- 0: none
- 1: knight
- 2: bishop
- 3: rook
- 4: queen
Example:
move := uint16(0x1234) // Some move from the book decoded := DecodeMove(move) fmt.Printf("From: %c%d, To: %c%d\n", 'a'+decoded.FromFile, decoded.FromRank+1, 'a'+decoded.ToFile, decoded.ToRank+1)
type Position ¶
type Position struct {
// contains filtered or unexported fields
}
Position represents the state of the game without reguard to its outcome. Position is translatable to FEN notation.
func StartingPosition ¶
func StartingPosition() *Position
StartingPosition returns the starting position rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1.
func (*Position) CastleRights ¶
func (pos *Position) CastleRights() CastleRights
CastleRights returns the castling rights of the position.
func (*Position) ChangeTurn ¶
ChangeTurn returns a new position with the turn changed.
func (*Position) EnPassantSquare ¶
EnPassantSquare returns the en-passant square.
func (*Position) HalfMoveClock ¶
HalfMoveClock returns the half-move clock (50-rule).
func (*Position) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*Position) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface and encodes the position's FEN.
func (*Position) Status ¶
Status returns the position's status as one of the outcome methods. Possible returns values include Checkmate, Stalemate, and NoMethod.
func (*Position) String ¶
String implements the fmt.Stringer interface and returns a string with the FEN format: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1.
func (*Position) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryMarshaler interface.
func (*Position) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnarshaler interface and assumes the data is in the FEN format.
func (*Position) Update ¶
Update returns a new position resulting from the given move. The move itself isn't validated, if validation is needed use Game's Move method. This method is more performant for bots that rely on the ValidMoves because it skips redundant validation.
func (*Position) ValidMoves ¶
ValidMoves returns a list of valid moves for the position. TODO: Can we make this more efficient? Maybe using an iterator?
type PushMoveOptions ¶
type PushMoveOptions struct { // ForceMainline makes this move the main line if variations exist ForceMainline bool }
PushMoveOptions contains options for pushing a move to the game
type ReaderBookSource ¶
type ReaderBookSource struct {
// contains filtered or unexported fields
}
ReaderBookSource implements BookSource for io.Reader
func NewReaderBookSource ¶
func NewReaderBookSource(reader io.Reader) (*ReaderBookSource, error)
NewReaderBookSource creates a new reader-based book source Note: This will read the entire input into memory to support Size() and multiple reads
func (*ReaderBookSource) Read ¶
func (r *ReaderBookSource) Read(p []byte) (n int, err error)
Read implements BookSource for ReaderBookSource
func (*ReaderBookSource) Size ¶
func (r *ReaderBookSource) Size() (int64, error)
Size implements BookSource for ReaderBookSource
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner struct to scan PGN games.
func NewScanner ¶
NewScanner function to create a new PGN scanner.
func (*Scanner) ScanGame ¶
func (s *Scanner) ScanGame() (*GameScanned, error)
ScanGame function to scan the next PGN game.
type Square ¶
type Square int8
A Square is one of the 64 rank and file combinations that make up a chess board.
type Token ¶
func TokenizeGame ¶
func TokenizeGame(game *GameScanned) ([]Token, error)
TokenizeGame function to tokenize a PGN game.
type TokenType ¶
type TokenType int
const ( EOF TokenType = iota Undefined TagStart // [ TagEnd // ] TagKey // The key part of a tag (e.g., "Site") TagValue // The value part of a tag (e.g., "Internet") MoveNumber // 1, 2, 3, etc. DOT // . ELLIPSIS // ... PIECE // N, B, R, Q, K SQUARE // e4, e5, etc. CommentStart // { CommentEnd // } COMMENT // The comment text RESULT // 1-0, 0-1, 1/2-1/2 CAPTURE // 'x' in moves FILE // a-h in moves when used as disambiguation RANK // 1-8 in moves when used as disambiguation KingsideCastle // 0-0 QueensideCastle // 0-0-0 PROMOTION // = in moves PromotionPiece // The piece being promoted to (Q, R, B, N) CHECK // + in moves CHECKMATE // # in moves NAG // Numeric Annotation Glyph (e.g., $1, $2, etc.) VariationStart // ( for starting a variation VariationEnd // ) for ending a variation CommandStart // [% CommandName // The command name (e.g., clk, eval) CommandParam // Command parameter CommandEnd // ] )
type UCINotation ¶
type UCINotation struct{}
UCINotation is a more computer friendly alternative to algebraic notation. This notation uses the same format as the UCI (Universal Chess Interface). Examples: e2e4, e7e5, e1g1 (white short castling), e7e8q (for promotion).
func (UCINotation) Decode ¶
func (UCINotation) Decode(pos *Position, s string) (*Move, error)
Decode implements the Decoder interface.
func (UCINotation) Encode ¶
func (UCINotation) Encode(_ *Position, m *Move) string
Encode implements the Encoder interface.
func (UCINotation) String ¶
func (UCINotation) String() string
String implements the fmt.Stringer interface and returns the notation's name.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package image is a go library that creates images from board positions
|
Package image is a go library that creates images from board positions |
Package opening implements chess opening determination and exploration.
|
Package opening implements chess opening determination and exploration. |