### Setup Class Constructors Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup-class.html Information about how to create a Setup object. ```APIDOC ## Constructors ### `Setup( required Board board, Pockets? pockets, required Side turn, required SquareSet castlingRights, Square? epSquare, required int halfmoves, required int fullmoves, (int, int)? remainingChecks )` Creates a new Setup with the provided values. ### `Setup.parseFen(String fen)` Parses a Forsyth-Edwards-Notation string and returns a Setup. **Type:** factory ``` -------------------------------- ### Setup Class Methods and Operators Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup-class.html Available methods and operators for the Setup class. ```APIDOC ## Methods ### `noSuchMethod(Invocation invocation) → dynamic` Invoked when a nonexistent method or property is accessed. *inherited* ### `toString() → String` A string representation of this object. *inherited* ## Operators ### `operator ==(Object other) → bool` The equality operator. *override* ``` -------------------------------- ### Setup Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup/Setup.html Initializes a new Setup object with the specified board state, turn, castling rights, and move counters. ```APIDOC ## Setup Constructor ### Description Creates a new Setup instance with the provided game state values. ### Parameters - **board** (Board) - Required - The current state of the board. - **pockets** (Pockets) - Optional - The contents of the pockets. - **turn** (Side) - Required - The side whose turn it is to move. - **castlingRights** (SquareSet) - Required - The current castling rights. - **epSquare** (Square) - Optional - The en passant square, if applicable. - **halfmoves** (int) - Required - The number of halfmoves played. - **fullmoves** (int) - Required - The number of fullmoves played. - **remainingChecks** ((int, int)) - Optional - The remaining checks for each side. ``` -------------------------------- ### Setup Class Properties Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup-class.html Details of the properties available on a Setup object. ```APIDOC ## Properties - **board** → Board Piece positions on the board. *final* - **castlingRights** → SquareSet Unmoved rooks positions used to determine castling rights. *final* - **epSquare** → Square? En passant target square. *final* - **fen** → String FEN representation of the setup. *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 setter* *override* - **pockets** → Pockets? Pockets in chess variants like Crazyhouse. *final* - **remainingChecks** → (int, int)? Number of remainingChecks for white and black. *final* - **runtimeType** → Type A representation of the runtime type of the object. *no setter* *inherited* - **turn** → Side Side to move. *final* - **turnLetter** → String FEN character for the side to move. *no setter* ``` -------------------------------- ### Setup Class Constants Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup-class.html Constants associated with the Setup class. ```APIDOC ## Constants ### `standard` → const Setup Initial position setup. ``` -------------------------------- ### Initialize Setup object Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup/Setup.html Defines the parameters required to instantiate a new Setup object for a chess game state. ```dart const Setup({ 1. required Board board, 2. Pockets? pockets, 3. required Side turn, 4. required SquareSet castlingRights, 5. Square? epSquare, 6. required int halfmoves, 7. required int fullmoves, 8. (int, int)? remainingChecks, }) ``` ```dart const Setup({ required this.board, this.pockets, required this.turn, required this.castlingRights, this.epSquare, required this.halfmoves, required this.fullmoves, this.remainingChecks, }); ``` -------------------------------- ### Initialize ThreeCheck from Setup Source: https://pub.dev/documentation/dartchess/latest/dartchess/ThreeCheck/ThreeCheck.fromSetup.html Creates a playable ThreeCheck position from a Setup object. Throws a PositionSetupException if the setup is invalid, unless ignoreImpossibleCheck is set to true. ```dart factory ThreeCheck.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { if (setup.remainingChecks == null) { throw PositionSetupException.variant; } else { final pos = ThreeCheck( board: setup.board, turn: setup.turn, castles: Castles.fromSetup(setup), epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, remainingChecks: setup.remainingChecks!, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } } ``` -------------------------------- ### Initialize Horde position from setup Source: https://pub.dev/documentation/dartchess/latest/dartchess/Horde/Horde.fromSetup.html Creates a new Horde instance from a Setup object. Throws a PositionSetupException if the setup is invalid unless ignoreImpossibleCheck is true. ```dart factory Horde.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = Horde( board: setup.board, turn: setup.turn, castles: Castles.fromSetup(setup), epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` -------------------------------- ### Initialize RacingKings from Setup Source: https://pub.dev/documentation/dartchess/latest/dartchess/RacingKings/RacingKings.fromSetup.html Creates a new RacingKings instance from a Setup object. Throws a PositionSetupException if the setup is invalid unless ignoreImpossibleCheck is set to true. ```dart factory RacingKings.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = RacingKings( board: setup.board, turn: setup.turn, castles: Castles.empty, halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` -------------------------------- ### Create Chess Position from Setup Source: https://pub.dev/documentation/dartchess/latest/dartchess/Chess/Chess.fromSetup.html Use this factory constructor to set up a playable Chess position from a `Setup` object. It optionally allows skipping validity checks by passing `ignoreImpossibleCheck: true`. Throws `PositionSetupException` if the setup is invalid and checks are not ignored. ```dart factory Chess.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = Chess( board: setup.board, pockets: setup.pockets, turn: setup.turn, castles: Castles.fromSetup(setup), epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` -------------------------------- ### Crazyhouse Initial Constant Source: https://pub.dev/documentation/dartchess/latest/dartchess/Crazyhouse/initial-constant.html The 'initial' constant defines the standard starting board setup for a Crazyhouse game, including pieces, turn, and game state. ```APIDOC ## Crazyhouse Initial Constant ### Description The initial position of a Crazyhouse game. ### Implementation ```dart static const initial = Crazyhouse( board: Board.standard, pockets: Pockets.empty, turn: Side.white, castles: Castles.standard, halfmoves: 0, fullmoves: 1, ); ``` ``` -------------------------------- ### Castles.fromSetup Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Castles/Castles.fromSetup.html Creates a Castles instance from a Setup object. It initializes castling rights based on the provided setup, considering rook positions relative to the king. ```APIDOC ## Castles.fromSetup Constructor ### Description Creates a Castles instance from a Setup. ### Method Factory Constructor ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A (Constructor returns an instance) #### Response Example N/A ### Implementation Details This factory constructor iterates through each side (white and black) to determine castling rights. It identifies rooks on the back rank and checks their positions relative to the king to establish castling availability for both the king's and queen's sides. ``` -------------------------------- ### ThreeCheck.fromSetup Source: https://pub.dev/documentation/dartchess/latest/dartchess/ThreeCheck-class.html Factory method to initialize a playable ThreeCheck position from a setup configuration. ```APIDOC ## Factory ThreeCheck.fromSetup ### Description Set up a playable ThreeCheck position from a provided setup object. ### Parameters #### Request Body - **setup** (Setup) - Required - The setup configuration. - **ignoreImpossibleCheck** (bool?) - Optional - Flag to ignore impossible check states. ``` -------------------------------- ### Define Standard Chess Initial Position Source: https://pub.dev/documentation/dartchess/latest/dartchess/Chess/initial-constant.html This constant defines the standard starting board setup, turn, castling rights, and move counters for a chess game. ```dart static const initial = Chess( board: Board.standard, turn: Side.white, castles: Castles.standard, halfmoves: 0, fullmoves: 1, ); ``` -------------------------------- ### ThreeCheck.fromSetup Factory Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/ThreeCheck/ThreeCheck.fromSetup.html Sets up a playable ThreeCheck position from a given Setup object. It optionally accepts a boolean to ignore impossible check requirements. Throws a PositionSetupException if the Setup does not meet basic validity requirements. ```APIDOC ## ThreeCheck.fromSetup Factory Constructor ### Description Sets up a playable ThreeCheck position from a given `Setup` object. It optionally accepts a boolean to ignore impossible check requirements. Throws a `PositionSetupException` if the `Setup` does not meet basic validity requirements. ### Method `factory` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **setup** (Setup) - Required - The setup object defining the initial board state. - **ignoreImpossibleCheck** (bool?) - Optional - If true, skips the requirement for the setup to meet basic validity requirements regarding impossible checks. ### Request Example ```json { "setup": { "board": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "turn": "w", "halfmoves": 0, "fullmoves": 1, "remainingChecks": null }, "ignoreImpossibleCheck": false } ``` ### Response #### Success Response (200) - **ThreeCheck** (ThreeCheck) - An instance of the ThreeCheck class representing the configured game position. #### Response Example ```json { "board": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "turn": "w", "castles": { "wKingSide": true, "wQueenSide": true, "bKingSide": true, "bQueenSide": true }, "epSquare": null, "halfmoves": 0, "fullmoves": 1, "remainingChecks": 0 } ``` ### Error Handling - **PositionSetupException**: Thrown if the `Setup` object does not meet basic validity requirements. ``` -------------------------------- ### Chess.fromSetup Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Chess/Chess.fromSetup.html Initializes a new Chess instance based on a provided setup configuration. ```APIDOC ## Chess.fromSetup ### Description Sets up a playable Chess position from a provided Setup object. Throws a PositionSetupException if the setup does not meet basic validity requirements. ### Parameters #### Arguments - **setup** (Setup) - Required - The configuration object containing board, pockets, turn, castles, epSquare, halfmoves, and fullmoves. - **ignoreImpossibleCheck** (bool?) - Optional - If true, skips the requirement to check for impossible board states. ### Request Example ```dart final setup = Setup(...); final game = Chess.fromSetup(setup, ignoreImpossibleCheck: true); ``` ``` -------------------------------- ### Crazyhouse.fromSetup Source: https://pub.dev/documentation/dartchess/latest/dartchess/Crazyhouse-class.html Factory constructor to initialize a playable Crazyhouse position from a setup object. ```APIDOC ## Factory: Crazyhouse.fromSetup ### Description Sets up a playable Crazyhouse position from a provided Setup object. ### Parameters - **setup** (Setup) - Required - The setup configuration. - **ignoreImpossibleCheck** (bool?) - Optional - Whether to ignore impossible check states. ``` -------------------------------- ### Crazyhouse.fromSetup Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Crazyhouse/Crazyhouse.fromSetup.html Initializes a new Crazyhouse position based on the provided setup configuration. ```APIDOC ## Crazyhouse.fromSetup ### Description Sets up a playable Crazyhouse position. Throws a PositionSetupException if the Setup does not meet basic validity requirements. ### Parameters #### Arguments - **setup** (Setup) - Required - The configuration object containing board state, pockets, turn, and move counters. #### Named Parameters - **ignoreImpossibleCheck** (bool?) - Optional - If true, skips the requirement to validate impossible check states. ### Implementation ```dart factory Crazyhouse.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = Crazyhouse( board: setup.board.withPromoted(setup.board.promoted .intersect(setup.board.occupied) .diff(setup.board.kings) .diff(setup.board.pawns)), pockets: setup.pockets ?? Pockets.empty, turn: setup.turn, castles: Castles.fromSetup(setup), epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` ``` -------------------------------- ### Create Antichess Position from Setup Source: https://pub.dev/documentation/dartchess/latest/dartchess/Antichess/Antichess.fromSetup.html Use this factory constructor to set up a playable Antichess position from a `Setup` object. It optionally allows skipping validity checks by passing `ignoreImpossibleCheck: true`. Throws `PositionSetupException` if the setup is invalid and checks are not ignored. ```dart factory Antichess.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = Antichess( board: setup.board, pockets: setup.pockets, turn: setup.turn, castles: Castles.empty, epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` -------------------------------- ### Crazyhouse.fromSetup Factory Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Crazyhouse/Crazyhouse.fromSetup.html Sets up a playable Crazyhouse position from a Setup object. Optionally ignores impossible check conditions. Throws PositionSetupException for invalid setups. ```dart factory Crazyhouse.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = Crazyhouse( board: setup.board.withPromoted(setup.board.promoted .intersect(setup.board.occupied) .diff(setup.board.kings) .diff(setup.board.pawns)), pockets: setup.pockets ?? Pockets.empty, turn: setup.turn, castles: Castles.fromSetup(setup), epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` -------------------------------- ### GET /constants/standard Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup/standard-constant.html Retrieves the standard initial chess position configuration. ```APIDOC ## GET /constants/standard ### Description Returns the default initial chess board setup, including piece placement, turn, castling rights, and move counters. ### Method GET ### Endpoint /constants/standard ### Response #### Success Response (200) - **board** (Board) - The standard initial board configuration. - **turn** (Side) - The starting side, set to white. - **castlingRights** (SquareSet) - Initial castling rights for all corners. - **halfmoves** (int) - Initial halfmove count set to 0. - **fullmoves** (int) - Initial fullmove count set to 1. #### Response Example { "board": "Board.standard", "turn": "Side.white", "castlingRights": "SquareSet.corners", "halfmoves": 0, "fullmoves": 1 } ``` -------------------------------- ### Initialize Atomic Position from Setup Source: https://pub.dev/documentation/dartchess/latest/dartchess/Atomic/Atomic.fromSetup.html Creates an Atomic position from a Setup object. Throws a PositionSetupException if the setup is invalid, unless ignoreImpossibleCheck is set to true. ```dart factory Atomic.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = Atomic( board: setup.board, pockets: setup.pockets, turn: setup.turn, castles: Castles.fromSetup(setup), epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` -------------------------------- ### Create Castles Instance from Setup Source: https://pub.dev/documentation/dartchess/latest/dartchess/Castles/Castles.fromSetup.html Use this factory constructor to initialize Castles based on the current board setup and castling rights. It iterates through sides to identify potential castling moves. ```dart factory Castles.fromSetup(Setup setup) { Castles castles = Castles.empty; final rooks = setup.castlingRights & setup.board.rooks; for (final side in Side.values) { final backrank = SquareSet.backrankOf(side); final king = setup.board.kingOf(side); if (king == null || !backrank.has(king)) continue; final backrankRooks = rooks & setup.board.bySide(side) & backrank; if (backrankRooks.first != null && backrankRooks.first! < king) { castles = castles._add(side, CastlingSide.queen, king, backrankRooks.first!) } if (backrankRooks.last != null && king < backrankRooks.last!) { castles = castles._add(side, CastlingSide.king, king, backrankRooks.last!) } } return castles; } ``` -------------------------------- ### RacingKings.fromSetup Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/RacingKings/RacingKings.fromSetup.html Initializes a new RacingKings position from a given setup configuration. ```APIDOC ## RacingKings.fromSetup ### Description Sets up a playable RacingKings position. Throws a PositionSetupException if the Setup does not meet basic validity requirements. ### Parameters #### Arguments - **setup** (Setup) - Required - The configuration object containing board, turn, halfmoves, and fullmoves data. - **ignoreImpossibleCheck** (bool) - Optional - If true, skips the impossible check validation requirement. ### Implementation ```dart factory RacingKings.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = RacingKings( board: setup.board, turn: setup.turn, castles: Castles.empty, halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` ``` -------------------------------- ### Get Initial Position for Chess Rule Source: https://pub.dev/documentation/dartchess/latest/dartchess/Position/initialPosition.html Use this method to retrieve the starting board state for a given chess rule. Ensure the Rule enum is imported. ```dart static Position initialPosition(Rule rule) { switch (rule) { case Rule.chess: return Chess.initial; case Rule.antichess: return Antichess.initial; case Rule.atomic: return Atomic.initial; case Rule.kingofthehill: return KingOfTheHill.initial; case Rule.threecheck: return ThreeCheck.initial; case Rule.crazyhouse: return Crazyhouse.initial; case Rule.horde: return Horde.initial; case Rule.racingKings: return RacingKings.initial; } } ``` -------------------------------- ### KingOfTheHill.fromSetup Factory Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/KingOfTheHill/KingOfTheHill.fromSetup.html Sets up a playable KingOfTheHill position from a Setup object. Throws PositionSetupException for invalid setups. Optionally ignores impossible check validation. ```dart factory KingOfTheHill.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = KingOfTheHill( board: setup.board, pockets: setup.pockets, turn: setup.turn, castles: Castles.fromSetup(setup), epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` -------------------------------- ### Atomic.fromSetup Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Atomic/Atomic.fromSetup.html Initializes a playable Atomic position from a Setup object with optional validation settings. ```APIDOC ## Atomic.fromSetup ### Description Sets up a playable Atomic position. Throws a PositionSetupException if the Setup does not meet basic validity requirements. ### Parameters #### Arguments - **setup** (Setup) - Required - The configuration object containing board, pockets, turn, and move data. #### Named Parameters - **ignoreImpossibleCheck** (bool?) - Optional - If true, skips the impossible check requirement during validation. ### Implementation ```dart factory Atomic.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = Atomic( board: setup.board, pockets: setup.pockets, turn: setup.turn, castles: Castles.fromSetup(setup), epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` ``` -------------------------------- ### static Position setupPosition Source: https://pub.dev/documentation/dartchess/latest/dartchess/Position/setupPosition.html Creates a Position object from a provided Setup and Rule configuration. ```APIDOC ## static Position setupPosition ### Description Creates a Position from a Setup and Rule. This method handles the instantiation of specific chess variants based on the provided rule set. ### Parameters - **rule** (Rule) - Required - The chess rule set to apply (e.g., chess, antichess, atomic, etc.). - **setup** (Setup) - Required - The configuration setup for the board. - **ignoreImpossibleCheck** (bool?) - Optional - Flag to ignore impossible check states during position creation. ### Response - **Position** - Returns a new Position instance corresponding to the selected rule set. ``` -------------------------------- ### Position Static Methods Source: https://pub.dev/documentation/dartchess/latest/dartchess/Position-class.html Details the static methods for creating initial or setup positions. ```APIDOC ## Static Methods ### initialPosition ```dart initialPosition(Rule rule) ``` Returns the initial Position for the corresponding Rule. ### setupPosition ```dart setupPosition(Rule rule, Setup setup, {bool? ignoreImpossibleCheck}) ``` Create a Position from a Setup and Rule. ``` -------------------------------- ### Chess Class Constructors Source: https://pub.dev/documentation/dartchess/latest/dartchess/Chess-class.html Details on how to create new Chess instances, either from scratch or from a setup configuration. ```APIDOC ## Chess Constructor ### Description Creates a new Chess position with specified board, turn, castling rights, en passant square, and move counters. ### Parameters - **board** (Board) - Required - Piece positions on the board. - **pockets** (Pockets?) - Optional - Pockets for chess variants like Crazyhouse. - **turn** (Side) - Required - The side to move. - **castles** (Castles) - Required - Castling rights and unmoved rooks. - **epSquare** (Square?) - Optional - The en passant target square. - **halfmoves** (int) - Required - Number of half-moves since the last capture or pawn move. - **fullmoves** (int) - Required - Current move number. ### Request Example ```dart var chess = Chess(board: board, pockets: pockets, turn: Side.white, castles: castles, epSquare: epSquare, halfmoves: 0, fullmoves: 1); ``` ## Chess.fromSetup Constructor ### Description Sets up a playable Chess position from a given Setup configuration. Optionally ignores impossible check conditions. ### Parameters - **setup** (Setup) - Required - The setup configuration for the chess position. - **ignoreImpossibleCheck** (bool?) - Optional - If true, ignores impossible check conditions during setup. ### Request Example ```dart var chess = Chess.fromSetup(setup); ``` ``` -------------------------------- ### Define PositionSetupException.empty constant Source: https://pub.dev/documentation/dartchess/latest/dartchess/PositionSetupException/empty-constant.html Represents an exception caused by an empty setup state. ```dart static const empty = PositionSetupException(IllegalSetupCause.empty); ``` -------------------------------- ### Implement Setup.parseFen constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup/Setup.parseFen.html This factory constructor parses a FEN string into a Setup object, throwing a FenException if the input format is invalid. ```dart factory Setup.parseFen(String fen) { final parts = fen.split(RegExp(r'[\s_]+')); if (parts.isEmpty) throw const FenException(IllegalFenCause.format); // board and pockets final boardPart = parts.removeAt(0); Pockets? pockets; Board board; if (boardPart.endsWith(']')) { final pocketStart = boardPart.indexOf('['); if (pocketStart == -1) { throw const FenException(IllegalFenCause.format); } board = Board.parseFen(boardPart.substring(0, pocketStart)); pockets = _parsePockets( boardPart.substring(pocketStart + 1, boardPart.length - 1)); } else { final pocketStart = _nthIndexOf(boardPart, '/', 7); if (pocketStart == -1) { board = Board.parseFen(boardPart); } else { board = Board.parseFen(boardPart.substring(0, pocketStart)); pockets = _parsePockets(boardPart.substring(pocketStart + 1)); } } // turn Side turn; if (parts.isEmpty) { turn = Side.white; } else { final turnPart = parts.removeAt(0); if (turnPart == 'w') { turn = Side.white; } else if (turnPart == 'b') { turn = Side.black; } else { throw const FenException(IllegalFenCause.turn); } } // Castling SquareSet castlingRights; if (parts.isEmpty) { castlingRights = SquareSet.empty; } else { final castlingPart = parts.removeAt(0); castlingRights = _parseCastlingFen(board, castlingPart); } // En passant square Square? epSquare; if (parts.isNotEmpty) { final epPart = parts.removeAt(0); if (epPart != '-') { epSquare = Square.parse(epPart); if (epSquare == null) { throw const FenException(IllegalFenCause.enPassant); } } } // move counters or remainingChecks String? halfmovePart = parts.isNotEmpty ? parts.removeAt(0) : null; (int, int)? earlyRemainingChecks; if (halfmovePart != null && halfmovePart.contains('+')) { earlyRemainingChecks = _parseRemainingChecks(halfmovePart); halfmovePart = parts.isNotEmpty ? parts.removeAt(0) : null; } final halfmoves = halfmovePart != null ? _parseSmallUint(halfmovePart) : 0; if (halfmoves == null) { throw const FenException(IllegalFenCause.halfmoveClock); } final fullmovesPart = parts.isNotEmpty ? parts.removeAt(0) : null; final fullmoves = fullmovesPart != null ? _parseSmallUint(fullmovesPart) : 1; if (fullmoves == null) { throw const FenException(IllegalFenCause.fullmoveNumber); } final remainingChecksPart = parts.isNotEmpty ? parts.removeAt(0) : null; (int, int)? remainingChecks; if (remainingChecksPart != null) { if (earlyRemainingChecks != null) { throw const FenException(IllegalFenCause.remainingChecks); } remainingChecks = _parseRemainingChecks(remainingChecksPart); } else if (earlyRemainingChecks != null) { remainingChecks = earlyRemainingChecks; } if (parts.isNotEmpty) { throw const FenException(IllegalFenCause.format); } return Setup( board: board, pockets: pockets, turn: turn, castlingRights: castlingRights, epSquare: epSquare, halfmoves: halfmoves, fullmoves: fullmoves, remainingChecks: remainingChecks, ); } ``` -------------------------------- ### operator == method Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup/operator_equals.html Defines the equality relation for the Setup class by comparing board state properties. ```APIDOC ## operator == ### Description Overrides the default equality operator to compare two Setup objects based on their internal state (board, turn, castling rights, en passant square, and move counters). ### Method Operator Overload ### Parameters #### Path Parameters - **other** (Object) - Required - The object to compare against the current instance. ### Implementation ```dart @override bool operator ==(Object other) { return identical(this, other) || other is Setup && other.board == board && other.turn == turn && other.castlingRights == castlingRights && other.epSquare == epSquare && other.halfmoves == halfmoves && other.fullmoves == fullmoves; } ``` ### Response - **bool** - Returns true if the objects are identical or if all relevant state properties match. ``` -------------------------------- ### Define Crazyhouse Initial Position Source: https://pub.dev/documentation/dartchess/latest/dartchess/Crazyhouse/initial-constant.html Use this constant to initialize a Crazyhouse game with the standard starting setup. It defines the board, empty pockets, white's turn, standard castling rights, and initial move counts. ```dart static const initial = Crazyhouse( board: Board.standard, pockets: Pockets.empty, turn: Side.white, castles: Castles.standard, halfmoves: 0, fullmoves: 1, ); ``` -------------------------------- ### KingOfTheHill Initial Constant Source: https://pub.dev/documentation/dartchess/latest/dartchess/KingOfTheHill/initial-constant.html Defines the starting configuration for a KingOfTheHill game instance. ```APIDOC ## KingOfTheHill.initial ### Description Represents the starting state of a KingOfTheHill game, initializing the board, turn, castling rights, and move counters. ### Implementation ```dart static const initial = KingOfTheHill( board: Board.standard, turn: Side.white, castles: Castles.standard, halfmoves: 0, fullmoves: 1, ); ``` ``` -------------------------------- ### Get FEN String - DartChess Source: https://pub.dev/documentation/dartchess/latest/dartchess/Position/fen.html Retrieves the FEN string for the current chess position. This method ensures the position is legal, unlike FEN from direct setup. It requires the board, pockets, turn, castling rights, en passant square, halfmove clock, and fullmove number. ```dart String get fen { return Setup( board: board, pockets: pockets, turn: turn, castlingRights: castles.castlingRights, epSquare: _legalEpSquare(), halfmoves: halfmoves, fullmoves: fullmoves, ).fen; } ``` -------------------------------- ### PositionSetupException.variant Constant Source: https://pub.dev/documentation/dartchess/latest/dartchess/PositionSetupException/variant-constant.html Provides the static constant for identifying illegal setup causes related to chess variants. ```APIDOC ## Constant: PositionSetupException.variant ### Description A static constant representing a PositionSetupException triggered by an illegal chess variant configuration. ### Implementation ```dart static const variant = PositionSetupException(IllegalSetupCause.variant); ``` ``` -------------------------------- ### ThreeCheck Initial Constant Source: https://pub.dev/documentation/dartchess/latest/dartchess/ThreeCheck/initial-constant.html The 'initial' constant defines the standard starting position for a ThreeCheck game. ```APIDOC ## ThreeCheck Initial Constant ### Description The initial position of a ThreeCheck game. ### Implementation ```dart static const initial = ThreeCheck( board: Board.standard, turn: Side.white, castles: Castles.standard, halfmoves: 0, fullmoves: 1, remainingChecks: _defaultRemainingChecks, ); ``` ``` -------------------------------- ### Horde.fromSetup Factory Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Horde/Horde.fromSetup.html Sets up a playable Horde position. Optionally pass `ignoreImpossibleCheck` to skip validity requirements. ```APIDOC ## Horde.fromSetup Factory Constructor ### Description Sets up a playable Horde position. Throws a PositionSetupException if the Setup does not meet basic validity requirements. Optionally pass `ignoreImpossibleCheck` if you want to skip that requirement. ### Method Factory Constructor ### Endpoint N/A (Dart Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```dart // Example usage (assuming Setup class is defined elsewhere) // final setup = Setup(...); // final hordePosition = Horde.fromSetup(setup, ignoreImpossibleCheck: true); ``` ### Response #### Success Response (Instance of Horde) - **Horde** (Instance) - A new Horde position object. #### Response Example ```dart // Example of a successful response (Horde object) // Horde(board: ..., turn: ..., ...) ``` ### Error Handling - **PositionSetupException**: Thrown if the `Setup` does not meet basic validity requirements. ``` -------------------------------- ### Setup.parseFen Factory Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup/Setup.parseFen.html Parses a Forsyth-Edwards-Notation string and returns a Setup object. The parser is relaxed and supports X-FEN, Shredder-FEN, and handles missing fields with default values. ```APIDOC ## Setup.parseFen Factory Constructor ### Description Parses a Forsyth-Edwards-Notation string and returns a Setup object. The parser is relaxed, supporting X-FEN and Shredder-FEN for castling rights, and accepting missing FEN fields by filling them with default values. ### Method Factory Constructor ### Parameters #### Path Parameters - **fen** (String) - Required - The Forsyth-Edwards-Notation string to parse. ### Request Example ```json { "fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" } ``` ### Response #### Success Response (Setup Object) - **board** (Board) - The board state. - **pockets** (Pockets) - The pockets state (optional). - **turn** (Side) - The current turn (white or black). - **castlingRights** (SquareSet) - The castling rights. - **epSquare** (Square) - The en passant square (optional). - **halfmoves** (int) - The halfmove clock. - **fullmoves** (int) - The fullmove number. - **remainingChecks** (Tuple) - The remaining checks (optional). #### Response Example ```json { "board": { ... }, "pockets": { ... }, "turn": "white", "castlingRights": { ... }, "epSquare": null, "halfmoves": 0, "fullmoves": 1, "remainingChecks": null } ``` ### Throws - **FenException** - If the provided FEN string is not valid, with specific causes like `IllegalFenCause.format`, `IllegalFenCause.turn`, `IllegalFenCause.enPassant`, `IllegalFenCause.halfmoveClock`, `IllegalFenCause.fullmoveNumber`, or `IllegalFenCause.remainingChecks`. ``` -------------------------------- ### RacingKings Initial Constant Source: https://pub.dev/documentation/dartchess/latest/dartchess/RacingKings/initial-constant.html Defines the starting configuration for a RacingKings game, including board state, turn, and move counters. ```APIDOC ## RacingKings Initial Constant ### Description Represents the starting position of a RacingKings game. ### Implementation ```dart static const initial = RacingKings( board: Board.racingKings, turn: Side.white, castles: Castles.empty, halfmoves: 0, fullmoves: 1, ); ``` ``` -------------------------------- ### Side get opposite Source: https://pub.dev/documentation/dartchess/latest/dartchess/Side/opposite.html Gets the opposite side (e.g., if the current side is white, it returns black, and vice versa). ```APIDOC ## Side get opposite ### Description Gets the opposite side. ### Implementation ```dart Side get opposite => this == Side.white ? Side.black : Side.white; ``` ``` -------------------------------- ### Static Method: startingPosition Source: https://pub.dev/documentation/dartchess/latest/dartchess/PgnGame-class.html Creates a chess position from PGN headers. ```APIDOC ## Static Method: startingPosition ### Description Creates a Position object for a variant based on the provided PGN headers. ### Parameters #### Query Parameters - **headers** (PgnHeaders) - Required - The headers of the game. - **ignoreImpossibleCheck** (bool) - Optional - Flag to ignore impossible check states. ### Response #### Success Response (200) - **Position** - The initialized chess position. ``` -------------------------------- ### Get Material Count by Role Source: https://pub.dev/documentation/dartchess/latest/dartchess/Board/materialCount.html Gets the number of pieces of each Role for the given Side. This implementation efficiently maps each role to its count. ```dart IMap materialCount(Side side) => IMap.fromEntries( Role.values.map((role) => MapEntry(role, piecesOf(side, role).size))); ``` -------------------------------- ### Get UCI Notation for a Move Source: https://pub.dev/documentation/dartchess/latest/dartchess/NormalMove/uci.html Returns the UCI notation for a chess move. Use this to get a standardized string representation of a move, including promotions. ```dart @override String get uci => from.name + to.name + (promotion != null ? promotion!.letter : ''); ``` -------------------------------- ### File Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/File/File.html Initializes a new File object representing a chessboard file index. ```APIDOC ## File Constructor ### Description Gets the chessboard File from a file index between 0 and 7. ### Parameters #### Path Parameters - **value** (int) - Required - A file index between 0 and 7. ### Request Example const File(0); ``` -------------------------------- ### Create Empty PgnHeaders Source: https://pub.dev/documentation/dartchess/latest/dartchess/PgnGame/emptyHeaders.html Use this static method to create an empty map for PGN headers. No setup is required. ```dart static PgnHeaders emptyHeaders() => {}; ``` -------------------------------- ### Get Role Letter Source: https://pub.dev/documentation/dartchess/latest/dartchess/Role/letter.html Gets the role letter in lowercase, as used for black pieces in FEN notation. This getter maps each Role enum value to its corresponding character. ```dart String get letter => switch (this) { Role.pawn => 'p', Role.knight => 'n', Role.bishop => 'b', Role.rook => 'r', Role.queen => 'q', Role.king => 'k', }; ``` -------------------------------- ### Get Piece at Square - DartChess Source: https://pub.dev/documentation/dartchess/latest/dartchess/Board/pieceAt.html Use this method to get the Piece at a specific Square. It returns null if no piece is present. Requires sideAt and roleAt methods to be available. ```dart Piece? pieceAt(Square square) { final side = sideAt(square); if (side == null) { return null; } final role = roleAt(square)!; final prom = promoted.has(square); return Piece(color: side, role: role, promoted: prom); } ``` -------------------------------- ### Get Rook Square by Side and Castling Side Source: https://pub.dev/documentation/dartchess/latest/dartchess/Castles/rookOf.html Use this method to get the Square of a specific rook. It requires the side (white/black) and castling side (queen/king) to identify the rook. ```dart Square? rookOf(Side side, CastlingSide cs) => switch (side) { Side.white => switch (cs) { CastlingSide.queen => _whiteRookQueenSide, CastlingSide.king => _whiteRookKingSide, }, Side.black => switch (cs) { CastlingSide.queen => _blackRookQueenSide, CastlingSide.king => _blackRookKingSide, }, }; ``` -------------------------------- ### Implement withPromotion Method Source: https://pub.dev/documentation/dartchess/latest/dartchess/NormalMove/withPromotion.html Returns a copy of the move with a specified promotion role. Use when a pawn promotes to another piece. ```dart NormalMove withPromotion(Role? promotion) => NormalMove(from: from, to: to, promotion: promotion); ``` -------------------------------- ### Antichess.fromSetup Factory Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/Antichess/Antichess.fromSetup.html This factory constructor creates an Antichess position from a `Setup` object. It optionally accepts `ignoreImpossibleCheck` to bypass basic validity requirements. ```APIDOC ## Antichess.fromSetup ### Description Sets up a playable Antichess position from a `Setup` object. Throws a `PositionSetupException` if the `Setup` does not meet basic validity requirements. Optionally pass `ignoreImpossibleCheck` if you want to skip that requirement. ### Method Factory Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) An `Antichess` object representing the configured position. #### Response Example None ### Implementation Details ```dart factory Antichess.fromSetup(Setup setup, {bool? ignoreImpossibleCheck}) { final pos = Antichess( board: setup.board, pockets: setup.pockets, turn: setup.turn, castles: Castles.empty, epSquare: _validEpSquare(setup), halfmoves: setup.halfmoves, fullmoves: setup.fullmoves, ); pos.validate(ignoreImpossibleCheck: ignoreImpossibleCheck); return pos; } ``` ``` -------------------------------- ### GET /rule Source: https://pub.dev/documentation/dartchess/latest/dartchess/Position/rule.html Retrieves the rule associated with the current position. ```APIDOC ## GET /rule ### Description Retrieves the rule of the current position. ### Method GET ### Endpoint /rule ### Implementation Rule get rule; ``` -------------------------------- ### Create Position from PGN Headers Source: https://pub.dev/documentation/dartchess/latest/dartchess/PgnGame/startingPosition.html Use this static method to create a chess position from PGN headers. It supports 'Variant' and 'Fen' keys. Throws `PositionSetupException` if the setup is invalid. Ensure the 'Variant' header is present. ```dart static Position startingPosition(PgnHeaders headers, {bool? ignoreImpossibleCheck}) { final rule = Rule.fromPgn(headers['Variant']); if (rule == null) throw PositionSetupException.variant; if (!headers.containsKey('FEN')) { return Position.initialPosition(rule); } final fen = headers['FEN']!; try { return Position.setupPosition(rule, Setup.parseFen(fen), ignoreImpossibleCheck: ignoreImpossibleCheck); } catch (err) { rethrow; } } ``` -------------------------------- ### GET bySide Source: https://pub.dev/documentation/dartchess/latest/dartchess/Board/bySide.html Retrieves all squares occupied by the specified side. ```APIDOC ## GET bySide ### Description Gets all squares occupied by the specified Side (white or black). ### Method GET ### Parameters #### Path Parameters - **side** (Side) - Required - The side to query (Side.white or Side.black). ### Request Example bySide(Side.white) ### Response #### Success Response (200) - **SquareSet** - A set of squares occupied by the requested side. ``` -------------------------------- ### GET squaresReversed Source: https://pub.dev/documentation/dartchess/latest/dartchess/SquareSet/squaresReversed.html Retrieves the squares in the set as an iterable in reverse order. ```APIDOC ## GET squaresReversed ### Description Returns the squares in the set as an iterable in reverse order. ### Method GET ### Endpoint squaresReversed ### Response - **Iterable** - An iterable containing the squares in reverse order. ``` -------------------------------- ### GET size property Source: https://pub.dev/documentation/dartchess/latest/dartchess/SquareSet/size.html Retrieves the number of squares currently in the set. ```APIDOC ## GET size ### Description Returns the total number of squares in the set. ### Method GET ### Endpoint /size ### Response #### Success Response (200) - **size** (int) - The number of squares in the set. ``` -------------------------------- ### GET /isNotEmpty Source: https://pub.dev/documentation/dartchess/latest/dartchess/SquareSet/isNotEmpty.html Retrieves the boolean status indicating if the set is not empty. ```APIDOC ## GET /isNotEmpty ### Description Returns a boolean value indicating whether the set is not empty. ### Method GET ### Endpoint /isNotEmpty ### Response #### Success Response (200) - **isNotEmpty** (bool) - Returns true if the set is not empty, false otherwise. ``` -------------------------------- ### Create a Position using setupPosition Source: https://pub.dev/documentation/dartchess/latest/dartchess/Position/setupPosition.html Initializes a game position by mapping a Rule to its corresponding variant implementation. ```dart static Position setupPosition(Rule rule, Setup setup, {bool? ignoreImpossibleCheck}) { switch (rule) { case Rule.chess: return Chess.fromSetup(setup, ignoreImpossibleCheck: ignoreImpossibleCheck); case Rule.antichess: return Antichess.fromSetup(setup, ignoreImpossibleCheck: ignoreImpossibleCheck); case Rule.atomic: return Atomic.fromSetup(setup, ignoreImpossibleCheck: ignoreImpossibleCheck); case Rule.kingofthehill: return KingOfTheHill.fromSetup(setup, ignoreImpossibleCheck: ignoreImpossibleCheck); case Rule.crazyhouse: return Crazyhouse.fromSetup(setup, ignoreImpossibleCheck: ignoreImpossibleCheck); case Rule.threecheck: return ThreeCheck.fromSetup(setup, ignoreImpossibleCheck: ignoreImpossibleCheck); case Rule.horde: return Horde.fromSetup(setup, ignoreImpossibleCheck: ignoreImpossibleCheck); case Rule.racingKings: return RacingKings.fromSetup(setup, ignoreImpossibleCheck: ignoreImpossibleCheck); } } ``` -------------------------------- ### KingOfTheHill.fromSetup Factory Constructor Source: https://pub.dev/documentation/dartchess/latest/dartchess/KingOfTheHill/KingOfTheHill.fromSetup.html Creates a playable KingOfTheHill position from a given setup. It includes an optional parameter to ignore impossible check validations. ```APIDOC ## KingOfTheHill.fromSetup Factory Constructor ### Description Sets up a playable KingOfTheHill position. Throws a PositionSetupException if the Setup does not meet basic validity requirements. Optionally pass `ignoreImpossibleCheck` if you want to skip that requirement. ### Method Factory Constructor ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **KingOfTheHill** (object) - An instance of the KingOfTheHill class representing the setup position. #### Response Example ```dart // Example usage (assuming Setup class is defined elsewhere) // final setup = Setup(...); // final kingOfTheHillGame = KingOfTheHill.fromSetup(setup, ignoreImpossibleCheck: true); ``` ``` -------------------------------- ### Initialize File with index Source: https://pub.dev/documentation/dartchess/latest/dartchess/File/File.html Creates a File object using an integer index. The index must be between 0 and 7 inclusive. ```dart const File(this.value) : assert(value >= 0 && value < 8); ``` -------------------------------- ### GET turnLetter property Source: https://pub.dev/documentation/dartchess/latest/dartchess/Setup/turnLetter.html Retrieves the FEN character for the side to move. ```APIDOC ## GET turnLetter ### Description Returns the FEN character representing the side currently to move. ### Method GET ### Response - **turnLetter** (String) - The FEN character for the side to move (e.g., 'w' or 'b'). ```