Game class

Tracks the state of the game, handles move generation and validation, and generates output.

Available Extensions

Constructors

Game({Variant? variant, String? fen, FenBuilder? fenBuilder, int zobristSeed = Bishop.defaultSeed, int? startPosSeed})
Game.fromPgn(String pgn)
factory

Properties

board List<int>
no setter
canUndo bool
no setter
castlingFileSymbols List<String>
getter/setter pair
castlingTargetK int?
getter/setter pair
castlingTargetQ int?
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hashHits int
Check the number of times the current position has occurred in the hash table.
no setter
history List<BishopState>
getter/setter pair
prevState BishopState?
no setter
royalCaptureOptions MoveGenParams
getter/setter pair
royalFile int?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size BoardSize
no setter
startedInInitialPosition bool
final
startPosition String
getter/setter pair
startPosSeed int?
final
state BishopState
no setter
turn Colour
no setter
variant BuiltVariant
The variant that specifies the gameplay rules for this game.
final
zobrist Zobrist
getter/setter pair
zobristSeed int
A random number generator seed. Used by the Zobrist hash table.
final

Methods

generateDrops(int colour, [bool legal = true]) List<Move>
Generates drop moves for colour. Used for variants with hands, e.g. Crazyhouse.
generateGatingMoves(StandardMove base) List<GatingMove>
Generates a move for each gating possibility for the base move. Doesn't include the option where a piece is not gated.
generateLegalMoves() List<Move>
Generates all legal moves for the player whose turn it is.
generatePass(int colour, [bool legal = true]) PassMove?
generatePieceMoves(int square, [MoveGenParams options = MoveGenParams.normal]) List<Move>
Generates all moves for the piece on square in accordance with options.
generatePlayerMoves(int player, [MoveGenParams? params]) List<Move>
Generates all moves for the specified player. See MoveGenParams for possibilities.
generatePremoves() List<Move>
Generates all possible moves that could be played by the other player next turn, not respecting blocking pieces or checks.
getAttackers(int square, int player) Set<int>
Finds all the pieces for player attacking square. Returns a list of the squares those pieces are on.
getKingAttackers(int player) Set<int>
Finds all pieces attacking player's king. Returns a list of the squares those pieces are on.
getRandomMove() Move
Gets a random valid move for the current player.
isAttacked(int square, int player) bool
Checks if square is attacked by player. Works by generating all legal moves for the other player, and therefore is slow.
isMoveValid(String move) bool
Checks whether an algebraic move string (e.g. e2e4, f7f8q) is a valid move.
kingAttacked(int player) bool
Check if player's king is currently attacked.
loadFen(String fen, {bool strict = false, bool initialSetup = false}) → void
makeMoveSan(String move, {bool checks = false}) bool
Makes a move from a SAN string, e.g. 'Nxf3', 'e4', 'O-O-O'. Return value indicates whether the move was valid. If checks is false, the '+' or '#' part of the SAN string will not be computed, which vastly increases efficiency in cases like PGN parsing.
makeMoveString(String move) bool
Makes a move from an algebraic move string (e.g. e2e4, f7f8q). Return value indicates whether the move was valid.
makeMultipleMoves(List<String> moves, {bool undoOnError = true, bool san = false}) int
Makes multiple moves in order, in algebraic format (e.g. e2e4, f7f8q). Returns the number of moves that were successfully made. If everything went fine, this should be equal to moves.length. If undoOnError is true, all moves made before the error will be undone.
makeRandomMove() Move
Makes a random valid move for the current player.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setup({String? fen, FenBuilder? fenBuilder}) → void
toString() String
A string representation of this object.
override

Operators

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