Chess class
Class handling game's state.
Constructors
- Chess()
- By default start with the standard chess starting position
- Chess.fromFEN(String fen, {bool check_validity = true})
- Start with a position from a FEN
Properties
- ascii → String
-
Returns a String representation of the current position
complete with ascii art
no setter
-
board
↔ List<
Piece?> -
Board: pieces values for all cells.
getter/setter pair
-
castling
↔ ColorMap<
int> -
getter/setter pair
- ep_square ↔ int?
-
Current En passant square of the game.
getter/setter pair
- fen → String
-
Get Forsyth-Edwards Notation for the current position.
no setter
- game_over → bool
-
Is it game over ?
no setter
- half_moves ↔ int
-
Half moves count for the draw.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- header ↔ Map
-
Headers of the game (for PGN).
getter/setter pair
-
history
↔ List<
State> -
History of the game.
getter/setter pair
- in_check → bool
-
Is it check in current position ?
no setter
- in_checkmate → bool
-
Is it checkmate in current position ?
no setter
- in_draw → bool
-
It is draw ?
no setter
- in_stalemate → bool
-
Is it stalemate in current position ?
no setter
- in_threefold_repetition → bool
-
Is it draw by threefold repetition in current position ?
no setter
- insufficient_material → bool
-
Is it draw by missing material in current position ?
no setter
-
kings
↔ ColorMap<
int> -
getter/setter pair
- move_number ↔ int
-
Move number.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- turn ↔ Color
-
Current player turn of the game.
getter/setter pair
Methods
-
attacked(
Color color, int square) → bool - Says whether a square is attacked by a piece of the given color.
-
build_move(
List< Piece?> board, dynamic from, dynamic to, dynamic flags, [PieceType? promotion]) → Move -
clear(
) → void - Reset all of the instance variables
-
copy(
) → Chess - Deep copy of the current Chess instance
-
generate_fen(
) → String - Returns a FEN String representing the current position
-
generate_moves(
[Map? options]) → List< Move> - Generates moves for the current position. Can be all moves, legal moves only (=> 'legal' option set to true).
-
get(
String square) → Piece? - Returns the piece at the square in question or null if there is none
-
get_disambiguator(
Move move) → String - This function is used to uniquely identify ambiguous moves.
-
getHistory(
[Map? options]) → List - Gets moves's history.
-
king_attacked(
Color color) → bool - Says whether the king of the given color is attacked.
-
load(
String fen, {bool check_validity = true}) → bool - Load a position from a FEN String
-
load_pgn(
String? pgn, [Map? options]) → bool -
Load the moves of a game stored in Portable Game Notation.
options
is an optional parameter that contains a 'newline_char' which is a string representation of a RegExp (and should not be pre-escaped) and defaults to '\r?\n'). Returnstrue
if the PGN was parsed successfully, otherwisefalse
. -
make_move(
Move move) → void - Make move.
-
make_pretty(
Move ugly_move) → Map< String, dynamic> - pretty = external move object
-
move(
dynamic move) → bool - The move function can be called with in the following parameters: .move('Nxb7') <- where 'move' is a case-sensitive SAN string .move({ from: 'h7', <- where the 'move' is a move object (additional to :'h8', fields are ignored) promotion: 'q', }) or it can be called with a Move object It returns true if the move was made, or false if it could not be.
-
move_to_san(
Move move) → String - Convert a move from 0x88 coordinates to Standard Algebraic Notation(SAN)
-
moves(
[Map? options]) → List - Returns a list of legals moves from the current position. The function takes an optional parameter which controls the single-square move generation and verbosity.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
perft(
int? depth) → int -
pgn(
[Map? options]) → String - Return the PGN representation of the game thus far
-
push(
Move move) → void - Add move to the history of the current game.
-
put(
Piece piece, String square) → bool -
Put
piece
onsquare
-
remove(
String square) → Piece? - Removes a piece from a square and returns it, or null if none is present
-
reset(
) → void - Go back to the chess starting position
-
san_moves(
) → List< String?> - return the san string representation of each move in history. Each string corresponds to one move.
-
set_header(
dynamic args) → Map - Updates header with the List of args and returns it
-
square_color(
dynamic square) → String? -
Returns the color of the square ('light' or 'dark'), or null if
square
is invalid -
toString(
) → String -
A string representation of this object.
inherited
-
trim(
String str) → String - Trim spaces from given string.
-
undo(
) → Map< String, dynamic> ? - Takeback the last half-move, returning a move Map if successful, otherwise null.
-
undo_move(
) → Move? - Undoes a move and returns it, or null if move history is empty
-
update_setup(
String fen) → void - called when the initial board setup is changed with put() or remove(). modifies the SetUp and FEN properties of the header object. if the FEN is equal to the default position, the SetUp and FEN are deleted the setup is only updated if history.length is zero, ie moves haven't been made.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
algebraic(
int i) → String - Get algebraic notation from given square index.
-
file(
int i) → int - Get file from given square index.
-
is_digit(
String c) → bool - Is the given char a digit ?
-
rank(
int i) → int - Get rank from given square index.
-
swap_color(
Color c) → Color - Swaps current turn.
-
validate_fen(
String fen) → Map - Check the formatting of a FEN String is correct Returns a Map with keys valid, error_number, and error
Constants
- ATTACKS → const List
- BISHOP → const PieceType
- Bishop piece type.
-
BITS
→ const Map<
String, int> - BITS_BIG_PAWN → const int
- BITS_CAPTURE → const int
- BITS_EP_CAPTURE → const int
- BITS_KSIDE_CASTLE → const int
- BITS_NORMAL → const int
- BITS_PROMOTION → const int
- BITS_QSIDE_CASTLE → const int
- BLACK → const Color
- Black side.
- DEFAULT_POSITION → const String
- Default position of chess, the very first one.
- EMPTY → const int
- Empty square.
-
FLAGS
→ const Map<
String, String> - Moves flags
- KING → const PieceType
- King piece type.
- KNIGHT → const PieceType
- Knight piece type.
- PAWN → const PieceType
- Pawn piece type.
-
PAWN_OFFSETS
→ const Map<
Color, List< int> > -
PIECE_OFFSETS
→ const Map<
PieceType, List< int> > -
PIECE_TYPES
→ const Map<
String, PieceType> - POSSIBLE_RESULTS → const List
- Possible results of the game.
- QUEEN → const PieceType
- Queen piece type.
- RANK_1 → const int
- Rank 1
- RANK_2 → const int
- Rank 2
- RANK_3 → const int
- Rank 3
- RANK_4 → const int
- Rank 4
- RANK_5 → const int
- Rank 5
- RANK_6 → const int
- Rank 6
- RANK_7 → const int
- Rank 7
- RANK_8 → const int
- Rank 8
-
RAYS
→ const List<
int> - ROOK → const PieceType
- Rook piece type.
- SQUARES → const Map
- Mapping of square name to index.
- SQUARES_A1 → const int
- A1 square index.
- SQUARES_A8 → const int
- A8 square index.
- SQUARES_H1 → const int
- H1 square index.
- SQUARES_H8 → const int
- H8 square index.
- SYMBOLS → const String
- WHITE → const Color
- White side.