Skip to main content

Crate esca

Crate esca 

Source
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§

AnnotatedMove
A legal move and its facts.
AttackFacts
The attack maps and what they say about the units standing on the board.
CastlingRights
Which castlings remain available, each named by its rook’s starting file.
Chess960
Fischer Random. Variant::start_position returns arrangement seed % 960, numbered as Scharnagl numbers are.
Classic
The standard game. The seed of Variant::start_position is ignored.
EndgameFacts
Where the kings stand, how the pawn race runs, and which drawn configuration the material is.
ExchangeFacts
One side’s captures, judged by the exchange they start.
Facts
Everything the v1 schema says about one position, plus its annotated legal moves.
FeatureSet
A subset of a schema’s features, by group and name.
FeatureSpec
One named value inside a group.
FileSet
A set of files, one bit per file.
FileSetIter
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.
GroupSet
A subset of a schema’s groups.
GroupSpec
A named, independently versioned block of features.
HistoryFacts
What the plies before this position say: the clock, repetition, and how forcing the recent play was.
IllegalMove
The move is not legal in the position it was played in.
Key
A Zobrist key.
KingFacts
King safety and shelter. Index 0 is our king, index 1 theirs.
MaterialFacts
Material and phase.
MobilityFacts
Mobility and space.
Move
One action of one side: origin, destination, promotion role and kind.
MoveFacts
What one legal move does, beyond what the move itself says.
MoveList
An ordered list of at most MAX_MOVES items, stored inline.
PawnFacts
Pawn structure.
Piece
A role plus a colour.
PieceFacts
Bishops, rooks, knights and queens.
PlacementFacts
Where the units stand: one square set per side and role.
PlaneFacts
The eight square sets the planes group 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.
SchemaId
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.
SquareParseError
The value was not a square name such as e4.
SquareSet
A set of squares, one bit per square.
SquareSetIter
Iterator over a SquareSet, in ascending square index.
StateFacts
Game-state flags: check, castling rights and the en-passant square.
TacticsFacts
One side’s one-ply tactical options.
ThreatFacts
What each side stands to lose, and the slider geometry behind it.

Enums§

CastledSide
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.
CastlingOutput
How castling is spelled in UCI text.
Colour
A player: White or Black.
DrawClaim
A draw a player may claim, leaving the position playable until one does.
DrawishMaterial
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.
MoveKind
What kind of move this is, by the first matching case in the order castling, en passant, promotion, capture, quiet.
MoveParseError
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.
PositionError
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§

CHESS960
Chess960, as a value.
CLASSIC
Classic chess, as a value.

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.