Position<T extends Position<T>> class abstract

A base class for playable chess or chess variant positions.

See Chess for a concrete implementation of standard rules.

Implementers
Annotations
  • @immutable

Constructors

Position({required Board board, Pockets? pockets, required Side turn, required Castles castles, Square? epSquare, required int halfmoves, required int fullmoves})
const

Properties

board Board
Piece positions on the board.
final
castles Castles
Castling paths and unmoved rooks.
final
checkers SquareSet
SquareSet of pieces giving check.
no setter
epSquare Square?
En passant target square.
final
fen String
Gets the FEN string of this position.
no setter
fullmoves int
Current move number.
final
halfmoves int
Number of half-moves since the last capture or pawn move.
final
hashCode int
The hash code for this object.
no setteroverride
hasSomeLegalMoves bool
Tests if the position has at least one legal move.
no setter
isCheck bool
Tests if the king is in check.
no setter
isCheckmate bool
Tests for checkmate.
no setter
isGameOver bool
Tests if the game is over.
no setter
isInsufficientMaterial bool
Tests if both Side have insufficient winning material.
no setter
isStalemate bool
Tests for stalemate.
no setter
isVariantEnd bool
Checks if the game is over due to a special variant end condition.
no setter
legalDrops SquareSet
Gets all the legal drops of this position.
no setter
legalMoves → IMap<Square, SquareSet>
Gets all the legal moves of this position.
no setter
outcome Outcome?
The outcome of the game, or null if the game is not over.
no setter
ply int
Gets the current ply.
no setter
pockets Pockets?
Pockets in chess variants like Crazyhouse.
final
rule Rule
The Rule of this position.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
turn Side
Side to move.
final
variantOutcome Outcome?
Tests special variant winning, losing and drawing conditions.
no setter

Methods

hasInsufficientMaterial(Side side) bool
Tests if a Side has insufficient winning material.
isLegal(Move move) bool
Tests a move for legality.
kingAttackers(Square square, Side attacker, {SquareSet? occupied}) SquareSet
Attacks that a king on square would have to deal with.
legalMovesOf(Square square) SquareSet
Gets the legal moves for that Square.
makeSan(Move move) → (Position<T>, String)
Returns the SAN of this Move and the updated Position.
makeSanUnchecked(Move move) → (Position<T>, String)
Returns the SAN of this Move and the updated Position, without checking if the move is legal.
normalizeMove(NormalMove move) Move
Returns the normalized form of a NormalMove to avoid castling inconsistencies.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseSan(String sanString) Move?
Parses a move in Standard Algebraic Notation.
play(Move move) Position<T>
Plays a move and returns the updated Position.
playToSan(Move move) → (Position<T>, String)
Returns the SAN representation of the Move with the updated Position.
playUnchecked(Move move) Position<T>
Plays a move without checking if the move is legal and returns the updated Position.
toSan(Move move) String
Returns the SAN of this Move from the current Position.
toString() String
A string representation of this object.
override
validate({bool? ignoreImpossibleCheck}) → void
Checks the legality of this position.

Operators

operator ==(Object other) bool
The equality operator.
override

Static Methods

initialPosition(Rule rule) Position<Position>
Returns the initial Position for the corresponding Rule.
setupPosition(Rule rule, Setup setup, {bool? ignoreImpossibleCheck}) Position<Position>
Create a Position from a Setup and Rule.