Expand description
A chess model that answers what is true about a position.
Position is placement and state, with no rules attached. Rules live in
Variant implementations — Classic and Chess960 — and a
Game pairs a variant with the moves played, which is what repetition
and claimable draws need.
Facts answers what is true about a position — material, pawn structure,
king safety, one-ply tactics — for a reader and, through Schema and the
encoders, as the flat f32 row a net consumes.
use esca::{Game, Schema, Side, classic};
let mut game = Game::new(classic());
game.play_san("e4").unwrap();
game.play_uci("e7e5").unwrap();
assert_eq!(game.position().fen(),
"rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e6 0 2");
let facts = game.facts();
assert_eq!(facts.material.phase, 1.0);
assert!(facts.pawns.open_files.is_empty());
assert_eq!(facts.tactics[Side::Us.index()].legal_move_count, 29);
let schema = Schema::v1();
assert_eq!(facts.encode(schema, schema.all()).len(), schema.width());Modules§
- explain
- The evidence behind a rules answer.
Structs§
- Annotated
Move - A legal move and its facts.
- Attack
Facts - The attack maps and what they say about the units standing on the board.
- Castling
Rights - Which castlings remain available, each named by its rook’s starting file.
- Chess960
- Fischer Random.
Variant::start_positionreturns arrangementseed % 960, numbered as Scharnagl numbers are. - Classic
- The standard game. The seed of
Variant::start_positionis ignored. - Endgame
Facts - Where the kings stand, how the pawn race runs, and which drawn configuration the material is.
- Exchange
Facts - One side’s captures, judged by the exchange they start.
- Facts
- Everything the v1 schema says about one position, plus its annotated legal moves.
- Feature
Set - A subset of a schema’s features, by group and name.
- Feature
Spec - One named value inside a group.
- FileSet
- A set of files, one bit per file.
- File
SetIter - Iterator over a
FileSet, from file a upwards. - Game
- A played game: the positions reached, and therefore the only thing that can answer repetition and claim questions.
- Group
Set - A subset of a schema’s groups.
- Group
Spec - A named, independently versioned block of features.
- History
Facts - What the plies before this position say: the clock, repetition, and how forcing the recent play was.
- Illegal
Move - The move is not legal in the position it was played in.
- Key
- A Zobrist key.
- King
Facts - King safety and shelter. Index 0 is our king, index 1 theirs.
- Material
Facts - Material and phase.
- Mobility
Facts - Mobility and space.
- Move
- One action of one side: origin, destination, promotion role and kind.
- Move
Facts - What one legal move does, beyond what the move itself says.
- Move
List - An ordered list of at most
MAX_MOVESitems, stored inline. - Pawn
Facts - Pawn structure.
- Piece
- A role plus a colour.
- Piece
Facts - Bishops, rooks, knights and queens.
- Placement
Facts - Where the units stand: one square set per side and role.
- Plane
Facts - The eight square sets the
planesgroup emits. - Position
- An immutable, variant-agnostic snapshot: placement, side to move, castling rights, en-passant square and clocks.
- RowError
- Which row of a batch a failure belongs to.
- Schema
- An ordered list of feature groups: what a feature vector carries.
- Schema
Id - A 128-bit hash over a schema’s canonical text.
- Scratch
- Reusable buffers for fact extraction. One per thread, or one per node of a search stack.
- Square
- One of the 64 cells, indexed 0 to 63 with a1 = 0 and h8 = 63.
- Square
Parse Error - The value was not a square name such as
e4. - Square
Set - A set of squares, one bit per square.
- Square
SetIter - Iterator over a
SquareSet, in ascending square index. - State
Facts - Game-state flags: check, castling rights and the en-passant square.
- Tactics
Facts - One side’s one-ply tactical options.
- Threat
Facts - What each side stands to lose, and the slider geometry behind it.
Enums§
- Castled
Side - The side a king’s square and its spent castling rights read as. A side that still holds a castling right has castled neither way.
- Castling
Output - How castling is spelled in UCI text.
- Colour
- A player: White or Black.
- Draw
Claim - A draw a player may claim, leaving the position playable until one does.
- Drawish
Material - A material configuration that draws although one side is ahead. The three exclude one another.
- FenError
- Why a FEN could not be read.
- File
- A column of the board, a to h.
- Move
Kind - What kind of move this is, by the first matching case in the order castling, en passant, promotion, capture, quiet.
- Move
Parse Error - Why move text did not name one legal move.
- Opposition
- Which opposition the kings stand in. The side not to move holds it.
- Outcome
- How a game ended, without a player having to claim it.
- Position
Error - Why a position is not one a variant can play on.
- Rank
- A row of the board, 1 to 8.
- Role
- What a piece is, without its colour.
- Score
- An evaluation of a position. Positive favours the side to move;
Mate(n)is a forced mate in n moves, negative when it is against the side to move. - Side
- Which side a fact is about, relative to the side to move.
Constants§
- MAX_
MOVES - The most moves any list has to hold. The largest legal move count of a position is 218.
Statics§
Traits§
- Variant
- A complete set of chess rules. Adding rules means adding an implementation.
Functions§
- chess960
- Chess960, shared.
- classic
- Classic chess, shared.
- encode_
fens - As
encode_positions, reading each row’s position from FEN text. - encode_
positions - Writes one row per position, row-major, into
out.