From e26b3f1745add303a3cb7ec7931387e9d886ffc9 Mon Sep 17 00:00:00 2001 From: docs-bot Date: Fri, 11 Jul 2025 03:15:58 +0000 Subject: [PATCH] Bot: update driver docs for commit: 197fc61 --- driver_docs/LICENSE.driver.md | 2 - driver_docs/Makefile.driver.md | 2 - driver_docs/README.md.driver.md | 2 - driver_docs/c_cpp_export_test/LICENSE.md | 12 + driver_docs/c_cpp_export_test/Makefile.md | 12 + driver_docs/c_cpp_export_test/README.md | 18 + .../c_cpp_export_test/cpp_src/README.md | 37 + .../c_cpp_export_test/cpp_src/bishop.cpp.md | 93 ++ .../c_cpp_export_test/cpp_src/bishop.h.md | 36 + .../c_cpp_export_test/cpp_src/board.cpp.md | 186 ++++ .../c_cpp_export_test/cpp_src/board.h.md | 41 + .../c_cpp_export_test/cpp_src/game.cpp.md | 136 +++ .../c_cpp_export_test/cpp_src/game.h.md | 42 + .../c_cpp_export_test/cpp_src/king.cpp.md | 97 ++ .../c_cpp_export_test/cpp_src/king.h.md | 35 + .../c_cpp_export_test/cpp_src/knight.cpp.md | 96 ++ .../c_cpp_export_test/cpp_src/knight.h.md | 38 + .../c_cpp_export_test/cpp_src/main.cpp.md | 42 + .../c_cpp_export_test/cpp_src/pawn.cpp.md | 136 +++ .../c_cpp_export_test/cpp_src/pawn.h.md | 40 + .../c_cpp_export_test/cpp_src/piece.cpp.md | 134 +++ .../c_cpp_export_test/cpp_src/piece.h.md | 43 + .../c_cpp_export_test/cpp_src/player.cpp.md | 170 ++++ .../c_cpp_export_test/cpp_src/player.h.md | 47 + .../c_cpp_export_test/cpp_src/queen.cpp.md | 92 ++ .../c_cpp_export_test/cpp_src/queen.h.md | 36 + .../cpp_src/restrictedPiece.cpp.md | 82 ++ .../cpp_src/restrictedPiece.h.md | 35 + .../c_cpp_export_test/cpp_src/rook.cpp.md | 95 ++ .../c_cpp_export_test/cpp_src/rook.h.md | 36 + .../c_cpp_export_test/cpp_src/square.cpp.md | 114 +++ .../c_cpp_export_test/cpp_src/square.h.md | 32 + .../c_cpp_export_test/include/README.md | 13 + .../include/chesslib/README.md | 21 + .../include/chesslib/board.h.md | 207 +++++ .../include/chesslib/boardlist.h.md | 103 +++ .../include/chesslib/chess.h.md | 336 +++++++ .../include/chesslib/move.h.md | 87 ++ .../include/chesslib/movelist.h.md | 113 +++ .../include/chesslib/piece.h.md | 111 +++ .../include/chesslib/piecemoves.h.md | 126 +++ .../include/chesslib/square.h.md | 103 +++ .../include/chesslib/squareset.h.md | 43 + driver_docs/c_cpp_export_test/src/README.md | 16 + .../c_cpp_export_test/src/chesslib/README.md | 21 + .../c_cpp_export_test/src/chesslib/board.c.md | 349 ++++++++ .../src/chesslib/boardlist.c.md} | 71 +- .../src/chesslib/chess.c.md} | 286 +++--- .../c_cpp_export_test/src/chesslib/move.c.md | 106 +++ .../src/chesslib/movelist.c.md} | 60 +- .../src/chesslib/piece.c.md} | 59 +- .../src/chesslib/piecemoves.c.md | 273 ++++++ .../src/chesslib/square.c.md | 127 +++ .../src/chesslib/squareset.c.md | 57 ++ driver_docs/c_cpp_export_test/src/tests.c.md | 794 ++++++++++++++++ driver_docs/c_cpp_export_test/src/tests.h.md | 278 ++++++ driver_docs/cpp_src.driver.md | 27 - driver_docs/cpp_src/bishop.cpp.driver.md | 91 -- driver_docs/cpp_src/bishop.h.driver.md | 26 - driver_docs/cpp_src/board.cpp.driver.md | 188 ---- driver_docs/cpp_src/board.h.driver.md | 33 - driver_docs/cpp_src/game.cpp.driver.md | 133 --- driver_docs/cpp_src/game.h.driver.md | 34 - driver_docs/cpp_src/king.cpp.driver.md | 94 -- driver_docs/cpp_src/king.h.driver.md | 27 - driver_docs/cpp_src/knight.cpp.driver.md | 95 -- driver_docs/cpp_src/knight.h.driver.md | 26 - driver_docs/cpp_src/main.cpp.driver.md | 30 - driver_docs/cpp_src/pawn.cpp.driver.md | 136 --- driver_docs/cpp_src/pawn.h.driver.md | 30 - driver_docs/cpp_src/piece.cpp.driver.md | 138 --- driver_docs/cpp_src/piece.h.driver.md | 33 - driver_docs/cpp_src/player.cpp.driver.md | 175 ---- driver_docs/cpp_src/player.h.driver.md | 37 - driver_docs/cpp_src/queen.cpp.driver.md | 92 -- driver_docs/cpp_src/queen.h.driver.md | 26 - .../cpp_src/restrictedPiece.cpp.driver.md | 80 -- .../cpp_src/restrictedPiece.h.driver.md | 25 - driver_docs/cpp_src/rook.cpp.driver.md | 94 -- driver_docs/cpp_src/rook.h.driver.md | 28 - driver_docs/cpp_src/square.cpp.driver.md | 118 --- driver_docs/cpp_src/square.h.driver.md | 22 - driver_docs/include.driver.md | 3 - driver_docs/include/chesslib.driver.md | 11 - .../include/chesslib/board.h.driver.md | 237 ----- .../include/chesslib/boardlist.h.driver.md | 117 --- .../include/chesslib/chess.h.driver.md | 385 -------- driver_docs/include/chesslib/move.h.driver.md | 86 -- .../include/chesslib/movelist.h.driver.md | 127 --- .../include/chesslib/piece.h.driver.md | 101 --- .../include/chesslib/piecemoves.h.driver.md | 183 ---- .../include/chesslib/square.h.driver.md | 102 --- .../include/chesslib/squareset.h.driver.md | 33 - driver_docs/src.driver.md | 6 - driver_docs/src/chesslib.driver.md | 11 - driver_docs/src/chesslib/board.c.driver.md | 350 -------- driver_docs/src/chesslib/move.c.driver.md | 101 --- .../src/chesslib/piecemoves.c.driver.md | 274 ------ driver_docs/src/chesslib/square.c.driver.md | 124 --- .../src/chesslib/squareset.c.driver.md | 48 - driver_docs/src/tests.c.driver.md | 847 ------------------ driver_docs/src/tests.h.driver.md | 295 ------ 102 files changed, 5529 insertions(+), 5529 deletions(-) delete mode 100644 driver_docs/LICENSE.driver.md delete mode 100644 driver_docs/Makefile.driver.md delete mode 100644 driver_docs/README.md.driver.md create mode 100644 driver_docs/c_cpp_export_test/LICENSE.md create mode 100644 driver_docs/c_cpp_export_test/Makefile.md create mode 100644 driver_docs/c_cpp_export_test/README.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/README.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/bishop.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/bishop.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/board.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/board.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/game.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/game.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/king.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/king.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/knight.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/knight.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/main.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/pawn.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/pawn.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/piece.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/piece.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/player.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/player.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/queen.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/queen.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/restrictedPiece.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/restrictedPiece.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/rook.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/rook.h.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/square.cpp.md create mode 100644 driver_docs/c_cpp_export_test/cpp_src/square.h.md create mode 100644 driver_docs/c_cpp_export_test/include/README.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/README.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/board.h.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/boardlist.h.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/chess.h.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/move.h.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/movelist.h.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/piece.h.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/piecemoves.h.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/square.h.md create mode 100644 driver_docs/c_cpp_export_test/include/chesslib/squareset.h.md create mode 100644 driver_docs/c_cpp_export_test/src/README.md create mode 100644 driver_docs/c_cpp_export_test/src/chesslib/README.md create mode 100644 driver_docs/c_cpp_export_test/src/chesslib/board.c.md rename driver_docs/{src/chesslib/boardlist.c.driver.md => c_cpp_export_test/src/chesslib/boardlist.c.md} (50%) rename driver_docs/{src/chesslib/chess.c.driver.md => c_cpp_export_test/src/chesslib/chess.c.md} (50%) create mode 100644 driver_docs/c_cpp_export_test/src/chesslib/move.c.md rename driver_docs/{src/chesslib/movelist.c.driver.md => c_cpp_export_test/src/chesslib/movelist.c.md} (53%) rename driver_docs/{src/chesslib/piece.c.driver.md => c_cpp_export_test/src/chesslib/piece.c.md} (54%) create mode 100644 driver_docs/c_cpp_export_test/src/chesslib/piecemoves.c.md create mode 100644 driver_docs/c_cpp_export_test/src/chesslib/square.c.md create mode 100644 driver_docs/c_cpp_export_test/src/chesslib/squareset.c.md create mode 100644 driver_docs/c_cpp_export_test/src/tests.c.md create mode 100644 driver_docs/c_cpp_export_test/src/tests.h.md delete mode 100644 driver_docs/cpp_src.driver.md delete mode 100644 driver_docs/cpp_src/bishop.cpp.driver.md delete mode 100644 driver_docs/cpp_src/bishop.h.driver.md delete mode 100644 driver_docs/cpp_src/board.cpp.driver.md delete mode 100644 driver_docs/cpp_src/board.h.driver.md delete mode 100644 driver_docs/cpp_src/game.cpp.driver.md delete mode 100644 driver_docs/cpp_src/game.h.driver.md delete mode 100644 driver_docs/cpp_src/king.cpp.driver.md delete mode 100644 driver_docs/cpp_src/king.h.driver.md delete mode 100644 driver_docs/cpp_src/knight.cpp.driver.md delete mode 100644 driver_docs/cpp_src/knight.h.driver.md delete mode 100644 driver_docs/cpp_src/main.cpp.driver.md delete mode 100644 driver_docs/cpp_src/pawn.cpp.driver.md delete mode 100644 driver_docs/cpp_src/pawn.h.driver.md delete mode 100644 driver_docs/cpp_src/piece.cpp.driver.md delete mode 100644 driver_docs/cpp_src/piece.h.driver.md delete mode 100644 driver_docs/cpp_src/player.cpp.driver.md delete mode 100644 driver_docs/cpp_src/player.h.driver.md delete mode 100644 driver_docs/cpp_src/queen.cpp.driver.md delete mode 100644 driver_docs/cpp_src/queen.h.driver.md delete mode 100644 driver_docs/cpp_src/restrictedPiece.cpp.driver.md delete mode 100644 driver_docs/cpp_src/restrictedPiece.h.driver.md delete mode 100644 driver_docs/cpp_src/rook.cpp.driver.md delete mode 100644 driver_docs/cpp_src/rook.h.driver.md delete mode 100644 driver_docs/cpp_src/square.cpp.driver.md delete mode 100644 driver_docs/cpp_src/square.h.driver.md delete mode 100644 driver_docs/include.driver.md delete mode 100644 driver_docs/include/chesslib.driver.md delete mode 100644 driver_docs/include/chesslib/board.h.driver.md delete mode 100644 driver_docs/include/chesslib/boardlist.h.driver.md delete mode 100644 driver_docs/include/chesslib/chess.h.driver.md delete mode 100644 driver_docs/include/chesslib/move.h.driver.md delete mode 100644 driver_docs/include/chesslib/movelist.h.driver.md delete mode 100644 driver_docs/include/chesslib/piece.h.driver.md delete mode 100644 driver_docs/include/chesslib/piecemoves.h.driver.md delete mode 100644 driver_docs/include/chesslib/square.h.driver.md delete mode 100644 driver_docs/include/chesslib/squareset.h.driver.md delete mode 100644 driver_docs/src.driver.md delete mode 100644 driver_docs/src/chesslib.driver.md delete mode 100644 driver_docs/src/chesslib/board.c.driver.md delete mode 100644 driver_docs/src/chesslib/move.c.driver.md delete mode 100644 driver_docs/src/chesslib/piecemoves.c.driver.md delete mode 100644 driver_docs/src/chesslib/square.c.driver.md delete mode 100644 driver_docs/src/chesslib/squareset.c.driver.md delete mode 100644 driver_docs/src/tests.c.driver.md delete mode 100644 driver_docs/src/tests.h.driver.md diff --git a/driver_docs/LICENSE.driver.md b/driver_docs/LICENSE.driver.md deleted file mode 100644 index f37ca27..0000000 --- a/driver_docs/LICENSE.driver.md +++ /dev/null @@ -1,2 +0,0 @@ -# Purpose -The provided content is a software license known as the MIT License, which is a permissive free software license. It grants users broad rights to use, copy, modify, merge, publish, distribute, sublicense, and sell copies of the software, as long as the original copyright notice and permission notice are included in all copies or substantial portions of the software. The license also disclaims any warranties, stating that the software is provided "as is" without any guarantees of merchantability, fitness for a particular purpose, or non-infringement. This license is designed to maximize freedom for developers and users while limiting liability for the authors. diff --git a/driver_docs/Makefile.driver.md b/driver_docs/Makefile.driver.md deleted file mode 100644 index e23c11e..0000000 --- a/driver_docs/Makefile.driver.md +++ /dev/null @@ -1,2 +0,0 @@ -# Purpose -This Makefile is designed for building a Chess implementation written in C. It specifies the use of the GNU Compiler Collection (GCC) with the `-Wall` flag to enable all compiler warnings. The file includes conditional logic to add debugging information based on the `DEBUG` variable, allowing for either debug or release builds. It defines source and object files, and handles platform independence by setting executable and library paths differently for Windows and other operating systems. The Makefile includes targets for building the chess library (`chesslib`), running tests (`tests`), and cleaning up build artifacts (`clean`). It also ensures the creation of a `bin` directory for storing compiled binaries and libraries. diff --git a/driver_docs/README.md.driver.md b/driver_docs/README.md.driver.md deleted file mode 100644 index 71c925d..0000000 --- a/driver_docs/README.md.driver.md +++ /dev/null @@ -1,2 +0,0 @@ -# Purpose -The provided content is a markdown file that serves as documentation for a C-based chess library called "chesslib." It outlines the build instructions for compiling the library, detailing the use of a makefile compatible with Linux and Windows (via MSYS2), and provides specific steps for setting up the build environment on Windows. Additionally, the document includes a sample C program that demonstrates how to use the library to simulate a random chess game, showcasing the library's functionality by printing moves in UCI format and the final board position in FEN format. The file also outlines future development plans for the library, such as adding support for SAN and PGN formats, improving documentation, and enhancing the API. diff --git a/driver_docs/c_cpp_export_test/LICENSE.md b/driver_docs/c_cpp_export_test/LICENSE.md new file mode 100644 index 0000000..4d1a93c --- /dev/null +++ b/driver_docs/c_cpp_export_test/LICENSE.md @@ -0,0 +1,12 @@ + + + + + +The `LICENSE` file in the `c_cpp_export_test` codebase contains the MIT License, granting permission to use, copy, modify, and distribute the software with certain conditions. + +# Purpose +The provided content is a software license known as the MIT License, which is a permissive free software license. It grants users broad rights to use, copy, modify, merge, publish, distribute, sublicense, and sell copies of the software, as long as the original copyright notice and permission notice are included in all copies or substantial portions of the software. This license is designed to maximize freedom for users while limiting liability for the authors, as it explicitly states that the software is provided "as is," without any warranties, and disclaims any liability for damages arising from its use. The inclusion of this license in a software project facilitates open-source collaboration and distribution by clearly defining the terms under which the software can be used and shared. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/Makefile.md b/driver_docs/c_cpp_export_test/Makefile.md new file mode 100644 index 0000000..5c7616d --- /dev/null +++ b/driver_docs/c_cpp_export_test/Makefile.md @@ -0,0 +1,12 @@ + + + + + +The `Makefile` in the `c_cpp_export_test` codebase is used to compile and build a Chess implementation in C, handling both library and test executable creation with platform-independent configurations. + +# Purpose +This Makefile is designed for building a Chess implementation written in C, facilitating the compilation and linking process using the GNU Compiler Collection (GCC). It defines several variables, such as `CC` for the compiler and `CFLAGS` for compiler flags, which include warnings and optional debugging information based on the `DEBUG` flag. The file uses pattern rules to compile source files located in the `src` and `src/chesslib` directories into object files, and it creates a static library `libchesslib.a` from these object files, excluding the test main object. It also specifies platform-independent rules for generating the test executable, `tests`, and includes targets for cleaning up build artifacts and running tests. The Makefile ensures that the necessary directories are created and that the build process is streamlined for both development and testing purposes. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/README.md b/driver_docs/c_cpp_export_test/README.md new file mode 100644 index 0000000..17a41ec --- /dev/null +++ b/driver_docs/c_cpp_export_test/README.md @@ -0,0 +1,18 @@ + + + + + +C and C++ chess game implementation with source code, headers, tests, build instructions, and licensing. + +## Folders +- **[cpp_src](cpp_src/README.md)**: C++ source and header files implementing a chess game with classes for pieces, board, player actions, and game logic. +- **[include](include/README.md)**: Header files for managing chess game components such as the board, pieces, moves, and game state. +- **[src](src/README.md)**: The `chesslib` folder implements a chess library in C, and `tests.c` and `tests.h` provide unit tests and function prototypes. + +## Files +- **[LICENSE](LICENSE.md)**: The `LICENSE` file in the `c_cpp_export_test` codebase contains the MIT License, granting permission to use, copy, modify, and distribute the software with certain conditions. +- **[Makefile](Makefile.md)**: The `Makefile` in the `c_cpp_export_test` codebase is used to compile and build a Chess implementation in C, handling both library and test executable creation with platform-independent configurations. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/README.md b/driver_docs/c_cpp_export_test/cpp_src/README.md new file mode 100644 index 0000000..095adfd --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/README.md @@ -0,0 +1,37 @@ + + + + + +C++ source and header files implementing a chess game with classes for pieces, board, player actions, and game logic. + + +## Files +- **[bishop.cpp](bishop.cpp.md)**: The `bishop.cpp` file implements the Bishop class for a chess game, defining its movement, value, and display characteristics. +- **[bishop.h](bishop.h.md)**: The `bishop.h` file defines a class representing a chess bishop piece, including methods for determining its value, legal moves, and displaying the piece. +- **[board.cpp](board.cpp.md)**: The `board.cpp` file implements a chess board for the ChessProject, including methods for board setup, checking clear paths for moves, and displaying the board state. +- **[board.h](board.h.md)**: The `board.h` file defines a `Board` class representing an 8x8 game board, including methods for accessing squares, checking clear paths, determining end rows, and displaying the board. +- **[game.cpp](game.cpp.md)**: The `game.cpp` file in the `c_cpp_export_test` codebase implements the initialization and management of a chess game, including setting up the board with pieces and handling player turns. +- **[game.h](game.h.md)**: The `game.h` file defines a class for representing a game of chess, including methods for initializing the game and managing player turns. +- **[king.cpp](king.cpp.md)**: The `king.cpp` file implements the behavior of a chess king piece, including its movement rules and display functionality. +- **[king.h](king.h.md)**: The `king.h` file defines a `King` class that represents a chess king piece, including methods for creating the piece, determining its point value, checking legal moves, and displaying it. +- **[knight.cpp](knight.cpp.md)**: The `knight.cpp` file implements the Knight piece for a chess game, including its movement logic and display functionality. +- **[knight.h](knight.h.md)**: The `knight.h` file defines a `Knight` class that represents a chess knight piece, including methods for creating a knight, determining its point value, checking legal moves, and displaying the piece. +- **[main.cpp](main.cpp.md)**: The `main.cpp` file contains the main program logic for playing a chess game, including initializing the game, displaying the board, and handling player moves. +- **[pawn.cpp](pawn.cpp.md)**: The `pawn.cpp` file implements the behavior of a pawn piece in a chess game, including movement, promotion to a queen, and display functionality. +- **[pawn.h](pawn.h.md)**: The `pawn.h` file defines a `Pawn` class representing a chess pawn piece, including methods for movement, location setting, and display functionality. +- **[piece.cpp](piece.cpp.md)**: The `piece.cpp` file implements the `Piece` class for a chess game, handling piece movement, capturing logic, and color assignment. +- **[piece.h](piece.h.md)**: The `piece.h` file defines an abstract class for a game piece, including methods for movement, color determination, and location management. +- **[player.cpp](player.cpp.md)**: The `player.cpp` file implements the `Player` class for a chess game, handling player actions such as making moves, checking for check status, capturing pieces, and calculating scores. +- **[player.h](player.h.md)**: The `player.h` file defines a `Player` class for a chess game, including methods for making moves, checking if the player is in check, capturing pieces, and accessing player attributes such as name, color, and score. +- **[queen.cpp](queen.cpp.md)**: The `queen.cpp` file implements the Queen class for a chess game, defining its movement capabilities and display representation. +- **[queen.h](queen.h.md)**: The `queen.h` file defines a `Queen` class representing a chess queen piece, including methods for determining legal moves, getting its point value, and displaying the piece. +- **[restrictedPiece.cpp](restrictedPiece.cpp.md)**: The `restrictedPiece.cpp` file defines the `RestrictedPiece` class for a chess project, which extends the `Piece` class to include functionality for tracking whether the piece has moved. +- **[restrictedPiece.h](restrictedPiece.h.md)**: The `restrictedPiece.h` file defines a `RestrictedPiece` class for a chess piece that tracks whether it has been moved, extending the functionality of a generic `Piece`. +- **[rook.cpp](rook.cpp.md)**: The `rook.cpp` file implements the Rook chess piece, including its movement logic and display functionality, for the ChessProject. +- **[rook.h](rook.h.md)**: The `rook.h` file defines a class representing a chess rook piece, including methods for determining legal moves, getting its point value, and displaying the piece. +- **[square.cpp](square.cpp.md)**: The `square.cpp` file implements the `Square` class for a chess project, managing the position and occupancy of a square on the chessboard. +- **[square.h](square.h.md)**: The `square.h` file defines a `Square` class for representing a square on a game board, including methods for setting and retrieving the piece occupying the square, as well as its position. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/bishop.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/bishop.cpp.md new file mode 100644 index 0000000..204b60d --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/bishop.cpp.md @@ -0,0 +1,93 @@ + + + + + +The `bishop.cpp` file implements the Bishop class for a chess game, defining its movement, value, and display characteristics. + +# Purpose +This C++ code defines the implementation of a [`Bishop`](#BishopBishop) class, which is part of a chess game project. The code provides narrow functionality specific to the behavior and characteristics of a bishop piece in chess. It is not an executable file but rather a C++ source file intended to be used in conjunction with other files, likely as part of a larger chess game application. The [`Bishop`](#BishopBishop) class inherits from a `Piece` class, indicating a hierarchical design where [`Bishop`](#BishopBishop) is a specialized type of `Piece`. The class includes methods to determine the bishop's value, check if it can move to a specified square based on chess rules (specifically moving diagonally), and display the bishop's representation on the board. The use of a destructor and constructor suggests proper resource management, although no dynamic memory allocation is evident in this snippet. +# Imports and Dependencies + +--- +- `bishop.h` + + +# Data Structures + +--- +### Bishop +- **Description**: [See definition](bishop.h.md#Bishop) +- **Member Functions**: + - [`Bishop::Bishop`](#BishopBishop) + - [`Bishop::~Bishop`](#BishopBishop) + - [`Bishop::value`](#Bishopvalue) + - [`Bishop::canMoveTo`](#BishopcanMoveTo) + - [`Bishop::display`](#Bishopdisplay) +- **Inherits From**: + - `Piece` + +**Methods** + +--- +#### Bishop::Bishop +The `Bishop` constructor initializes a Bishop object with a specified color by calling the base class `Piece` constructor. +- **Inputs**: + - `isWhite`: A boolean indicating whether the Bishop is white (true) or black (false). +- **Control Flow**: + - The constructor `Bishop::Bishop(bool isWhite)` is called with a boolean parameter `isWhite`. + - The constructor initializes the Bishop object by calling the base class `Piece` constructor with the `isWhite` parameter. +- **Output**: There is no return value as this is a constructor for initializing a Bishop object. +- **See also**: [`Bishop`](bishop.h.md#Bishop) (Data Structure) + + +--- +#### Bishop::\~Bishop +The `Bishop::~Bishop()` function is the default destructor for the `Bishop` class, which currently performs no specific actions upon object destruction. +- **Inputs**: None +- **Control Flow**: + - The destructor is called when a `Bishop` object goes out of scope or is explicitly deleted. + - Currently, the destructor does not contain any code, so it performs no operations. +- **Output**: There is no output from this destructor as it is empty and performs no actions. +- **See also**: [`Bishop`](bishop.h.md#Bishop) (Data Structure) + + +--- +#### Bishop::value +The `value` function returns the fixed point value of a Bishop piece in a chess game. +- **Inputs**: None +- **Control Flow**: + - The function is a constant member function of the `Bishop` class, indicating it does not modify the state of the object. + - It directly returns the integer value `3`, which represents the point value of a Bishop in chess. +- **Output**: The function returns an integer value of `3`. +- **See also**: [`Bishop`](bishop.h.md#Bishop) (Data Structure) + + +--- +#### Bishop::canMoveTo +The `canMoveTo` function checks if a Bishop can legally move to a specified square by verifying if the path is a clear diagonal. +- **Inputs**: + - `location`: A reference to a `Square` object representing the destination square to which the Bishop intends to move. +- **Control Flow**: + - Initialize a boolean variable `validMove` to `false`. + - Check if the path from the Bishop's current location to the target `location` is a clear diagonal using `Board::getBoard()->isClearDiagonal`. + - If the path is clear, set `validMove` to `true`. + - Return the value of `validMove`. +- **Output**: A boolean value indicating whether the Bishop can legally move to the specified square. +- **See also**: [`Bishop`](bishop.h.md#Bishop) (Data Structure) + + +--- +#### Bishop::display +The `display` function outputs the color and type of the Bishop piece to the console. +- **Inputs**: None +- **Control Flow**: + - The function uses the `cout` stream to output the Bishop's color followed by the letter 'B' to represent the Bishop piece. +- **Output**: The function does not return any value; it outputs directly to the console. +- **See also**: [`Bishop`](bishop.h.md#Bishop) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/bishop.h.md b/driver_docs/c_cpp_export_test/cpp_src/bishop.h.md new file mode 100644 index 0000000..3f9befd --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/bishop.h.md @@ -0,0 +1,36 @@ + + + + + +The `bishop.h` file defines a class representing a chess bishop piece, including methods for determining its value, legal moves, and displaying the piece. + +# Purpose +The provided code is a C++ header file, `bishop.h`, which defines a class representing a chess bishop piece. This class, `Bishop`, inherits from a base class `Piece`, suggesting a broader chess game application where different chess pieces are modeled as classes. The functionality of this code is relatively narrow, focusing specifically on the behavior and characteristics of a bishop in a chess game. It includes methods for creating a bishop with a specified color, determining its point value, checking if a move to a given square is legal, and displaying the piece. This header file is intended to be included in other parts of a chess program, where the implementation details of these methods would be defined, likely in a corresponding `.cpp` file. +# Imports and Dependencies + +--- +- `iostream` +- `piece.h` +- `square.h` + + +# Data Structures + +--- +### Bishop +- **Type**: `class` +- **Description**: The `Bishop` class represents a chess bishop piece in a chess game, inheriting from the `Piece` class. It includes a constructor to initialize the bishop with a color, a destructor, and methods to get the point value of the bishop, determine if a move to a given square is legal based on diagonal movement, and display the bishop on the board. The bishop's value is set to 3, and it can move diagonally across the board if the path is clear. +- **Member Functions**: + - [`Bishop::Bishop`](bishop.cpp.md#BishopBishop) + - [`Bishop::~Bishop`](bishop.cpp.md#BishopBishop) + - [`Bishop::value`](bishop.cpp.md#Bishopvalue) + - [`Bishop::canMoveTo`](bishop.cpp.md#BishopcanMoveTo) + - [`Bishop::display`](bishop.cpp.md#Bishopdisplay) +- **Inherits From**: + - `Piece` + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/board.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/board.cpp.md new file mode 100644 index 0000000..c406063 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/board.cpp.md @@ -0,0 +1,186 @@ + + + + + +The `board.cpp` file implements a chess board for the ChessProject, including methods for board setup, checking clear paths for moves, and displaying the board state. + +# Purpose +The `board.cpp` file is part of a Chess project and is responsible for implementing the [`Board`](#BoardBoard) class, which models the chessboard in the game. This file provides a focused functionality centered around managing the state and behavior of the chessboard. The [`Board`](#BoardBoard) class includes methods for initializing the board, checking the clarity of paths (vertical, horizontal, and diagonal) between squares, and displaying the board's current state. The class uses a singleton pattern, as evidenced by the `getBoard()` method, which ensures that only one instance of the [`Board`](#BoardBoard) exists throughout the application. This is achieved by maintaining a static pointer `_theBoard` to the single instance. + +The technical components of this file include the constructor and destructor for setting up and cleaning up the board, respectively, and several methods for checking the state of the board, such as [`isClearVertical`](#BoardisClearVertical), [`isClearHorizontal`](#BoardisClearHorizontal), and [`isClearDiagonal`](#BoardisClearDiagonal). These methods are crucial for validating moves in a chess game by ensuring that no pieces obstruct the path between two squares. The [`display`](#Boarddisplay) method outputs the current state of the board to a given output stream, showing the position of pieces on the board. The file also includes a method [`isEndRow`](#BoardisEndRow) to determine if a square is on the end row, which is significant for pawn promotion in chess. Overall, `board.cpp` is a critical component of the Chess project, providing essential functionality for managing and interacting with the chessboard. +# Imports and Dependencies + +--- +- `board.h` +- `piece.h` + + +# Global Variables + +--- +### \_theBoard +- **Type**: `Board*` +- **Description**: `_theBoard` is a static pointer to a `Board` object, initialized to `NULL`. It is used to implement the singleton pattern for the `Board` class, ensuring that only one instance of the `Board` exists throughout the application. +- **Use**: This variable is used to store and access the single instance of the `Board` class, created and managed through the `getBoard()` method. + + +# Data Structures + +--- +### Board +- **Description**: [See definition](board.h.md#Board) +- **Member Functions**: + - [`Board::Board`](#BoardBoard) + - [`Board::~Board`](#BoardBoard) + - [`Board::getBoard`](#BoardgetBoard) + - [`Board::squareAt`](#BoardsquareAt) + - [`Board::isClearVertical`](#BoardisClearVertical) + - [`Board::isClearHorizontal`](#BoardisClearHorizontal) + - [`Board::isClearDiagonal`](#BoardisClearDiagonal) + - [`Board::isEndRow`](#BoardisEndRow) + - [`Board::display`](#Boarddisplay) + +**Methods** + +--- +#### Board::Board +The `Board` constructor initializes an 8x8 chess board by creating `Square` objects for each position on the board. +- **Inputs**: None +- **Control Flow**: + - The constructor iterates over a fixed dimension (8x8) using two nested loops. + - For each pair of indices (i, j), it creates a new `Square` object with coordinates (i, j). + - The newly created `Square` object is stored in the `_squares` array at position [i][j]. +- **Output**: The constructor does not return any value as it is a constructor for the `Board` class. +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + +--- +#### Board::\~Board +The `~Board` destructor deallocates memory for a dynamically allocated 2D array of `Square` objects in a chess board. +- **Inputs**: None +- **Control Flow**: + - Iterate over each row of the `_squares` 2D array using a loop with index `i`. + - Within each row, iterate over each column using a loop with index `j`. + - For each `Square` object at position `[i][j]`, deallocate its memory using `delete[]`. + - After deallocating all `Square` objects in a row, deallocate the memory for the row itself using `delete[]`. + - Finally, deallocate the memory for the entire `_squares` array using `delete[]`. +- **Output**: The function does not return any value as it is a destructor. +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + +--- +#### Board::getBoard +The `getBoard` function implements the singleton pattern to ensure only one instance of the `Board` class is created and returned. +- **Inputs**: None +- **Control Flow**: + - Check if the static member `_theBoard` is `NULL`. + - If `_theBoard` is `NULL`, create a new instance of `Board` and assign it to `_theBoard`. + - Return the `_theBoard` instance. +- **Output**: A pointer to the single instance of the `Board` class. +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + +--- +#### Board::squareAt +The `squareAt` function retrieves a pointer to a `Square` object located at the specified coordinates on the board. +- **Inputs**: + - `x`: The x-coordinate of the square on the board. + - `y`: The y-coordinate of the square on the board. +- **Control Flow**: + - Access the 2D array `_squares` using the provided x and y coordinates. + - Return the `Square` pointer located at `_squares[x][y]`. +- **Output**: A pointer to the `Square` object at the specified coordinates on the board. +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + +--- +#### Board::isClearVertical +The `isClearVertical` function checks if the vertical path between two squares on a board is clear of any occupied squares. +- **Inputs**: + - `from`: A reference to the starting `Square` object. + - `to`: A reference to the ending `Square` object. +- **Control Flow**: + - Initialize pointers `start` and `end` to determine the order of squares based on their y-values. + - Assign `start` to the square with the smaller y-value and `end` to the other square. + - Check if the x-values of `start` and `end` are equal to ensure no horizontal movement; if not, set `valid` to false. + - If the x-values are equal, iterate over the y-values between `start` and `end`. + - For each square in the vertical path, check if it is occupied using the [`squareAt`](#BoardsquareAt) method. + - If any square is occupied, set `valid` to false. + - Return the boolean value `valid` indicating if the path is clear. +- **Output**: A boolean value indicating whether the vertical path between the two squares is clear (true) or not (false). +- **Functions called**: + - [`Board::squareAt`](#BoardsquareAt) +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + +--- +#### Board::isClearHorizontal +The `isClearHorizontal` function checks if the horizontal path between two squares on a chess board is clear of any occupied squares. +- **Inputs**: + - `from`: A reference to the starting `Square` object. + - `to`: A reference to the ending `Square` object. +- **Control Flow**: + - Initialize pointers `start` and `end` to determine the direction of horizontal traversal based on the x-values of `from` and `to`. + - Check if there is no vertical movement by comparing the y-values of `start` and `end`; if they differ, set `valid` to false. + - If the y-values are the same, iterate over the x-values between `start` and `end` to check if any square is occupied. + - If any square in the path is occupied, set `valid` to false. + - Return the boolean value `valid` indicating whether the path is clear. +- **Output**: A boolean value indicating whether the horizontal path between the two squares is clear (true) or not (false). +- **Functions called**: + - [`Board::squareAt`](#BoardsquareAt) +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + +--- +#### Board::isClearDiagonal +The `isClearDiagonal` function checks if the diagonal path between two squares on a chess board is unobstructed by any pieces. +- **Inputs**: + - `from`: A reference to the starting `Square` object on the board. + - `to`: A reference to the ending `Square` object on the board. +- **Control Flow**: + - Initialize `valid` as true, and calculate the translation in x and y directions between the `from` and `to` squares. + - Determine the direction of movement in x (`xDir`) and y (`yDir`) based on the sign of the translations. + - Check if the movement is diagonal by comparing the absolute values of the x and y translations; if they don't match, set `valid` to false. + - If the movement is diagonal, iterate over each square along the diagonal path (excluding the start and end squares). + - For each square in the path, check if it is occupied using the [`squareAt`](#BoardsquareAt) method; if any square is occupied, set `valid` to false. + - Return the value of `valid`, indicating whether the diagonal path is clear. +- **Output**: A boolean value indicating whether the diagonal path between the two squares is clear (true) or obstructed (false). +- **Functions called**: + - [`Board::squareAt`](#BoardsquareAt) +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + +--- +#### Board::isEndRow +The `isEndRow` function checks if a given square is located on the first or last row of the board. +- **Inputs**: + - `location`: A reference to a `Square` object representing the location on the board to be checked. +- **Control Flow**: + - Retrieve the Y-coordinate of the `location` square using `location.getY()`. + - Check if the Y-coordinate is either 0 or `_DIMENSION - 1`, which represent the first and last rows of the board, respectively. + - Return `true` if the Y-coordinate matches either of these values, otherwise return `false`. +- **Output**: A boolean value indicating whether the square is on the first or last row of the board. +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + +--- +#### Board::display +The `display` function outputs the current state of the chess board to a given output stream, showing the position of pieces on an 8x8 grid. +- **Inputs**: + - `outStream`: An output stream where the board's current state will be printed. +- **Control Flow**: + - The function begins by printing the column labels (a to h) and a separator line to the output stream. + - It then iterates over each row of the board from top to bottom (black pieces at the top, white at the bottom). + - For each row, it prints the row number, followed by the contents of each square in that row, separated by vertical bars. + - If a square is occupied, it calls the `display` method of the piece occupying the square to print its representation; otherwise, it prints an empty space. + - After printing all squares in a row, it prints the row number again and a separator line. + - Finally, it prints the column labels again at the bottom of the board. +- **Output**: The function outputs the visual representation of the chess board to the provided output stream, showing the positions of any pieces on the board. +- **See also**: [`Board`](board.h.md#Board) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/board.h.md b/driver_docs/c_cpp_export_test/cpp_src/board.h.md new file mode 100644 index 0000000..cc7cbaa --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/board.h.md @@ -0,0 +1,41 @@ + + + + + +The `board.h` file defines a `Board` class representing an 8x8 game board, including methods for accessing squares, checking clear paths, determining end rows, and displaying the board. + +# Purpose +The provided code is a C++ header file (`board.h`) that defines a class `Board`, which represents a game board, likely for a board game such as chess or checkers. This code offers narrow functionality specific to managing and interacting with a game board, including methods to access specific squares, check clear paths between squares in various directions (vertical, horizontal, diagonal), and determine if a square is on an end row. The class also includes a method to display the board, suggesting it might be used in a console-based application. The `Board` class is implemented as a singleton, indicated by the static method `getBoard()` and the private static member `_theBoard`, ensuring only one instance of the board exists. The board is fixed at an 8x8 dimension, as defined by the constant `_DIMENSION`, and it relies on a `Square` class, which is presumably defined in the included "square.h" file. +# Imports and Dependencies + +--- +- `ostream` +- `square.h` + + +# Data Structures + +--- +### Board +- **Type**: `class` +- **Members**: + - `_theBoard`: A static pointer to the singleton instance of the Board class. + - `_DIMENSION`: A static constant integer representing the dimension of the board, set to 8. + - `_squares`: A 2D array of pointers to Square objects, representing the squares on the board. +- **Description**: The Board class represents a game board, specifically an 8x8 grid, typically used for games like chess or checkers. It is implemented as a singleton, ensuring only one instance of the board exists at any time. The class provides methods to access specific squares, check if paths between squares are clear in vertical, horizontal, or diagonal directions, and determine if a square is on an end row. It also includes functionality to display the board's current state. The board is initialized with each square being an instance of the Square class, and it manages the memory for these squares, ensuring they are properly allocated and deallocated. +- **Member Functions**: + - [`Board::Board`](board.cpp.md#BoardBoard) + - [`Board::~Board`](board.cpp.md#BoardBoard) + - [`Board::getBoard`](board.cpp.md#BoardgetBoard) + - [`Board::squareAt`](board.cpp.md#BoardsquareAt) + - [`Board::isClearVertical`](board.cpp.md#BoardisClearVertical) + - [`Board::isClearHorizontal`](board.cpp.md#BoardisClearHorizontal) + - [`Board::isClearDiagonal`](board.cpp.md#BoardisClearDiagonal) + - [`Board::isEndRow`](board.cpp.md#BoardisEndRow) + - [`Board::display`](board.cpp.md#Boarddisplay) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/game.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/game.cpp.md new file mode 100644 index 0000000..1101fd4 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/game.cpp.md @@ -0,0 +1,136 @@ + + + + + +The `game.cpp` file in the `c_cpp_export_test` codebase implements the initialization and management of a chess game, including setting up the board with pieces and handling player turns. + +# Purpose +The `game.cpp` file is a core component of a chess application, responsible for managing the overall game state and the interactions between players and pieces. It defines the [`Game`](#GameGame) class, which encapsulates the initialization and management of chess pieces and players. The file includes headers for various chess piece classes such as `queen.h`, `bishop.h`, `knight.h`, `rook.h`, `pawn.h`, and `king.h`, indicating that it relies on these classes to represent the different types of chess pieces. The [`Game`](#GameGame) class contains methods for initializing the game board with pieces in their starting positions, managing the lifecycle of the pieces and players, and determining the next player to move. + +The [`Game`](#GameGame) class provides a structured approach to setting up a chess game by creating and positioning pieces on the board, associating them with players, and managing the turn-based nature of the game. It uses sets to store the white and black pieces, ensuring efficient management and cleanup of resources. The class also includes methods like `getNextPlayer()` and `opponentOf()` to facilitate player interactions and determine the flow of the game. This file is not an executable on its own but is intended to be part of a larger chess application, serving as a central component that coordinates the game's logic and state. +# Imports and Dependencies + +--- +- `game.h` +- `queen.h` +- `bishop.h` +- `knight.h` +- `rook.h` +- `pawn.h` +- `king.h` +- `square.h` + + +# Global Variables + +--- +### player1 +- **Type**: `Player*` +- **Description**: The `player1` variable is a global pointer to a `Player` object within the `Game` class. It is used to represent the first player in the chess game, typically the player controlling the white pieces. +- **Use**: This variable is used to store and manage the state and actions of the first player in the game, including their pieces and moves. + + +--- +### player2 +- **Type**: `Player*` +- **Description**: The `player2` variable is a global pointer to a `Player` object representing the second player in the game, typically the player controlling the black pieces in a chess game. It is initialized to `NULL` and later assigned a `Player` object in the `initialize` method of the `Game` class. +- **Use**: `player2` is used to store and manage the state and actions of the second player in the chess game. + + +--- +### nextPlayer +- **Type**: `Player*` +- **Description**: `nextPlayer` is a global pointer variable of type `Player*` that is part of the `Game` class. It is initialized to `NULL` and is used to keep track of the player whose turn it is to play next in the game. +- **Use**: This variable is used to determine and update the current player in the game flow, switching between players after each turn. + + +# Data Structures + +--- +### Game +- **Description**: [See definition](game.h.md#Game) +- **Member Functions**: + - [`Game::Game`](#GameGame) + - [`Game::~Game`](#GameGame) + - [`Game::initialize`](#Gameinitialize) + - [`Game::getNextPlayer`](#GamegetNextPlayer) + - [`Game::opponentOf`](#GameopponentOf) + +**Methods** + +--- +#### Game::Game +The `Game` constructor initializes a new instance of the `Game` class without performing any specific actions. +- **Inputs**: None +- **Control Flow**: + - The constructor is defined but does not contain any code or logic, indicating it performs no operations when a `Game` object is instantiated. +- **Output**: There is no output from this constructor as it does not perform any operations. +- **See also**: [`Game`](game.h.md#Game) (Data Structure) + + +--- +#### Game::\~Game +The `~Game` destructor deallocates memory for all chess pieces and players associated with a game instance. +- **Inputs**: None +- **Control Flow**: + - Iterates over the `whitePieces` set, deleting each `Piece` pointer and then clears the set. + - Iterates over the `blackPieces` set, deleting each `Piece` pointer and then clears the set. + - Deletes the `player1` and `player2` objects. +- **Output**: This function does not return any value as it is a destructor. +- **See also**: [`Game`](game.h.md#Game) (Data Structure) + + +--- +#### Game::initialize +The `initialize` function sets up a new chess game by creating and positioning all pieces on the board, assigning them to players, and determining the starting player. +- **Inputs**: None +- **Control Flow**: + - Initialize local pointers for Piece, King, and Square objects. + - Create sets for white and black pieces. + - Instantiate and position a white Queen at (3, 0) and a black Queen at (3, 7), then add them to their respective sets. + - Instantiate and position two white Bishops at (2, 0) and (5, 0) and two black Bishops at (2, 7) and (5, 7), then add them to their respective sets. + - Instantiate and position two white Knights at (1, 0) and (6, 0) and two black Knights at (1, 7) and (6, 7), then add them to their respective sets. + - Instantiate and position two white Rooks at (0, 0) and (7, 0) and two black Rooks at (0, 7) and (7, 7), then add them to their respective sets. + - Use a loop to instantiate and position eight white Pawns at row 1 and eight black Pawns at row 6, then add them to their respective sets. + - Instantiate and position a white King at (4, 0) and a black King at (4, 7), then add them to their respective sets. + - Create a Player object for the white player with their pieces and King, and assign it to `player1`. + - Create a Player object for the black player with their pieces and King, and assign it to `player2`. + - Set `nextPlayer` to `player2`, indicating the black player starts. +- **Output**: The function does not return any value; it initializes the game state by setting up the board and players. +- **See also**: [`Game`](game.h.md#Game) (Data Structure) + + +--- +#### Game::getNextPlayer +The `getNextPlayer` function updates and returns the player whose turn is next in the game. +- **Inputs**: None +- **Control Flow**: + - The function calls [`opponentOf`](#GameopponentOf) with the current `nextPlayer` to determine the opponent player. + - It updates `nextPlayer` to the opponent player returned by [`opponentOf`](#GameopponentOf). + - The function returns the updated `nextPlayer`. +- **Output**: A pointer to the `Player` object representing the next player to take a turn. +- **Functions called**: + - [`Game::opponentOf`](#GameopponentOf) +- **See also**: [`Game`](game.h.md#Game) (Data Structure) + + +--- +#### Game::opponentOf +The `opponentOf` function returns the opponent player of the given player in a chess game. +- **Inputs**: + - `player`: A reference to a `Player` object for whom the opponent is to be determined. +- **Control Flow**: + - Declare a pointer `opponent` to hold the opponent player. + - Check if the given player's name matches `player1`'s name. + - If it matches, set `opponent` to `player2`. + - If it does not match, set `opponent` to `player1`. + - Return the `opponent` pointer. +- **Output**: A pointer to the `Player` object representing the opponent of the given player. +- **See also**: [`Game`](game.h.md#Game) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/game.h.md b/driver_docs/c_cpp_export_test/cpp_src/game.h.md new file mode 100644 index 0000000..9b8f361 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/game.h.md @@ -0,0 +1,42 @@ + + + + + +The `game.h` file defines a class for representing a game of chess, including methods for initializing the game and managing player turns. + +# Purpose +The provided code is a C++ header file (`game.h`) that defines a class representing a game of chess, indicating narrow functionality specific to chess game management. This header file is intended to be included in other C++ source files, as it declares the `Game` class with methods and attributes necessary for setting up and managing a chess game. The class includes static methods for initializing the game, determining the next player, and identifying the opponent of a given player, suggesting that it manages game state and player turns. The use of static attributes and methods implies that the class is designed to handle a single game instance at a time, with private attributes for storing player and piece information. The inclusion of other headers like `board.h`, `piece.h`, and `player.h` suggests that this class interacts with other components of a chess game system. +# Imports and Dependencies + +--- +- `set` +- `iostream` +- `board.h` +- `piece.h` +- `player.h` + + +# Data Structures + +--- +### Game +- **Type**: `class` +- **Members**: + - `player1`: A static pointer to the first player in the game, representing the white player. + - `player2`: A static pointer to the second player in the game, representing the black player. + - `nextPlayer`: A static pointer to the player whose turn is next. + - `whitePieces`: A static set containing pointers to all the white pieces in the game. + - `blackPieces`: A static set containing pointers to all the black pieces in the game. +- **Description**: The `Game` class represents a game of chess, managing the players and pieces involved. It includes static methods to initialize the game, determine the next player, and find the opponent of a given player. The class maintains static attributes for the two players, the next player to move, and sets of pieces for both white and black sides. The class is designed to encapsulate the state and behavior of a chess game, providing functionality to manage the game's lifecycle and player interactions. +- **Member Functions**: + - [`Game::Game`](game.cpp.md#GameGame) + - [`Game::~Game`](game.cpp.md#GameGame) + - [`Game::initialize`](game.cpp.md#Gameinitialize) + - [`Game::getNextPlayer`](game.cpp.md#GamegetNextPlayer) + - [`Game::opponentOf`](game.cpp.md#GameopponentOf) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/king.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/king.cpp.md new file mode 100644 index 0000000..c24cfc8 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/king.cpp.md @@ -0,0 +1,97 @@ + + + + + +The `king.cpp` file implements the behavior of a chess king piece, including its movement rules and display functionality. + +# Purpose +The provided code is a C++ source file, `king.cpp`, which is part of a larger chess project. It defines the implementation of the [`King`](#KingKing) class, which inherits from a `RestrictedPiece` class, likely representing a chess piece with limited movement capabilities. The [`King`](#KingKing) class constructor initializes the piece's color, and the destructor is defined but does not perform any specific actions. The [`value`](#Kingvalue) method returns a constant integer, possibly indicating the king's value in the game, though it is set to zero, which might imply a special status rather than a point value. The [`canMoveTo`](#KingcanMoveTo) method implements the king's movement logic, allowing it to move one square in any direction (forward, backward, sideways, or diagonally), adhering to standard chess rules. Finally, the [`display`](#Kingdisplay) method outputs the king's representation, combining its color and the letter "K" to the console, which is useful for visualizing the board state. This code provides narrow functionality specific to the behavior and representation of a king piece in a chess game. +# Imports and Dependencies + +--- +- `king.h` + + +# Data Structures + +--- +### King +- **Description**: [See definition](king.h.md#King) +- **Member Functions**: + - [`King::King`](#KingKing) + - [`King::~King`](#KingKing) + - [`King::value`](#Kingvalue) + - [`King::canMoveTo`](#KingcanMoveTo) + - [`King::display`](#Kingdisplay) +- **Inherits From**: + - `RestrictedPiece` + +**Methods** + +--- +#### King::King +The `King` constructor initializes a `King` object by calling the constructor of its parent class `RestrictedPiece` with a boolean indicating the piece's color. +- **Inputs**: + - `isWhite`: A boolean indicating whether the King piece is white (true) or black (false). +- **Control Flow**: + - The constructor `King::King(bool isWhite)` is called with a boolean parameter `isWhite`. + - The constructor initializes the `King` object by invoking the constructor of its parent class `RestrictedPiece` with the `isWhite` parameter. +- **Output**: There is no return value as this is a constructor for the `King` class. +- **See also**: [`King`](king.h.md#King) (Data Structure) + + +--- +#### King::\~King +The destructor `~King()` is a default destructor for the `King` class that performs no specific actions. +- **Inputs**: None +- **Control Flow**: + - The destructor `~King()` is called when a `King` object is destroyed. + - No specific actions or resource deallocations are performed within the destructor. +- **Output**: There is no output or return value from the destructor. +- **See also**: [`King`](king.h.md#King) (Data Structure) + + +--- +#### King::value +The `value` function returns the point value of the King piece, which is 0. +- **Inputs**: None +- **Control Flow**: + - The function simply returns the integer value 0. +- **Output**: The function returns an integer value of 0, representing the point value of the King piece in a chess game. +- **See also**: [`King`](king.h.md#King) (Data Structure) + + +--- +#### King::canMoveTo +The `canMoveTo` function determines if a King chess piece can legally move to a specified square based on standard chess rules for a King's movement. +- **Inputs**: + - `location`: A reference to a `Square` object representing the target location to which the King is attempting to move. +- **Control Flow**: + - Initialize `validMove` to `false`. + - Calculate `translationX` as the difference between the x-coordinate of the target location and the current x-coordinate of the King. + - Calculate `translationY` as the difference between the y-coordinate of the target location and the current y-coordinate of the King. + - Check if the move is one square forward or backward (i.e., `abs(translationY) == 1` and `translationX == 0`), and set `validMove` to `true` if so. + - Check if the move is one square sideways (i.e., `abs(translationX) == 1` and `translationY == 0`), and set `validMove` to `true` if so. + - Check if the move is one square diagonally (i.e., `abs(translationX) == 1` and `abs(translationY) == 1`), and set `validMove` to `true` if so. + - Return the value of `validMove`. +- **Output**: A boolean value indicating whether the King can legally move to the specified square (`true` if the move is legal, `false` otherwise). +- **See also**: [`King`](king.h.md#King) (Data Structure) + + +--- +#### King::display +The `display` function outputs the color and type of the King piece to the console. +- **Inputs**: None +- **Control Flow**: + - The function accesses the `_color` member variable of the `King` class, which indicates the color of the piece. + - It concatenates the color with the character 'K', representing the King piece. + - The concatenated string is then output to the console using `cout`. +- **Output**: The function outputs a string to the console, which is the color of the King piece followed by the letter 'K'. +- **See also**: [`King`](king.h.md#King) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/king.h.md b/driver_docs/c_cpp_export_test/cpp_src/king.h.md new file mode 100644 index 0000000..3de0552 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/king.h.md @@ -0,0 +1,35 @@ + + + + + +The `king.h` file defines a `King` class that represents a chess king piece, including methods for creating the piece, determining its point value, checking legal moves, and displaying it. + +# Purpose +The provided code is a C++ header file (`king.h`) that defines a class representing a chess king piece, which is part of a broader chess game application. This class, `King`, inherits from a base class `RestrictedPiece`, suggesting it shares common functionality with other restricted chess pieces, such as the queen or bishop. The class offers narrow functionality specific to the king piece, including methods to determine its point value, check if a move is legal, and display the piece. The constructor initializes the king with a specified color, and the destructor is defined but not explicitly implemented in this header. This file is intended to be included in other parts of the application where the king's behavior and properties are needed. +# Imports and Dependencies + +--- +- `iostream` +- `restrictedPiece.h` + + +# Data Structures + +--- +### King +- **Type**: `class` +- **Description**: The `King` class represents a chess king piece and inherits from the `RestrictedPiece` class. It includes a constructor to initialize the king with a specified color, a destructor, and methods to determine the point value of the king, check if a move to a specific square is legal, and display the king on an output stream. The king can move one square in any direction, which is implemented in the `canMoveTo` method. +- **Member Functions**: + - [`King::King`](king.cpp.md#KingKing) + - [`King::~King`](king.cpp.md#KingKing) + - [`King::value`](king.cpp.md#Kingvalue) + - [`King::canMoveTo`](king.cpp.md#KingcanMoveTo) + - [`King::display`](king.cpp.md#Kingdisplay) +- **Inherits From**: + - [`RestrictedPiece`](restrictedPiece.h.md#RestrictedPiece) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/knight.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/knight.cpp.md new file mode 100644 index 0000000..ff2bdbd --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/knight.cpp.md @@ -0,0 +1,96 @@ + + + + + +The `knight.cpp` file implements the Knight piece for a chess game, including its movement logic and display functionality. + +# Purpose +The `knight.cpp` file is part of a larger Chess project and implements the behavior specific to the Knight piece in a game of chess. This file provides a narrow functionality focused on defining the characteristics and movement rules of the Knight. It includes the implementation of the [`Knight`](#KnightKnight) class, which inherits from a base class `Piece`, indicating that it is part of a polymorphic design where different chess pieces share common attributes and behaviors. The constructor initializes the Knight with a color, and the destructor is defined, though it does not perform any specific actions. + +The file defines several key methods for the Knight. The `value()` method returns the standard chess value of a Knight, which is 3. The `canMoveTo(Square& location)` method implements the unique L-shaped movement pattern of the Knight, checking if a move to a given square is valid based on the Knight's ability to move two squares in one direction and one square in a perpendicular direction. The `display()` method outputs a representation of the Knight, using "N" to denote the piece, prefixed by its color. This file is intended to be part of a larger system, likely imported and used by other components of the Chess project to simulate and manage the game state. +# Imports and Dependencies + +--- +- `knight.h` + + +# Data Structures + +--- +### Knight +- **Description**: [See definition](knight.h.md#Knight) +- **Member Functions**: + - [`Knight::Knight`](#KnightKnight) + - [`Knight::~Knight`](#KnightKnight) + - [`Knight::value`](#Knightvalue) + - [`Knight::canMoveTo`](#KnightcanMoveTo) + - [`Knight::display`](#Knightdisplay) +- **Inherits From**: + - `Piece` + +**Methods** + +--- +#### Knight::Knight +The `Knight` constructor initializes a `Knight` object by calling the `Piece` constructor with a boolean indicating the piece's color. +- **Inputs**: + - `isWhite`: A boolean value indicating whether the knight is white (true) or black (false). +- **Control Flow**: + - The constructor `Knight::Knight(bool isWhite)` is called with a boolean parameter `isWhite`. + - The constructor initializes the `Knight` object by invoking the constructor of its base class `Piece` with the `isWhite` parameter. +- **Output**: A `Knight` object is created and initialized with the specified color. +- **See also**: [`Knight`](knight.h.md#Knight) (Data Structure) + + +--- +#### Knight::\~Knight +The `Knight::~Knight` function is the default destructor for the `Knight` class, which currently performs no specific actions upon object destruction. +- **Inputs**: None +- **Control Flow**: + - The destructor is called when a `Knight` object goes out of scope or is explicitly deleted. + - Currently, the destructor does not contain any code, so it performs no operations. +- **Output**: There is no output from this destructor as it is empty and performs no actions. +- **See also**: [`Knight`](knight.h.md#Knight) (Data Structure) + + +--- +#### Knight::value +The `value` function returns the point value of a Knight piece in a chess game. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the integer value 3, representing the point value of a Knight in chess. +- **Output**: The function returns an integer value of 3. +- **See also**: [`Knight`](knight.h.md#Knight) (Data Structure) + + +--- +#### Knight::canMoveTo +The `canMoveTo` function determines if a Knight piece can legally move to a specified square based on chess movement rules for a Knight. +- **Inputs**: + - `location`: A reference to a `Square` object representing the target location to which the Knight is attempting to move. +- **Control Flow**: + - Initialize `validMove` to `false`. + - Calculate `translationX` as the difference between the target square's x-coordinate and the Knight's current x-coordinate. + - Calculate `translationY` as the difference between the target square's y-coordinate and the Knight's current y-coordinate. + - Check if the move is valid by verifying if the absolute values of `translationY` and `translationX` match the Knight's L-shaped movement pattern (1 square in one direction and 2 squares in the perpendicular direction). + - If either condition for a valid Knight move is met, set `validMove` to `true`. + - Return the value of `validMove`. +- **Output**: A boolean value indicating whether the Knight can legally move to the specified square (`true` if the move is valid, `false` otherwise). +- **See also**: [`Knight`](knight.h.md#Knight) (Data Structure) + + +--- +#### Knight::display +The `display` function outputs the knight's color followed by the letter 'N' to represent the knight piece in a chess game. +- **Inputs**: None +- **Control Flow**: + - The function uses the `cout` stream to output the knight's color concatenated with the letter 'N'. +- **Output**: The function outputs a string to the standard output stream, representing the knight's color and type. +- **See also**: [`Knight`](knight.h.md#Knight) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/knight.h.md b/driver_docs/c_cpp_export_test/cpp_src/knight.h.md new file mode 100644 index 0000000..3a5bd6a --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/knight.h.md @@ -0,0 +1,38 @@ + + + + + +The `knight.h` file defines a `Knight` class that represents a chess knight piece, including methods for creating a knight, determining its point value, checking legal moves, and displaying the piece. + +# Purpose +The provided code is a C++ header file, `knight.h`, which defines the `Knight` class, representing a knight piece in a chess game. This class inherits from a base class `Piece`, indicating that it is part of a larger chess-related software system. The `Knight` class encapsulates the specific behaviors and attributes of a knight chess piece, such as its color, point value, and movement capabilities. The class provides a constructor to initialize a knight with a specified color, a destructor, and several member functions that define its functionality. These functions include `value()`, which returns the point value of the knight, `canMoveTo()`, which determines if the knight can legally move to a specified square, and `display()`, which outputs the knight's representation to a given output stream. + +The `Knight` class is a specialized component within a broader chess application, focusing on the unique movement and characteristics of the knight piece. It interfaces with other components, such as the `Square` class, to determine legal moves, suggesting that the system models a chessboard and its rules. The use of inheritance from the `Piece` class implies a polymorphic design, allowing for the extension and management of different chess pieces within the application. This header file is intended to be included in other parts of the program, providing a public API for interacting with knight objects, and it is likely part of a larger library or application that simulates or manages chess games. +# Imports and Dependencies + +--- +- `iostream` +- `square.h` +- `piece.h` + + +# Data Structures + +--- +### Knight +- **Type**: `class` +- **Description**: The `Knight` class represents a chess knight piece and inherits from the `Piece` class. It includes a constructor to initialize the knight with a specified color, a destructor, and several member functions. The `value` function returns the point value of the knight, which is 3. The `canMoveTo` function determines if the knight can legally move to a given square based on the unique L-shaped movement pattern of a knight in chess. The `display` function outputs the knight's representation, which includes its color and the letter 'N' for knight. +- **Member Functions**: + - [`Knight::Knight`](knight.cpp.md#KnightKnight) + - [`Knight::~Knight`](knight.cpp.md#KnightKnight) + - [`Knight::value`](knight.cpp.md#Knightvalue) + - [`Knight::canMoveTo`](knight.cpp.md#KnightcanMoveTo) + - [`Knight::display`](knight.cpp.md#Knightdisplay) +- **Inherits From**: + - `Piece` + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/main.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/main.cpp.md new file mode 100644 index 0000000..827c008 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/main.cpp.md @@ -0,0 +1,42 @@ + + + + + +The `main.cpp` file contains the main program logic for playing a chess game, including initializing the game, displaying the board, and handling player moves. + +# Purpose +This C++ source code file serves as the main entry point for a chess game application. It is designed to initialize and manage the flow of a chess game by interacting with other components, specifically the `Game` and `Board` classes, which are likely defined in the included headers "game.h" and "board.h". The code initializes the game state and enters a loop where players alternate turns to make moves. The `Game::initialize()` function is called to set up the initial game state, and the `Board::getBoard()->display(cout)` function is used to display the current state of the chessboard to the standard output. + +The main technical components of this file include the game loop, which continuously prompts players to make moves, and the error handling mechanism that ensures only valid moves are accepted. The `currentPlayer` pointer is used to track the player whose turn it is, and the `Game::getNextPlayer()` function is called to switch turns between players. The file does not define public APIs or external interfaces but rather orchestrates the interaction between the game logic and the user interface. This code is intended to be compiled into an executable that runs the chess game, leveraging the functionality provided by the `Game` and `Board` classes. +# Imports and Dependencies + +--- +- `iostream` +- `game.h` +- `board.h` + + +# Functions + +--- +### main +The `main` function initializes and runs a continuous loop for a chess game where players alternate making moves until a valid move is made. +- **Inputs**: + - `argc`: The number of command-line arguments passed to the program. + - `argv`: An array of C-style strings representing the command-line arguments. +- **Control Flow**: + - Initialize a pointer `currentPlayer` to `NULL`. + - Call `Game::initialize()` to set up the chess game. + - Display the initial state of the board using `Board::getBoard()->display(cout)`. + - Enter an infinite loop to alternate player turns. + - Within the loop, get the next player using `Game::getNextPlayer()`. + - Attempt to make a move with `currentPlayer->makeMove()`, repeating until a valid move is made. + - If a move is invalid, output an error message to `cerr`. + - After a valid move, display the updated board state with `Board::getBoard()->display(cout)`. +- **Output**: The function returns an integer `0`, indicating successful execution. + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/pawn.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/pawn.cpp.md new file mode 100644 index 0000000..35643b2 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/pawn.cpp.md @@ -0,0 +1,136 @@ + + + + + +The `pawn.cpp` file implements the behavior of a pawn piece in a chess game, including movement, promotion to a queen, and display functionality. + +# Purpose +The provided C++ source code file, `pawn.cpp`, is part of a chess game implementation, specifically handling the behavior and rules associated with the pawn piece. This file defines the [`Pawn`](#PawnPawn) class, which inherits from a `RestrictedPiece` class, indicating that it has specific movement constraints. The [`Pawn`](#PawnPawn) class encapsulates the logic for pawn-specific actions, such as moving forward, capturing diagonally, and promoting to a queen upon reaching the opponent's end of the board. The class uses a delegate pattern to handle the promotion of a pawn to a queen, dynamically switching its behavior to that of a `Queen` object when necessary. + +The [`Pawn`](#PawnPawn) class provides several key methods: [`setLocation`](#PawnsetLocation) to update the pawn's position, [`value`](#Pawnvalue) to return the pawn's point value, [`moveTo`](#PawnmoveTo) to execute a move and handle promotion, and [`canMoveTo`](#PawncanMoveTo) to validate potential moves based on chess rules. The [`display`](#Pawndisplay) method outputs the pawn's representation, which changes if it has been promoted. The code is designed to be part of a larger chess application, interacting with other components like `Square`, `Player`, and `Board`. It does not define a public API but rather serves as an internal component of the chess game logic, focusing on the pawn's unique movement and promotion rules. +# Imports and Dependencies + +--- +- `pawn.h` +- `queen.h` +- `board.h` + + +# Data Structures + +--- +### Pawn +- **Description**: [See definition](pawn.h.md#Pawn) +- **Member Functions**: + - [`Pawn::Pawn`](#PawnPawn) + - [`Pawn::~Pawn`](#PawnPawn) + - [`Pawn::setLocation`](#PawnsetLocation) + - [`Pawn::value`](#Pawnvalue) + - [`Pawn::moveTo`](#PawnmoveTo) + - [`Pawn::canMoveTo`](#PawncanMoveTo) + - [`Pawn::display`](#Pawndisplay) +- **Inherits From**: + - `RestrictedPiece` + +**Methods** + +--- +#### Pawn::Pawn +The `Pawn` constructor initializes a `Pawn` object with a specified color and sets its delegate to NULL. +- **Inputs**: + - `isWhite`: A boolean indicating whether the pawn is white (true) or black (false). +- **Control Flow**: + - The constructor initializes the `Pawn` object by calling the constructor of its superclass `RestrictedPiece` with the `isWhite` parameter. + - It sets the private member `_delegate` to NULL, indicating that the pawn has not been promoted to another piece. +- **Output**: A `Pawn` object is created with the specified color and no delegate piece. +- **See also**: [`Pawn`](pawn.h.md#Pawn) (Data Structure) + + +--- +#### Pawn::\~Pawn +The destructor for the `Pawn` class deallocates memory for the `_delegate` member if it is not null. +- **Inputs**: None +- **Control Flow**: + - Check if the `_delegate` pointer is not null. + - If `_delegate` is not null, delete the memory allocated for `_delegate`. +- **Output**: The destructor does not return any value. +- **See also**: [`Pawn`](pawn.h.md#Pawn) (Data Structure) + + +--- +#### Pawn::setLocation +The `setLocation` function sets the location of a `Pawn` object by calling the `setLocation` method of its base class `Piece`. +- **Inputs**: + - `location`: A pointer to a `Square` object representing the new location for the `Pawn`. +- **Control Flow**: + - The function takes a `Square*` as an argument, which represents the new location for the `Pawn`. + - It calls the `setLocation` method of the base class `Piece` with the provided `location` argument. +- **Output**: The function does not return any value. +- **See also**: [`Pawn`](pawn.h.md#Pawn) (Data Structure) + + +--- +#### Pawn::value +The `value` function returns the point value of a Pawn piece in a chess game. +- **Inputs**: None +- **Control Flow**: + - The function is a simple getter that returns a constant integer value. + - There are no conditional statements or loops; it directly returns the integer 1. +- **Output**: The function returns an integer value of 1, representing the point value of a Pawn in chess. +- **See also**: [`Pawn`](pawn.h.md#Pawn) (Data Structure) + + +--- +#### Pawn::moveTo +The `moveTo` function attempts to move a pawn to a specified square, handling both normal pawn movement and promotion to a queen if applicable. +- **Inputs**: + - `byPlayer`: A reference to the Player object attempting to move the pawn. + - `to`: A reference to the Square object representing the destination square for the pawn. +- **Control Flow**: + - Initialize a boolean variable `valid` to false to track the validity of the move. + - Check if the pawn has been promoted by verifying if `_delegate` is not null. + - If promoted, use the delegate piece's `moveTo` method to determine move validity. + - If the move is valid, update the pawn's current and new square occupiers and set the new location. + - If not promoted, use the `RestrictedPiece`'s `moveTo` method to attempt a normal pawn move. + - If the move is valid and the pawn reaches the opponent's end row, promote the pawn to a queen by creating a new `Queen` object and setting it as the delegate. + - Return the boolean `valid` indicating whether the move was successful. +- **Output**: A boolean value indicating whether the move was successful. +- **Functions called**: + - [`Pawn::setLocation`](#PawnsetLocation) +- **See also**: [`Pawn`](pawn.h.md#Pawn) (Data Structure) + + +--- +#### Pawn::canMoveTo +The `canMoveTo` function determines if a pawn can legally move to a specified square based on its current position, movement rules, and whether it has been promoted. +- **Inputs**: + - `location`: A reference to a `Square` object representing the target location to which the pawn is attempting to move. +- **Control Flow**: + - Initialize `validMove` to false and calculate `translationX` and `translationY` as the differences in x and y coordinates between the target location and the pawn's current location. + - Check if the pawn has been promoted (i.e., has a delegate piece); if so, use the delegate's `canMoveTo` method to determine move validity. + - If the pawn is not promoted, adjust `translationX` and `translationY` for black pieces to account for their movement direction being opposite to white pieces. + - Check if the move is a valid one-square forward move to an unoccupied square and set `validMove` to true if so. + - Check if the move is a valid two-square forward move from the starting position to an unoccupied square along a clear vertical path and set `validMove` to true if so. + - Check if the move is a valid capture move to an occupied square on an adjacent diagonal and set `validMove` to true if so. + - Return the value of `validMove`. +- **Output**: A boolean value indicating whether the pawn can legally move to the specified square. +- **See also**: [`Pawn`](pawn.h.md#Pawn) (Data Structure) + + +--- +#### Pawn::display +The `display` function outputs the visual representation of a `Pawn` object, either by delegating to another piece or displaying its own symbol. +- **Inputs**: None +- **Control Flow**: + - Check if the `_delegate` pointer is not null. + - If `_delegate` is not null, call the `display` method on the `_delegate` object. + - If `_delegate` is null, output the pawn's color followed by the letter 'P' to represent the pawn. +- **Output**: The function outputs the pawn's representation to the standard output stream. +- **See also**: [`Pawn`](pawn.h.md#Pawn) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/pawn.h.md b/driver_docs/c_cpp_export_test/cpp_src/pawn.h.md new file mode 100644 index 0000000..974ed72 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/pawn.h.md @@ -0,0 +1,40 @@ + + + + + +The `pawn.h` file defines a `Pawn` class representing a chess pawn piece, including methods for movement, location setting, and display functionality. + +# Purpose +The provided code is a C++ header file (`pawn.h`) that defines a class representing a chess pawn piece, which is a specific type of chess piece with restricted movement capabilities. This class, `Pawn`, inherits from `RestrictedPiece`, suggesting it is part of a broader chess game implementation where different pieces have varying movement rules. The class offers narrow functionality specific to the pawn, including methods for setting its location, determining its point value, moving to a new square, checking the legality of a move, and displaying the piece. The header file is intended to be included in other parts of a chess program, as indicated by the inclusion guards and the use of other classes like `Square` and `Player`, which are likely defined elsewhere in the program. +# Imports and Dependencies + +--- +- `iostream` +- `square.h` +- `restrictedPiece.h` + + +# Data Structures + +--- +### Pawn +- **Type**: `class` +- **Members**: + - `_delegate`: A pointer to a Piece object used for delegation when the pawn is promoted. +- **Description**: The Pawn class represents a pawn piece in a chess game, inheriting from the RestrictedPiece class. It encapsulates the behavior and attributes specific to a pawn, including its movement rules and promotion to a queen when reaching the opponent's end of the board. The class uses a delegate pattern to handle the pawn's promotion, allowing it to adopt the movement capabilities of a queen. The Pawn class provides methods to set its location, determine its point value, move to a new square, check if a move is legal, and display itself. The private member _delegate is used to manage the pawn's promotion state. +- **Member Functions**: + - [`Pawn::Pawn`](pawn.cpp.md#PawnPawn) + - [`Pawn::~Pawn`](pawn.cpp.md#PawnPawn) + - [`Pawn::setLocation`](pawn.cpp.md#PawnsetLocation) + - [`Pawn::value`](pawn.cpp.md#Pawnvalue) + - [`Pawn::moveTo`](pawn.cpp.md#PawnmoveTo) + - [`Pawn::canMoveTo`](pawn.cpp.md#PawncanMoveTo) + - [`Pawn::display`](pawn.cpp.md#Pawndisplay) +- **Inherits From**: + - [`RestrictedPiece`](restrictedPiece.h.md#RestrictedPiece) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/piece.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/piece.cpp.md new file mode 100644 index 0000000..736fc18 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/piece.cpp.md @@ -0,0 +1,134 @@ + + + + + +The `piece.cpp` file implements the `Piece` class for a chess game, handling piece movement, capturing logic, and color assignment. + +# Purpose +The provided C++ source file, `piece.cpp`, is part of a larger chess application, likely named "ChessProject". This file implements the [`Piece`](#PiecePiece) class, which represents a chess piece in the game. The class provides functionality to manage the state and behavior of a chess piece, including its color, current location on the board, and the ability to move to a new square. The [`Piece`](#PiecePiece) class constructor initializes the piece's color based on whether it is white or black, and the destructor is defined but does not perform any specific actions. + +The core functionality of the [`Piece`](#PiecePiece) class is encapsulated in the [`moveTo`](#PiecemoveTo) method, which handles the logic for moving a piece from its current square to a target square. This method checks if the move is valid by ensuring it is performed by the correct player, adheres to the piece's movement rules, and does not leave the player's king in check. The method also manages capturing opponent pieces and updating the board state accordingly. Additional methods such as [`setLocation`](#PiecesetLocation), [`isWhite`](#PieceisWhite), [`color`](#Piececolor), [`isOnSquare`](#PieceisOnSquare), and [`location`](#Piecelocation) provide access to the piece's attributes and current state. This file is a crucial component of the chess application, focusing on the individual behavior and rules governing chess pieces. +# Imports and Dependencies + +--- +- `string` +- `piece.h` +- `player.h` + + +# Data Structures + +--- +### Piece +- **Description**: [See definition](piece.h.md#Piece) +- **Member Functions**: + - [`Piece::Piece`](#PiecePiece) + - [`Piece::~Piece`](#PiecePiece) + - [`Piece::moveTo`](#PiecemoveTo) + - [`Piece::setLocation`](#PiecesetLocation) + - [`Piece::isWhite`](#PieceisWhite) + - [`Piece::color`](#Piececolor) + - [`Piece::isOnSquare`](#PieceisOnSquare) + - [`Piece::location`](#Piecelocation) + +**Methods** + +--- +#### Piece::Piece +The `Piece` constructor initializes a chess piece with a specified color and sets its initial square to null. +- **Inputs**: + - `isWhite`: A boolean indicating whether the piece is white (true) or black (false). +- **Control Flow**: + - The constructor initializes the `_isWhite` member variable with the value of `isWhite`. + - The `_square` member variable is initialized to `NULL`, indicating that the piece is not on any square initially. + - A conditional check is performed on `isWhite` to set the `_color` member variable to "W" if `isWhite` is true, or "B" if false. +- **Output**: The constructor does not return a value as it is used to initialize an object of the `Piece` class. +- **See also**: [`Piece`](piece.h.md#Piece) (Data Structure) + + +--- +#### Piece::\~Piece +The `Piece::~Piece()` function is the default destructor for the `Piece` class, which currently performs no specific actions upon object destruction. +- **Inputs**: None +- **Control Flow**: + - The destructor is called when a `Piece` object goes out of scope or is explicitly deleted. + - Currently, the destructor does not contain any code, so it performs no operations. +- **Output**: There is no output from this destructor as it performs no actions. +- **See also**: [`Piece`](piece.h.md#Piece) (Data Structure) + + +--- +#### Piece::moveTo +The `moveTo` function attempts to move a chess piece to a specified square, ensuring the move is legal according to chess rules and does not leave the player's king in check. +- **Inputs**: + - `byPlayer`: A reference to the Player object attempting to move the piece, used to verify the move's legality and color. + - `toSquare`: A reference to the Square object representing the destination square for the piece. +- **Control Flow**: + - Initialize `validMove` to false and `toCapture` to NULL, and store the current square in `fromSquare`. + - Check if the piece is being moved by its owner by comparing the piece's color with the player's color. + - Verify if the piece can legally move to the target square using `canMoveTo`. + - If the target square is occupied, check if the occupying piece can be captured (i.e., it is of the opposite color). + - If the move is valid, tentatively move the piece to the target square and update the square's occupier. + - Check if the move leaves the player's king in check using `byPlayer.inCheck()`. + - If the move results in a check, undo the move and restore the original state. + - If the move does not result in a check, finalize the move and capture the opponent's piece if applicable. +- **Output**: Returns a boolean indicating whether the move was valid and successfully executed. +- **See also**: [`Piece`](piece.h.md#Piece) (Data Structure) + + +--- +#### Piece::setLocation +The `setLocation` function assigns a new square location to a chess piece. +- **Inputs**: + - `location`: A pointer to a `Square` object representing the new location for the piece. +- **Control Flow**: + - The function assigns the provided `Square` pointer to the private member variable `_square`, effectively updating the piece's current location. +- **Output**: This function does not return any value. +- **See also**: [`Piece`](piece.h.md#Piece) (Data Structure) + + +--- +#### Piece::isWhite +The `isWhite` function checks if a chess piece is white. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the value of the private member variable `_isWhite`. +- **Output**: A boolean value indicating whether the piece is white (`true`) or not (`false`). +- **See also**: [`Piece`](piece.h.md#Piece) (Data Structure) + + +--- +#### Piece::color +The `color` function returns the color of the chess piece as a string. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the value of the private member variable `_color`. +- **Output**: A string representing the color of the piece, either "W" for white or "B" for black. +- **See also**: [`Piece`](piece.h.md#Piece) (Data Structure) + + +--- +#### Piece::isOnSquare +The `isOnSquare` function checks if a chess piece is currently located on a square. +- **Inputs**: None +- **Control Flow**: + - The function simply returns the value of the private member variable `_square`. +- **Output**: A boolean value indicating whether the piece is on a square (true if `_square` is not null, false otherwise). +- **See also**: [`Piece`](piece.h.md#Piece) (Data Structure) + + +--- +#### Piece::location +The `location` function returns the current square on which the piece is located. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the private member variable `_square`. +- **Output**: A pointer to a `Square` object representing the current location of the piece. +- **See also**: [`Piece`](piece.h.md#Piece) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/piece.h.md b/driver_docs/c_cpp_export_test/cpp_src/piece.h.md new file mode 100644 index 0000000..89e0d40 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/piece.h.md @@ -0,0 +1,43 @@ + + + + + +The `piece.h` file defines an abstract class for a game piece, including methods for movement, color determination, and location management. + +# Purpose +The provided code is a C++ header file, `piece.h`, which defines an abstract class `Piece` representing a game piece, likely for a board game such as chess. This class provides a broad set of functionalities related to the management and behavior of game pieces, including movement, color determination, and location management. The class is designed to be extended, as indicated by the presence of pure virtual functions like `value()`, `display()`, and `canMoveTo()`, which must be implemented by derived classes. This design allows for the creation of specific types of pieces with unique behaviors and characteristics. + +The `Piece` class includes several important technical components. It maintains attributes such as `_isWhite` to determine the piece's color and `_square` to track its current location on the board. The class provides public methods for moving the piece (`moveTo`), setting and getting its location (`setLocation`, `location`), and checking its color (`isWhite`, `color`). The inclusion of the `Player`, `Square`, and `Board` classes, as well as the use of the `ostream` library, suggests that this class is part of a larger game framework. The header file defines a public API for interacting with game pieces, making it a crucial component for any game logic that involves piece movement and interaction on a board. +# Imports and Dependencies + +--- +- `ostream` +- `square.h` +- `board.h` + + +# Data Structures + +--- +### Piece +- **Type**: `class` +- **Members**: + - `_isWhite`: A boolean indicating if the piece is white. + - `_color`: A string representing the color of the piece, either 'W' for white or 'B' for black. + - `_square`: A pointer to the Square object where the piece is currently located. +- **Description**: The `Piece` class represents a game piece in a board game, such as chess. It includes attributes to determine the piece's color and its current location on the board. The class provides methods to move the piece, check if a move is legal, and determine the piece's value, among other functionalities. It serves as a base class for specific types of pieces, requiring derived classes to implement certain virtual functions like `value`, `display`, and `canMoveTo`. The class ensures that moves are legal and handles capturing of opponent pieces, while also checking if a move results in a player's king being in check. +- **Member Functions**: + - [`Piece::Piece`](piece.cpp.md#PiecePiece) + - [`Piece::~Piece`](piece.cpp.md#PiecePiece) + - [`Piece::moveTo`](piece.cpp.md#PiecemoveTo) + - [`Piece::setLocation`](piece.cpp.md#PiecesetLocation) + - [`Piece::isWhite`](piece.cpp.md#PieceisWhite) + - [`Piece::color`](piece.cpp.md#Piececolor) + - [`Piece::isOnSquare`](piece.cpp.md#PieceisOnSquare) + - [`Piece::location`](piece.cpp.md#Piecelocation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/player.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/player.cpp.md new file mode 100644 index 0000000..ed73054 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/player.cpp.md @@ -0,0 +1,170 @@ + + + + + +The `player.cpp` file implements the `Player` class for a chess game, handling player actions such as making moves, checking for check status, capturing pieces, and calculating scores. + +# Purpose +The `player.cpp` file is part of a Chess game project and implements the functionality related to a player in the game. This file defines the [`Player`](#PlayerPlayer) class, which encapsulates the attributes and behaviors of a chess player, such as their name, the color they are playing (white or black), their pieces, and their king. The class provides methods for making moves, checking if the player is in check, capturing opponent pieces, and calculating the player's score based on captured pieces. The [`makeMove`](#PlayermakeMove) method is particularly important as it handles player input for moves, validates the input, and executes the move on the board if valid. The [`inCheck`](#PlayerinCheck) method determines if the player's king is under threat from any of the opponent's pieces, which is a critical aspect of chess gameplay. + +This file is a C++ source file that likely works in conjunction with other components of the Chess project, such as `board.h` and `game.h`, which are included at the beginning of the file. The [`Player`](#PlayerPlayer) class interacts with these components to manage the state of the game, such as the board's configuration and the pieces' positions. The file does not define a public API or external interface but rather provides the internal logic necessary for player-related operations within the game. The use of standard input/output functions indicates that this file may be part of a console-based application where players input their moves directly. +# Imports and Dependencies + +--- +- `iostream` +- `player.h` +- `board.h` +- `game.h` + + +# Data Structures + +--- +### Player +- **Description**: [See definition](player.h.md#Player) +- **Member Functions**: + - [`Player::Player`](#PlayerPlayer) + - [`Player::~Player`](#PlayerPlayer) + - [`Player::makeMove`](#PlayermakeMove) + - [`Player::inCheck`](#PlayerinCheck) + - [`Player::capture`](#Playercapture) + - [`Player::getName`](#PlayergetName) + - [`Player::isWhite`](#PlayerisWhite) + - [`Player::score`](#Playerscore) + - [`Player::myPieces`](#PlayermyPieces) + - [`Player::myKing`](#PlayermyKing) + +**Methods** + +--- +#### Player::Player +The `Player` constructor initializes a `Player` object with a name, color, a reference to their king, and a set of their pieces. +- **Inputs**: + - `name`: A string representing the player's name. + - `isWhite`: A boolean indicating whether the player is playing with the white pieces. + - `myKing`: A reference to the `King` object that belongs to the player. + - `myPieces`: A reference to a set of pointers to `Piece` objects representing the player's pieces. +- **Control Flow**: + - The constructor initializes the `_name` member variable with the provided `name` argument. + - The `_isWhite` member variable is initialized with the `isWhite` argument to indicate the player's color. + - The `_myPieces` member variable is initialized with the reference to the set of pieces provided by `myPieces`. + - The `_myKing` member variable is initialized with the reference to the `King` object provided by `myKing`. +- **Output**: The constructor does not return any value as it is used to initialize a `Player` object. +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::\~Player +The `Player::~Player()` function is the default destructor for the `Player` class, which currently does not perform any specific operations upon object destruction. +- **Inputs**: None +- **Control Flow**: + - The destructor is defined but contains no code, indicating it does not perform any specific actions when a `Player` object is destroyed. +- **Output**: There is no output or return value from this destructor, as it is a default destructor with no operations. +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::makeMove +The `makeMove` function allows a player to input and execute a move on the chessboard, ensuring the move is valid and in algebraic notation. +- **Inputs**: + - `None`: The function does not take any parameters; it relies on user input for the move. +- **Control Flow**: + - Check if the player is in check and announce it if true. + - Prompt the player to enter a move in algebraic notation (e.g., 'a2 a4'). + - Validate the input to ensure it is in the correct format and the starting square is occupied. + - If the input is invalid, prompt the player again until a valid move is entered. + - Translate the algebraic notation into board coordinates. + - Move the piece from the starting square to the destination square using the `moveTo` method. +- **Output**: Returns a boolean indicating whether the move was successfully executed. +- **Functions called**: + - [`Player::inCheck`](#PlayerinCheck) +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::inCheck +The `inCheck` function determines if the current player's king is in check by checking if any opponent's piece can move to the king's location. +- **Inputs**: None +- **Control Flow**: + - Initialize a boolean variable `check` to false. + - Iterate over each piece in the opponent's set of pieces. + - For each piece, check if it is located on the board and can move to the current player's king's location. + - If such a piece is found, set `check` to true. + - Return the value of `check`. +- **Output**: A boolean value indicating whether the player's king is in check (true if in check, false otherwise). +- **Functions called**: + - [`Player::myKing`](#PlayermyKing) +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::capture +The `capture` function removes a piece from the board and adds it to the player's set of captured pieces. +- **Inputs**: + - `aPiece`: A pointer to the `Piece` object that is to be captured. +- **Control Flow**: + - The function first sets the location of the piece `aPiece` to `NULL`, effectively removing it from the board. + - Then, it inserts the piece into the player's `_capturedPieces` set, which keeps track of all pieces captured by the player. +- **Output**: The function does not return any value. +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::getName +The `getName` function returns the name of the player. +- **Inputs**: None +- **Control Flow**: + - The function accesses the private member variable `_name` of the `Player` class. + - It returns the value of `_name`. +- **Output**: A string representing the player's name. +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::isWhite +The `isWhite` function checks if the player is the white player in a chess game. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the value of the private member variable `_isWhite`. +- **Output**: A boolean value indicating whether the player is the white player (`true`) or not (`false`). +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::score +The `score` function calculates and returns the total score of all pieces captured by the player. +- **Inputs**: None +- **Control Flow**: + - Initialize a local variable `score` to 0. + - Iterate over each piece in the player's `_capturedPieces` set. + - For each piece, add its value (obtained by calling the `value()` method on the piece) to the `score`. + - Return the accumulated `score`. +- **Output**: The function returns an integer representing the total score of the captured pieces. +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::myPieces +The `myPieces` function returns a pointer to the set of pieces owned by the player. +- **Inputs**: None +- **Control Flow**: + - The function simply returns the address of the `_myPieces` member variable, which is a reference to a set of `Piece*`. +- **Output**: A pointer to a `set` representing the player's pieces. +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + +--- +#### Player::myKing +The `myKing` function returns a pointer to the `King` object associated with the `Player` instance. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the address of the `_myKing` member variable, which is a reference to a `King` object. +- **Output**: A pointer to the `King` object associated with the `Player` instance. +- **See also**: [`Player`](player.h.md#Player) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/player.h.md b/driver_docs/c_cpp_export_test/cpp_src/player.h.md new file mode 100644 index 0000000..526c950 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/player.h.md @@ -0,0 +1,47 @@ + + + + + +The `player.h` file defines a `Player` class for a chess game, including methods for making moves, checking if the player is in check, capturing pieces, and accessing player attributes such as name, color, and score. + +# Purpose +The provided code is a C++ header file, `player.h`, which defines the `Player` class for a chess game application. This class encapsulates the attributes and behaviors associated with a chess player, such as their name, color (white or black), the pieces they control, and their king. The class provides a range of functionalities, including making moves, checking if the player is in check, capturing opponent pieces, and calculating the player's score based on captured pieces. The class also includes methods to access the player's name, color, set of pieces, and king, which are essential for managing the state and actions of a player during a chess game. + +The `Player` class is designed to be a part of a larger chess game system, as indicated by its dependencies on other classes like `Piece` and `King`. It provides a public API that includes constructors, a destructor, and several member functions that facilitate interaction with the player's state and actions. The use of a set to manage the player's pieces and captured pieces ensures efficient handling of these collections. The class is structured to be integrated into a broader application, likely alongside other components that manage the game board, rules, and interactions between players. +# Imports and Dependencies + +--- +- `set` +- `piece.h` +- `king.h` + + +# Data Structures + +--- +### Player +- **Type**: `class` +- **Members**: + - `_name`: Stores the name of the player. + - `_isWhite`: Indicates whether the player is playing with the white pieces. + - `_myPieces`: References the set of pieces currently owned by the player. + - `_capturedPieces`: Holds the set of pieces captured by the player. + - `_myKing`: References the player's king piece. +- **Description**: The `Player` class represents a chess player in a game, encapsulating the player's identity, their pieces, and their actions during the game. It includes attributes for the player's name, whether they are playing as white, their set of pieces, captured pieces, and their king. The class provides functionality to make moves, check if the player is in check, capture pieces, and calculate the score based on captured pieces. It serves as a central entity in managing a player's state and actions in a chess game. +- **Member Functions**: + - [`Player::Player`](player.cpp.md#PlayerPlayer) + - [`Player::~Player`](player.cpp.md#PlayerPlayer) + - [`Player::makeMove`](player.cpp.md#PlayermakeMove) + - [`Player::inCheck`](player.cpp.md#PlayerinCheck) + - [`Player::capture`](player.cpp.md#Playercapture) + - [`Player::getName`](player.cpp.md#PlayergetName) + - [`Player::isWhite`](player.cpp.md#PlayerisWhite) + - [`Player::score`](player.cpp.md#Playerscore) + - [`Player::myPieces`](player.cpp.md#PlayermyPieces) + - [`Player::myKing`](player.cpp.md#PlayermyKing) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/queen.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/queen.cpp.md new file mode 100644 index 0000000..9188c19 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/queen.cpp.md @@ -0,0 +1,92 @@ + + + + + +The `queen.cpp` file implements the Queen class for a chess game, defining its movement capabilities and display representation. + +# Purpose +The provided code is a C++ source file, `queen.cpp`, which is part of a larger chess project. It defines the implementation of a [`Queen`](#QueenQueen) class, which inherits from a `Piece` class, likely representing a chess piece. The functionality is relatively narrow, focusing specifically on the behavior and characteristics of a queen piece in chess. The class includes a constructor and destructor, a method to return the queen's value (9, as per chess piece values), and a [`canMoveTo`](#QueencanMoveTo) method that checks if the queen can move to a specified square based on clear vertical, horizontal, or diagonal paths, utilizing a `Board` class for these checks. Additionally, the [`display`](#Queendisplay) method outputs the queen's representation, indicating its color and type. This file is intended to be part of a larger chess application, likely imported and used alongside other piece implementations. +# Imports and Dependencies + +--- +- `queen.h` + + +# Data Structures + +--- +### Queen +- **Description**: [See definition](queen.h.md#Queen) +- **Member Functions**: + - [`Queen::Queen`](#QueenQueen) + - [`Queen::~Queen`](#QueenQueen) + - [`Queen::value`](#Queenvalue) + - [`Queen::canMoveTo`](#QueencanMoveTo) + - [`Queen::display`](#Queendisplay) +- **Inherits From**: + - `Piece` + +**Methods** + +--- +#### Queen::Queen +The `Queen` constructor initializes a Queen object by setting its color through the base class `Piece` constructor. +- **Inputs**: + - `isWhite`: A boolean indicating whether the Queen is white (true) or black (false). +- **Control Flow**: + - The constructor `Queen::Queen(bool isWhite)` is called with a boolean parameter `isWhite`. + - The constructor initializes the `Queen` object by calling the base class `Piece` constructor with the `isWhite` parameter. +- **Output**: There is no explicit output from the constructor, but it initializes a `Queen` object with the specified color. +- **See also**: [`Queen`](queen.h.md#Queen) (Data Structure) + + +--- +#### Queen::\~Queen +The destructor for the Queen class is a default destructor that performs no specific actions. +- **Inputs**: None +- **Control Flow**: + - The destructor is defined but contains no code, indicating it performs no operations when a Queen object is destroyed. +- **Output**: There is no output or return value from this destructor. +- **See also**: [`Queen`](queen.h.md#Queen) (Data Structure) + + +--- +#### Queen::value +The `value` function returns the fixed point value of a Queen piece in chess. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the integer value 9, which represents the point value of a Queen in chess. +- **Output**: The function returns an integer value of 9. +- **See also**: [`Queen`](queen.h.md#Queen) (Data Structure) + + +--- +#### Queen::canMoveTo +The `canMoveTo` function determines if a Queen piece can legally move to a specified square on the chessboard by checking if the path is clear vertically, horizontally, or diagonally. +- **Inputs**: + - `location`: A reference to a `Square` object representing the target location on the chessboard where the Queen is attempting to move. +- **Control Flow**: + - Initialize a boolean variable `validMove` to `false`. + - Check if the path from the Queen's current location to the target location is clear vertically using `Board::getBoard()->isClearVertical`. If true, set `validMove` to `true`. + - If the vertical path is not clear, check if the path is clear horizontally using `Board::getBoard()->isClearHorizontal`. If true, set `validMove` to `true`. + - If neither the vertical nor horizontal paths are clear, check if the path is clear diagonally using `Board::getBoard()->isClearDiagonal`. If true, set `validMove` to `true`. + - Return the value of `validMove`. +- **Output**: A boolean value indicating whether the Queen can legally move to the specified square (`true` if the move is legal, `false` otherwise). +- **See also**: [`Queen`](queen.h.md#Queen) (Data Structure) + + +--- +#### Queen::display +The `display` function outputs the Queen's color and the letter 'Q' to represent the Queen piece on the console. +- **Inputs**: None +- **Control Flow**: + - The function uses the `cout` stream to output the Queen's color followed by the letter 'Q'. +- **Output**: The function does not return any value; it outputs directly to the console. +- **See also**: [`Queen`](queen.h.md#Queen) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/queen.h.md b/driver_docs/c_cpp_export_test/cpp_src/queen.h.md new file mode 100644 index 0000000..cb90e15 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/queen.h.md @@ -0,0 +1,36 @@ + + + + + +The `queen.h` file defines a `Queen` class representing a chess queen piece, including methods for determining legal moves, getting its point value, and displaying the piece. + +# Purpose +The provided code is a C++ header file (`queen.h`) that defines a class representing a chess queen piece, offering narrow functionality specific to chess game logic. This class, `Queen`, inherits from a base class `Piece`, suggesting a broader chess game framework where different pieces share common characteristics. The class includes a constructor to initialize a queen with a specified color, a destructor, and several member functions: `value()` to return the point value of the queen, `canMoveTo()` to determine if a move to a specified square is legal, and `display()` to output the queen's representation. The header file is intended to be included in other parts of a chess application, likely alongside implementations in corresponding source files. +# Imports and Dependencies + +--- +- `iostream` +- `square.h` +- `piece.h` + + +# Data Structures + +--- +### Queen +- **Type**: `class` +- **Description**: The `Queen` class represents a chess queen piece in a chess game, inheriting from the `Piece` class. It encapsulates the behavior and characteristics of a queen, including its ability to move vertically, horizontally, or diagonally across the board, as determined by the `canMoveTo` method. The class also provides a method to retrieve the point value of the queen, which is 9, and a method to display the queen on the board. The constructor initializes the queen with a specified color, and the class includes a destructor for cleanup. +- **Member Functions**: + - [`Queen::Queen`](queen.cpp.md#QueenQueen) + - [`Queen::~Queen`](queen.cpp.md#QueenQueen) + - [`Queen::value`](queen.cpp.md#Queenvalue) + - [`Queen::canMoveTo`](queen.cpp.md#QueencanMoveTo) + - [`Queen::display`](queen.cpp.md#Queendisplay) +- **Inherits From**: + - `Piece` + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/restrictedPiece.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/restrictedPiece.cpp.md new file mode 100644 index 0000000..6cc8d21 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/restrictedPiece.cpp.md @@ -0,0 +1,82 @@ + + + + + +The `restrictedPiece.cpp` file defines the `RestrictedPiece` class for a chess project, which extends the `Piece` class to include functionality for tracking whether the piece has moved. + +# Purpose +The provided code defines a C++ class [`RestrictedPiece`](#RestrictedPieceRestrictedPiece), which is part of a chess game project, as indicated by the file name `restrictedPiece.cpp` and the comment header. This class inherits from a base class `Piece` and is designed to represent a chess piece with restricted movement capabilities, specifically tracking whether the piece has moved. The class constructor initializes the piece's color and sets a private member `_moved` to `false`, indicating the piece has not yet moved. The [`moveTo`](#RestrictedPiecemoveTo) method attempts to move the piece to a new square, updating `_moved` to `true` only if the move is valid and the piece has not previously moved. The [`hasMoved`](#RestrictedPiecehasMoved) method provides a way to check if the piece has moved. This code provides narrow functionality specific to the chess game logic and is intended to be part of a larger project, likely imported and used by other components of the chess game. +# Imports and Dependencies + +--- +- `player.h` +- `restrictedPiece.h` + + +# Data Structures + +--- +### RestrictedPiece +- **Description**: [See definition](restrictedPiece.h.md#RestrictedPiece) +- **Member Functions**: + - [`RestrictedPiece::RestrictedPiece`](#RestrictedPieceRestrictedPiece) + - [`RestrictedPiece::~RestrictedPiece`](#RestrictedPieceRestrictedPiece) + - [`RestrictedPiece::moveTo`](#RestrictedPiecemoveTo) + - [`RestrictedPiece::hasMoved`](#RestrictedPiecehasMoved) +- **Inherits From**: + - `Piece` + +**Methods** + +--- +#### RestrictedPiece::RestrictedPiece +The `RestrictedPiece` constructor initializes a chess piece with a specified color and sets its moved status to false. +- **Inputs**: + - `isWhite`: A boolean indicating whether the piece is white (true) or black (false). +- **Control Flow**: + - The constructor initializes the base class `Piece` with the `isWhite` parameter to set the color of the piece. + - It sets the private member variable `_moved` to `false`, indicating that the piece has not been moved yet. +- **Output**: There is no output from the constructor; it initializes the object state. +- **See also**: [`RestrictedPiece`](restrictedPiece.h.md#RestrictedPiece) (Data Structure) + + +--- +#### RestrictedPiece::\~RestrictedPiece +The destructor for the `RestrictedPiece` class performs no specific actions upon object destruction. +- **Inputs**: None +- **Control Flow**: + - The destructor is defined but contains no code, indicating no special cleanup or resource management is required for `RestrictedPiece` objects. +- **Output**: There is no output or return value from the destructor. +- **See also**: [`RestrictedPiece`](restrictedPiece.h.md#RestrictedPiece) (Data Structure) + + +--- +#### RestrictedPiece::moveTo +The `moveTo` function attempts to move a `RestrictedPiece` to a new square and updates its moved status if the move is valid and the piece hasn't been moved before. +- **Inputs**: + - `byPlayer`: A reference to the `Player` object attempting to move the piece. + - `to`: A reference to the `Square` object representing the destination square for the move. +- **Control Flow**: + - Call the `moveTo` method of the base class `Piece` to determine if the move is valid. + - Check if the move is valid and if the piece has not been moved before. + - If both conditions are true, set the `_moved` attribute to `true`. + - Return the result of the base class `moveTo` method indicating if the move was valid. +- **Output**: A boolean value indicating whether the move was successful. +- **See also**: [`RestrictedPiece`](restrictedPiece.h.md#RestrictedPiece) (Data Structure) + + +--- +#### RestrictedPiece::hasMoved +The `hasMoved` function checks if a `RestrictedPiece` has been moved from its initial position. +- **Inputs**: None +- **Control Flow**: + - The function simply returns the value of the private member variable `_moved`. +- **Output**: A boolean value indicating whether the `RestrictedPiece` has been moved (`true`) or not (`false`). +- **See also**: [`RestrictedPiece`](restrictedPiece.h.md#RestrictedPiece) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/restrictedPiece.h.md b/driver_docs/c_cpp_export_test/cpp_src/restrictedPiece.h.md new file mode 100644 index 0000000..2889f7e --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/restrictedPiece.h.md @@ -0,0 +1,35 @@ + + + + + +The `restrictedPiece.h` file defines a `RestrictedPiece` class for a chess piece that tracks whether it has been moved, extending the functionality of a generic `Piece`. + +# Purpose +The provided code is a C++ header file (`restrictedPiece.h`) that defines a class `RestrictedPiece`, which inherits from a base class `Piece`. This class is designed to represent a chess piece with the additional functionality of tracking whether it has been moved. The functionality is relatively narrow, focusing specifically on the movement state of a chess piece. The class includes a constructor to initialize the piece with a color, a destructor, a method `moveTo` to attempt moving the piece to a new square, and a method `hasMoved` to check if the piece has been moved previously. The private attribute `_moved` is used to store the movement state of the piece. This header file is intended to be included in other C++ files where the `RestrictedPiece` class functionality is required. +# Imports and Dependencies + +--- +- `piece.h` + + +# Data Structures + +--- +### RestrictedPiece +- **Type**: `class` +- **Members**: + - `_moved`: A boolean attribute that indicates whether the piece has been moved. +- **Description**: The `RestrictedPiece` class is a specialized type of chess piece that extends the `Piece` class, adding functionality to track whether the piece has been moved. It includes a private boolean attribute `_moved` to store this state. The class provides a constructor to initialize the piece with a color, a destructor, and methods to move the piece and check if it has been moved. The `moveTo` method updates the `_moved` attribute only if a valid move is made and the piece has not been moved before, ensuring that the state accurately reflects the piece's movement history. +- **Member Functions**: + - [`RestrictedPiece::RestrictedPiece`](restrictedPiece.cpp.md#RestrictedPieceRestrictedPiece) + - [`RestrictedPiece::~RestrictedPiece`](restrictedPiece.cpp.md#RestrictedPieceRestrictedPiece) + - [`RestrictedPiece::moveTo`](restrictedPiece.cpp.md#RestrictedPiecemoveTo) + - [`RestrictedPiece::hasMoved`](restrictedPiece.cpp.md#RestrictedPiecehasMoved) +- **Inherits From**: + - `Piece` + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/rook.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/rook.cpp.md new file mode 100644 index 0000000..3d561d5 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/rook.cpp.md @@ -0,0 +1,95 @@ + + + + + +The `rook.cpp` file implements the Rook chess piece, including its movement logic and display functionality, for the ChessProject. + +# Purpose +The provided code is a C++ implementation file (`rook.cpp`) for a class named [`Rook`](#RookRook), which is part of a chess game project. This file defines the behavior and characteristics of a rook piece in chess, inheriting from a base class `RestrictedPiece`. The functionality is relatively narrow, focusing specifically on the movement and display logic of a rook. The [`Rook`](#RookRook) class includes a constructor and destructor, a method to return the piece's value (`value()`), a method to determine if a move is valid based on chess rules for rooks (`canMoveTo()`), and a method to display the rook on the console (`display()`). The `canMoveTo()` function checks if the rook can move vertically or horizontally without obstruction, utilizing methods from a `Board` class. This file is intended to be part of a larger chess application, likely imported and used alongside other piece implementations. +# Imports and Dependencies + +--- +- `rook.h` + + +# Data Structures + +--- +### Rook +- **Description**: [See definition](rook.h.md#Rook) +- **Member Functions**: + - [`Rook::Rook`](#RookRook) + - [`Rook::~Rook`](#RookRook) + - [`Rook::value`](#Rookvalue) + - [`Rook::canMoveTo`](#RookcanMoveTo) + - [`Rook::display`](#Rookdisplay) +- **Inherits From**: + - `RestrictedPiece` + +**Methods** + +--- +#### Rook::Rook +The Rook constructor initializes a Rook object by calling the constructor of its parent class, RestrictedPiece, with a boolean indicating the piece's color. +- **Inputs**: + - `isWhite`: A boolean value indicating whether the Rook is white (true) or black (false). +- **Control Flow**: + - The constructor of the Rook class is called with a boolean parameter 'isWhite'. + - The constructor of the parent class, RestrictedPiece, is invoked with the 'isWhite' parameter to initialize the Rook object. +- **Output**: There is no output from this constructor function; it initializes a Rook object. +- **See also**: [`Rook`](rook.h.md#Rook) (Data Structure) + + +--- +#### Rook::\~Rook +The destructor for the Rook class is a default destructor that performs no specific actions. +- **Inputs**: None +- **Control Flow**: + - The destructor is called when a Rook object is destroyed. + - No specific actions or resource deallocations are performed within the destructor. +- **Output**: There is no output from this destructor as it performs no operations. +- **See also**: [`Rook`](rook.h.md#Rook) (Data Structure) + + +--- +#### Rook::value +The `value` function returns the fixed point value of a Rook piece in a chess game. +- **Inputs**: None +- **Control Flow**: + - The function is a constant member function of the `Rook` class, indicating it does not modify the state of the object. + - It directly returns the integer value `5`, which represents the point value of a Rook in chess. +- **Output**: The function returns an integer value of `5`. +- **See also**: [`Rook`](rook.h.md#Rook) (Data Structure) + + +--- +#### Rook::canMoveTo +The `canMoveTo` function determines if a Rook can legally move to a specified square by checking for clear vertical or horizontal paths on the board. +- **Inputs**: + - `location`: A reference to a `Square` object representing the target location to which the Rook is attempting to move. +- **Control Flow**: + - Initialize a boolean variable `validMove` to `false`. + - Check if the path from the Rook's current location to the target location is clear vertically using `Board::getBoard()->isClearVertical`. + - If the vertical path is clear, set `validMove` to `true`. + - If the vertical path is not clear, check if the path is clear horizontally using `Board::getBoard()->isClearHorizontal`. + - If the horizontal path is clear, set `validMove` to `true`. + - Return the value of `validMove`. +- **Output**: A boolean value indicating whether the Rook can legally move to the specified square (true if the move is valid, false otherwise). +- **See also**: [`Rook`](rook.h.md#Rook) (Data Structure) + + +--- +#### Rook::display +The `display` function outputs the color and type of the Rook piece to the console. +- **Inputs**: None +- **Control Flow**: + - The function uses the `cout` stream to output the Rook's color followed by the letter 'R', representing the Rook piece. +- **Output**: The function does not return a value; it outputs directly to the console. +- **See also**: [`Rook`](rook.h.md#Rook) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/rook.h.md b/driver_docs/c_cpp_export_test/cpp_src/rook.h.md new file mode 100644 index 0000000..8dd86c1 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/rook.h.md @@ -0,0 +1,36 @@ + + + + + +The `rook.h` file defines a class representing a chess rook piece, including methods for determining legal moves, getting its point value, and displaying the piece. + +# Purpose +The provided code is a C++ header file (`rook.h`) that defines the interface for a `Rook` class, which represents a rook chess piece. This code offers narrow functionality, specifically tailored to encapsulate the behavior and characteristics of a rook within a chess game. The `Rook` class inherits from a `RestrictedPiece` class, suggesting that it shares common functionality with other restricted chess pieces, likely implementing specific movement rules. The class includes a constructor to initialize the rook's color, a destructor, and several member functions: `value()` to return the rook's point value, `canMoveTo()` to determine if a move to a specified square is legal, and `display()` to output the rook's representation. This header file is intended to be included in other C++ source files where the `Rook` class functionality is required. +# Imports and Dependencies + +--- +- `iostream` +- `restrictedPiece.h` +- `square.h` + + +# Data Structures + +--- +### Rook +- **Type**: `class` +- **Description**: The `Rook` class represents a chess rook piece and is derived from the `RestrictedPiece` class. It encapsulates the behavior and characteristics of a rook, including its ability to move vertically or horizontally across the board, as determined by the `canMoveTo` method. The class provides a constructor to initialize the rook with a specific color, a destructor, a method to return the point value of the rook (which is 5), and a method to display the rook on the board. The `Rook` class does not have any additional member variables beyond those inherited from `RestrictedPiece`. +- **Member Functions**: + - [`Rook::Rook`](rook.cpp.md#RookRook) + - [`Rook::~Rook`](rook.cpp.md#RookRook) + - [`Rook::value`](rook.cpp.md#Rookvalue) + - [`Rook::canMoveTo`](rook.cpp.md#RookcanMoveTo) + - [`Rook::display`](rook.cpp.md#Rookdisplay) +- **Inherits From**: + - [`RestrictedPiece`](restrictedPiece.h.md#RestrictedPiece) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/square.cpp.md b/driver_docs/c_cpp_export_test/cpp_src/square.cpp.md new file mode 100644 index 0000000..9e0c574 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/square.cpp.md @@ -0,0 +1,114 @@ + + + + + +The `square.cpp` file implements the `Square` class for a chess project, managing the position and occupancy of a square on the chessboard. + +# Purpose +The provided code is a C++ source file, likely part of a larger project, specifically a chess-related application named "ChessProject." It defines the implementation of a [`Square`](#SquareSquare) class, which represents a square on a chessboard. The class provides narrow functionality focused on managing the state of a single square, including its coordinates (`_x` and `_y`) and the chess piece occupying it (`_piece`). The class includes methods to set and retrieve the piece occupying the square, check if the square is occupied, and access the square's coordinates. This file is intended to be compiled as part of the project and is not a standalone executable, as it lacks a `main` function. +# Imports and Dependencies + +--- +- `piece.h` +- `square.h` + + +# Data Structures + +--- +### Square +- **Description**: [See definition](square.h.md#Square) +- **Member Functions**: + - [`Square::Square`](#SquareSquare) + - [`Square::~Square`](#SquareSquare) + - [`Square::setOccupier`](#SquaresetOccupier) + - [`Square::getX`](#SquaregetX) + - [`Square::getY`](#SquaregetY) + - [`Square::occupied`](#Squareoccupied) + - [`Square::occupiedBy`](#SquareoccupiedBy) + +**Methods** + +--- +#### Square::Square +The `Square` constructor initializes a `Square` object with specified x and y coordinates and sets the occupying piece to NULL. +- **Inputs**: + - `x`: The x-coordinate of the square on the board. + - `y`: The y-coordinate of the square on the board. +- **Control Flow**: + - The constructor initializes the private member variable `_x` with the value of the input parameter `x`. + - The constructor initializes the private member variable `_y` with the value of the input parameter `y`. + - The constructor sets the private member variable `_piece` to NULL, indicating that the square is initially unoccupied. +- **Output**: There is no return value as this is a constructor for the `Square` class. +- **See also**: [`Square`](square.h.md#Square) (Data Structure) + + +--- +#### Square::\~Square +The destructor for the `Square` class is a default destructor that performs no specific actions. +- **Inputs**: None +- **Control Flow**: + - The destructor `~Square()` is defined but contains no code, indicating it performs no operations when a `Square` object is destroyed. +- **Output**: There is no output or return value from the destructor, as it is a default destructor with no specific logic implemented. +- **See also**: [`Square`](square.h.md#Square) (Data Structure) + + +--- +#### Square::setOccupier +The `setOccupier` function assigns a `Piece` pointer to the `_piece` member variable of a `Square` object, indicating which piece occupies the square. +- **Inputs**: + - `piece`: A pointer to a `Piece` object that is to be set as the occupier of the square. +- **Control Flow**: + - The function takes a single argument, `piece`, which is a pointer to a `Piece` object. + - The function assigns the `piece` pointer to the private member variable `_piece` of the `Square` class. +- **Output**: The function does not return any value. +- **See also**: [`Square`](square.h.md#Square) (Data Structure) + + +--- +#### Square::getX +The `getX` function returns the X-coordinate of a `Square` object. +- **Inputs**: None +- **Control Flow**: + - The function accesses the private member variable `_x` of the `Square` class. + - It returns the value of `_x`. +- **Output**: The function returns an integer representing the X-coordinate of the square. +- **See also**: [`Square`](square.h.md#Square) (Data Structure) + + +--- +#### Square::getY +The `getY` function returns the Y-coordinate of a `Square` object. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the value of the private member variable `_y`. +- **Output**: The function returns an integer representing the Y-coordinate of the square. +- **See also**: [`Square`](square.h.md#Square) (Data Structure) + + +--- +#### Square::occupied +The `occupied` function checks if a `Square` object is occupied by a `Piece`. +- **Inputs**: None +- **Control Flow**: + - The function accesses the private member `_piece` of the `Square` class. + - It returns the boolean value of `_piece`, which is `true` if `_piece` is not `NULL` (indicating the square is occupied), and `false` if `_piece` is `NULL` (indicating the square is not occupied). +- **Output**: A boolean value indicating whether the square is occupied by a piece. +- **See also**: [`Square`](square.h.md#Square) (Data Structure) + + +--- +#### Square::occupiedBy +The `occupiedBy` function returns the `Piece` object that currently occupies the `Square`. +- **Inputs**: None +- **Control Flow**: + - The function directly returns the private member variable `_piece`, which is a pointer to a `Piece` object. +- **Output**: A pointer to a `Piece` object that occupies the `Square`, or `NULL` if no piece is present. +- **See also**: [`Square`](square.h.md#Square) (Data Structure) + + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/cpp_src/square.h.md b/driver_docs/c_cpp_export_test/cpp_src/square.h.md new file mode 100644 index 0000000..b7b9a62 --- /dev/null +++ b/driver_docs/c_cpp_export_test/cpp_src/square.h.md @@ -0,0 +1,32 @@ + + + + + +The `square.h` file defines a `Square` class for representing a square on a game board, including methods for setting and retrieving the piece occupying the square, as well as its position. + +# Purpose +The provided code is a C++ header file (`square.h`) that defines a class `Square`, which represents a square on a game board. This class offers narrow functionality, specifically tailored for managing the state and properties of a single square, such as its position on the board and the piece occupying it. The class includes a constructor for initializing the square's position, a destructor, and several member functions to set and retrieve the square's occupier, as well as to check if the square is occupied. The use of a forward declaration for the `Piece` class suggests that this header is part of a larger system, likely a game, where pieces interact with squares on a board. The file is intended to be included in other C++ source files that require the `Square` class functionality. +# Data Structures + +--- +### Square +- **Type**: `class` +- **Members**: + - `_x`: Stores the X-coordinate of the square on the board. + - `_y`: Stores the Y-coordinate of the square on the board. + - `_piece`: Pointer to the Piece object that occupies the square, or NULL if unoccupied. +- **Description**: The `Square` class represents a square on a game board, characterized by its X and Y coordinates and the piece that occupies it. It provides methods to set and retrieve the piece occupying the square, as well as to check if the square is occupied. The class encapsulates the position and occupancy state of a square, making it a fundamental component for board-based games. +- **Member Functions**: + - [`Square::Square`](square.cpp.md#SquareSquare) + - [`Square::~Square`](square.cpp.md#SquareSquare) + - [`Square::setOccupier`](square.cpp.md#SquaresetOccupier) + - [`Square::getX`](square.cpp.md#SquaregetX) + - [`Square::getY`](square.cpp.md#SquaregetY) + - [`Square::occupied`](square.cpp.md#Squareoccupied) + - [`Square::occupiedBy`](square.cpp.md#SquareoccupiedBy) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/README.md b/driver_docs/c_cpp_export_test/include/README.md new file mode 100644 index 0000000..2e42387 --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/README.md @@ -0,0 +1,13 @@ + + + + + +Header files for managing chess game components such as the board, pieces, moves, and game state. + +## Folders +- **[chesslib](chesslib/README.md)**: Header files that define structures and functions for managing chess game aspects like board, pieces, moves, and game state. + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/README.md b/driver_docs/c_cpp_export_test/include/chesslib/README.md new file mode 100644 index 0000000..5a7a81c --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/README.md @@ -0,0 +1,21 @@ + + + + + +Header files that define structures and functions for managing chess game aspects like board, pieces, moves, and game state. + + +## Files +- **[board.h](board.h.md)**: The `board.h` file defines the structure and functions for managing a chess board, including initialization, move generation, and state comparison, within the `c_cpp_export_test` codebase. +- **[boardlist.h](boardlist.h.md)**: The `boardlist.h` file defines a linked list structure and operations for managing a list of chess boards, including creation, addition, retrieval, undo, and memory deallocation. +- **[chess.h](chess.h.md)**: The `chess.h` file defines the structures and functions necessary for managing a chess game, including game initialization, move handling, and draw claims, within the `c_cpp_export_test` codebase. +- **[move.h](move.h.md)**: The `move.h` file defines structures and functions for representing and manipulating chess moves, including conversion to and from UCI notation. +- **[movelist.h](movelist.h.md)**: The `movelist.h` file defines data structures and functions for managing a list of chess moves, including creation, addition, retrieval, and conversion to UCI string format. +- **[piece.h](piece.h.md)**: The `piece.h` file defines enumerations and functions for representing and manipulating chess pieces, including their types, colors, and corresponding letters. +- **[piecemoves.h](piecemoves.h.md)**: The `piecemoves.h` file defines functions for generating potential move lists for different chess pieces, including leapers, riders, and specific pieces like pawns, knights, bishops, rooks, queens, and kings, while avoiding circular dependencies. +- **[square.h](square.h.md)**: The `square.h` file defines a `sq` struct for representing chessboard squares, along with functions for creating, indexing, and comparing these squares, as well as determining their color. +- **[squareset.h](squareset.h.md)**: The `squareset.h` file defines a 64-bit square set for representing the state of each square on a chessboard and includes functions to set and get the state of individual squares. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/board.h.md b/driver_docs/c_cpp_export_test/include/chesslib/board.h.md new file mode 100644 index 0000000..2beec41 --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/board.h.md @@ -0,0 +1,207 @@ + + + + + +The `board.h` file defines the structure and functions for managing a chess board, including initialization, move generation, and state comparison, within the `c_cpp_export_test` codebase. + +# Purpose +This C header file defines the structure and functions necessary for managing a chess board within a chess game application. It includes essential components such as the `board` struct, which encapsulates the state of a chess board, including piece positions, the current player, castling rights, and move counters. The file provides functions for creating and initializing a board, either from scratch or from a Forsyth-Edwards Notation (FEN) string, which is a standard notation for describing a particular board position. Additionally, it includes functions for manipulating the board, such as setting and retrieving pieces, generating possible moves, checking for attacks and checks, and determining board equality. This header file is crucial for implementing the logic required to simulate and manage chess games programmatically. +# Imports and Dependencies + +--- +- `chesslib/square.h` +- `chesslib/piece.h` +- `chesslib/movelist.h` + + +# Data Structures + +--- +### board +- **Type**: `struct` +- **Members**: + - `pieces`: An array of 64 pieces representing the chessboard's squares. + - `currentPlayer`: Indicates the current player's color. + - `castleState`: A bitmask that describes the castling rights for both players. + - `epTarget`: The en passant target square, if applicable. + - `halfMoveClock`: Counts the number of half-moves since the last capture or pawn advance. + - `moveNumber`: Tracks the number of full moves in the game. +- **Description**: The 'board' structure represents the state of a chess game, encapsulating the positions of pieces on a standard 8x8 chessboard, the current player's turn, castling rights, en passant target square, and move counters. It is designed to facilitate the management and manipulation of a chess game state, supporting operations such as move generation, move execution, and state comparison. + + +# Function Declarations (Public API) + +--- +### boardCreate +Allocates and initializes a chess board to the standard starting position. +- **Description**: This function creates a new chess board initialized to the standard starting position using the Forsyth-Edwards Notation (FEN) string defined by INITIAL_FEN. It returns a pointer to the newly allocated board structure. The caller is responsible for freeing the allocated memory when it is no longer needed. This function is useful for setting up a new game of chess with the standard initial setup. It is expected to be called when a fresh game board is required. If the function fails to create the board, it will return NULL. +- **Inputs**: None +- **Output**: A pointer to a newly allocated board structure initialized to the standard starting position, or NULL if the allocation fails. +- **See also**: [`boardCreate`](../../src/chesslib/board.c.md#boardCreate) (Implementation) + + +--- +### boardCreateFromFen +Creates a chess board from a FEN string. +- **Description**: This function allocates memory for a new chess board and initializes it using the provided FEN (Forsyth-Edwards Notation) string, which describes a particular board position. It is useful for setting up a board to a specific state as described by the FEN. The function returns a pointer to the newly created board, or NULL if the initialization fails, indicating an invalid FEN string or memory allocation failure. The caller is responsible for freeing the allocated board to avoid memory leaks. +- **Inputs**: + - `fen`: A null-terminated string representing the board position in Forsyth-Edwards Notation. The string must be valid and correctly formatted according to FEN standards. If the string is invalid, the function returns NULL. +- **Output**: A pointer to a newly allocated and initialized board structure, or NULL if the FEN string is invalid or memory allocation fails. +- **See also**: [`boardCreateFromFen`](../../src/chesslib/board.c.md#boardCreateFromFen) (Implementation) + + +--- +### boardInitInPlace +Initializes a chess board to the standard starting position. +- **Description**: This function sets up the provided chess board structure to represent the initial position of a standard chess game. It should be used when you want to reset or initialize a board to the starting configuration. The function must be called with a valid pointer to a `board` structure, which it will modify in place. Ensure that the board pointer is not null before calling this function to avoid undefined behavior. +- **Inputs**: + - `b`: A pointer to a `board` structure that will be initialized. Must not be null, as the function will modify the board in place to represent the initial chess position. +- **Output**: None +- **See also**: [`boardInitInPlace`](../../src/chesslib/board.c.md#boardInitInPlace) (Implementation) + + +--- +### boardInitFromFenInPlace +Initializes a chess board from a FEN string in place. +- **Description**: This function sets up a chess board based on the provided FEN (Forsyth-Edwards Notation) string, directly modifying the given board structure. It should be used when you want to initialize or reset a board to a specific state described by a FEN string. The function expects a valid FEN string and a pre-allocated board structure. It returns an error code if the FEN string is malformed or if any constraints are violated, such as incorrect piece placement or invalid characters. The function modifies the board's pieces, current player, castling rights, en passant target, half-move clock, and move number based on the FEN data. +- **Inputs**: + - `b`: A pointer to a pre-allocated board structure that will be initialized. The caller retains ownership and must ensure it is not null. + - `fen`: A null-terminated string containing the FEN representation of the board state. It must be a valid FEN string, and the function will return an error if the string is malformed or contains invalid characters. +- **Output**: Returns 0 on successful initialization, or 1 if the FEN string is invalid or an error occurs during parsing. +- **See also**: [`boardInitFromFenInPlace`](../../src/chesslib/board.c.md#boardInitFromFenInPlace) (Implementation) + + +--- +### boardSetPiece +Sets a piece on a specified square of the board. +- **Description**: This function places a specified chess piece on a given square of the board. It is typically used to update the board state during gameplay or setup. The board must be properly initialized before calling this function. The function does not perform any validation on the square or piece, so it is the caller's responsibility to ensure that the square is within valid bounds and the piece is a valid chess piece. The function directly modifies the board's internal state. +- **Inputs**: + - `b`: A pointer to a board structure where the piece will be placed. Must not be null and should point to a valid, initialized board. + - `s`: A square identifier indicating the position on the board where the piece will be placed. It should be a valid square within the board's range. + - `p`: The chess piece to be placed on the specified square. It should be a valid piece as defined in the chess library. +- **Output**: None +- **See also**: [`boardSetPiece`](../../src/chesslib/board.c.md#boardSetPiece) (Implementation) + + +--- +### boardGetPiece +Retrieve the piece located at a specific square on the board. +- **Description**: Use this function to obtain the piece that is currently positioned on a specified square of the chess board. This function is useful when you need to inspect the board's state or validate moves. It requires a valid board pointer and a square identifier. Ensure that the board has been properly initialized before calling this function to avoid undefined behavior. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should point to a valid, initialized board. + - `s`: An identifier for the square on the board from which to retrieve the piece. Must be a valid square within the board's boundaries. +- **Output**: The piece located at the specified square on the board. +- **See also**: [`boardGetPiece`](../../src/chesslib/board.c.md#boardGetPiece) (Implementation) + + +--- +### boardGenerateMoves +Generates all legal moves for the current player on the board. +- **Description**: This function generates a list of all legal moves available for the current player on the given chess board. It should be called when you need to determine the possible moves a player can make in their current turn. The function considers all pieces of the current player, checks for legal moves, and includes special moves like castling if applicable. The board must be properly initialized and represent a valid game state before calling this function. The caller is responsible for freeing the returned move list to avoid memory leaks. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should be properly initialized with a valid game state. +- **Output**: A pointer to a moveList structure containing all legal moves for the current player. The caller is responsible for freeing this list. +- **See also**: [`boardGenerateMoves`](../../src/chesslib/board.c.md#boardGenerateMoves) (Implementation) + + +--- +### boardIsSquareAttacked +Determine if a square is attacked by a specified color. +- **Description**: This function checks if a given square on the chess board is under attack by any piece of the specified color. It is useful for determining threats and planning defensive or offensive strategies in a chess game. The function requires a valid board state and a square to check, along with the color of the potential attacking pieces. It returns a non-zero value if the square is attacked, and zero if it is not. The board must be properly initialized before calling this function. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should be properly initialized. + - `s`: The square to check for attacks. It should be a valid square on the board. + - `attacker`: The color of the pieces to check for attacks. Must be a valid pieceColor value representing either white or black. +- **Output**: Returns a non-zero value if the square is attacked by the specified color, otherwise returns zero. +- **See also**: [`boardIsSquareAttacked`](../../src/chesslib/board.c.md#boardIsSquareAttacked) (Implementation) + + +--- +### boardIsInCheck +Checks if the current player is in check. +- **Description**: Use this function to determine if the current player on the given chess board is in a state of check, meaning their king is under threat of capture. This function is useful for validating moves and ensuring game rules are followed. It should be called on a valid board structure that has been properly initialized. The function does not modify the board or any of its properties. +- **Inputs**: + - `b`: A pointer to a 'board' structure representing the current state of the chess game. The board must be initialized and not null. If 'b' is invalid or null, the behavior is undefined. +- **Output**: Returns a non-zero value if the current player's king is in check, otherwise returns zero. +- **See also**: [`boardIsInCheck`](../../src/chesslib/board.c.md#boardIsInCheck) (Implementation) + + +--- +### boardIsPlayerInCheck +Checks if the specified player is in check on the given board. +- **Description**: This function determines whether the player of the specified color is currently in check on the provided chess board. It should be used when you need to verify the check status of a player during a game. The function requires a valid board pointer and a player color as inputs. It iterates over the board to find the player's king and checks if it is under attack by any opposing pieces. The function returns a non-zero value if the player is in check, and zero otherwise. Ensure that the board is properly initialized before calling this function. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should be properly initialized. + - `player`: The color of the player to check for being in check. Must be a valid pieceColor value, either pcWhite or pcBlack. +- **Output**: Returns 1 if the specified player is in check, otherwise returns 0. +- **See also**: [`boardIsPlayerInCheck`](../../src/chesslib/board.c.md#boardIsPlayerInCheck) (Implementation) + + +--- +### boardIsInsufficientMaterial +Determines if a chess board position has insufficient material to checkmate. +- **Description**: This function checks whether the current position on a chess board is such that neither player has enough material to force a checkmate, which would result in a draw. It should be used when you need to determine if the game can be declared a draw due to insufficient material. The function assumes that the board is properly initialized and contains valid chess pieces. It handles standard cases of insufficient material, such as only kings remaining, or kings with a single minor piece (knight or bishop), or kings with bishops all on the same color. The function does not handle more complex scenarios beyond these cases. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. The board must be initialized and must not be null. The function does not modify the board. +- **Output**: Returns 1 if the position is a draw due to insufficient material, otherwise returns 0. +- **See also**: [`boardIsInsufficientMaterial`](../../src/chesslib/board.c.md#boardIsInsufficientMaterial) (Implementation) + + +--- +### boardPlayMove +Returns a new board with the specified move applied. +- **Description**: Use this function to create a new board state by applying a move to an existing board. It is useful when you need to preserve the original board state and work with a modified version. The function allocates memory for the new board, which must be freed by the caller to avoid memory leaks. Ensure that the input board is valid and initialized before calling this function. +- **Inputs**: + - `b`: A pointer to the board on which the move will be applied. Must not be null and should point to a valid, initialized board structure. + - `m`: The move to be applied to the board. It should be a valid move within the context of the current board state. +- **Output**: A pointer to a new board structure with the move applied. The caller is responsible for freeing this memory. +- **See also**: [`boardPlayMove`](../../src/chesslib/board.c.md#boardPlayMove) (Implementation) + + +--- +### boardPlayMoveInPlace +Plays a move on the given chess board, modifying it in place. +- **Description**: This function updates the state of a chess board by applying a specified move directly to it. It should be used when you want to modify the existing board state rather than creating a new one. The function handles special moves such as castling and en passant, updates the move counters, and switches the current player. It assumes the board is in a valid state and the move is legal. Callers must ensure the board is properly initialized before invoking this function. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should be properly initialized before calling this function. The board is modified in place. + - `m`: A move structure representing the move to be played. It must represent a legal move according to the current state of the board. +- **Output**: None +- **See also**: [`boardPlayMoveInPlace`](../../src/chesslib/board.c.md#boardPlayMoveInPlace) (Implementation) + + +--- +### boardEq +Determine if two chess boards are equal in all aspects. +- **Description**: Use this function to check if two chess board states are identical, including all attributes such as the current player, castle state, en passant target square, half-move clock, move number, and the arrangement of pieces on the board. This function is useful for validating board states in applications where exact board state comparison is necessary, such as in testing or game state validation. Both board pointers must be valid and non-null, and the function will return a non-zero value if the boards are equal, or zero if they differ in any aspect. +- **Inputs**: + - `b1`: A pointer to the first board structure to compare. Must not be null and should point to a valid board. + - `b2`: A pointer to the second board structure to compare. Must not be null and should point to a valid board. +- **Output**: Returns 1 if the boards are equal in all aspects, otherwise returns 0. +- **See also**: [`boardEq`](../../src/chesslib/board.c.md#boardEq) (Implementation) + + +--- +### boardEqContext +Compares two chess boards for equality, ignoring move counters and filtering en passant target squares. +- **Description**: Use this function to determine if two chess boards are equivalent in terms of piece positions, current player, castling rights, and valid en passant targets, while ignoring move counters. This function is useful when you need to compare boards for game state equivalence without considering the number of moves or half-moves. It is important to ensure that both board pointers are valid and initialized before calling this function. The function will return a non-zero value if the boards are considered equal under these conditions, and zero otherwise. +- **Inputs**: + - `b1`: A pointer to the first board structure to compare. Must not be null and should be properly initialized. + - `b2`: A pointer to the second board structure to compare. Must not be null and should be properly initialized. +- **Output**: Returns a non-zero value if the boards are equal in terms of piece positions, current player, castling rights, and valid en passant targets; returns zero otherwise. +- **See also**: [`boardEqContext`](../../src/chesslib/board.c.md#boardEqContext) (Implementation) + + +--- +### boardGetFen +Generates a FEN string representing the current state of the chess board. +- **Description**: This function creates a Forsyth-Edwards Notation (FEN) string that describes the current state of the given chess board. It is useful for saving the board state or for interoperability with other chess software that uses FEN. The function allocates memory for the FEN string, which the caller is responsible for freeing. It assumes that the input board is properly initialized and contains valid data. The function handles all aspects of the FEN format, including piece placement, active color, castling availability, en passant target square, halfmove clock, and fullmove number. +- **Inputs**: + - `b`: A pointer to a 'board' structure representing the current state of the chess game. Must not be null and should be properly initialized with valid data. +- **Output**: A dynamically allocated string containing the FEN representation of the board. The caller is responsible for freeing this memory. +- **See also**: [`boardGetFen`](../../src/chesslib/board.c.md#boardGetFen) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/boardlist.h.md b/driver_docs/c_cpp_export_test/include/chesslib/boardlist.h.md new file mode 100644 index 0000000..8f8b157 --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/boardlist.h.md @@ -0,0 +1,103 @@ + + + + + +The `boardlist.h` file defines a linked list structure and operations for managing a list of chess boards, including creation, addition, retrieval, undo, and memory deallocation. + +# Purpose +This C header file defines a data structure and associated operations for managing a linked list of chess boards, likely as part of a larger chess application. It includes the definition of two structures: `boardListNode`, which represents a node in the linked list containing a pointer to a `board` and a pointer to the next node, and `boardList`, which manages the linked list with pointers to the head and tail nodes and tracks the list's size. The file declares functions for creating and managing these lists, including creating new lists and nodes, adding boards to the list, retrieving a board by index, undoing the last addition, and freeing the entire list. This header file is essential for organizing and manipulating sequences of chess board states, which can be useful for implementing features like move history or undo functionality in a chess program. +# Imports and Dependencies + +--- +- `stddef.h` +- `chesslib/board.h` + + +# Data Structures + +--- +### boardListNode +- **Type**: `struct` +- **Members**: + - `board`: A pointer to a board structure, representing a chess board. + - `next`: A pointer to the next node in the linked list, allowing traversal. +- **Description**: The `boardListNode` is a node structure used in a linked list to store and manage a sequence of chess boards. Each node contains a pointer to a `board` structure, which represents a chess board, and a pointer to the next `boardListNode`, enabling the creation of a singly linked list. This structure is part of a larger system for managing a list of chess boards, allowing operations such as adding, retrieving, and undoing moves in a chess game. + + +--- +### boardList +- **Type**: `struct` +- **Members**: + - `head`: A pointer to the first node in the board list. + - `tail`: A pointer to the last node in the board list. + - `size`: The number of nodes currently in the board list. +- **Description**: The `boardList` structure is a linked list designed to manage a sequence of `board` objects, which are presumably part of a chess library. It maintains pointers to the first (`head`) and last (`tail`) nodes of the list, allowing for efficient additions to the end of the list. The `size` member keeps track of the total number of nodes in the list, facilitating operations that depend on the list's length. This structure is useful for managing dynamic collections of chess boards, such as in a game history or move sequence. + + +# Function Declarations (Public API) + +--- +### boardListCreate +Create an empty board list. +- **Description**: This function initializes and returns a new, empty board list, which is a data structure designed to hold a sequence of board elements. It allocates memory for the board list and sets its initial state with no elements. This function should be called when a new board list is needed, and the caller is responsible for managing the memory of the returned list, including eventually freeing it with `boardListFree` to avoid memory leaks. +- **Inputs**: None +- **Output**: A pointer to a newly allocated `boardList` structure, initialized to be empty. +- **See also**: [`boardListCreate`](../../src/chesslib/boardlist.c.md#boardListCreate) (Implementation) + + +--- +### boardListNodeCreate +Creates a new board list node with the specified board. +- **Description**: Use this function to create a new node for a linked list of boards, initializing it with a given board. This function allocates memory for the node, sets its board pointer to the provided board, and initializes the next pointer to NULL. It is typically used when constructing or extending a linked list of boards. Ensure that the provided board pointer is valid and that the caller manages the memory for the board itself. The caller is responsible for freeing the allocated node to prevent memory leaks. +- **Inputs**: + - `b`: A pointer to a board structure that the new node will reference. Must be a valid pointer, and the caller retains ownership of the board. The function does not check for null pointers, so passing a null pointer will result in undefined behavior. +- **Output**: A pointer to the newly created boardListNode, or NULL if memory allocation fails. +- **See also**: [`boardListNodeCreate`](../../src/chesslib/boardlist.c.md#boardListNodeCreate) (Implementation) + + +--- +### boardListAdd +Adds a board to the end of a board list. +- **Description**: This function appends a new board to the end of the specified board list. It should be used when you want to maintain a sequence of boards, such as in a game history. The function assumes that the list has been properly initialized and is not null. It updates the list's head and tail pointers as necessary and increments the size of the list. The caller is responsible for ensuring that the board pointer is valid and that the list is in a consistent state before calling this function. +- **Inputs**: + - `list`: A pointer to a boardList structure where the board will be added. Must not be null and should be properly initialized. + - `b`: A pointer to a board structure to be added to the list. Must not be null and should point to a valid board. +- **Output**: None +- **See also**: [`boardListAdd`](../../src/chesslib/boardlist.c.md#boardListAdd) (Implementation) + + +--- +### boardListGet +Retrieve a board from the board list at the specified index. +- **Description**: Use this function to access a specific board from a board list by providing the index of the desired board. The function assumes that the index is within the bounds of the list, meaning it should be less than the size of the list. It is the caller's responsibility to ensure that the index is valid, as providing an out-of-bounds index will result in undefined behavior. This function does not modify the list or the boards within it. +- **Inputs**: + - `list`: A pointer to a boardList from which a board is to be retrieved. Must not be null, and should point to a valid, initialized boardList. + - `index`: An unsigned integer representing the position of the board to retrieve. Must be less than the size of the list to avoid undefined behavior. +- **Output**: A pointer to the board at the specified index in the list. The caller does not take ownership of the board. +- **See also**: [`boardListGet`](../../src/chesslib/boardlist.c.md#boardListGet) (Implementation) + + +--- +### boardListUndo +Removes the last board from the board list. +- **Description**: Use this function to remove the most recently added board from a `boardList`. It should be called when you need to undo the last operation that added a board to the list. The function safely handles cases where the list is empty or contains only one board, ensuring no operation is performed if the list is already empty. It decrements the size of the list accordingly and updates the list's tail pointer. +- **Inputs**: + - `list`: A pointer to a `boardList` structure. Must not be null. The function does nothing if the list is null or empty. +- **Output**: None +- **See also**: [`boardListUndo`](../../src/chesslib/boardlist.c.md#boardListUndo) (Implementation) + + +--- +### boardListFree +Frees all memory associated with a board list. +- **Description**: Use this function to release all memory allocated for a board list and its nodes when the list is no longer needed. This function should be called to prevent memory leaks after you are done using the board list. It is important to ensure that the list pointer is valid and that the list has been properly initialized before calling this function. After calling this function, the list pointer should not be used unless it is reinitialized. +- **Inputs**: + - `list`: A pointer to a boardList structure that must have been previously allocated and initialized. The pointer must not be null, and the function will free all associated memory, including the boards within each node. +- **Output**: None +- **See also**: [`boardListFree`](../../src/chesslib/boardlist.c.md#boardListFree) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/chess.h.md b/driver_docs/c_cpp_export_test/include/chesslib/chess.h.md new file mode 100644 index 0000000..1f68604 --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/chess.h.md @@ -0,0 +1,336 @@ + + + + + +The `chess.h` file defines the structures and functions necessary for managing a chess game, including game initialization, move handling, and draw claims, within the `c_cpp_export_test` codebase. + +# Purpose +This C header file defines the structure and functionality for managing a chess game, encapsulating the game's state and operations. It provides a comprehensive API for creating, initializing, and manipulating a chess game, including functions to handle game state transitions, move execution, and draw claims. The file includes definitions for a `chess` struct, which maintains the current legal moves, terminal state, board history, move history, and repetition count. The `terminalState` enumeration defines various end-game conditions, such as checkmate and different types of draws. + +The file offers a range of functions for interacting with the chess game, including creating a new game from scratch or from a FEN string, retrieving game state information, and executing or undoing moves. It also provides utility functions that mirror operations on the board structure for convenience, such as getting the piece at a specific square or checking if a square is attacked. Additionally, the file includes functions for handling draw claims based on the 50-move rule and threefold repetition. This header file is designed to be included in other C source files, providing a robust interface for chess game management and facilitating the development of chess-related applications. +# Imports and Dependencies + +--- +- `chesslib/boardlist.h` +- `chesslib/movelist.h` +- `chesslib/squareset.h` + + +# Data Structures + +--- +### terminalState +- **Type**: `enum` +- **Members**: + - `tsOngoing`: Represents a game state where the game is still ongoing. + - `tsCheckmate`: Indicates that the game has ended in checkmate. + - `tsDrawStalemate`: Represents a draw due to stalemate. + - `tsDrawClaimed50MoveRule`: Indicates a draw claimed by the 50-move rule. + - `tsDraw75MoveRule`: Represents a draw automatically enforced by the 75-move rule. + - `tsDrawClaimedThreefold`: Indicates a draw claimed by threefold repetition. + - `tsDrawFivefold`: Represents a draw automatically enforced by fivefold repetition. + - `tsDrawInsufficient`: Indicates a draw due to insufficient material to checkmate. +- **Description**: The `terminalState` enum defines the possible end states of a chess game, including ongoing play, checkmate, and various types of draws such as stalemate, 50-move rule, threefold repetition, and insufficient material. It is used to track the current status of a chess game and determine if the game has reached a conclusion. + + +--- +### chess +- **Type**: `struct` +- **Members**: + - `currentLegalMoves`: A pointer to a list of currently legal moves in the chess game. + - `terminal`: An enumeration indicating the terminal state of the game, such as ongoing, checkmate, or draw. + - `boardHistory`: A pointer to a list of all board states that have occurred during the game. + - `moveHistory`: A pointer to a list of all moves that have been played in the game. + - `repetitions`: A counter for how many times the current board position has been repeated. +- **Description**: The 'chess' struct is a comprehensive data structure designed to encapsulate the state of a chess game. It includes pointers to lists of legal moves, board history, and move history, allowing for tracking the progression of the game. The 'terminal' field indicates the current state of the game, such as whether it is ongoing or has ended in checkmate or a draw. The 'repetitions' field helps in determining draw conditions based on repeated positions. This struct is central to managing and manipulating the state of a chess game programmatically. + + +# Function Declarations (Public API) + +--- +### chessCreate +Creates and initializes a new chess game instance. +- **Description**: This function is used to create and initialize a new chess game instance with the standard initial position. It is suitable for starting a new game of chess from the traditional starting setup. The function allocates memory for the chess game structure, and the caller is responsible for freeing this memory using `chessFree` when the game is no longer needed. This function does not require any parameters and will return a pointer to the initialized chess game structure. If the initialization fails, it will return NULL. +- **Inputs**: None +- **Output**: Returns a pointer to a newly created chess game instance, or NULL if initialization fails. +- **See also**: [`chessCreate`](../../src/chesslib/chess.c.md#chessCreate) (Implementation) + + +--- +### chessCreateFen +Creates and initializes a chess game from a FEN string. +- **Description**: This function allocates and initializes a new chess game structure based on the provided FEN (Forsyth-Edwards Notation) string, which describes a specific board position. It is useful for setting up a game from a known position. The function returns a pointer to the initialized chess game structure if the FEN string is valid. If the FEN string is invalid, the function returns NULL, indicating that the game could not be initialized. The caller is responsible for freeing the returned chess game structure using `chessFree` when it is no longer needed. +- **Inputs**: + - `fen`: A null-terminated string representing the board position in Forsyth-Edwards Notation. The string must be valid FEN; otherwise, the function will return NULL. The caller retains ownership of this string, and it must not be null. +- **Output**: A pointer to a newly allocated and initialized chess game structure if the FEN is valid; otherwise, NULL if the FEN is invalid. +- **See also**: [`chessCreateFen`](../../src/chesslib/chess.c.md#chessCreateFen) (Implementation) + + +--- +### chessInitInPlace +Initializes a chess game to the standard starting position. +- **Description**: Use this function to set up a chess game to the standard initial position. It should be called on a `chess` structure that has already been allocated. This function is useful when you want to start a new game from the standard starting position without creating a new `chess` object. Ensure that the `chess` structure is properly allocated before calling this function to avoid undefined behavior. +- **Inputs**: + - `c`: A pointer to a `chess` structure that must be allocated before calling this function. The caller retains ownership and is responsible for managing the memory of this structure. The function assumes the pointer is valid and does not perform null checks. +- **Output**: None +- **See also**: [`chessInitInPlace`](../../src/chesslib/chess.c.md#chessInitInPlace) (Implementation) + + +--- +### chessInitFenInPlace +Initializes a chess game state from a FEN string. +- **Description**: This function initializes a given chess game structure using a FEN (Forsyth-Edwards Notation) string, which describes a specific board position. It should be used when you want to set up a chess game to a specific state as described by the FEN string. The function must be called with a valid chess structure and a valid FEN string. If the FEN string is invalid, the function returns 1 and does not modify the chess structure. Otherwise, it returns 0 and initializes the chess structure with the board position, move history, and other relevant game state information. +- **Inputs**: + - `c`: A pointer to a chess structure that will be initialized. Must not be null and should be a valid, allocated chess structure. + - `fen`: A pointer to a null-terminated string containing the FEN representation of the chess board state. Must not be null. If the FEN is invalid, the function returns 1 and does not modify the chess structure. +- **Output**: Returns 0 if the FEN string is valid and the chess structure is successfully initialized; returns 1 if the FEN string is invalid. +- **See also**: [`chessInitFenInPlace`](../../src/chesslib/chess.c.md#chessInitFenInPlace) (Implementation) + + +--- +### chessFree +Frees a chess game and all its components. +- **Description**: Use this function to release all resources associated with a chess game when it is no longer needed. It is essential to call this function to prevent memory leaks after you are done using a chess game object created with `chessCreate` or `chessCreateFen`. Ensure that the pointer `c` is not used after calling this function, as it will be invalidated. This function does not handle null pointers, so ensure that `c` is a valid pointer before calling. +- **Inputs**: + - `c`: A pointer to a `chess` structure that represents the chess game to be freed. Must not be null. The caller loses ownership of the memory pointed to by `c` after this function is called. +- **Output**: None +- **See also**: [`chessFree`](../../src/chesslib/chess.c.md#chessFree) (Implementation) + + +--- +### chessGetBoard +Retrieves the current board state from a chess game. +- **Description**: Use this function to obtain the current board state of a chess game represented by the `chess` structure. This function is useful when you need to analyze or display the current position of pieces on the board. It is expected that the `chess` structure has been properly initialized and is in a valid state before calling this function. The function does not modify the state of the chess game or the board. +- **Inputs**: + - `c`: A pointer to a `chess` structure representing the current game. Must not be null and should point to a valid, initialized chess game. If the `chess` structure is not properly initialized, the behavior is undefined. +- **Output**: A pointer to a `board` structure representing the current board state of the chess game. The caller does not own this pointer and should not attempt to free it. +- **See also**: [`chessGetBoard`](../../src/chesslib/chess.c.md#chessGetBoard) (Implementation) + + +--- +### chessGetLegalMoves +Retrieves the list of legal moves for the current game state. +- **Description**: Use this function to obtain the current list of legal moves available in the ongoing chess game. This function is useful for determining the possible actions a player can take at any given point in the game. It is important to ensure that the chess game has been properly initialized before calling this function, as it relies on the current game state to provide accurate legal moves. The function does not modify the game state or the list of moves; it simply returns a reference to the existing list. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current game state. Must not be null, and the game should be properly initialized before calling this function. +- **Output**: A pointer to a moveList structure containing the legal moves for the current game state. The caller should not modify or free this list. +- **See also**: [`chessGetLegalMoves`](../../src/chesslib/chess.c.md#chessGetLegalMoves) (Implementation) + + +--- +### chessGetTerminalState +Retrieve the current terminal state of a chess game. +- **Description**: Use this function to determine the current terminal state of a chess game, which indicates whether the game is ongoing, in checkmate, or drawn under various conditions. This function is useful for checking the game's status after moves have been played. It should be called on a valid chess game object that has been properly initialized. The function does not modify the game state or any of its components. +- **Inputs**: + - `c`: A pointer to a chess game object. Must not be null and should point to a valid, initialized chess game structure. If the pointer is invalid, the behavior is undefined. +- **Output**: Returns the current terminal state of the chess game, which is an enumeration value of type `terminalState`. +- **See also**: [`chessGetTerminalState`](../../src/chesslib/chess.c.md#chessGetTerminalState) (Implementation) + + +--- +### chessGetBoardHistory +Retrieve the history of board states in a chess game. +- **Description**: Use this function to access the sequence of board states that have occurred throughout the game. It is useful for analyzing the progression of the game or for implementing features that require knowledge of past board configurations. This function should be called on a valid chess game object, and it assumes that the game has been properly initialized. The caller should not modify the returned board history directly. +- **Inputs**: + - `c`: A pointer to a chess game object. Must not be null and should point to a valid, initialized chess game structure. The function does not modify the chess object. +- **Output**: A pointer to a boardList representing the history of board states in the game. The caller does not own this pointer and should not attempt to free or modify it. +- **See also**: [`chessGetBoardHistory`](../../src/chesslib/chess.c.md#chessGetBoardHistory) (Implementation) + + +--- +### chessGetMoveHistory +Retrieves the history of moves made in the chess game. +- **Description**: This function is used to obtain the list of all moves that have been played in a given chess game instance. It is useful for analyzing the game's progression or for displaying the move history to users. The function should be called on a valid chess game object, and it does not modify the game state. The returned move list reflects the current state of the game's move history. +- **Inputs**: + - `c`: A pointer to a chess game object. This must be a valid, initialized chess object, and must not be null. The caller retains ownership of the chess object. +- **Output**: A pointer to a moveList object representing the history of moves made in the game. The caller should not modify or free this list directly. +- **See also**: [`chessGetMoveHistory`](../../src/chesslib/chess.c.md#chessGetMoveHistory) (Implementation) + + +--- +### chessGetRepetitions +Retrieve the number of times the current board position has been repeated. +- **Description**: Use this function to determine how many times the current board position has occurred during the game, which can be useful for detecting potential draw conditions such as the threefold repetition rule. This function should be called on a valid `chess` object that has been properly initialized. It does not modify the state of the game or the `chess` object. +- **Inputs**: + - `c`: A pointer to a `chess` object representing the current game state. Must not be null, and the game must be initialized before calling this function. +- **Output**: Returns the number of times the current board position has been repeated as an unsigned 8-bit integer. +- **See also**: [`chessGetRepetitions`](../../src/chesslib/chess.c.md#chessGetRepetitions) (Implementation) + + +--- +### chessPlayMove +Attempts to play a specified move in a chess game. +- **Description**: This function is used to attempt playing a move in an ongoing chess game. It should be called when you want to execute a move that is expected to be legal. The function checks if the game is still ongoing and if the move is among the current legal moves. If the move is legal and the game is ongoing, it updates the game state by applying the move, adding it to the move history, and recalculating the game fields. If the move is illegal or the game has already ended, the function returns an error code. This function should be used only when the game is in progress and the move is expected to be valid. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current game state. Must not be null and the game must be ongoing (i.e., terminal state is tsOngoing). The caller retains ownership. + - `m`: A move structure representing the move to be played. It should be a valid move that is expected to be in the list of current legal moves. +- **Output**: Returns 0 if the move was successfully played, or 1 if the move was illegal or the game is not ongoing. +- **See also**: [`chessPlayMove`](../../src/chesslib/chess.c.md#chessPlayMove) (Implementation) + + +--- +### chessUndo +Undoes the last move or draw claim in a chess game. +- **Description**: Use this function to revert the most recent move or draw claim in a chess game, effectively stepping back one move in the game's history. This function is useful when implementing features like undo in a chess application. It must be called on a valid chess game instance that has at least one move in its history; otherwise, it will return an error. The function also resets the terminal state if a draw was claimed due to the threefold repetition or the 50-move rule. Ensure that the chess game instance is properly initialized and contains a valid move history before calling this function. +- **Inputs**: + - `c`: A pointer to a chess game instance. This must be a valid, initialized chess game object with a non-empty move history. The caller retains ownership of this pointer. If the move history is empty, the function will return an error. +- **Output**: Returns 0 if the undo operation is successful, or 1 if unsuccessful (e.g., no moves left to undo). +- **See also**: [`chessUndo`](../../src/chesslib/chess.c.md#chessUndo) (Implementation) + + +--- +### chessGetPiece +Retrieves the piece located at a specific square on the chessboard. +- **Description**: Use this function to obtain the piece present at a given square in the current state of a chess game. This function is useful for querying the board to determine what piece, if any, occupies a specific location. It is important to ensure that the chess game has been properly initialized before calling this function. The function does not modify the state of the game or the board. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current state of the chess game. Must not be null, and the chess game should be initialized before use. + - `s`: An identifier for the square on the chessboard from which to retrieve the piece. The square must be valid within the context of the chessboard. +- **Output**: The function returns the piece located at the specified square. If the square is empty, it returns a value indicating no piece is present. +- **See also**: [`chessGetPiece`](../../src/chesslib/chess.c.md#chessGetPiece) (Implementation) + + +--- +### chessGetPlayer +Retrieve the current player's color in a chess game. +- **Description**: Use this function to determine which player's turn it is in the current state of a chess game. It is useful for game logic that depends on knowing whether it is the white or black player's turn. This function should be called on a valid chess game object that has been properly initialized. The function does not modify the game state and is safe to call at any point after initialization. +- **Inputs**: + - `c`: A pointer to a chess game object. This must not be null and should point to a valid, initialized chess game structure. If the pointer is invalid, the behavior is undefined. +- **Output**: The function returns a value of type pieceColor, indicating the color of the player whose turn it is. +- **See also**: [`chessGetPlayer`](../../src/chesslib/chess.c.md#chessGetPlayer) (Implementation) + + +--- +### chessGetCastleState +Retrieve the current castling rights state of the chess game. +- **Description**: Use this function to obtain the current castling rights state of a chess game represented by the `chess` structure. This function is useful when you need to check which castling moves are still available in the game. It should be called with a valid `chess` pointer that has been properly initialized. The function does not modify the state of the game or the input structure. +- **Inputs**: + - `c`: A pointer to a `chess` structure representing the current state of a chess game. Must not be null and should be properly initialized before calling this function. +- **Output**: Returns an 8-bit unsigned integer representing the castling rights state of the game. +- **See also**: [`chessGetCastleState`](../../src/chesslib/chess.c.md#chessGetCastleState) (Implementation) + + +--- +### chessGetEpTarget +Retrieves the en passant target square for the current board state. +- **Description**: This function is used to obtain the en passant target square from the current state of a chess game. It is useful when determining if an en passant capture is possible in the current position. The function should be called when you need to check or display the en passant target square during a game. It assumes that the chess game has been properly initialized and is in a valid state. The function does not modify the game state or any of its components. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current game state. It must not be null, and the chess game must be properly initialized before calling this function. If the pointer is invalid, the behavior is undefined. +- **Output**: The function returns the square that is the en passant target, which is relevant for determining en passant captures. +- **See also**: [`chessGetEpTarget`](../../src/chesslib/chess.c.md#chessGetEpTarget) (Implementation) + + +--- +### chessGetHalfMoveClock +Retrieve the half-move clock from the chess game state. +- **Description**: Use this function to obtain the current half-move clock value from a chess game, which is a count of the number of half-moves (or ply) since the last capture or pawn advance. This value is used in determining draw conditions such as the fifty-move rule. The function should be called on a valid chess game object, and it assumes that the game has been properly initialized. The function does not modify the game state. +- **Inputs**: + - `c`: A pointer to a chess game object. Must not be null and should point to a valid, initialized chess game structure. If the pointer is invalid, the behavior is undefined. +- **Output**: Returns the current half-move clock as an unsigned integer, representing the number of half-moves since the last capture or pawn move. +- **See also**: [`chessGetHalfMoveClock`](../../src/chesslib/chess.c.md#chessGetHalfMoveClock) (Implementation) + + +--- +### chessGetMoveNumber +Retrieve the current move number in the chess game. +- **Description**: Use this function to obtain the current move number of an ongoing chess game. It is useful for tracking the progress of the game and is typically called after the game has been initialized. The function requires a valid pointer to a chess game structure, which must have been previously initialized using one of the provided initialization functions. The move number is incremented as moves are played in the game. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current state of the game. This pointer must not be null and should point to a properly initialized chess game. If the pointer is invalid, the behavior is undefined. +- **Output**: Returns the current move number as an unsigned integer, indicating how many moves have been played in the game so far. +- **See also**: [`chessGetMoveNumber`](../../src/chesslib/chess.c.md#chessGetMoveNumber) (Implementation) + + +--- +### chessGetMoveHistoryUci +Returns a string of all moves in the game's history in UCI format. +- **Description**: Use this function to obtain a string representation of all moves made in a chess game, formatted according to the Universal Chess Interface (UCI) standard. This function is useful for logging, analysis, or exporting the move history of a game. The returned string must be freed by the caller to avoid memory leaks. Ensure that the chess game object is properly initialized and contains a valid move history before calling this function. +- **Inputs**: + - `c`: A pointer to a chess game object. Must not be null and should be a valid, initialized chess game instance. The function assumes that the move history within the chess object is correctly maintained. +- **Output**: A dynamically allocated string containing the UCI representation of the move history. The caller is responsible for freeing this string. +- **See also**: [`chessGetMoveHistoryUci`](../../src/chesslib/chess.c.md#chessGetMoveHistoryUci) (Implementation) + + +--- +### chessIsInCheck +Checks if the current player's king is in check. +- **Description**: Use this function to determine if the current player's king is in check in a given chess game state. This function is useful for validating game states and ensuring that moves do not leave the king in check. It should be called when you need to verify the safety of the king after a move or during game analysis. The function requires a valid chess game object and assumes that the game has been properly initialized. It does not modify the game state. +- **Inputs**: + - `c`: A pointer to a chess game object. Must not be null and should point to a valid, initialized chess game structure. The function does not modify the object. +- **Output**: Returns 1 if the current player's king is in check, otherwise returns 0. +- **See also**: [`chessIsInCheck`](../../src/chesslib/chess.c.md#chessIsInCheck) (Implementation) + + +--- +### chessIsSquareAttacked +Determines if a specific square is attacked by the opponent. +- **Description**: This function checks whether a given square on the chessboard is under attack by the opponent's pieces. It is useful for determining threats to specific squares, such as when evaluating the safety of a king or planning defensive strategies. The function should be called with a valid chess game state and a valid square identifier. It assumes that the chess game has been properly initialized and is in a valid state. The function does not modify the game state or any of its components. +- **Inputs**: + - `c`: A pointer to a chess game structure. It must not be null and should represent a valid, initialized chess game state. + - `s`: An identifier for the square to be checked. It should be a valid square within the bounds of the chessboard. +- **Output**: Returns 1 if the square is attacked by the opponent, otherwise returns 0. +- **See also**: [`chessIsSquareAttacked`](../../src/chesslib/chess.c.md#chessIsSquareAttacked) (Implementation) + + +--- +### chessGetFen +Returns a string containing the current board position in FEN format. +- **Description**: This function provides the current state of the chess board in the Forsyth-Edwards Notation (FEN), which is a standard notation for describing a particular board position of a chess game. It is useful for saving the game state, analyzing positions, or sharing the current game setup. The returned string must be freed by the caller to avoid memory leaks. This function should be called when a snapshot of the current game state is needed in FEN format. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current game state. Must not be null, as passing a null pointer will result in undefined behavior. +- **Output**: A dynamically allocated string containing the FEN representation of the current board position. The caller is responsible for freeing this string. +- **See also**: [`chessGetFen`](../../src/chesslib/chess.c.md#chessGetFen) (Implementation) + + +--- +### chessCanClaimDraw50 +Determines if a draw can be claimed under the 50-move rule. +- **Description**: Use this function to check if a draw can be claimed in a chess game due to the 50-move rule, which applies when no pawn has been moved and no capture has been made in the last 50 moves by each player. This function should be called when you need to verify if the conditions for claiming a draw under this rule are met. It is important to ensure that the game is ongoing before calling this function, as it only returns a valid result in that state. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current state of the game. Must not be null. The game must be in an ongoing state for the function to return a meaningful result. +- **Output**: Returns a non-zero value if a draw can be claimed under the 50-move rule, and zero otherwise. +- **See also**: [`chessCanClaimDraw50`](../../src/chesslib/chess.c.md#chessCanClaimDraw50) (Implementation) + + +--- +### chessCanClaimDrawThreefold +Determines if a draw can be claimed due to threefold repetition. +- **Description**: This function checks whether the current state of a chess game allows a player to claim a draw based on the threefold repetition rule. It should be called when a player wants to verify if they can claim a draw due to the same board position occurring three times. The function requires that the game is ongoing and that the current position has been repeated at least three times. It does not modify the game state or any input parameters. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current game state. Must not be null, and the game must be initialized and ongoing for the function to return a valid result. +- **Output**: Returns a non-zero value if a draw can be claimed due to threefold repetition, otherwise returns zero. +- **See also**: [`chessCanClaimDrawThreefold`](../../src/chesslib/chess.c.md#chessCanClaimDrawThreefold) (Implementation) + + +--- +### chessClaimDraw50 +Claims a draw under the 50-move rule if applicable. +- **Description**: This function is used to claim a draw in a chess game when the 50-move rule condition is met. The 50-move rule states that a player can claim a draw if no pawn has been moved and no capture has been made in the last 50 moves by each player. This function should be called when a player wishes to claim such a draw. It checks if the draw can be claimed using the `chessCanClaimDraw50` function and, if so, updates the game's terminal state to indicate that a draw has been claimed under the 50-move rule. This function must be called with a valid `chess` object that has been properly initialized. +- **Inputs**: + - `c`: A pointer to a `chess` structure representing the current state of the chess game. Must not be null and must point to a valid, initialized chess game object. If the pointer is invalid, the behavior is undefined. +- **Output**: None +- **See also**: [`chessClaimDraw50`](../../src/chesslib/chess.c.md#chessClaimDraw50) (Implementation) + + +--- +### chessClaimDrawThreefold +Claims a draw by threefold repetition if possible. +- **Description**: This function is used to claim a draw in a chess game when the same position has occurred three times, which is a condition for a draw by threefold repetition. It should be called when a player believes the current board position has been repeated three times during the game. The function checks if the draw can be claimed using the current game state and updates the game's terminal state to indicate a draw if the condition is met. It is important to ensure that the game state is correctly maintained and updated before calling this function to avoid incorrect claims. +- **Inputs**: + - `c`: A pointer to a chess game structure. Must not be null. The game state should be valid and up-to-date, as the function relies on the current board history and repetition count to determine if a draw can be claimed. +- **Output**: None +- **See also**: [`chessClaimDrawThreefold`](../../src/chesslib/chess.c.md#chessClaimDrawThreefold) (Implementation) + + +--- +### chessCalculateFields +Updates the chess game's legal moves, repetition count, and terminal state. +- **Description**: This function updates the state of a chess game by recalculating the list of legal moves, counting the number of times the current board position has been repeated, and determining the game's terminal state. It should be called internally after each move to ensure the game state is accurate. The function handles various terminal conditions such as checkmate, stalemate, and draw scenarios based on repetition, move count, or insufficient material. It assumes that the chess game structure is properly initialized and that the current board state is valid. +- **Inputs**: + - `c`: A pointer to a chess structure representing the current game state. Must not be null and should be properly initialized before calling this function. The function will update the fields within this structure. +- **Output**: None +- **See also**: [`chessCalculateFields`](../../src/chesslib/chess.c.md#chessCalculateFields) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/move.h.md b/driver_docs/c_cpp_export_test/include/chesslib/move.h.md new file mode 100644 index 0000000..4018110 --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/move.h.md @@ -0,0 +1,87 @@ + + + + + +The `move.h` file defines structures and functions for representing and manipulating chess moves, including conversion to and from UCI notation. + +# Purpose +This C header file defines structures and functions related to chess move operations, likely as part of a larger chess application. It includes necessary dependencies from other modules, specifically `square.h` and `piece.h`, which suggest that it relies on predefined types for squares and pieces. The `move` structure encapsulates a chess move, including the starting and ending squares and an optional promotion piece type. The file declares functions for creating moves ([`moveSq`](#moveSq) and [`movePromote`](#movePromote)), comparing moves ([`moveEq`](#moveEq)), and converting moves to and from UCI (Universal Chess Interface) notation ([`moveGetUci`](#moveGetUci) and [`moveFromUci`](#moveFromUci)). This header is designed to facilitate the manipulation and representation of chess moves within the application. +# Imports and Dependencies + +--- +- `chesslib/square.h` +- `chesslib/piece.h` + + +# Data Structures + +--- +### move +- **Type**: `struct` +- **Members**: + - `from`: The starting square of the move. + - `to`: The destination square of the move. + - `promotion`: The type of piece to promote to, if applicable. +- **Description**: The `move` structure represents a chess move, encapsulating the starting and destination squares, as well as the type of piece to promote to if the move involves a pawn promotion. This structure is fundamental in representing and manipulating chess moves within the program, allowing for operations such as move creation, comparison, and conversion to UCI notation. + + +# Function Declarations (Public API) + +--- +### moveSq +Creates a move from one square to another without promotion. +- **Description**: Use this function to create a move structure representing a chess move from one square to another without any piece promotion. This function is typically used when a piece is moved on the board without changing its type, such as moving a pawn forward without reaching the promotion rank. Ensure that the squares provided are valid and represent positions on the chessboard. +- **Inputs**: + - `from`: The starting square of the move. Must be a valid square on the chessboard. + - `to`: The destination square of the move. Must be a valid square on the chessboard. +- **Output**: Returns a move structure with the specified from and to squares, and no promotion. +- **See also**: [`moveSq`](../../src/chesslib/move.c.md#moveSq) (Implementation) + + +--- +### movePromote +Creates a move with a promotion from one square to another. +- **Description**: This function constructs a chess move that includes a promotion, specifying the starting square, the destination square, and the type of piece to promote to. It is typically used when a pawn reaches the opposite end of the board and is promoted to another piece. The function returns a move structure encapsulating these details. Ensure that the 'from' and 'to' squares are valid board positions and that the promotion piece type is appropriate for a promotion (e.g., not a pawn or king). +- **Inputs**: + - `from`: The starting square of the move. Must be a valid square on the chessboard. + - `to`: The destination square of the move. Must be a valid square on the chessboard. + - `promotion`: The type of piece to promote to. Should be a valid piece type for promotion, typically a queen, rook, bishop, or knight. +- **Output**: Returns a move structure representing the move from the starting square to the destination square with the specified promotion. +- **See also**: [`movePromote`](../../src/chesslib/move.c.md#movePromote) (Implementation) + + +--- +### moveEq +Compares two chess moves for equality. +- **Description**: Use this function to determine if two chess moves are identical in terms of their starting and ending squares, as well as any promotion involved. This function is useful when you need to check if two moves are the same in a chess game context. It requires both moves to be fully specified, including the promotion piece type if applicable. The function returns a non-zero value if the moves are equal and zero if they are not. +- **Inputs**: + - `m1`: The first move to compare. It must be a valid move structure with defined 'from', 'to', and 'promotion' fields. + - `m2`: The second move to compare. It must also be a valid move structure with defined 'from', 'to', and 'promotion' fields. +- **Output**: Returns a non-zero value if the moves are equal, otherwise returns zero. +- **See also**: [`moveEq`](../../src/chesslib/move.c.md#moveEq) (Implementation) + + +--- +### moveGetUci +Converts a chess move to its UCI notation string. +- **Description**: This function generates a string representing a chess move in UCI (Universal Chess Interface) notation. It should be used when you need a textual representation of a move for logging, communication, or processing purposes. The function allocates memory for the resulting string, which includes the starting and ending squares of the move, and appends the promotion piece type if applicable. The caller is responsible for freeing the allocated memory to avoid memory leaks. Ensure that the move structure is properly initialized before calling this function. +- **Inputs**: + - `m`: A move structure containing the starting square, ending square, and an optional promotion piece type. The structure must be properly initialized, and the squares must be valid chessboard positions. If the promotion field is non-zero, it should represent a valid piece type for promotion. +- **Output**: A dynamically allocated string containing the UCI notation of the move. The caller must free this string after use. +- **See also**: [`moveGetUci`](../../src/chesslib/move.c.md#moveGetUci) (Implementation) + + +--- +### moveFromUci +Converts a UCI string to a move structure. +- **Description**: This function is used to convert a Universal Chess Interface (UCI) formatted string into a move structure, which includes the starting and ending squares and any promotion piece type. It is typically called when parsing moves from a UCI string representation. The function expects a valid UCI string of at least four characters, representing the starting and ending squares, and optionally a fifth character for promotion. If the promotion character is not provided or is invalid, no promotion is assumed. The function does not handle null pointers and expects the input string to be properly formatted. +- **Inputs**: + - `uci`: A pointer to a null-terminated string representing a move in UCI format. The string must be at least four characters long, with the first two characters representing the starting square and the next two representing the ending square. An optional fifth character can specify a promotion piece ('n', 'b', 'r', 'q', 'k'). The caller retains ownership of the string, and it must not be null. +- **Output**: A move structure containing the parsed starting and ending squares and the promotion piece type, if specified. +- **See also**: [`moveFromUci`](../../src/chesslib/move.c.md#moveFromUci) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/movelist.h.md b/driver_docs/c_cpp_export_test/include/chesslib/movelist.h.md new file mode 100644 index 0000000..316fbe1 --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/movelist.h.md @@ -0,0 +1,113 @@ + + + + + +The `movelist.h` file defines data structures and functions for managing a list of chess moves, including creation, addition, retrieval, and conversion to UCI string format. + +# Purpose +This C header file defines a data structure and associated operations for managing a list of chess moves, likely as part of a larger chess application. It includes the definition of two structures: `moveListNode`, which represents a single node containing a chess move and a pointer to the next node, and `moveList`, which manages the linked list of these nodes, including pointers to the head and tail of the list and a size counter. The file declares several functions for creating and manipulating these lists, such as adding moves, retrieving moves by index, undoing the last move, and converting the list to a UCI (Universal Chess Interface) string format. Additionally, it provides a function to free the memory used by the list and its nodes, ensuring proper resource management. This header file is essential for handling sequences of moves in a chess game, facilitating operations like move tracking and conversion to standard formats. +# Imports and Dependencies + +--- +- `stddef.h` +- `chesslib/move.h` + + +# Data Structures + +--- +### moveListNode +- **Type**: `struct` +- **Members**: + - `move`: A move object representing a single move in a chess game. + - `next`: A pointer to the next moveListNode in the linked list. +- **Description**: The `moveListNode` is a structure used to represent a node in a linked list of chess moves. Each node contains a `move` object, which holds the details of a single chess move, and a `next` pointer, which points to the subsequent node in the list. This structure is part of a larger system for managing sequences of chess moves, allowing for operations such as adding moves, retrieving moves by index, and undoing moves. + + +--- +### moveList +- **Type**: `struct` +- **Members**: + - `head`: A pointer to the first node in the move list. + - `tail`: A pointer to the last node in the move list. + - `size`: The number of nodes currently in the move list. +- **Description**: The `moveList` structure is a linked list data structure used to store a sequence of moves in a chess game. It contains pointers to the head and tail of the list, allowing for efficient addition of moves to the end of the list. The `size` member keeps track of the total number of moves stored in the list, facilitating operations that require knowledge of the list's length. This structure is designed to support operations such as adding new moves, retrieving moves by index, undoing the last move, and converting the list of moves into a UCI (Universal Chess Interface) string format. + + +# Function Declarations (Public API) + +--- +### moveListCreate +Create an empty move list. +- **Description**: This function initializes and returns a new, empty move list, which is a data structure used to store a sequence of moves. It allocates memory for the move list and sets its initial state with no moves. The function should be called when a new move list is needed, and the caller is responsible for managing the memory of the returned list, including freeing it when it is no longer needed using the appropriate function. +- **Inputs**: None +- **Output**: A pointer to a newly allocated moveList structure, initialized to be empty. +- **See also**: [`moveListCreate`](../../src/chesslib/movelist.c.md#moveListCreate) (Implementation) + + +--- +### moveListNodeCreate +Create a new move list node with a specified move. +- **Description**: This function is used to create a new node for a move list, initializing it with a specified move. It allocates memory for the node and sets the move field to the provided move, while the next pointer is initialized to NULL. This function is typically used when constructing or modifying a move list in a chess application. Ensure that the allocated node is eventually freed to avoid memory leaks. +- **Inputs**: + - `move`: The move to be stored in the new node. It must be a valid move as defined by the chess library. The caller retains ownership of the move data. +- **Output**: A pointer to the newly created moveListNode containing the specified move, or NULL if memory allocation fails. +- **See also**: [`moveListNodeCreate`](../../src/chesslib/movelist.c.md#moveListNodeCreate) (Implementation) + + +--- +### moveListAdd +Adds a move to the end of a move list. +- **Description**: This function appends a new move to the end of the specified move list, updating the list's size accordingly. It is typically used to build or extend a sequence of moves in a chess game. The function assumes that the move list has been properly initialized before calling. If the list is empty, the new move becomes both the head and the tail of the list. The function does not handle invalid input and expects the list pointer to be valid. +- **Inputs**: + - `list`: A pointer to a moveList structure where the move will be added. Must not be null and should be properly initialized before calling. + - `move`: The move to be added to the list. It is assumed to be a valid move as per the move type definition. +- **Output**: None +- **See also**: [`moveListAdd`](../../src/chesslib/movelist.c.md#moveListAdd) (Implementation) + + +--- +### moveListGet +Retrieve a move from the move list at the specified index. +- **Description**: This function retrieves a move from a move list at a specified index, allowing access to individual moves within the list. It is useful when you need to examine or process a specific move from a sequence of moves stored in a move list. The function assumes that the index provided is within the bounds of the list, meaning it should be less than the size of the list. If the index is out of bounds, the behavior is undefined, so it is the caller's responsibility to ensure the index is valid. +- **Inputs**: + - `list`: A pointer to a moveList from which the move will be retrieved. Must not be null, and should point to a valid moveList structure. + - `index`: An unsigned integer representing the position of the move to retrieve. Must be less than the size of the list to avoid undefined behavior. +- **Output**: The move located at the specified index in the move list. +- **See also**: [`moveListGet`](../../src/chesslib/movelist.c.md#moveListGet) (Implementation) + + +--- +### moveListUndo +Removes the last move from the move list. +- **Description**: Use this function to remove the most recently added move from a move list, effectively undoing the last move. This function should be called when you need to backtrack or reverse the last move in a sequence. It is important to ensure that the move list is not null and contains at least one move before calling this function, as it will not perform any action if the list is empty or null. The function updates the list's size and tail pointer accordingly. +- **Inputs**: + - `list`: A pointer to a moveList structure representing the list of moves. Must not be null and should contain at least one move. If the list is null or empty, the function does nothing. +- **Output**: None +- **See also**: [`moveListUndo`](../../src/chesslib/movelist.c.md#moveListUndo) (Implementation) + + +--- +### moveListGetUciString +Creates a UCI string representation of the moves in the given move list. +- **Description**: This function generates a string in UCI (Universal Chess Interface) format representing all the moves contained in the provided move list. It is useful for converting a sequence of chess moves into a standardized string format for further processing or communication with UCI-compatible chess engines. The function allocates memory for the resulting string, which the caller is responsible for freeing. If the move list is empty, the function returns an empty string. The function assumes that the move list is properly initialized and populated with valid moves. +- **Inputs**: + - `list`: A pointer to a moveList structure containing the moves to be converted. The list must be initialized and can be empty. The caller retains ownership of the list, and it must not be null. +- **Output**: A dynamically allocated string containing the UCI representation of the moves in the list. The caller is responsible for freeing this string. If the list is empty, an empty string is returned. +- **See also**: [`moveListGetUciString`](../../src/chesslib/movelist.c.md#moveListGetUciString) (Implementation) + + +--- +### moveListFree +Frees a move list and all its nodes. +- **Description**: Use this function to release all memory associated with a move list, including all its nodes. It should be called when the move list is no longer needed to prevent memory leaks. Ensure that the list pointer is valid and was previously allocated by moveListCreate. After calling this function, the list pointer should not be used unless it is reinitialized. +- **Inputs**: + - `list`: A pointer to a moveList structure that must have been created by moveListCreate. The pointer must not be null, and it is the caller's responsibility to ensure the list is not used after being freed. +- **Output**: None +- **See also**: [`moveListFree`](../../src/chesslib/movelist.c.md#moveListFree) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/piece.h.md b/driver_docs/c_cpp_export_test/include/chesslib/piece.h.md new file mode 100644 index 0000000..0c2fa1f --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/piece.h.md @@ -0,0 +1,111 @@ + + + + + +The `piece.h` file defines enumerations and functions for representing and manipulating chess pieces, including their types, colors, and corresponding letters. + +# Purpose +This C header file defines enumerations and function prototypes related to chess pieces, likely for use in a chess game application. It includes three enumerations: `pieceType`, which categorizes the types of chess pieces (e.g., pawn, knight, etc.); `piece`, which represents specific pieces with their color (e.g., white pawn, black knight, etc.); and `pieceColor`, which distinguishes between no color, white, and black. The file also declares several functions: [`pieceGetType`](#pieceGetType) and [`pieceGetColor`](#pieceGetColor) for retrieving the type and color of a piece, respectively; [`pieceTypeGetLetter`](#pieceTypeGetLetter) and [`pieceGetLetter`](#pieceGetLetter) for obtaining a character representation of a piece type or specific piece; and [`pieceMake`](#pieceMake) for creating a piece given its type and color. This header file is essential for managing and manipulating chess pieces within the broader context of a chess program. +# Data Structures + +--- +### pieceType +- **Type**: `enum` +- **Members**: + - `ptEmpty`: Represents an empty square or no piece. + - `ptPawn`: Represents a pawn piece. + - `ptKnight`: Represents a knight piece. + - `ptBishop`: Represents a bishop piece. + - `ptRook`: Represents a rook piece. + - `ptQueen`: Represents a queen piece. + - `ptKing`: Represents a king piece. +- **Description**: The `pieceType` enum defines the different types of chess pieces that can exist on a chessboard, including an empty state to represent the absence of a piece. Each enumerator corresponds to a specific type of chess piece, allowing for easy identification and manipulation of pieces within a chess program. + + +--- +### piece +- **Type**: `enum` +- **Members**: + - `pEmpty`: Represents an empty square on the chessboard. + - `pWPawn`: Represents a white pawn piece. + - `pWKnight`: Represents a white knight piece. + - `pWBishop`: Represents a white bishop piece. + - `pWRook`: Represents a white rook piece. + - `pWQueen`: Represents a white queen piece. + - `pWKing`: Represents a white king piece. + - `pBPawn`: Represents a black pawn piece. + - `pBKnight`: Represents a black knight piece. + - `pBBishop`: Represents a black bishop piece. + - `pBRook`: Represents a black rook piece. + - `pBQueen`: Represents a black queen piece. + - `pBKing`: Represents a black king piece. +- **Description**: The 'piece' enum is a data structure used to represent the different types of chess pieces in a game, including both white and black pieces, as well as an empty square. Each enumerator corresponds to a specific piece, allowing for easy identification and manipulation of chess pieces within the program. + + +--- +### pieceColor +- **Type**: `enum` +- **Members**: + - `pcNoColor`: Represents a piece with no color. + - `pcWhite`: Represents a white-colored piece. + - `pcBlack`: Represents a black-colored piece. +- **Description**: The `pieceColor` enum is used to define the color of a chess piece, with possible values indicating no color, white, or black. This enumeration is essential for distinguishing between the two opposing sides in a chess game, allowing for operations and logic that depend on the color of the pieces. + + +# Function Declarations (Public API) + +--- +### pieceGetType +Retrieve the type of a chess piece. +- **Description**: This function is used to determine the type of a given chess piece, such as pawn, knight, bishop, etc. It is useful when you need to identify the role of a piece on the board, regardless of its color. The function expects a valid piece enumeration value as input and will return the corresponding piece type. It handles both white and black pieces by normalizing the input to a common type enumeration. Ensure that the input is a valid piece value to avoid undefined behavior. +- **Inputs**: + - `p`: A value of type `piece` representing a chess piece. It must be a valid enumeration value from the `piece` enum, such as `pWPawn`, `pBKnight`, etc. Invalid values may lead to undefined behavior. +- **Output**: Returns a `pieceType` enumeration value corresponding to the type of the input piece, such as `ptPawn`, `ptKnight`, etc. +- **See also**: [`pieceGetType`](../../src/chesslib/piece.c.md#pieceGetType) (Implementation) + + +--- +### pieceGetColor +Determines the color of a chess piece. +- **Description**: Use this function to identify the color of a given chess piece. It is useful when you need to differentiate between white and black pieces in a chess game. The function expects a valid piece enumeration value and returns the corresponding color. If the piece does not correspond to a valid white or black piece, the function returns a value indicating no color. This function is typically used in chess game logic to handle piece-specific operations based on color. +- **Inputs**: + - `p`: A chess piece represented by the 'piece' enumeration. It must be a valid piece value, such as pWPawn or pBKing. If the value does not correspond to a defined piece, the function will return pcNoColor. +- **Output**: Returns a 'pieceColor' enumeration value indicating the color of the piece: pcWhite for white pieces, pcBlack for black pieces, and pcNoColor if the piece is not a valid white or black piece. +- **See also**: [`pieceGetColor`](../../src/chesslib/piece.c.md#pieceGetColor) (Implementation) + + +--- +### pieceTypeGetLetter +Returns the character representation of a chess piece type. +- **Description**: This function provides a character representation for a given chess piece type, which can be useful for displaying or logging purposes. It maps each piece type to a specific character: 'P' for pawn, 'N' for knight, 'B' for bishop, 'R' for rook, 'Q' for queen, 'K' for king, and a space character for an empty piece type. If the input does not match any defined piece type, the function returns a null character. This function should be used when a textual representation of a piece type is needed, and it assumes that the input is a valid pieceType enumeration value. +- **Inputs**: + - `pe`: The piece type to be converted to a character. It must be a valid value from the pieceType enumeration. If the value is not recognized, the function returns a null character. +- **Output**: The function returns a character corresponding to the given piece type, or a null character if the input is invalid. +- **See also**: [`pieceTypeGetLetter`](../../src/chesslib/piece.c.md#pieceTypeGetLetter) (Implementation) + + +--- +### pieceGetLetter +Returns the character representation of a chess piece. +- **Description**: This function provides the character representation of a given chess piece, which is useful for displaying or logging the piece in a human-readable format. The character returned corresponds to the type of the piece, with uppercase letters representing white pieces and lowercase letters representing black pieces. It is important to ensure that the input piece is valid, as the function relies on the piece's type and color to determine the correct character. The function does not handle invalid piece values explicitly, so the caller should ensure that the piece is within the defined enumeration. +- **Inputs**: + - `p`: A chess piece of type `piece`, which must be a valid value from the `piece` enumeration. The caller retains ownership and must ensure the piece is valid, as invalid values may lead to undefined behavior. +- **Output**: The function returns a `char` representing the piece's type, with the case indicating the piece's color (uppercase for white, lowercase for black). +- **See also**: [`pieceGetLetter`](../../src/chesslib/piece.c.md#pieceGetLetter) (Implementation) + + +--- +### pieceMake +Create a chess piece of a specified type and color. +- **Description**: Use this function to create a chess piece by specifying its type and color. It is essential to provide a valid piece type and a valid color (either white or black) to obtain a meaningful piece. If the color is invalid, the function returns an empty piece. Similarly, if the type is not recognized, the function also returns an empty piece. This function is useful for initializing or manipulating chess pieces in a program that simulates or manages a chess game. +- **Inputs**: + - `type`: Specifies the type of the chess piece to create. Must be one of the defined pieceType values (e.g., ptKing, ptQueen). If an unrecognized type is provided, the function returns pEmpty. + - `color`: Specifies the color of the chess piece. Must be either pcWhite or pcBlack. If an invalid color is provided, the function returns pEmpty. +- **Output**: Returns a piece of the specified type and color, or pEmpty if the inputs are invalid. +- **See also**: [`pieceMake`](../../src/chesslib/piece.c.md#pieceMake) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/piecemoves.h.md b/driver_docs/c_cpp_export_test/include/chesslib/piecemoves.h.md new file mode 100644 index 0000000..cf0798b --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/piecemoves.h.md @@ -0,0 +1,126 @@ + + + + + +The `piecemoves.h` file defines functions for generating potential move lists for different chess pieces, including leapers, riders, and specific pieces like pawns, knights, bishops, rooks, queens, and kings, while avoiding circular dependencies. + +# Purpose +This C header file defines functions related to generating potential moves for chess pieces on a board, likely as part of a larger chess game application. It includes functions for both "leaper" and "rider" pieces, which are terms used to describe how certain chess pieces move; leapers like knights move to specific squares based on offsets, while riders like bishops and rooks can move continuously in a direction until blocked. The file provides specific functions to generate move lists for each type of chess piece, including pawns, knights, bishops, rooks, queens, and kings, with a special function for pawn attacks due to their unique movement rules. The header file avoids circular dependencies by not including itself in other headers, and it relies on external definitions from "chesslib/board.h" and "chesslib/movelist.h" to function. +# Imports and Dependencies + +--- +- `chesslib/board.h` +- `chesslib/movelist.h` + + +# Function Declarations (Public API) + +--- +### pmLeaperMoveList +Generates a list of potential moves for a leaper piece on a chessboard. +- **Description**: This function is used to determine all potential moves for a leaper piece, such as a knight, on a given chessboard. It should be called when you need to calculate the possible destinations a piece can move to from a specific square, based on its movement pattern defined by directional offsets. The function requires a valid board state and the piece type must match the piece located at the specified square. It returns a list of potential moves, which may include moves that leave the player in check. The function handles out-of-bounds moves by ignoring them. +- **Inputs**: + - `b`: A pointer to the board structure representing the current state of the chessboard. Must not be null. + - `s`: The square from which the leaper piece is moving. It should be a valid square on the board. + - `pt`: The type of the piece expected at the square 's'. It is used to verify that the piece at the square matches the expected type. + - `dirs`: An array of integer pairs representing the possible directional offsets for the leaper's movement. Each pair defines a file and rank offset. + - `numDirs`: The number of directional offsets provided in the 'dirs' array. It determines how many potential moves are considered. +- **Output**: Returns a pointer to a moveList containing potential moves for the leaper piece. The list may be empty if no valid moves are found. +- **See also**: [`pmLeaperMoveList`](../../src/chesslib/piecemoves.c.md#pmLeaperMoveList) (Implementation) + + +--- +### pmRiderMoveList +Generates a list of potential moves for a rider piece from a given position. +- **Description**: This function is used to determine all possible moves for a rider piece, such as a rook, bishop, or queen, from a specified position on the board. It should be called when you need to evaluate the potential moves for these types of pieces, considering their ability to move in a straight line in any direction until they encounter another piece or the edge of the board. The function assumes that the piece at the starting position matches the specified piece type. It returns a list of potential moves, which may include moves that leave the current player in check. The function does not modify the board or any input parameters. +- **Inputs**: + - `b`: A pointer to the board structure representing the current state of the chess game. Must not be null. + - `s`: The starting square from which the rider piece will move. It should be a valid square on the board. + - `pt`: The type of the piece expected at the starting square. The function checks if the piece at the starting square matches this type. + - `dirs`: An array of direction offsets, where each offset is a pair of integers representing a direction in which the piece can move. The array must contain valid direction pairs for the piece type. + - `numDirs`: The number of direction pairs in the dirs array. Must be a non-negative integer. +- **Output**: A pointer to a moveList structure containing all potential moves for the rider piece from the given position. The list may be empty if no valid moves are found. +- **See also**: [`pmRiderMoveList`](../../src/chesslib/piecemoves.c.md#pmRiderMoveList) (Implementation) + + +--- +### pmGetPawnMoves +Generates a list of potential moves for a pawn on a chessboard. +- **Description**: This function is used to determine all potential moves for a pawn located at a specific square on a given chessboard. It should be called when you need to evaluate the possible moves a pawn can make, including forward moves and captures, but it does not account for whether these moves would leave the player in check. The function assumes the board and square are valid and that the square contains a pawn. It returns a move list that may include moves that are not legal in the context of the entire game, such as moves that would leave the king in check. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chessboard. Must not be null, and must be properly initialized before calling this function. + - `s`: A square structure representing the position of the pawn on the board. Must be a valid square on the board and should contain a pawn piece. +- **Output**: A pointer to a moveList structure containing all potential moves for the pawn at the specified square. The list may be empty if no moves are possible. +- **See also**: [`pmGetPawnMoves`](../../src/chesslib/piecemoves.c.md#pmGetPawnMoves) (Implementation) + + +--- +### pmGetKnightMoves +Generates a list of potential knight moves from a given board position. +- **Description**: This function is used to obtain a list of all potential moves for a knight located at a specific square on a given chess board. It is useful when determining possible actions for a knight piece during a game. The function must be called with a valid board and a square that contains a knight. The returned move list includes all potential moves, but it does not account for moves that would leave the player's king in check. This function is typically used in the context of evaluating game states or generating move options for a knight. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null, and should be properly initialized before calling this function. + - `s`: A square on the board where the knight is currently located. It should be a valid square index within the board's dimensions. +- **Output**: A pointer to a moveList structure containing potential moves for the knight. The caller is responsible for managing the memory of the returned moveList. +- **See also**: [`pmGetKnightMoves`](../../src/chesslib/piecemoves.c.md#pmGetKnightMoves) (Implementation) + + +--- +### pmGetBishopMoves +Generates a list of potential bishop moves from a given board position. +- **Description**: This function is used to obtain a list of all potential moves for a bishop located at a specific square on a chess board. It is useful when determining possible actions for a bishop during a game. The function must be called with a valid board state and a square that contains a bishop. The returned move list includes all potential moves, but it does not account for whether these moves would leave the player's king in check. Therefore, additional validation is required to ensure the legality of each move in the context of the game. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null, and should be a valid board configuration. + - `s`: The square on the board where the bishop is located. It should be a valid square index within the board's boundaries. +- **Output**: A pointer to a moveList structure containing potential moves for the bishop. The caller is responsible for managing the memory of the returned move list. +- **See also**: [`pmGetBishopMoves`](../../src/chesslib/piecemoves.c.md#pmGetBishopMoves) (Implementation) + + +--- +### pmGetRookMoves +Generates a list of potential rook moves from a given board position. +- **Description**: Use this function to obtain all potential moves for a rook located at a specific square on the chess board. This function is useful when you need to evaluate possible rook moves without considering whether the moves leave the current player in check. It is important to ensure that the board and square parameters are valid and represent a current game state before calling this function. The function returns a moveList containing all possible moves for the rook, which may include moves that are not legal in the context of the entire game (e.g., moves that would leave the king in check). +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should be properly initialized. + - `s`: The square on the board where the rook is currently located. Must be a valid square within the board's boundaries. +- **Output**: A pointer to a moveList structure containing potential moves for the rook from the specified square. The caller is responsible for managing the memory of the returned moveList. +- **See also**: [`pmGetRookMoves`](../../src/chesslib/piecemoves.c.md#pmGetRookMoves) (Implementation) + + +--- +### pmGetQueenMoves +Generates a list of potential moves for a queen on a chessboard. +- **Description**: This function is used to obtain a list of all potential moves for a queen piece located at a specific square on a given chessboard. It is useful in chess engines or applications that need to calculate possible moves for a queen, taking into account the board's current state. The function returns a move list that includes all possible moves the queen can make, but it does not consider whether these moves would leave the player's king in check. Therefore, additional validation is required to ensure the legality of the moves in the context of the game rules. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chessboard. Must not be null, as it is used to determine the positions of all pieces on the board. + - `s`: The square on the board where the queen is currently located. It must be a valid square within the board's boundaries, typically represented by an integer or an enumeration. +- **Output**: A pointer to a moveList structure containing all potential moves for the queen from the specified square. The caller is responsible for managing the memory of the returned moveList. +- **See also**: [`pmGetQueenMoves`](../../src/chesslib/piecemoves.c.md#pmGetQueenMoves) (Implementation) + + +--- +### pmGetKingMoves +Generates a list of potential king moves from a given square on the board. +- **Description**: This function is used to determine all potential moves for a king piece located at a specific square on a chess board. It should be called when you need to evaluate the possible moves a king can make from its current position. The function returns a list of moves that the king can potentially make, but it does not account for moves that would leave the king in check. It is important to ensure that the board is properly initialized and the square is valid before calling this function. +- **Inputs**: + - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null, and should be properly initialized before calling this function. + - `s`: The square on the board from which the king's moves are to be calculated. It should be a valid square within the board's boundaries. +- **Output**: A pointer to a moveList structure containing the potential moves for the king. The caller is responsible for managing the memory of the returned moveList. +- **See also**: [`pmGetKingMoves`](../../src/chesslib/piecemoves.c.md#pmGetKingMoves) (Implementation) + + +--- +### pmGetPawnAttacks +Generates a list of potential attack moves for a pawn on a given square. +- **Description**: This function is used to determine the potential attack moves for a pawn located on a specific square of the chess board. It should be called when you need to evaluate the attacking capabilities of a pawn, considering the current state of the board. The function assumes that the board and square are valid and that the square contains a pawn. It returns a list of moves that represent the squares the pawn can attack, which may include capturing an opponent's piece. The function does not validate whether the moves leave the player in check. +- **Inputs**: + - `b`: A pointer to the board structure representing the current state of the chess game. Must not be null. The caller retains ownership. + - `s`: The square on the board where the pawn is located. It must be a valid square index within the board's boundaries. +- **Output**: A pointer to a moveList structure containing potential attack moves for the pawn. The list may be empty if no valid attacks are possible. The caller is responsible for managing the memory of the returned moveList. +- **See also**: [`pmGetPawnAttacks`](../../src/chesslib/piecemoves.c.md#pmGetPawnAttacks) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/square.h.md b/driver_docs/c_cpp_export_test/include/chesslib/square.h.md new file mode 100644 index 0000000..4a5bba7 --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/square.h.md @@ -0,0 +1,103 @@ + + + + + +The `square.h` file defines a `sq` struct for representing chessboard squares, along with functions for creating, indexing, and comparing these squares, as well as determining their color. + +# Purpose +This C header file defines a structure and associated functions for handling chessboard squares. The `sq` struct represents a square on a chessboard using two `uint8_t` values for the file and rank, which are constrained to the range 1-8. The file provides utility functions to create squares from integer coordinates or Standard Algebraic Notation (SAN) strings, convert squares to and from a linear index (0-63), and retrieve the SAN string representation of a square. Additionally, it includes functions to determine if a square is dark-colored and to compare two squares for equality. The `SQ_INVALID` macro defines an invalid square with both file and rank set to -1, which is useful for error handling or initialization. +# Imports and Dependencies + +--- +- `stdint.h` + + +# Data Structures + +--- +### sq +- **Type**: `struct` +- **Members**: + - `file`: Represents the file (column) of a square on a chessboard, ranging from 1 to 8. + - `rank`: Represents the rank (row) of a square on a chessboard, ranging from 1 to 8. +- **Description**: The `sq` struct is a simple data structure used to represent a square on a chessboard, with two members: `file` and `rank`, both of which are 8-bit unsigned integers. These members correspond to the column and row of the square, respectively, and are constrained to values between 1 and 8, reflecting the standard 8x8 chessboard. This struct is used in various functions to create, manipulate, and compare chessboard squares, as well as to convert between different representations of squares, such as indices and SAN (Standard Algebraic Notation) strings. + + +# Function Declarations (Public API) + +--- +### sqI +Creates a square from file and rank values. +- **Description**: This function constructs a square object using the provided file and rank values, which represent positions on a chessboard. It is useful when you need to create a square based on specific file and rank coordinates. The function expects both file and rank to be within the range of 1 to 8, inclusive. If either value is outside this range, the function returns a special invalid square constant, SQ_INVALID. This function is typically used in chess-related applications where board positions need to be represented programmatically. +- **Inputs**: + - `file`: The file component of the square, representing the column on a chessboard. Valid values are from 1 to 8, inclusive. If the value is outside this range, the function returns SQ_INVALID. + - `rank`: The rank component of the square, representing the row on a chessboard. Valid values are from 1 to 8, inclusive. If the value is outside this range, the function returns SQ_INVALID. +- **Output**: Returns a square object with the specified file and rank if both are valid; otherwise, returns SQ_INVALID. +- **See also**: [`sqI`](../../src/chesslib/square.c.md#sqI) (Implementation) + + +--- +### sqS +Creates a square from a SAN square string. +- **Description**: This function converts a string representing a square in Standard Algebraic Notation (SAN) into a `sq` struct. It expects a two-character string where the first character is a file ('a' to 'h') and the second character is a rank ('1' to '8'). If the input string does not conform to this format, the function returns `SQ_INVALID`. This function is useful for parsing chess moves or positions from SAN strings into a structured format. Ensure that the input string is not null and is properly formatted before calling this function. +- **Inputs**: + - `str`: A pointer to a null-terminated string representing a square in SAN format. The string must be exactly two characters long, with the first character being a file ('a' to 'h') and the second character being a rank ('1' to '8'). The caller retains ownership of the string. If the string is not in the correct format, the function returns `SQ_INVALID`. +- **Output**: Returns a `sq` struct representing the square if the input is valid, or `SQ_INVALID` if the input is invalid. +- **See also**: [`sqS`](../../src/chesslib/square.c.md#sqS) (Implementation) + + +--- +### sqIndex +Converts an index to a square representation. +- **Description**: This function converts a given index, representing a position on a chessboard, into a square structure. It is useful for translating between a linear index and a two-dimensional board representation. The function expects an index in the range of 0 to 63, where 0 corresponds to the square 'a1' and 63 corresponds to 'h8'. If the index is outside this range, the function returns a special invalid square constant. This function is typically used in applications dealing with chessboard representations where positions are indexed linearly. +- **Inputs**: + - `index`: An unsigned 8-bit integer representing the position on a chessboard, expected to be in the range 0 to 63. If the index is outside this range, the function returns an invalid square. +- **Output**: Returns a square structure corresponding to the given index, or an invalid square if the index is out of range. +- **See also**: [`sqIndex`](../../src/chesslib/square.c.md#sqIndex) (Implementation) + + +--- +### sqGetIndex +Converts a square to its corresponding index on a chessboard. +- **Description**: This function calculates the zero-based index of a given square on a chessboard, where the index ranges from 0 to 63. It is useful for mapping a square's file and rank to a single linear index, which can be used in array representations of a chessboard. The function expects the square's file and rank to be within the range of 1 to 8, inclusive. If the square's file or rank is outside this range, the function returns -1, indicating an invalid square. +- **Inputs**: + - `s`: A square structure containing 'file' and 'rank' fields, both of which must be in the range 1 to 8. If either field is outside this range, the function returns -1. +- **Output**: Returns a uint8_t representing the zero-based index of the square on a chessboard, or -1 if the square is invalid. +- **See also**: [`sqGetIndex`](../../src/chesslib/square.c.md#sqGetIndex) (Implementation) + + +--- +### sqGetStr +Returns the SAN string representation of a given square. +- **Description**: Use this function to obtain the Standard Algebraic Notation (SAN) string for a given square. This function is useful when you need a human-readable representation of a square on a chessboard. The input square must be valid, with an index between 0 and 63, inclusive. If the square index is out of this range, the function returns a placeholder string "##" indicating an invalid square. The returned string does not need to be freed by the caller. +- **Inputs**: + - `s`: A square structure representing a position on a chessboard. The square must be valid, with an index between 0 and 63. If the square is invalid, the function returns "##". +- **Output**: A pointer to a constant character string representing the SAN of the square, or "##" if the square is invalid. +- **See also**: [`sqGetStr`](../../src/chesslib/square.c.md#sqGetStr) (Implementation) + + +--- +### sqIsDark +Determine if a chessboard square is dark-colored. +- **Description**: Use this function to check whether a given chessboard square is dark-colored. This is useful in applications where the color of the square affects gameplay or display logic. The function expects a valid square structure with file and rank values in the range of 1 to 8. It returns 1 if the square is dark and 0 if it is light. Ensure that the square provided is valid, as the behavior for invalid squares is not defined. +- **Inputs**: + - `s`: A square structure representing a chessboard square, with 'file' and 'rank' fields both expected to be in the range 1 to 8. The caller must ensure the square is valid, as invalid values may lead to undefined behavior. +- **Output**: Returns 1 if the square is dark-colored, and 0 if it is light-colored. +- **See also**: [`sqIsDark`](../../src/chesslib/square.c.md#sqIsDark) (Implementation) + + +--- +### sqEq +Compares two chessboard squares for equality. +- **Description**: Use this function to determine if two chessboard squares, represented by the `sq` struct, are equal in terms of their file and rank. This function is useful when you need to check if two positions on a chessboard are the same. It handles invalid square values by setting them to a predefined invalid state before comparison. Ensure that the `file` and `rank` values of the `sq` structs are within the valid range of 1 to 8 before calling this function to avoid them being marked as invalid. +- **Inputs**: + - `s1`: The first square to compare, represented as an `sq` struct. The `file` and `rank` must be in the range 1 to 8. If out of range, it is treated as invalid. + - `s2`: The second square to compare, represented as an `sq` struct. The `file` and `rank` must be in the range 1 to 8. If out of range, it is treated as invalid. +- **Output**: Returns 1 if the squares are equal (same file and rank), or 0 if they are not. +- **See also**: [`sqEq`](../../src/chesslib/square.c.md#sqEq) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/include/chesslib/squareset.h.md b/driver_docs/c_cpp_export_test/include/chesslib/squareset.h.md new file mode 100644 index 0000000..56df0d9 --- /dev/null +++ b/driver_docs/c_cpp_export_test/include/chesslib/squareset.h.md @@ -0,0 +1,43 @@ + + + + + +The `squareset.h` file defines a 64-bit square set for representing the state of each square on a chessboard and includes functions to set and get the state of individual squares. + +# Purpose +This C header file defines a data structure and associated functions for managing a "square set" in a chess-related application. The square set is represented as a 64-bit integer (`uint64_t`), where each bit corresponds to a square on a chessboard, indicating whether it is "on" or "off." The file includes function prototypes for [`sqSetSet`](#sqSetSet) and [`sqSetGet`](#sqSetGet), which are used to modify and retrieve the state of a specific square within the set, respectively. The file also includes a `TODO` comment suggesting the need for conditional typedefs to accommodate systems that do not support `uint64_t`, potentially using a struct of 8 bytes as an alternative. This header file is part of a larger library, as indicated by the inclusion of "chesslib/square.h". +# Imports and Dependencies + +--- +- `chesslib/square.h` + + +# Function Declarations (Public API) + +--- +### sqSetSet +Sets the state of a square in a square set. +- **Description**: This function modifies the state of a specific square within a square set, which is represented as a 64-bit integer. It should be used to mark a square as either 'on' or 'off' based on the provided value. The function does nothing if the square is invalid. It is important to ensure that the square set pointer is valid and that the square is not invalid before calling this function. +- **Inputs**: + - `ss`: A pointer to a sqSet, which is a 64-bit integer representing the set of squares. Must not be null, as the function modifies the value it points to. + - `s`: The square to be modified within the square set. It must be a valid square; otherwise, the function will not alter the square set. + - `value`: A uint8_t value indicating the desired state of the square: non-zero to set the square 'on', and zero to set it 'off'. +- **Output**: None +- **See also**: [`sqSetSet`](../../src/chesslib/squareset.c.md#sqSetSet) (Implementation) + + +--- +### sqSetGet +Retrieve the status of a square in a square set. +- **Description**: This function checks whether a specific square in a square set is marked as 'on' or 'off'. It is used to determine the current state of a square within a 64-square board representation. The function should be called with a valid square set and a valid square identifier. If the square identifier is invalid, the function returns 0, indicating the square is 'off'. This function is useful in scenarios where you need to query the state of individual squares on a chessboard or similar grid-based systems. +- **Inputs**: + - `ss`: A pointer to a sqSet, which is a 64-bit number representing the state of each square on a board. Must not be null, as it is dereferenced to access the square set. + - `s`: A square identifier of type sq. It must represent a valid square; otherwise, the function treats it as 'off' and returns 0. +- **Output**: Returns 1 if the specified square is 'on' in the square set, and 0 if it is 'off' or if the square identifier is invalid. +- **See also**: [`sqSetGet`](../../src/chesslib/squareset.c.md#sqSetGet) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/README.md b/driver_docs/c_cpp_export_test/src/README.md new file mode 100644 index 0000000..4dce61c --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/README.md @@ -0,0 +1,16 @@ + + + + + +The `chesslib` folder implements a chess library in C, and `tests.c` and `tests.h` provide unit tests and function prototypes. + +## Folders +- **[chesslib](chesslib/README.md)**: C source files that implement a chess library with board management, move handling, and piece logic. + +## Files +- **[tests.c](tests.c.md)**: The `tests.c` file in the `c_cpp_export_test` codebase contains a comprehensive suite of unit tests for various components of a chess implementation in C, including tests for squares, moves, move lists, boards, piece moves, attacked squares, move generation, FEN generation, and draw conditions. +- **[tests.h](tests.h.md)**: The `tests.h` file defines function prototypes for various test cases related to a Chess implementation in C, including tests for squares, moves, boards, and FEN generation. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/chesslib/README.md b/driver_docs/c_cpp_export_test/src/chesslib/README.md new file mode 100644 index 0000000..e8da203 --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/chesslib/README.md @@ -0,0 +1,21 @@ + + + + + +C source files that implement a chess library with board management, move handling, and piece logic. + + +## Files +- **[board.c](board.c.md)**: The `board.c` file in the `c_cpp_export_test` codebase implements a chess board, including functions for creating a board from a FEN string, generating legal moves, checking for check and checkmate, and converting the board state back to a FEN string. +- **[boardlist.c](boardlist.c.md)**: The `boardlist.c` file implements a singly linked list for managing a list of chess boards, including functions to create, add, retrieve, undo, and free the list. +- **[chess.c](chess.c.md)**: The `chess.c` file implements a chess game, providing functions for creating and managing chess games, handling moves, and determining game states such as checkmate and draw conditions. +- **[move.c](move.c.md)**: The `move.c` file in the `c_cpp_export_test` codebase implements functions for handling chess moves, including creating moves, comparing them, and converting between moves and UCI strings. +- **[movelist.c](movelist.c.md)**: The `movelist.c` file implements a linked list structure for managing chess moves, including functions for creating, adding, retrieving, undoing moves, and generating a UCI string representation of the move list. +- **[piece.c](piece.c.md)**: The `piece.c` file in the `c_cpp_export_test` codebase implements functions for handling chess pieces, including determining their type, color, and corresponding letter representation. +- **[piecemoves.c](piecemoves.c.md)**: The `piecemoves.c` file in the `c_cpp_export_test` codebase implements the movement logic for chess pieces, including pawns, knights, bishops, rooks, queens, and kings, while avoiding circular dependencies. +- **[square.c](square.c.md)**: The `square.c` file in the `c_cpp_export_test` codebase provides functions for creating and manipulating chessboard squares, including conversion between different representations and checking square properties. +- **[squareset.c](squareset.c.md)**: The `squareset.c` file implements functions for setting and getting values in a square set, which is part of a chess library. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/chesslib/board.c.md b/driver_docs/c_cpp_export_test/src/chesslib/board.c.md new file mode 100644 index 0000000..4d67e16 --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/chesslib/board.c.md @@ -0,0 +1,349 @@ + + + + + +The `board.c` file in the `c_cpp_export_test` codebase implements a chess board, including functions for creating a board from a FEN string, generating legal moves, checking for check and checkmate, and converting the board state back to a FEN string. + +# Purpose +This C source code file implements a chess board management system, providing functionality to create, manipulate, and evaluate chess board states. The code is designed to handle chess positions using the Forsyth-Edwards Notation (FEN), which is a standard notation for describing a particular board position of a chess game. The file includes functions to initialize a board from a FEN string, generate legal moves, check for check conditions, and determine if a position has insufficient material to continue the game. It also provides utilities to play moves on the board, check for board equality, and convert a board state back into a FEN string. + +The code is structured around a `board` data structure, which encapsulates the state of a chess game, including piece positions, castling rights, en passant targets, and move counters. Key functions include [`boardCreateFromFen`](#boardCreateFromFen) for initializing a board from a FEN string, [`boardGenerateMoves`](#boardGenerateMoves) for generating all legal moves for the current player, and [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) for determining if a player is in check. The file also includes error handling for invalid FEN strings and ensures that moves are only played if they are legal. This code is part of a larger chess library, as indicated by the inclusion of headers like "chesslib/board.h" and "chesslib/piecemoves.h", and is intended to be used as a backend component for chess applications, providing essential board state management and move generation capabilities. +# Imports and Dependencies + +--- +- `stdio.h` +- `ctype.h` +- `stdlib.h` +- `string.h` +- `chesslib/board.h` +- `chesslib/piecemoves.h` + + +# Functions + +--- +### boardCreate +The `boardCreate` function initializes a new chess board using the standard initial position in FEN notation. +- **Inputs**: None +- **Control Flow**: + - The function calls [`boardCreateFromFen`](#boardCreateFromFen) with `INITIAL_FEN` as the argument, which represents the standard initial position of a chess game. + - The function returns the result of [`boardCreateFromFen`](#boardCreateFromFen), which is a pointer to a newly created `board` structure initialized with the initial chess position. +- **Output**: A pointer to a `board` structure initialized with the standard initial chess position, or `NULL` if initialization fails. +- **Functions called**: + - [`boardCreateFromFen`](#boardCreateFromFen) + + +--- +### boardCreateFromFen +The `boardCreateFromFen` function allocates memory for a new chess board and initializes it using a FEN string, returning the board if successful or NULL if initialization fails. +- **Inputs**: + - `fen`: A string representing the board position in Forsyth-Edwards Notation (FEN). +- **Control Flow**: + - Allocate memory for a new `board` structure. + - Call [`boardInitFromFenInPlace`](#boardInitFromFenInPlace) to initialize the board with the given FEN string. + - If initialization fails (returns non-zero), free the allocated memory and return NULL. + - If initialization succeeds, return the pointer to the newly created board. +- **Output**: A pointer to a `board` structure initialized with the FEN string, or NULL if initialization fails. +- **Functions called**: + - [`boardInitFromFenInPlace`](#boardInitFromFenInPlace) + + +--- +### boardInitInPlace +The `boardInitInPlace` function initializes a chess board to the standard starting position using the FEN string for the initial setup. +- **Inputs**: + - `b`: A pointer to a `board` structure that will be initialized to the standard starting position. +- **Control Flow**: + - The function calls [`boardInitFromFenInPlace`](#boardInitFromFenInPlace) with the board pointer `b` and the constant `INITIAL_FEN` which represents the standard starting position in FEN notation. +- **Output**: The function does not return a value; it modifies the board in place to represent the initial chess position. +- **Functions called**: + - [`boardInitFromFenInPlace`](#boardInitFromFenInPlace) + + +--- +### boardInitFromFenInPlace +The function `boardInitFromFenInPlace` initializes a chess board structure from a given FEN (Forsyth-Edwards Notation) string, setting up the board pieces, current player, castling rights, en passant target, and move counters. +- **Inputs**: + - `b`: A pointer to a `board` structure that will be initialized based on the FEN string. + - `fen`: A constant character pointer representing the FEN string that describes the board state to be initialized. +- **Control Flow**: + - Initialize the starting square to the top-left of the board (file 1, rank 8). + - Iterate over the FEN string to set up the board pieces, handling numbers for empty squares, slashes for rank changes, and specific characters for different pieces. + - Check for errors such as misplaced slashes, unknown characters, or premature end of the FEN string, returning an error code if any are found. + - After setting up pieces, read the current player's turn from the FEN string and validate it. + - Parse the castling rights from the FEN string, updating the board's castling state accordingly. + - Read the en passant target square from the FEN string, validating and setting it on the board. + - Parse the half-move clock and full move number from the FEN string using `sscanf`. + - Return 0 to indicate successful initialization, or 1 if any errors were encountered. +- **Output**: Returns a `uint8_t` value, 0 if the board was successfully initialized from the FEN string, or 1 if an error occurred during parsing. +- **Functions called**: + - [`sqI`](square.c.md#sqI) + - [`boardSetPiece`](#boardSetPiece) + - [`boardGetPiece`](#boardGetPiece) + - [`sqS`](square.c.md#sqS) + + +--- +### boardSetPiece +The `boardSetPiece` function sets a specific piece on a given square of a chess board. +- **Inputs**: + - `b`: A pointer to the `board` structure where the piece is to be set. + - `s`: The square (`sq` type) on the board where the piece should be placed. + - `p`: The piece (`piece` type) to be placed on the specified square. +- **Control Flow**: + - Calculate the index of the square `s` using the [`sqGetIndex`](square.c.md#sqGetIndex) function. + - Set the piece `p` at the calculated index in the `pieces` array of the board `b`. +- **Output**: The function does not return a value; it modifies the board in place by setting the specified piece at the given square. +- **Functions called**: + - [`sqGetIndex`](square.c.md#sqGetIndex) + + +--- +### boardGetPiece +The `boardGetPiece` function retrieves the chess piece located at a specified square on a given chess board. +- **Inputs**: + - `b`: A pointer to a `board` structure representing the chess board from which the piece is to be retrieved. + - `s`: A `sq` type representing the square on the board from which the piece is to be retrieved. +- **Control Flow**: + - The function calls [`sqGetIndex`](square.c.md#sqGetIndex) with the square `s` to get the index of the square in the board's piece array. + - It then accesses the `pieces` array of the board `b` using the calculated index to retrieve the piece located at that square. +- **Output**: The function returns a `piece` type, which is the chess piece located at the specified square on the board. +- **Functions called**: + - [`sqGetIndex`](square.c.md#sqGetIndex) + + +--- +### boardGenerateMoves +The `boardGenerateMoves` function generates a list of all legal moves for the current player on a given chess board, including castling moves, and returns this list. +- **Inputs**: + - `b`: A pointer to a `board` structure representing the current state of the chess board. +- **Control Flow**: + - Create an empty move list using [`moveListCreate`](movelist.c.md#moveListCreate). + - Iterate over each square on the board (64 squares total). + - For each square, retrieve the piece and check if it belongs to the current player; if not, continue to the next square. + - Determine the type of piece and generate potential moves for that piece using the appropriate function (e.g., [`pmGetPawnMoves`](piecemoves.c.md#pmGetPawnMoves) for pawns). + - For each potential move, simulate the move on a copy of the board and check if it results in the current player being in check; if not, add the move to the move list. + - Free the list of potential moves after processing. + - Check if castling is possible for the current player by verifying the castling state and ensuring the path is clear and not under attack. + - Add valid castling moves to the move list if conditions are met. + - Return the list of legal moves. +- **Output**: A pointer to a `moveList` structure containing all legal moves for the current player, which must be freed after use. +- **Functions called**: + - [`moveListCreate`](movelist.c.md#moveListCreate) + - [`sqIndex`](square.c.md#sqIndex) + - [`boardGetPiece`](#boardGetPiece) + - [`pieceGetColor`](piece.c.md#pieceGetColor) + - [`pieceGetType`](piece.c.md#pieceGetType) + - [`pmGetPawnMoves`](piecemoves.c.md#pmGetPawnMoves) + - [`pmGetKnightMoves`](piecemoves.c.md#pmGetKnightMoves) + - [`pmGetBishopMoves`](piecemoves.c.md#pmGetBishopMoves) + - [`pmGetRookMoves`](piecemoves.c.md#pmGetRookMoves) + - [`pmGetQueenMoves`](piecemoves.c.md#pmGetQueenMoves) + - [`pmGetKingMoves`](piecemoves.c.md#pmGetKingMoves) + - [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) + - [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) + - [`moveListAdd`](movelist.c.md#moveListAdd) + - [`moveListFree`](movelist.c.md#moveListFree) + - [`sqI`](square.c.md#sqI) + - [`boardIsSquareAttacked`](#boardIsSquareAttacked) + - [`moveSq`](move.c.md#moveSq) + + +--- +### boardIsSquareAttacked +The function `boardIsSquareAttacked` checks if a specific square on a chess board is attacked by any piece of a given color. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chess board. + - `s`: The square (`sq` type) on the board to check for attacks. + - `attacker`: The color of the pieces (`pieceColor` type) that are considered as potential attackers. +- **Control Flow**: + - Iterate over all 64 squares on the board. + - For each square, retrieve the piece located there and check if it matches the attacker's color. + - If the piece matches the attacker's color, determine its type and generate a list of possible moves or attacks for that piece type. + - Iterate through the generated move list to check if any move targets the specified square `s`. + - If a move targets the square `s`, set a flag indicating the square is attacked and break out of the loop. + - Free the move list memory after checking. + - Return 1 if the square is attacked, otherwise continue checking other pieces. + - Return 0 if no attacking piece is found after checking all squares. +- **Output**: Returns `1` if the square `s` is attacked by any piece of the specified color, otherwise returns `0`. +- **Functions called**: + - [`sqIndex`](square.c.md#sqIndex) + - [`boardGetPiece`](#boardGetPiece) + - [`pieceGetColor`](piece.c.md#pieceGetColor) + - [`pieceGetType`](piece.c.md#pieceGetType) + - [`pmGetPawnAttacks`](piecemoves.c.md#pmGetPawnAttacks) + - [`pmGetKnightMoves`](piecemoves.c.md#pmGetKnightMoves) + - [`pmGetBishopMoves`](piecemoves.c.md#pmGetBishopMoves) + - [`pmGetRookMoves`](piecemoves.c.md#pmGetRookMoves) + - [`pmGetQueenMoves`](piecemoves.c.md#pmGetQueenMoves) + - [`pmGetKingMoves`](piecemoves.c.md#pmGetKingMoves) + - [`sqEq`](square.c.md#sqEq) + - [`moveListFree`](movelist.c.md#moveListFree) + + +--- +### boardIsInCheck +The `boardIsInCheck` function checks if the current player on a given chess board is in check. +- **Inputs**: + - `b`: A pointer to a `board` structure representing the current state of the chess game. +- **Control Flow**: + - The function calls [`boardIsPlayerInCheck`](#boardIsPlayerInCheck), passing the board and the current player as arguments. + - It returns the result of the [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) function, which determines if the current player's king is under attack. +- **Output**: A `uint8_t` value indicating whether the current player is in check (1 if in check, 0 otherwise). +- **Functions called**: + - [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) + + +--- +### boardIsPlayerInCheck +The function `boardIsPlayerInCheck` checks if a player's king is in check on a given chess board. +- **Inputs**: + - `b`: A pointer to a `board` structure representing the current state of the chess board. + - `player`: A `pieceColor` value indicating the color of the player (either `pcWhite` or `pcBlack`) whose king's check status is being evaluated. +- **Control Flow**: + - Determine the type of the player's king (`pWKing` for white, `pBKing` for black) and the opponent's color. + - Iterate over all 64 squares of the board to find the player's king. + - For each square, check if it contains the player's king. + - If the king is found, check if the square is attacked by any piece of the opponent's color using [`boardIsSquareAttacked`](#boardIsSquareAttacked). + - If the square is attacked, return 1 indicating the king is in check. + - If no attack is found on the king's square after checking all squares, return 0 indicating the king is not in check. +- **Output**: Returns `1` if the player's king is in check, otherwise returns `0`. +- **Functions called**: + - [`sqIndex`](square.c.md#sqIndex) + - [`boardGetPiece`](#boardGetPiece) + - [`boardIsSquareAttacked`](#boardIsSquareAttacked) + + +--- +### boardIsInsufficientMaterial +The function `boardIsInsufficientMaterial` checks if a chess board position is a draw due to insufficient material to checkmate. +- **Inputs**: + - `b`: A pointer to a `board` structure representing the current state of the chess board. +- **Control Flow**: + - Initialize counters for pieces, knights, bishops on dark squares, bishops on light squares, and kings. + - Iterate over all 64 squares of the board to count the number of each type of piece. + - Check if the board only has kings, which is always a draw, and return 1 if true. + - Check if there is one white king and one black king, and if the total number of pieces equals the sum of kings, knights, and bishops. + - If there are only two kings and one minor piece (knight or bishop), return 1 indicating a draw. + - If there are only two kings and bishops all on the same color, return 1 indicating a draw. + - Return 0 if none of the conditions for insufficient material are met. +- **Output**: Returns 1 if the board position is a draw due to insufficient material, otherwise returns 0. +- **Functions called**: + - [`sqIndex`](square.c.md#sqIndex) + - [`boardGetPiece`](#boardGetPiece) + - [`pieceGetType`](piece.c.md#pieceGetType) + - [`sqIsDark`](square.c.md#sqIsDark) + + +--- +### boardPlayMove +The `boardPlayMove` function creates a new chess board state by applying a given move to an existing board. +- **Inputs**: + - `b`: A pointer to the current board state represented by a `board` structure. + - `m`: A `move` structure representing the move to be applied to the board. +- **Control Flow**: + - Allocate memory for a new `board` structure and assign it to `newBoard`. + - Copy the contents of the existing board `b` into `newBoard` using `memcpy`. + - Call [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) to apply the move `m` to `newBoard` in place. + - Return the pointer to the newly created `newBoard` with the move applied. +- **Output**: A pointer to a new `board` structure that represents the board state after the move `m` has been applied. +- **Functions called**: + - [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) + + +--- +### boardPlayMoveInPlace +The `boardPlayMoveInPlace` function executes a given chess move on a board, updating the board's state accordingly, including handling special moves like castling and en passant. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chess board. + - `m`: A `move` structure representing the move to be played, including the starting and ending positions and any promotion details. +- **Control Flow**: + - If the current player is black, increment the move number. + - Determine if the move is irreversible (pawn move or capture) and reset or increment the half-move clock accordingly. + - Check if the move is a castling move and update the board by moving the rook and clearing the castling rights. + - If a rook moves or is captured, update the castling rights accordingly. + - Handle en passant captures by removing the captured pawn from the board. + - Move the piece from the source to the destination square, handling promotions if applicable. + - Set the en passant target square if a pawn moves two squares forward, otherwise invalidate it. + - Switch the current player to the other player. +- **Output**: The function does not return a value; it modifies the board in place to reflect the move played. +- **Functions called**: + - [`pieceGetType`](piece.c.md#pieceGetType) + - [`boardGetPiece`](#boardGetPiece) + - [`boardSetPiece`](#boardSetPiece) + - [`sqI`](square.c.md#sqI) + - [`sqEq`](square.c.md#sqEq) + - [`pieceMake`](piece.c.md#pieceMake) + + +--- +### boardEq +The `boardEq` function checks if two chess board states are fully equal by comparing various attributes and the board's memory. +- **Inputs**: + - `b1`: A pointer to the first board structure to be compared. + - `b2`: A pointer to the second board structure to be compared. +- **Control Flow**: + - Check if the current player of both boards is the same; if not, return 0. + - Check if the castling state of both boards is the same; if not, return 0. + - Check if the en passant target squares of both boards are equal using [`sqEq`](square.c.md#sqEq); if not, return 0. + - Check if the half-move clock values of both boards are the same; if not, return 0. + - Check if the move numbers of both boards are the same; if not, return 0. + - Use `memcmp` to compare the memory of both boards for the first 64 pieces; if they differ, return 0. + - If all checks pass, return 1 indicating the boards are fully equal. +- **Output**: Returns 1 if the boards are fully equal, otherwise returns 0. +- **Functions called**: + - [`sqEq`](square.c.md#sqEq) + + +--- +### boardEqContext +The `boardEqContext` function checks if two chess boards are contextually equal, ignoring move counters and filtering en passant target squares. +- **Inputs**: + - `b1`: A pointer to the first board structure to compare. + - `b2`: A pointer to the second board structure to compare. +- **Control Flow**: + - Check if the current player on both boards is the same; if not, return 0. + - Check if the castling state on both boards is the same; if not, return 0. + - Compare the memory of the two boards for the first 64 pieces; if they differ, return 0. + - Filter the en passant target square for board b1 by checking if any pawns can attack it; if not, set it to SQ_INVALID. + - Filter the en passant target square for board b2 by checking if any pawns can attack it; if not, set it to SQ_INVALID. + - Compare the filtered en passant target squares of both boards; if they differ, return 0. + - If all checks pass, return 1 indicating the boards are contextually equal. +- **Output**: Returns 1 if the boards are contextually equal, otherwise returns 0. +- **Functions called**: + - [`sqEq`](square.c.md#sqEq) + - [`sqI`](square.c.md#sqI) + - [`boardGetPiece`](#boardGetPiece) + - [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) + - [`moveSq`](move.c.md#moveSq) + - [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) + + +--- +### boardGetFen +The `boardGetFen` function generates a FEN (Forsyth-Edwards Notation) string representing the current state of a chess board. +- **Inputs**: + - `b`: A pointer to a `board` structure representing the current state of the chess game. +- **Control Flow**: + - Initialize a buffer `buf` to store the FEN string and a pointer `c` to traverse the buffer. + - Iterate over each rank from 8 to 1 and each file from 1 to 8 to encode the piece positions on the board. + - For each square, check if it contains a piece; if so, append the piece's letter to the buffer, otherwise count consecutive empty squares and append the count when a piece is encountered or the rank ends. + - After processing each rank, append a '/' to separate ranks, except after the last rank. + - Append the current player's turn ('w' for white, 'b' for black) to the buffer. + - Encode the castling availability by checking the `castleState` and appending 'K', 'Q', 'k', 'q' as applicable, or '-' if no castling is available. + - Encode the en passant target square by checking `epTarget` and appending its string representation or '-' if invalid. + - Use `sprintf` to append the half-move clock and full move number to the buffer. + - Allocate memory for the final FEN string, copy the buffer content into it, and return the allocated string. +- **Output**: A dynamically allocated string containing the FEN representation of the board, which must be freed by the caller. +- **Functions called**: + - [`sqI`](square.c.md#sqI) + - [`boardGetPiece`](#boardGetPiece) + - [`pieceGetLetter`](piece.c.md#pieceGetLetter) + - [`sqEq`](square.c.md#sqEq) + - [`sqGetStr`](square.c.md#sqGetStr) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/src/chesslib/boardlist.c.driver.md b/driver_docs/c_cpp_export_test/src/chesslib/boardlist.c.md similarity index 50% rename from driver_docs/src/chesslib/boardlist.c.driver.md rename to driver_docs/c_cpp_export_test/src/chesslib/boardlist.c.md index 5649425..bd339b5 100644 --- a/driver_docs/src/chesslib/boardlist.c.driver.md +++ b/driver_docs/c_cpp_export_test/src/chesslib/boardlist.c.md @@ -1,7 +1,14 @@ + + + + + +The `boardlist.c` file implements a singly linked list for managing a list of chess boards, including functions to create, add, retrieve, undo, and free the list. + # Purpose -This C source code file implements a linked list data structure specifically designed to manage a collection of chess boards, as indicated by the inclusion of "chesslib/boardlist.h". The primary purpose of this code is to provide a dynamic list that can store, retrieve, and manage chess board states, which is useful in applications such as chess engines or games where board states need to be tracked over time. The code defines several functions to create and manipulate the list: [`boardListCreate`](#boardListCreate) initializes a new list, [`boardListNodeCreate`](#boardListNodeCreate) creates a new node for a board, [`boardListAdd`](#boardListAdd) appends a board to the list, [`boardListGet`](#boardListGet) retrieves a board at a specified index, [`boardListUndo`](#boardListUndo) removes the last board from the list, and [`boardListFree`](#boardListFree) deallocates the entire list. +This C source code file implements a linked list data structure specifically designed to manage a collection of chess boards, as indicated by the inclusion of "chesslib/boardlist.h". The primary purpose of this code is to provide a set of functions to create, manipulate, and manage a list of chess board states, which can be useful in applications such as chess engines or games where tracking multiple board states is necessary. The code defines several key functions: [`boardListCreate`](#boardListCreate) initializes a new list, [`boardListNodeCreate`](#boardListNodeCreate) creates a new node containing a chess board, [`boardListAdd`](#boardListAdd) appends a new board to the list, [`boardListGet`](#boardListGet) retrieves a board at a specified index, [`boardListUndo`](#boardListUndo) removes the last board from the list, and [`boardListFree`](#boardListFree) deallocates the entire list and its contents. -The implementation uses a singly linked list structure, with each node containing a pointer to a chess board and a pointer to the next node. The list maintains pointers to both the head and tail nodes, facilitating efficient additions to the end of the list. However, the [`boardListUndo`](#boardListUndo) function highlights a limitation of the singly linked list, as it requires traversal from the head to find the penultimate node when removing the last element. This code is part of a broader library, as suggested by the inclusion of a header file, and is intended to be used as a module within larger chess-related software systems. It does not define public APIs or external interfaces directly but provides essential internal functionality for managing sequences of chess board states. +The implementation uses a singly linked list structure, with each node containing a pointer to a chess board and a pointer to the next node. The list maintains pointers to both the head and tail nodes, facilitating efficient additions to the end of the list. However, the [`boardListUndo`](#boardListUndo) function highlights a limitation of the singly linked list, as it requires traversal from the head to find the penultimate node when removing the last node. This code is part of a broader library, as suggested by the inclusion of a header file, and is intended to be used as a module within larger chess-related software systems. It does not define public APIs or external interfaces directly but provides essential internal functionality for managing sequences of chess board states. # Imports and Dependencies --- @@ -14,46 +21,42 @@ The implementation uses a singly linked list structure, with each node containin --- ### boardListCreate The `boardListCreate` function initializes and returns a new, empty `boardList` structure. -- **Inputs**: - - None +- **Inputs**: None - **Control Flow**: - - Allocate memory for a new `boardList` structure. + - Allocate memory for a new `boardList` structure using `malloc`. - Initialize the `head` pointer of the list to `NULL`, indicating the list is empty. - Initialize the `tail` pointer of the list to `NULL`, indicating the list is empty. - - Set the `size` of the list to 0, indicating there are no elements in the list. + - Set the `size` of the list to `0`, indicating there are no elements in the list. - Return the pointer to the newly created `boardList`. -- **Output**: - - A pointer to a newly allocated and initialized `boardList` structure. +- **Output**: A pointer to a newly allocated and initialized `boardList` structure. --- ### boardListNodeCreate -The function `boardListNodeCreate` allocates memory for a new `boardListNode`, initializes it with a given `board`, and sets its `next` pointer to `NULL`. +The `boardListNodeCreate` function allocates memory for a new `boardListNode`, initializes it with a given `board`, and sets its `next` pointer to `NULL`. - **Inputs**: - - `b`: A pointer to a `board` structure that the new `boardListNode` will hold. + - `b`: A pointer to a `board` structure that the new node will hold. - **Control Flow**: - - Allocate memory for a new `boardListNode` structure using `malloc`. - - Assign the provided `board` pointer `b` to the `board` field of the newly created `boardListNode`. - - Set the `next` pointer of the new `boardListNode` to `NULL`. - - Return the pointer to the newly created `boardListNode`. -- **Output**: - - A pointer to the newly created `boardListNode` structure. + - Allocate memory for a new `boardListNode` structure. + - Assign the provided `board` pointer `b` to the `board` field of the new node. + - Set the `next` pointer of the new node to `NULL`. + - Return the newly created node. +- **Output**: A pointer to the newly created `boardListNode` containing the provided `board` and a `next` pointer set to `NULL`. --- ### boardListAdd The `boardListAdd` function appends a new board node to the end of a linked list of boards, updating the list's head, tail, and size accordingly. - **Inputs**: - - `list`: A pointer to a `boardList` structure, representing the linked list to which the board will be added. - - `b`: A pointer to a `board` structure, representing the board to be added to the list. + - `list`: A pointer to a `boardList` structure representing the linked list to which the board will be added. + - `b`: A pointer to a `board` structure that represents the board to be added to the list. - **Control Flow**: - Create a new `boardListNode` using the provided board `b`. - Check if the list's head is `NULL`, indicating the list is empty. - If the list is empty, set both the head and tail of the list to the new node. - If the list is not empty, link the current tail's `next` pointer to the new node and update the list's tail to the new node. - Increment the list's size by one. -- **Output**: - - The function does not return a value; it modifies the `boardList` structure in place by adding a new node to it. +- **Output**: This function does not return a value; it modifies the `boardList` structure in place. - **Functions called**: - [`boardListNodeCreate`](#boardListNodeCreate) @@ -62,14 +65,15 @@ The `boardListAdd` function appends a new board node to the end of a linked list ### boardListGet The `boardListGet` function retrieves a board from a linked list of boards at a specified index. - **Inputs**: - - `list`: A pointer to a `boardList` structure, which is a linked list of boards. + - `list`: A pointer to a `boardList` structure, which represents the linked list of boards. - `index`: An unsigned integer representing the position in the list from which to retrieve the board. - **Control Flow**: - Initialize `currNode` to the head of the list. - - Iterate through the list, moving `currNode` to the next node and decrementing `index` until `index` reaches zero. - - Return the board associated with the current node. -- **Output**: - - Returns a pointer to the `board` at the specified index in the list. + - Enter a loop that continues while `index` is non-zero. + - In each iteration, move `currNode` to the next node in the list and decrement `index`. + - Once `index` reaches zero, exit the loop. + - Return the `board` associated with the current node (`currNode`). +- **Output**: A pointer to the `board` at the specified index in the list. --- @@ -79,28 +83,29 @@ The `boardListUndo` function removes the last node from a singly linked list of - `list`: A pointer to a `boardList` structure, which represents a singly linked list of board nodes. - **Control Flow**: - Check if the list is NULL or if the list's head is NULL; if so, return immediately as there is nothing to undo. - - If the list contains only one node, free the board and the node, then set both the head and tail of the list to NULL. + - If the list contains only one node, free the board and node, then set both the head and tail of the list to NULL. - If the list contains more than one node, traverse the list to find the last node and its predecessor. - Free the board and the last node, update the predecessor's next pointer to NULL, and set the list's tail to the predecessor. - Decrement the size of the list by one. -- **Output**: - - The function does not return a value; it modifies the input `boardList` by removing the last node and updating its size and tail. +- **Output**: The function does not return a value; it modifies the input `boardList` by removing the last node and updating its size and tail. --- ### boardListFree -The `boardListFree` function deallocates all memory associated with a `boardList` and its nodes. +The `boardListFree` function deallocates all memory associated with a `boardList` and its nodes, effectively destroying the list. - **Inputs**: - - `list`: A pointer to a `boardList` structure that needs to be freed. + - `list`: A pointer to the `boardList` structure that is to be freed. - **Control Flow**: - Initialize a pointer `node` to the head of the list. - Enter a loop that continues as long as `node` is not NULL. - Inside the loop, store the next node in a temporary pointer `next`. - - Free the memory allocated for the `board` in the current node. + - Free the memory allocated for the `board` within the current node. - Free the memory allocated for the current node itself. - Move to the next node by setting `node` to `next`. - After the loop, free the memory allocated for the `boardList` structure itself. -- **Output**: - - The function does not return any value; it performs memory deallocation for the given `boardList` and its nodes. +- **Output**: The function does not return any value; it performs memory deallocation. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/src/chesslib/chess.c.driver.md b/driver_docs/c_cpp_export_test/src/chesslib/chess.c.md similarity index 50% rename from driver_docs/src/chesslib/chess.c.driver.md rename to driver_docs/c_cpp_export_test/src/chesslib/chess.c.md index 13e6810..de8ae87 100644 --- a/driver_docs/src/chesslib/chess.c.driver.md +++ b/driver_docs/c_cpp_export_test/src/chesslib/chess.c.md @@ -1,7 +1,14 @@ + + + + + +The `chess.c` file implements a chess game, providing functions for creating and managing chess games, handling moves, and determining game states such as checkmate and draw conditions. + # Purpose -This C source code file implements a chess game engine, providing core functionalities for creating, managing, and interacting with a chess game state. The code is structured around a `chess` data structure, which encapsulates the current state of a chess game, including the board configuration, move history, and game status. The file includes functions to initialize a chess game from a standard starting position or a given FEN (Forsyth-Edwards Notation) string, manage the game's progression by playing and undoing moves, and determine the game's terminal state, such as checkmate or draw conditions. The code also provides utility functions to retrieve various aspects of the game state, such as the current board, legal moves, and move history in UCI (Universal Chess Interface) format. +This C source code file implements a chess game engine, providing core functionalities for creating, managing, and interacting with a chess game state. The code is structured around a `chess` data structure, which encapsulates the state of a chess game, including the board configuration, move history, and game status. The file includes functions to initialize a chess game from a standard starting position or a given FEN (Forsyth-Edwards Notation) string, manage the game's progression by playing and undoing moves, and determine the game's terminal state, such as checkmate or draw conditions. The code also provides utility functions to retrieve various aspects of the game state, such as the current board, legal moves, and move history in UCI (Universal Chess Interface) format. -The file is part of a broader chess library, as indicated by the inclusion of headers like "chesslib/chess.h" and "chesslib/move.h". It defines a public API for interacting with the chess game, allowing external code to create and manipulate chess games through a well-defined interface. Key technical components include memory management for dynamic data structures, such as board and move lists, and logic for calculating game state properties, such as legal moves and draw conditions. The code is designed to be integrated into larger applications, providing a robust foundation for building chess-related software, such as game engines, analysis tools, or user interfaces. +The file is part of a larger chess library, as indicated by the inclusion of headers like "chesslib/chess.h" and "chesslib/move.h". It defines a public API for interacting with the chess game, allowing external code to create and manipulate chess games through a well-defined interface. Key technical components include memory management for dynamic data structures, such as board and move lists, and logic for calculating game state properties, such as legal moves and draw conditions. The code is designed to be integrated into a larger application or library, providing a robust foundation for building chess-related software, such as a chess-playing AI or a graphical user interface for playing chess. # Imports and Dependencies --- @@ -15,14 +22,12 @@ The file is part of a broader chess library, as indicated by the inclusion of he --- ### chessCreate The `chessCreate` function initializes a new chess game using the standard initial position in FEN notation. -- **Inputs**: - - None +- **Inputs**: None - **Control Flow**: - The function calls [`chessCreateFen`](#chessCreateFen) with `INITIAL_FEN` as the argument, which represents the standard starting position of a chess game. - The [`chessCreateFen`](#chessCreateFen) function allocates memory for a new `chess` structure and initializes it using the provided FEN string. - - If the initialization is successful, the new `chess` structure is returned; otherwise, the allocated memory is freed and `NULL` is returned. -- **Output**: - - A pointer to a newly created `chess` structure initialized to the standard starting position, or `NULL` if initialization fails. + - If initialization fails, the allocated memory is freed and `NULL` is returned; otherwise, the initialized `chess` structure is returned. +- **Output**: A pointer to a newly created `chess` structure initialized to the standard starting position, or `NULL` if initialization fails. - **Functions called**: - [`chessCreateFen`](#chessCreateFen) @@ -31,14 +36,13 @@ The `chessCreate` function initializes a new chess game using the standard initi ### chessCreateFen The `chessCreateFen` function allocates and initializes a new chess game state from a given FEN string. - **Inputs**: - - `fen`: A string representing the board position in Forsyth-Edwards Notation (FEN). + - `fen`: A string representing the board position in Forsyth-Edwards Notation (FEN) format, which describes the current state of a chess game. - **Control Flow**: - Allocate memory for a new `chess` structure. - - Call [`chessInitFenInPlace`](#chessInitFenInPlace) to initialize the `chess` structure with the given FEN string. - - If initialization fails (returns non-zero), free the allocated memory and return `NULL`. - - If initialization succeeds, return the pointer to the newly created `chess` structure. -- **Output**: - - Returns a pointer to a newly allocated and initialized `chess` structure, or `NULL` if initialization fails. + - Call [`chessInitFenInPlace`](#chessInitFenInPlace) to initialize the `chess` structure with the provided FEN string. + - If [`chessInitFenInPlace`](#chessInitFenInPlace) returns a non-zero value (indicating failure), free the allocated memory and return `NULL`. + - If initialization is successful, return the pointer to the newly created `chess` structure. +- **Output**: Returns a pointer to a newly allocated and initialized `chess` structure, or `NULL` if initialization fails. - **Functions called**: - [`chessInitFenInPlace`](#chessInitFenInPlace) @@ -49,34 +53,32 @@ The `chessInitInPlace` function initializes a given chess game structure to the - **Inputs**: - `c`: A pointer to a `chess` structure that will be initialized to the starting position. - **Control Flow**: - - The function calls [`chessInitFenInPlace`](#chessInitFenInPlace) with the provided `chess` structure pointer `c` and the constant `INITIAL_FEN` to set up the chess board to the initial game state. -- **Output**: - - This function does not return any value; it initializes the chess structure in place. + - The function calls [`chessInitFenInPlace`](#chessInitFenInPlace) with the chess structure `c` and the constant `INITIAL_FEN` to set up the initial board state. +- **Output**: This function does not return a value; it initializes the chess structure in place. - **Functions called**: - [`chessInitFenInPlace`](#chessInitFenInPlace) --- ### chessInitFenInPlace -The `chessInitFenInPlace` function initializes a chess game state from a given FEN string and sets up the necessary data structures for tracking the game's progress. +The `chessInitFenInPlace` function initializes a chess game state from a given FEN string and updates the chess structure with the initial board and move history. - **Inputs**: - `c`: A pointer to a `chess` structure that will be initialized. - `fen`: A constant character pointer representing the FEN (Forsyth-Edwards Notation) string used to set up the initial board state. - **Control Flow**: - - Create a new board from the provided FEN string using [`boardCreateFromFen`](board.c.driver.md#boardCreateFromFen) and assign it to `b`. - - Check if `b` is `NULL`, indicating an error in board creation, and return 1 if so. - - Initialize `c->boardHistory` with a new board list and add the created board `b` to this list. - - Initialize `c->moveHistory` with a new move list. - - Set `c->currentLegalMoves` to `NULL`, `c->repetitions` to 1, and `c->terminal` to `tsOngoing`. - - Call [`chessCalculateFields`](#chessCalculateFields) to compute the repetitions and terminal state of the game. + - Create a board from the given FEN string using [`boardCreateFromFen`](board.c.md#boardCreateFromFen) and check if the board creation was successful. + - If the board creation fails (returns NULL), return 1 to indicate an error. + - Initialize the `boardHistory` of the chess structure by creating a new board list and adding the created board to it. + - Initialize the `moveHistory` of the chess structure by creating a new move list. + - Set `currentLegalMoves` to NULL, `repetitions` to 1, and `terminal` to `tsOngoing` to represent the ongoing state of the game. + - Call [`chessCalculateFields`](#chessCalculateFields) to compute the repetitions and determine the terminal state of the game. - Return 0 to indicate successful initialization. -- **Output**: - - Returns 0 on successful initialization, or 1 if the board creation from the FEN string fails. +- **Output**: Returns a `uint8_t` value, 0 if the initialization is successful, or 1 if there is an error in creating the board from the FEN string. - **Functions called**: - - [`boardCreateFromFen`](board.c.driver.md#boardCreateFromFen) - - [`boardListCreate`](boardlist.c.driver.md#boardListCreate) - - [`boardListAdd`](boardlist.c.driver.md#boardListAdd) - - [`moveListCreate`](movelist.c.driver.md#moveListCreate) + - [`boardCreateFromFen`](board.c.md#boardCreateFromFen) + - [`boardListCreate`](boardlist.c.md#boardListCreate) + - [`boardListAdd`](boardlist.c.md#boardListAdd) + - [`moveListCreate`](movelist.c.md#moveListCreate) - [`chessCalculateFields`](#chessCalculateFields) @@ -84,30 +86,28 @@ The `chessInitFenInPlace` function initializes a chess game state from a given F ### chessFree The `chessFree` function deallocates memory associated with a chess game instance, including its board history, move history, and current legal moves. - **Inputs**: - - `c`: A pointer to a `chess` structure representing the chess game instance to be freed. + - `c`: A pointer to a `chess` structure that represents the chess game instance to be freed. - **Control Flow**: - - Call [`boardListFree`](boardlist.c.driver.md#boardListFree) to free the memory allocated for the board history of the chess game. - - Call [`moveListFree`](movelist.c.driver.md#moveListFree) to free the memory allocated for the move history of the chess game. - - Call [`moveListFree`](movelist.c.driver.md#moveListFree) again to free the memory allocated for the current legal moves of the chess game. + - Call [`boardListFree`](boardlist.c.md#boardListFree) to free the memory allocated for the board history of the chess game. + - Call [`moveListFree`](movelist.c.md#moveListFree) to free the memory allocated for the move history of the chess game. + - Call [`moveListFree`](movelist.c.md#moveListFree) again to free the memory allocated for the current legal moves of the chess game. - Call `free` to deallocate the memory for the `chess` structure itself. -- **Output**: - - This function does not return any value; it performs memory deallocation for the provided chess game instance. +- **Output**: This function does not return any value; it performs memory deallocation for the provided chess game instance. - **Functions called**: - - [`boardListFree`](boardlist.c.driver.md#boardListFree) - - [`moveListFree`](movelist.c.driver.md#moveListFree) + - [`boardListFree`](boardlist.c.md#boardListFree) + - [`moveListFree`](movelist.c.md#moveListFree) --- ### chessGetBoard -The function `chessGetBoard` retrieves the current board state from a chess game instance. +The `chessGetBoard` function retrieves the current board state from a chess game instance. - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of a chess game. - **Control Flow**: - Access the `boardHistory` field of the `chess` structure pointed to by `c`. - - Retrieve the `tail` node from the `boardHistory` linked list, which represents the most recent board state. - - Return the `board` field from the `tail` node, which is the current board state. -- **Output**: - - A pointer to a `board` structure representing the current state of the chess board. + - Navigate to the `tail` node of the `boardHistory` linked list. + - Return the `board` field from the `tail` node, which represents the current board state. +- **Output**: A pointer to a `board` structure representing the current state of the chess board. --- @@ -116,10 +116,8 @@ The function `chessGetLegalMoves` retrieves the list of currently legal moves fo - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - The function directly accesses the `currentLegalMoves` field of the `chess` structure pointed to by `c`. - - It returns the value of `currentLegalMoves`, which is a pointer to a `moveList` structure containing the legal moves. -- **Output**: - - A pointer to a `moveList` structure representing the current legal moves available in the chess game. + - The function directly returns the `currentLegalMoves` member of the `chess` structure pointed to by `c`. +- **Output**: A pointer to a `moveList` structure containing the legal moves available in the current game state. --- @@ -128,34 +126,30 @@ The function `chessGetTerminalState` retrieves the current terminal state of a c - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - The function accesses the `terminal` field of the `chess` structure pointed to by `c`. - - It returns the value of the `terminal` field, which represents the current terminal state of the game. -- **Output**: - - The function returns a `terminalState` value, indicating the current terminal state of the chess game, such as ongoing, checkmate, stalemate, or various draw conditions. + - The function directly returns the `terminal` field from the `chess` structure pointed to by `c`. +- **Output**: The function returns a `terminalState` value, which indicates the current terminal state of the chess game, such as ongoing, checkmate, stalemate, or various draw conditions. --- ### chessGetBoardHistory -The function `chessGetBoardHistory` retrieves the history of board states from a chess game instance. +The function `chessGetBoardHistory` retrieves the history of board states from a chess game object. - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of a chess game. - **Control Flow**: - - The function accesses the `boardHistory` member of the `chess` structure pointed to by `c`. + - The function directly accesses the `boardHistory` member of the `chess` structure pointed to by `c`. - It returns the `boardHistory`, which is a list of board states representing the history of the game. -- **Output**: - - A pointer to a `boardList` structure, which contains the history of board states for the chess game. +- **Output**: A pointer to a `boardList` structure, which contains the history of board states in the chess game. --- ### chessGetMoveHistory The function `chessGetMoveHistory` retrieves the move history of a chess game. - **Inputs**: - - `c`: A pointer to a `chess` structure representing the current state of the chess game. + - `c`: A pointer to a `chess` structure representing the current state of a chess game. - **Control Flow**: - - The function directly accesses the `moveHistory` member of the `chess` structure pointed to by `c`. + - The function accesses the `moveHistory` member of the `chess` structure pointed to by `c`. - It returns the `moveHistory`, which is a pointer to a `moveList` structure. -- **Output**: - - A pointer to a `moveList` structure that contains the history of moves made in the chess game. +- **Output**: A pointer to a `moveList` structure containing the history of moves made in the chess game. --- @@ -164,35 +158,33 @@ The function `chessGetRepetitions` retrieves the number of times the current boa - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - The function directly accesses the `repetitions` field of the `chess` structure pointed to by `c`. + - The function accesses the `repetitions` field of the `chess` structure pointed to by `c`. - It returns the value of the `repetitions` field. -- **Output**: - - The function returns an 8-bit unsigned integer (`uint8_t`) representing the number of repetitions of the current board position. +- **Output**: The function returns an 8-bit unsigned integer (`uint8_t`) representing the number of repetitions of the current board position. --- ### chessPlayMove -The `chessPlayMove` function attempts to play a given move in a chess game, updating the game state and history if the move is legal and the game is ongoing. +The `chessPlayMove` function attempts to play a given move in a chess game, updating the game state if the move is legal and the game is ongoing. - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - `m`: A `move` structure representing the move to be played. - **Control Flow**: - Check if the game is ongoing by verifying if `c->terminal` is `tsOngoing`; if not, return 1 indicating failure. - Initialize a `found` flag to 0 and iterate over the list of current legal moves. - - For each legal move, check if it matches the move `m` using [`moveEq`](move.c.driver.md#moveEq); if a match is found, set `found` to 1 and break the loop. + - For each move in the list, check if it matches the move `m` using [`moveEq`](move.c.md#moveEq); if a match is found, set `found` to 1 and break the loop. - If `found` is still 0 after the loop, return 1 indicating the move is not legal. - - If the move is legal, use [`boardPlayMove`](board.c.driver.md#boardPlayMove) to apply the move to the current board and obtain a new board state. + - If the move is legal, use [`boardPlayMove`](board.c.md#boardPlayMove) to apply the move to the current board and obtain a new board state. - Add the new board state to the board history and the move to the move history. - - Call [`chessCalculateFields`](#chessCalculateFields) to update the game state, including legal moves and terminal state. + - Recalculate the game fields using [`chessCalculateFields`](#chessCalculateFields) to update the game state. - Return 0 indicating the move was successfully played. -- **Output**: - - Returns 0 if the move was successfully played, or 1 if the move was illegal or the game is not ongoing. +- **Output**: Returns 0 if the move is successfully played, or 1 if the move is illegal or the game is not ongoing. - **Functions called**: - - [`moveEq`](move.c.driver.md#moveEq) - - [`boardPlayMove`](board.c.driver.md#boardPlayMove) + - [`moveEq`](move.c.md#moveEq) + - [`boardPlayMove`](board.c.md#boardPlayMove) - [`chessGetBoard`](#chessGetBoard) - - [`boardListAdd`](boardlist.c.driver.md#boardListAdd) - - [`moveListAdd`](movelist.c.driver.md#moveListAdd) + - [`boardListAdd`](boardlist.c.md#boardListAdd) + - [`moveListAdd`](movelist.c.md#moveListAdd) - [`chessCalculateFields`](#chessCalculateFields) @@ -203,32 +195,29 @@ The `chessUndo` function reverts the last move in a chess game, updating the gam - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - Check if there is only one board in the history (indicating no moves have been made); if so, return failure (1). - - If the game is in a terminal state due to a draw claim (threefold repetition or 50-move rule), reset the terminal state to ongoing. - - Otherwise, undo the last board and move in their respective histories. + - Check if the game is in a terminal state due to a draw claim (threefold repetition or 50-move rule); if so, reset the terminal state to ongoing. + - If the game is not in a terminal draw state, undo the last board and move from their respective histories. - Recalculate the game fields to update the current state of the game. - - Return success (0) after successfully undoing the move. -- **Output**: - - Returns 0 on success (move undone) or 1 on failure (no moves to undo). +- **Output**: Returns 0 on successful undo of the last move, or 1 if undoing is not possible (e.g., no moves to undo). - **Functions called**: - - [`boardListUndo`](boardlist.c.driver.md#boardListUndo) - - [`moveListUndo`](movelist.c.driver.md#moveListUndo) + - [`boardListUndo`](boardlist.c.md#boardListUndo) + - [`moveListUndo`](movelist.c.md#moveListUndo) - [`chessCalculateFields`](#chessCalculateFields) --- ### chessGetPiece -The `chessGetPiece` function retrieves the chess piece located at a specific square on the board of a given chess game state. +The function `chessGetPiece` retrieves the chess piece located at a specific square on the board of a given chess game state. - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - `s`: A `sq` type representing the specific square on the chess board from which to retrieve the piece. - **Control Flow**: - The function calls [`chessGetBoard`](#chessGetBoard) with the chess game state `c` to obtain the current board. - - It then calls [`boardGetPiece`](board.c.driver.md#boardGetPiece) with the obtained board and the square `s` to retrieve the piece at that square. + - It then calls [`boardGetPiece`](board.c.md#boardGetPiece) with the obtained board and the square `s` to retrieve the piece located at that square. - The retrieved piece is returned as the output of the function. -- **Output**: - - The function returns a `piece` type, which represents the chess piece located at the specified square on the board. +- **Output**: The function returns a `piece` type, which represents the chess piece located at the specified square on the board. - **Functions called**: - - [`boardGetPiece`](board.c.driver.md#boardGetPiece) + - [`boardGetPiece`](board.c.md#boardGetPiece) - [`chessGetBoard`](#chessGetBoard) @@ -239,24 +228,21 @@ The function `chessGetPlayer` retrieves the current player's color from a chess - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - The function calls [`chessGetBoard`](#chessGetBoard) with the chess game state `c` to obtain the current board. - - It accesses the `currentPlayer` field of the board structure to get the current player's color. - - The function returns the value of `currentPlayer`. -- **Output**: - - The function returns a `pieceColor` value indicating the color of the current player (either white or black). + - It then accesses the `currentPlayer` field of the board to determine which player's turn it is. +- **Output**: The function returns a `pieceColor` value indicating the color of the current player (either white or black). - **Functions called**: - [`chessGetBoard`](#chessGetBoard) --- ### chessGetCastleState -The function `chessGetCastleState` retrieves the current castling rights state from a chess game structure. +The function `chessGetCastleState` retrieves the castling state from the current board of a chess game. - **Inputs**: - - `c`: A pointer to a `chess` structure representing the current state of a chess game. + - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - The function calls [`chessGetBoard`](#chessGetBoard) with the chess structure `c` to obtain the current board state. + - The function calls [`chessGetBoard`](#chessGetBoard) with the chess game pointer `c` to obtain the current board. - It accesses the `castleState` field of the board structure and returns it. -- **Output**: - - The function returns an 8-bit unsigned integer representing the castling rights state of the current board. +- **Output**: The function returns an 8-bit unsigned integer representing the castling state of the current board. - **Functions called**: - [`chessGetBoard`](#chessGetBoard) @@ -267,24 +253,22 @@ The function `chessGetEpTarget` retrieves the en passant target square from the - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of a chess game. - **Control Flow**: - - The function calls [`chessGetBoard`](#chessGetBoard) with the chess game pointer `c` to obtain the current board state. - - It then accesses the `epTarget` field of the board structure and returns it. -- **Output**: - - The function returns a value of type `sq`, which represents the en passant target square on the chess board. + - Call the function [`chessGetBoard`](#chessGetBoard) with the chess game pointer `c` to obtain the current board. + - Access the `epTarget` field of the board structure and return its value. +- **Output**: The function returns a value of type `sq`, which represents the en passant target square on the chess board. - **Functions called**: - [`chessGetBoard`](#chessGetBoard) --- ### chessGetHalfMoveClock -The function `chessGetHalfMoveClock` retrieves the half-move clock value from the current board state of a chess game. +The function `chessGetHalfMoveClock` retrieves the half-move clock from the current board state in a chess game. - **Inputs**: - - `c`: A pointer to a `chess` structure representing the current state of a chess game. + - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - The function calls [`chessGetBoard`](#chessGetBoard) with the chess game pointer `c` to obtain the current board state. + - The function calls [`chessGetBoard`](#chessGetBoard) with the chess game pointer `c` to obtain the current board. - It accesses the `halfMoveClock` field from the board structure and returns its value. -- **Output**: - - The function returns an unsigned integer representing the half-move clock, which counts the number of half-moves since the last capture or pawn advance. +- **Output**: An unsigned integer representing the half-move clock of the current board state. - **Functions called**: - [`chessGetBoard`](#chessGetBoard) @@ -295,10 +279,9 @@ The function `chessGetMoveNumber` retrieves the current move number from a chess - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of a chess game. - **Control Flow**: - - The function calls [`chessGetBoard`](#chessGetBoard) with the chess game state `c` to obtain the current board. - - It accesses the `moveNumber` field from the board structure and returns it. -- **Output**: - - The function returns an unsigned integer representing the current move number in the chess game. + - Call the function [`chessGetBoard`](#chessGetBoard) with the chess game state `c` to get the current board. + - Access the `moveNumber` field of the board structure and return its value. +- **Output**: The function returns an unsigned integer representing the current move number in the chess game. - **Functions called**: - [`chessGetBoard`](#chessGetBoard) @@ -309,13 +292,12 @@ The function `chessGetMoveHistoryUci` retrieves the move history of a chess game - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - The function calls [`chessGetMoveHistory`](#chessGetMoveHistory) with the chess game pointer `c` to obtain the move history as a `moveList`. - - It then calls [`moveListGetUciString`](movelist.c.driver.md#moveListGetUciString) with the retrieved move history to convert it into a UCI string format. - - Finally, it returns the UCI string representing the move history. -- **Output**: - - A string representing the move history of the chess game in UCI format. + - Call the function [`chessGetMoveHistory`](#chessGetMoveHistory) with the chess game pointer `c` to obtain the move history as a `moveList`. + - Pass the obtained `moveList` to the function [`moveListGetUciString`](movelist.c.md#moveListGetUciString) to convert the move history into a UCI formatted string. + - Return the UCI formatted string. +- **Output**: A string representing the move history of the chess game in UCI format. - **Functions called**: - - [`moveListGetUciString`](movelist.c.driver.md#moveListGetUciString) + - [`moveListGetUciString`](movelist.c.md#moveListGetUciString) - [`chessGetMoveHistory`](#chessGetMoveHistory) @@ -325,13 +307,11 @@ The `chessIsInCheck` function checks if the current player's king is in check on - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - The function calls [`chessGetBoard`](#chessGetBoard) with the `chess` pointer `c` to retrieve the current board state. - - It then calls [`boardIsInCheck`](board.c.driver.md#boardIsInCheck) with the retrieved board to determine if the current player's king is in check. - - The result from [`boardIsInCheck`](board.c.driver.md#boardIsInCheck) is returned as the output of the function. -- **Output**: - - Returns a `uint8_t` value indicating whether the current player's king is in check (non-zero if in check, zero otherwise). + - The function retrieves the current board from the chess game using `chessGetBoard(c)`. + - It then calls [`boardIsInCheck`](board.c.md#boardIsInCheck) with the retrieved board to determine if the king is in check. +- **Output**: Returns a `uint8_t` value, where a non-zero value indicates the king is in check, and zero indicates it is not. - **Functions called**: - - [`boardIsInCheck`](board.c.driver.md#boardIsInCheck) + - [`boardIsInCheck`](board.c.md#boardIsInCheck) - [`chessGetBoard`](#chessGetBoard) @@ -340,30 +320,28 @@ The `chessIsInCheck` function checks if the current player's king is in check on The function `chessIsSquareAttacked` checks if a specific square on the chessboard is attacked by the opponent's pieces. - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - - `s`: A square (`sq` type) on the chessboard to check if it is attacked. + - `s`: A square (`sq`) on the chessboard to be checked for being attacked. - **Control Flow**: - - Retrieve the current board from the chess game structure `c` using [`chessGetBoard`](#chessGetBoard) function. - - Determine the opponent's color based on the current player stored in the board structure. - - Call [`boardIsSquareAttacked`](board.c.driver.md#boardIsSquareAttacked) with the board, the square `s`, and the opponent's color to check if the square is attacked. -- **Output**: - - Returns a `uint8_t` value indicating whether the square is attacked (non-zero) or not (zero). + - Retrieve the current board from the chess game structure using [`chessGetBoard`](#chessGetBoard) function. + - Determine the opponent's color based on the current player stored in the board. + - Call [`boardIsSquareAttacked`](board.c.md#boardIsSquareAttacked) with the board, the square `s`, and the opponent's color to check if the square is attacked. +- **Output**: Returns a `uint8_t` value indicating whether the square is attacked (non-zero) or not (zero). - **Functions called**: - [`chessGetBoard`](#chessGetBoard) - - [`boardIsSquareAttacked`](board.c.driver.md#boardIsSquareAttacked) + - [`boardIsSquareAttacked`](board.c.md#boardIsSquareAttacked) --- ### chessGetFen -The `chessGetFen` function retrieves the FEN (Forsyth-Edwards Notation) string representation of the current board state in a chess game. +The function `chessGetFen` retrieves the FEN (Forsyth-Edwards Notation) string representation of the current board state in a chess game. - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - The function calls [`chessGetBoard`](#chessGetBoard) with the `chess` pointer `c` to obtain the current board from the chess game. - - It then calls [`boardGetFen`](board.c.driver.md#boardGetFen) with the retrieved board to get the FEN string representation of the board. -- **Output**: - - A string representing the FEN notation of the current board state. + - It then calls [`boardGetFen`](board.c.md#boardGetFen) with the retrieved board to get the FEN string representation of the board. +- **Output**: A pointer to a character string containing the FEN representation of the current board state. - **Functions called**: - - [`boardGetFen`](board.c.driver.md#boardGetFen) + - [`boardGetFen`](board.c.md#boardGetFen) - [`chessGetBoard`](#chessGetBoard) @@ -373,11 +351,10 @@ The function `chessCanClaimDraw50` checks if a chess game can claim a draw based - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - Check if the game's terminal state is `tsOngoing`, indicating the game is still in progress. - - Retrieve the current board from the chess game structure using `chessGetBoard(c)`. - - Check if the `halfMoveClock` of the current board is greater than or equal to 100, which corresponds to 50 moves without a pawn move or capture. -- **Output**: - - Returns a `uint8_t` value (1 or 0) indicating whether a draw can be claimed based on the 50-move rule. + - Check if the game's terminal state is ongoing (`tsOngoing`). + - Retrieve the current board from the chess game structure. + - Check if the `halfMoveClock` of the board is greater than or equal to 100. +- **Output**: Returns a `uint8_t` value (1 or 0) indicating whether a draw can be claimed based on the 50-move rule. - **Functions called**: - [`chessGetBoard`](#chessGetBoard) @@ -389,9 +366,8 @@ The function `chessCanClaimDrawThreefold` checks if a chess game can claim a dra - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - The function checks if the game's terminal state is `tsOngoing`, indicating the game is still in progress. - - It then checks if the number of repetitions of the current board position is 3 or more. -- **Output**: - - Returns a `uint8_t` value that is non-zero (true) if the game can claim a draw due to threefold repetition, otherwise zero (false). + - It then checks if the number of repetitions of the current board state is 3 or more. +- **Output**: Returns a `uint8_t` value that is non-zero (true) if the game can claim a draw due to threefold repetition, otherwise zero (false). --- @@ -402,8 +378,7 @@ The function `chessClaimDraw50` sets the terminal state of a chess game to a dra - **Control Flow**: - The function checks if a draw can be claimed due to the 50-move rule by calling [`chessCanClaimDraw50`](#chessCanClaimDraw50) with the chess game state `c`. - If [`chessCanClaimDraw50`](#chessCanClaimDraw50) returns true, the function sets the `terminal` field of the chess game state `c` to `tsDrawClaimed50MoveRule`. -- **Output**: - - The function does not return a value; it modifies the `terminal` field of the `chess` structure if the draw condition is met. +- **Output**: The function does not return a value; it modifies the `terminal` field of the `chess` structure if the draw condition is met. - **Functions called**: - [`chessCanClaimDraw50`](#chessCanClaimDraw50) @@ -415,35 +390,36 @@ The function `chessClaimDrawThreefold` sets the terminal state of a chess game t - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - The function checks if a draw can be claimed due to threefold repetition by calling [`chessCanClaimDrawThreefold`](#chessCanClaimDrawThreefold) with the chess game state `c`. - - If the condition is true, it sets the `terminal` field of the chess game state `c` to `tsDrawClaimedThreefold`. -- **Output**: - - The function does not return a value; it modifies the `terminal` field of the `chess` structure if the draw condition is met. + - If the function [`chessCanClaimDrawThreefold`](#chessCanClaimDrawThreefold) returns true, the terminal state of the chess game is set to `tsDrawClaimedThreefold`. +- **Output**: The function does not return a value; it modifies the terminal state of the chess game if the draw condition is met. - **Functions called**: - [`chessCanClaimDrawThreefold`](#chessCanClaimDrawThreefold) --- ### chessCalculateFields -The `chessCalculateFields` function updates the state of a chess game by recalculating the number of board repetitions, generating legal moves, and determining the terminal state of the game. +The `chessCalculateFields` function updates the chess game's state by recalculating the number of board repetitions, generating legal moves, and determining the terminal state of the game. - **Inputs**: - `c`: A pointer to a `chess` structure representing the current state of the chess game. - **Control Flow**: - - Retrieve the current board from the chess game structure `c`. + - Retrieve the current board from the chess game structure. - Initialize the repetition count to zero. - - Iterate over the board history to count how many times the current board state has occurred. + - Iterate over the board history to count how many times the current board state has been repeated. - Free the current list of legal moves if it exists. - - Generate a new list of legal moves for the current board state and assign it to `c->currentLegalMoves`. + - Generate a new list of legal moves for the current board state. - Check if there are no legal moves available; if so, determine if the game is in checkmate or stalemate and set the terminal state accordingly. - - If there are legal moves, check for draw conditions such as fivefold repetition, 75-move rule, or insufficient material, and update the terminal state accordingly. - - If none of the draw conditions are met and the terminal state is not a claimed draw, set the terminal state to ongoing. -- **Output**: - - The function does not return a value but updates the `repetitions`, `currentLegalMoves`, and `terminal` fields of the `chess` structure `c`. + - If there are legal moves, check for various draw conditions such as fivefold repetition, 75-move rule, and insufficient material, updating the terminal state as needed. + - If none of the draw conditions are met and the game is not claimed as a draw, set the terminal state to ongoing. +- **Output**: The function does not return a value but updates the `chess` structure's `repetitions`, `currentLegalMoves`, and `terminal` fields. - **Functions called**: - [`chessGetBoard`](#chessGetBoard) - - [`boardEqContext`](board.c.driver.md#boardEqContext) - - [`moveListFree`](movelist.c.driver.md#moveListFree) - - [`boardGenerateMoves`](board.c.driver.md#boardGenerateMoves) - - [`boardIsInCheck`](board.c.driver.md#boardIsInCheck) - - [`boardIsInsufficientMaterial`](board.c.driver.md#boardIsInsufficientMaterial) + - [`boardEqContext`](board.c.md#boardEqContext) + - [`moveListFree`](movelist.c.md#moveListFree) + - [`boardGenerateMoves`](board.c.md#boardGenerateMoves) + - [`boardIsInCheck`](board.c.md#boardIsInCheck) + - [`boardIsInsufficientMaterial`](board.c.md#boardIsInsufficientMaterial) + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/chesslib/move.c.md b/driver_docs/c_cpp_export_test/src/chesslib/move.c.md new file mode 100644 index 0000000..b5c1743 --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/chesslib/move.c.md @@ -0,0 +1,106 @@ + + + + + +The `move.c` file in the `c_cpp_export_test` codebase implements functions for handling chess moves, including creating moves, comparing them, and converting between moves and UCI strings. + +# Purpose +This C source code file is part of a chess-related software library, specifically handling the representation and manipulation of chess moves. The file provides functions to create, compare, and convert chess moves to and from the Universal Chess Interface (UCI) format. The primary functions include [`moveSq`](#moveSq), which creates a move without promotion, and [`movePromote`](#movePromote), which allows for the specification of a promotion piece type. The [`moveEq`](#moveEq) function checks for equality between two moves, while [`moveGetUci`](#moveGetUci) and [`moveFromUci`](#moveFromUci) handle the conversion of moves to and from UCI strings, respectively. The code is designed to be part of a larger chess library, as indicated by the inclusion of "chesslib/move.h", and it does not define a standalone executable but rather provides utility functions for use in other parts of the chess software. + +The file's functionality is narrowly focused on the manipulation of chess moves, with a common theme of facilitating the conversion between internal move representations and the UCI format, which is a standard for communicating chess moves in software. The code includes memory allocation for UCI strings and assumes the presence of other functions and types, such as `sqEq`, `sqGetStr`, and `pieceTypeGetLetter`, which are likely defined elsewhere in the chess library. The lack of error checking in [`moveFromUci`](#moveFromUci) suggests that this function assumes valid input, which is typical in lower-level utility functions where performance is prioritized over robustness. Overall, this file is a specialized component of a chess software library, providing essential move-related operations. +# Imports and Dependencies + +--- +- `stdio.h` +- `stdlib.h` +- `ctype.h` +- `chesslib/move.h` + + +# Functions + +--- +### moveSq +The `moveSq` function creates a move from one square to another without any promotion in a chess game. +- **Inputs**: + - `from`: The starting square of the move. + - `to`: The destination square of the move. +- **Control Flow**: + - The function calls [`movePromote`](#movePromote) with the `from` and `to` squares and `ptEmpty` as the promotion type. + - The [`movePromote`](#movePromote) function constructs a `move` structure with the given squares and promotion type. + - The constructed `move` is returned. +- **Output**: A `move` structure representing a move from the `from` square to the `to` square with no promotion. +- **Functions called**: + - [`movePromote`](#movePromote) + + +--- +### movePromote +The `movePromote` function creates and returns a `move` structure initialized with the given starting square, destination square, and promotion piece type. +- **Inputs**: + - `from`: The starting square of the move, represented by the type `sq`. + - `to`: The destination square of the move, represented by the type `sq`. + - `promotion`: The type of piece to promote to, represented by the type `pieceType`. +- **Control Flow**: + - A `move` structure `m` is declared. + - The `from` field of `m` is set to the input `from`. + - The `to` field of `m` is set to the input `to`. + - The `promotion` field of `m` is set to the input `promotion`. + - The function returns the `move` structure `m`. +- **Output**: A `move` structure initialized with the specified `from`, `to`, and `promotion` values. + + +--- +### moveEq +The `moveEq` function checks if two chess moves are equivalent by comparing their starting and ending squares and promotion type. +- **Inputs**: + - `m1`: The first move to compare, represented as a `move` structure. + - `m2`: The second move to compare, represented as a `move` structure. +- **Control Flow**: + - The function calls [`sqEq`](square.c.md#sqEq) to compare the `from` squares of `m1` and `m2`. + - It then calls [`sqEq`](square.c.md#sqEq) to compare the `to` squares of `m1` and `m2`. + - Finally, it checks if the `promotion` fields of `m1` and `m2` are equal. + - The function returns the logical AND of these three comparisons. +- **Output**: A `uint8_t` value that is non-zero (true) if the moves are equivalent, and zero (false) otherwise. +- **Functions called**: + - [`sqEq`](square.c.md#sqEq) + + +--- +### moveGetUci +The `moveGetUci` function generates a UCI (Universal Chess Interface) string representation of a given chess move, including promotion if applicable. +- **Inputs**: + - `m`: A `move` structure containing the source square, destination square, and optional promotion piece type. +- **Control Flow**: + - Initialize a character array `p` to store the promotion piece letter, if any. + - Check if the move includes a promotion; if so, convert the promotion piece type to a lowercase letter and store it in `p[0]`, then allocate memory for a 6-character string. + - If there is no promotion, allocate memory for a 5-character string. + - Use `sprintf` to format the move's source square, destination square, and promotion piece (if any) into the allocated string. + - Return the formatted UCI string. +- **Output**: A dynamically allocated string representing the UCI format of the move, which must be freed by the caller. +- **Functions called**: + - [`pieceTypeGetLetter`](piece.c.md#pieceTypeGetLetter) + - [`sqGetStr`](square.c.md#sqGetStr) + + +--- +### moveFromUci +The `moveFromUci` function converts a UCI (Universal Chess Interface) string into a `move` structure, representing a chess move with optional promotion. +- **Inputs**: + - `uci`: A string representing a chess move in UCI format, typically consisting of four characters for the starting and ending squares, and optionally a fifth character for promotion. +- **Control Flow**: + - Extracts the first two characters from the `uci` string to form the `from` square and the next two characters to form the `to` square. + - Initializes a `promotion` variable of type `pieceType` to determine if the move includes a promotion. + - Uses a `switch` statement to check the fifth character of the `uci` string to set the `promotion` type, defaulting to `ptEmpty` if no valid promotion character is found. + - Creates a `move` structure `m`, setting its `from` and `to` fields using the [`sqS`](square.c.md#sqS) function to convert the `from` and `to` strings into square representations. + - Sets the `promotion` field of the `move` structure `m` to the determined `promotion` type. + - Returns the constructed `move` structure `m`. +- **Output**: A `move` structure representing the chess move described by the UCI string, including the starting and ending squares and any promotion. +- **Functions called**: + - [`sqS`](square.c.md#sqS) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/src/chesslib/movelist.c.driver.md b/driver_docs/c_cpp_export_test/src/chesslib/movelist.c.md similarity index 53% rename from driver_docs/src/chesslib/movelist.c.driver.md rename to driver_docs/c_cpp_export_test/src/chesslib/movelist.c.md index f428e79..f37852c 100644 --- a/driver_docs/src/chesslib/movelist.c.driver.md +++ b/driver_docs/c_cpp_export_test/src/chesslib/movelist.c.md @@ -1,7 +1,14 @@ + + + + + +The `movelist.c` file implements a linked list structure for managing chess moves, including functions for creating, adding, retrieving, undoing moves, and generating a UCI string representation of the move list. + # Purpose -This C source code file implements a linked list data structure specifically designed to manage a list of moves, likely for a chess game, as suggested by the inclusion of "chesslib/movelist.h". The primary components of this implementation include functions for creating and managing a `moveList`, which is a singly linked list where each node represents a move. Key functions include [`moveListCreate`](#moveListCreate) for initializing a new list, [`moveListNodeCreate`](#moveListNodeCreate) for creating a new node, [`moveListAdd`](#moveListAdd) for appending a move to the list, [`moveListGet`](#moveListGet) for retrieving a move by its index, and [`moveListUndo`](#moveListUndo) for removing the last move from the list. Additionally, the [`moveListGetUciString`](#moveListGetUciString) function generates a UCI (Universal Chess Interface) formatted string from the list of moves, which is a common format used in chess engines for move representation. +This C source code file implements a linked list data structure specifically designed to manage a list of moves, likely for a chess application, as suggested by the inclusion of "chesslib/movelist.h". The primary functionality provided by this code is the creation, manipulation, and management of a move list, which includes operations such as adding moves, retrieving moves by index, undoing the last move, and converting the list of moves into a UCI (Universal Chess Interface) string format. The code defines several key functions: [`moveListCreate`](#moveListCreate) initializes a new move list, [`moveListNodeCreate`](#moveListNodeCreate) creates a new node for a move, [`moveListAdd`](#moveListAdd) appends a move to the list, [`moveListGet`](#moveListGet) retrieves a move at a specified index, [`moveListUndo`](#moveListUndo) removes the last move, [`moveListGetUciString`](#moveListGetUciString) generates a UCI string representation of the move list, and [`moveListFree`](#moveListFree) deallocates the memory used by the move list. -The code is structured to provide a narrow functionality focused on managing a sequence of moves, with a clear emphasis on operations typical for a linked list, such as adding, retrieving, and removing elements. The implementation is not a standalone executable but rather a component intended to be part of a larger system, likely a chess engine or application, as indicated by its reliance on external definitions such as `move` and `moveGetUci`. The file does not define public APIs or external interfaces directly but provides essential internal functionality that can be utilized by other parts of the chess application through the `movelist.h` header. The code also includes memory management functions like [`moveListFree`](#moveListFree) to ensure proper deallocation of resources, highlighting the importance of efficient memory handling in C programming. +The code is structured to be part of a larger chess library, as indicated by the inclusion of a header file from "chesslib". It does not define a main function, suggesting that it is intended to be compiled as part of a library rather than an executable. The move list is implemented as a singly linked list, with each node containing a move and a pointer to the next node. The code handles memory allocation and deallocation explicitly, which is crucial in C to prevent memory leaks. The [`moveListGetUciString`](#moveListGetUciString) function is particularly noteworthy as it converts the list of moves into a format that can be used by chess engines and interfaces that support the UCI protocol, highlighting the code's role in facilitating communication between different components of a chess application. # Imports and Dependencies --- @@ -15,16 +22,14 @@ The code is structured to provide a narrow functionality focused on managing a s --- ### moveListCreate The `moveListCreate` function allocates and initializes a new `moveList` structure with default values. -- **Inputs**: - - None +- **Inputs**: None - **Control Flow**: - Allocate memory for a new `moveList` structure using `malloc`. - Initialize the `head` pointer of the list to `NULL`, indicating an empty list. - Initialize the `tail` pointer of the list to `NULL`, indicating an empty list. - - Set the `size` of the list to `0`, indicating that the list is currently empty. + - Set the `size` of the list to `0`, indicating that the list is empty. - Return the pointer to the newly created `moveList` structure. -- **Output**: - - A pointer to a newly allocated and initialized `moveList` structure. +- **Output**: A pointer to a newly allocated and initialized `moveList` structure. --- @@ -33,12 +38,11 @@ The function `moveListNodeCreate` allocates memory for a new `moveListNode`, ini - **Inputs**: - `move`: A `move` structure that contains the data to be stored in the new node. - **Control Flow**: - - Allocate memory for a new `moveListNode` using `malloc`. + - Allocate memory for a new `moveListNode` structure. - Assign the provided `move` to the `move` field of the newly created node. - - Set the `next` pointer of the node to `NULL` to indicate it is the last node in the list. + - Set the `next` pointer of the node to `NULL`, indicating it is the last node in the list. - Return the pointer to the newly created node. -- **Output**: - - A pointer to the newly created `moveListNode` containing the specified move and a `NULL` next pointer. +- **Output**: A pointer to the newly created `moveListNode` structure. --- @@ -51,10 +55,9 @@ The `moveListAdd` function appends a new move to the end of a move list, updatin - Create a new `moveListNode` using the provided `move` by calling [`moveListNodeCreate`](#moveListNodeCreate). - Check if the `head` of the list is `NULL`, indicating the list is empty. - If the list is empty, set both the `head` and `tail` of the list to the newly created node. - - If the list is not empty, set the `next` pointer of the current `tail` node to the new node and update the `tail` to the new node. + - If the list is not empty, set the `next` pointer of the current `tail` to the new node and update the `tail` to this new node. - Increment the `size` of the list by one. -- **Output**: - - The function does not return a value; it modifies the `moveList` structure in place by adding a new node to it. +- **Output**: The function does not return a value; it modifies the `moveList` structure in place. - **Functions called**: - [`moveListNodeCreate`](#moveListNodeCreate) @@ -69,23 +72,21 @@ The `moveListGet` function retrieves a move from a linked list of moves at a spe - Initialize `currNode` to the head of the list. - Iterate through the list, moving to the next node and decrementing `index` until `index` is zero. - Return the move stored in the current node. -- **Output**: - - The function returns the `move` located at the specified index in the `moveList`. +- **Output**: The function returns a `move` from the specified index in the `moveList`. --- ### moveListUndo -The `moveListUndo` function removes the last move from a singly linked list of moves, updating the list's head, tail, and size accordingly. +The `moveListUndo` function removes the last move from a singly linked list of moves, effectively undoing the most recent move. - **Inputs**: - `list`: A pointer to a `moveList` structure, which represents a singly linked list of moves. - **Control Flow**: - Check if the list is NULL or if the list's head is NULL; if so, return immediately as there is nothing to undo. - - If the list contains only one node, free the head node and set both the head and tail pointers to NULL. - - If the list contains more than one node, traverse the list to find the second-to-last node. - - Free the last node, update the second-to-last node's next pointer to NULL, and set the list's tail to the second-to-last node. - - Decrement the list's size by one. -- **Output**: - - The function does not return a value; it modifies the input `moveList` in place by removing the last node and updating the list's metadata. + - Check if the list contains only one node (i.e., `list->head->next` is NULL); if true, free the head node and set both the head and tail pointers to NULL. + - If the list contains more than one node, iterate through the list to find the last node and its predecessor. + - Free the last node, set the predecessor's `next` pointer to NULL, and update the list's tail pointer to the predecessor node. + - Decrement the size of the list by one. +- **Output**: The function does not return a value; it modifies the `moveList` structure in place by removing the last node and updating the list's size. --- @@ -96,15 +97,14 @@ The function `moveListGetUciString` generates a UCI (Universal Chess Interface) - **Control Flow**: - Check if the move list is empty; if so, allocate a single character for the string, set it to null, and return it. - If the move list contains only one move, convert that move to a UCI string and return it. - - Calculate the required size for the UCI string, considering 4 characters per move, a space between moves, and additional space for promotion characters. + - Calculate the required size for the UCI string, accounting for each move's characters, spaces, and any promotion characters. - Allocate memory for the UCI string based on the calculated size. - Iterate over each move in the list, convert it to a UCI string, append it to the result string, and add a space after each move. - Replace the last space with a null terminator to properly end the string. - Return the constructed UCI string. -- **Output**: - - A dynamically allocated string containing the UCI representation of the moves in the list, which must be freed by the caller. +- **Output**: A dynamically allocated string containing the UCI representation of the moves in the list, which must be freed by the caller. - **Functions called**: - - [`moveGetUci`](move.c.driver.md#moveGetUci) + - [`moveGetUci`](move.c.md#moveGetUci) --- @@ -119,7 +119,9 @@ The `moveListFree` function deallocates all memory associated with a `moveList` - Free the current node. - Move to the next node by setting `node` to `next`. - After the loop, free the `moveList` structure itself. -- **Output**: - - The function does not return any value; it performs memory deallocation for the provided `moveList` and its nodes. +- **Output**: The function does not return any value; it frees the memory occupied by the `moveList` and its nodes. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/src/chesslib/piece.c.driver.md b/driver_docs/c_cpp_export_test/src/chesslib/piece.c.md similarity index 54% rename from driver_docs/src/chesslib/piece.c.driver.md rename to driver_docs/c_cpp_export_test/src/chesslib/piece.c.md index 9bcb709..3d91ea9 100644 --- a/driver_docs/src/chesslib/piece.c.driver.md +++ b/driver_docs/c_cpp_export_test/src/chesslib/piece.c.md @@ -1,7 +1,14 @@ + + + + + +The `piece.c` file in the `c_cpp_export_test` codebase implements functions for handling chess pieces, including determining their type, color, and corresponding letter representation. + # Purpose This C source code file provides functionality for handling chess pieces within a chess library. It defines several functions that operate on a custom data type, `piece`, which likely represents a chess piece with both type and color attributes. The file includes functions to determine the type and color of a piece ([`pieceGetType`](#pieceGetType) and [`pieceGetColor`](#pieceGetColor)), convert a piece type to its corresponding letter representation ([`pieceTypeGetLetter`](#pieceTypeGetLetter)), and obtain the letter representation of a piece considering its color ([`pieceGetLetter`](#pieceGetLetter)). Additionally, it includes a function to create a piece given its type and color ([`pieceMake`](#pieceMake)). The code is structured to handle both white and black pieces, and it uses enumerations or constants such as `pWPawn`, `pBPawn`, `ptPawn`, `pcWhite`, and `pcBlack` to represent different piece types and colors. -The file is part of a broader chess library, as indicated by the inclusion of "chesslib/piece.h", suggesting that it is intended to be used as a component within a larger chess application. The functions defined here provide a narrow but essential functionality focused on the representation and manipulation of chess pieces, which is a fundamental aspect of any chess-related software. The code does not define public APIs or external interfaces directly but rather implements the logic that would be used by other parts of the chess library or application to manage chess pieces effectively. +The file is part of a broader chess library, as indicated by the inclusion of "chesslib/piece.h", suggesting that it is intended to be used as a component within a larger chess application. The functions defined here provide a narrow but essential set of operations for managing chess pieces, focusing on their identification and representation. The code does not define a public API or external interfaces directly but rather implements internal logic that can be utilized by other parts of the chess library or application. The presence of a TODO comment suggests that the handling of empty piece types may need further consideration, indicating ongoing development or refinement. # Imports and Dependencies --- @@ -20,30 +27,28 @@ The function `pieceGetType` determines the type of a chess piece from its encode - Check if the piece `p` is greater than or equal to `pBPawn`, indicating it is a black piece. - If true, adjust `p` by subtracting `pBPawn` and adding 1 to normalize it to a type value. - Cast the adjusted or original `p` to `pieceType` and return it. -- **Output**: - - The function returns a `pieceType`, which is an enumeration representing the type of the chess piece (e.g., pawn, knight, bishop, etc.). +- **Output**: The function returns a `pieceType`, which is an enumeration representing the type of the chess piece (e.g., pawn, knight, bishop, etc.). --- ### pieceGetColor The function `pieceGetColor` determines the color of a chess piece based on its enumeration value. - **Inputs**: - - `p`: An enumeration value representing a chess piece, which can be a white or black piece, or an invalid piece. + - `p`: An enumeration value representing a chess piece, which can be a white or black piece, or an empty piece. - **Control Flow**: - Check if the piece `p` is within the range of white pieces (`pWPawn` to `pWKing`); if true, return `pcWhite`. - Check if the piece `p` is within the range of black pieces (`pBPawn` to `pBKing`); if true, return `pcBlack`. - - If neither condition is met, return `pcNoColor` indicating the piece has no valid color. -- **Output**: - - The function returns a `pieceColor` enumeration value, which can be `pcWhite`, `pcBlack`, or `pcNoColor`. + - If neither condition is met, return `pcNoColor` indicating the piece has no color. +- **Output**: The function returns a `pieceColor` enumeration value, which can be `pcWhite`, `pcBlack`, or `pcNoColor`, indicating the color of the piece. --- ### pieceTypeGetLetter The function `pieceTypeGetLetter` returns the corresponding character representation of a chess piece type. - **Inputs**: - - `pe`: A `pieceType` enumeration value representing the type of a chess piece. + - `pe`: An enumeration value of type `pieceType` representing a chess piece type. - **Control Flow**: - - The function uses a switch statement to determine the character representation based on the `pieceType` value `pe`. + - The function uses a switch statement to determine the character representation based on the input `pieceType` value. - If `pe` is `ptPawn`, it returns 'P'. - If `pe` is `ptKnight`, it returns 'N'. - If `pe` is `ptBishop`, it returns 'B'. @@ -51,24 +56,22 @@ The function `pieceTypeGetLetter` returns the corresponding character representa - If `pe` is `ptQueen`, it returns 'Q'. - If `pe` is `ptKing`, it returns 'K'. - If `pe` is `ptEmpty`, it returns a space character ' '. - - For any other value of `pe`, it returns 0. -- **Output**: - - The function returns a `char` representing the letter associated with the given `pieceType`, or 0 if the type is unrecognized. + - If `pe` does not match any of the specified cases, it returns 0. +- **Output**: A character representing the chess piece type, or 0 if the type is unrecognized. --- ### pieceGetLetter The function `pieceGetLetter` returns the character representation of a chess piece, adjusting for color by converting to lowercase if the piece is black. - **Inputs**: - - `p`: A `piece` type representing a chess piece, which includes both type and color information. + - `p`: A `piece` type representing a chess piece, which encodes both the type and color of the piece. - **Control Flow**: - Call `pieceGetType(p)` to determine the type of the piece `p`. - - Call `pieceTypeGetLetter()` with the result from `pieceGetType(p)` to get the character representation of the piece type. + - Call `pieceTypeGetLetter()` with the result from `pieceGetType(p)` to get the uppercase letter representing the piece type. - Check the color of the piece using `pieceGetColor(p)`. - - If the piece color is `pcBlack`, convert the character to lowercase using `tolower()`. - - Return the character representation of the piece. -- **Output**: - - The function returns a `char` representing the piece type, in uppercase for white pieces and lowercase for black pieces. + - If the piece is black (`pcBlack`), convert the letter to lowercase using `tolower()`. + - Return the character representing the piece, adjusted for color. +- **Output**: A `char` representing the piece type, in uppercase for white pieces and lowercase for black pieces. - **Functions called**: - [`pieceTypeGetLetter`](#pieceTypeGetLetter) - [`pieceGetType`](#pieceGetType) @@ -77,16 +80,18 @@ The function `pieceGetLetter` returns the character representation of a chess pi --- ### pieceMake -The `pieceMake` function creates a chess piece based on the specified type and color, returning an empty piece if the color is invalid or the type is unrecognized. +The `pieceMake` function creates a chess piece of a specified type and color, returning an empty piece if the color is invalid. - **Inputs**: - - `type`: The type of the chess piece, represented by the `pieceType` enum, such as ptKing, ptQueen, etc. - - `color`: The color of the chess piece, represented by the `pieceColor` enum, such as pcWhite or pcBlack. + - `type`: The type of the chess piece to be created, represented by the `pieceType` enum (e.g., ptKing, ptQueen, etc.). + - `color`: The color of the chess piece to be created, represented by the `pieceColor` enum (e.g., pcWhite, pcBlack). - **Control Flow**: - - Check if the color is neither pcWhite nor pcBlack; if so, return pEmpty. - - Use a switch statement to determine the piece type. - - For each case in the switch statement (ptKing, ptQueen, ptRook, ptBishop, ptKnight, ptPawn), return the corresponding piece for the given color (white or black). - - If the type does not match any case, return pEmpty. -- **Output**: - - The function returns a `piece` which is a specific chess piece corresponding to the given type and color, or pEmpty if the color is invalid or the type is unrecognized. + - Check if the `color` is neither `pcWhite` nor `pcBlack`; if so, return `pEmpty`. + - Use a switch statement to determine the `type` of the piece. + - For each case in the switch statement (ptKing, ptQueen, ptRook, ptBishop, ptKnight, ptPawn), return the corresponding piece constant based on the `color` (e.g., `pWKing` for white king, `pBKing` for black king). + - If the `type` does not match any case, return `pEmpty`. +- **Output**: The function returns a `piece` which is a specific chess piece constant based on the given type and color, or `pEmpty` if the color is invalid or the type is unrecognized. + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/chesslib/piecemoves.c.md b/driver_docs/c_cpp_export_test/src/chesslib/piecemoves.c.md new file mode 100644 index 0000000..da3ec41 --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/chesslib/piecemoves.c.md @@ -0,0 +1,273 @@ + + + + + +The `piecemoves.c` file in the `c_cpp_export_test` codebase implements the movement logic for chess pieces, including pawns, knights, bishops, rooks, queens, and kings, while avoiding circular dependencies. + +# Purpose +This C source code file is part of a chess engine, specifically focusing on the movement logic for different chess pieces. It provides implementations for generating possible moves for each type of chess piece, including pawns, knights, bishops, rooks, queens, and kings. The file defines several functions that calculate valid moves based on the current state of the chessboard, taking into account the rules of chess such as piece-specific movement patterns, capturing logic, and special moves like pawn promotion. The code is structured to avoid circular dependencies by including the necessary header file `chesslib/piecemoves.h`, which likely contains declarations for the functions and types used here. + +The file contains helper functions like [`canMoveHere`](#canMoveHere) to determine if a piece can move to a specific square, and [`addPawnMoveToMoveList`](#addPawnMoveToMoveList) to handle pawn promotions. It uses two main movement strategies: "leaper" for pieces like knights and kings, which move to a fixed set of squares, and "rider" for pieces like bishops, rooks, and queens, which can move any number of squares in a direction until blocked. The code is modular, with each piece type having its own function to generate moves, ensuring clarity and maintainability. This file is not an executable but rather a library component intended to be used by other parts of the chess engine to evaluate and execute piece movements. +# Imports and Dependencies + +--- +- `chesslib/piecemoves.h` + + +# Global Variables + +--- +### knightOffsets +- **Type**: `int8_t[8][2]` +- **Description**: The `knightOffsets` variable is a two-dimensional array of integers that represents the possible moves a knight can make on a chessboard. Each sub-array contains two integers, representing the change in file and rank, respectively, for each of the knight's eight possible moves. +- **Use**: This variable is used to calculate the potential new positions a knight can move to from its current position on the chessboard. + + +--- +### bishopOffsets +- **Type**: `int8_t[4][2]` +- **Description**: The `bishopOffsets` variable is a two-dimensional array of integers that represents the possible movement directions for a bishop in a chess game. Each sub-array contains two integers, indicating the change in file and rank for a bishop's diagonal movement on the chessboard. +- **Use**: This variable is used to determine the possible moves for a bishop by providing direction vectors for diagonal movement in the `pmGetBishopMoves` function. + + +--- +### rookOffsets +- **Type**: `int8_t[4][2]` +- **Description**: The `rookOffsets` variable is a two-dimensional array of integers that represents the possible movement directions for a rook in a chess game. Each sub-array contains two integers, where the first integer represents the change in the file (column) and the second integer represents the change in the rank (row). +- **Use**: This variable is used to determine the valid movement directions for a rook piece on a chessboard. + + +--- +### royalOffsets +- **Type**: `int8_t[8][2]` +- **Description**: The `royalOffsets` variable is a two-dimensional array of 8 elements, each containing a pair of integers. These pairs represent the possible movement directions for chess pieces that can move one square in any direction, such as the king and queen. The array includes all eight possible directions: north, northeast, east, southeast, south, southwest, west, and northwest. +- **Use**: This variable is used to determine the movement directions for the king and queen in chess, allowing them to move one square in any of the eight possible directions on the board. + + +# Functions + +--- +### canMoveHere +The `canMoveHere` function determines if a piece can move to a specified square on the board without encountering a piece of the same color. +- **Inputs**: + - `b`: A pointer to the board structure representing the current state of the chess board. + - `s`: The square on the board to which the piece is attempting to move. + - `ourColor`: The color of the piece attempting to move, represented by the `pieceColor` type. +- **Control Flow**: + - Retrieve the piece located at square `s` on the board `b` using [`boardGetPiece`](board.c.md#boardGetPiece) function. + - Check if the retrieved piece is `pEmpty`, indicating the square is empty; if so, return 1 (true) allowing the move. + - If the square is not empty, get the color of the piece on the square using [`pieceGetColor`](piece.c.md#pieceGetColor). + - Compare the color of the piece on the square with `ourColor`; if they are different, return 1 (true), otherwise return 0 (false). +- **Output**: Returns an integer value: 1 if the move is possible (either the square is empty or occupied by an opponent's piece), and 0 if the square is occupied by a piece of the same color. +- **Functions called**: + - [`boardGetPiece`](board.c.md#boardGetPiece) + - [`pieceGetColor`](piece.c.md#pieceGetColor) + + +--- +### pmLeaperMoveList +The `pmLeaperMoveList` function generates a list of valid moves for leaper-type chess pieces from a given position on the board. +- **Inputs**: + - `b`: A pointer to the chess board structure, representing the current state of the game. + - `s`: The current square (position) of the piece on the board, represented as a structure containing file and rank. + - `pt`: The type of the piece for which the move list is being generated, ensuring the function only processes moves for the correct piece type. + - `dirs`: A 2D array of integers representing the possible directions the piece can move, with each direction being a pair of file and rank offsets. + - `numDirs`: The number of directions available in the `dirs` array, indicating how many potential moves need to be evaluated. +- **Control Flow**: + - Create an empty move list using [`moveListCreate`](movelist.c.md#moveListCreate). + - Retrieve the piece at the given square `s` on the board `b`. + - Check if the piece type matches the specified `pt`; if not, return the empty move list. + - Determine the color of the piece to ensure moves are valid for the piece's color. + - Iterate over each direction in `dirs` to calculate potential new squares by applying the direction offsets to the current square `s`. + - Check if the new square is within the bounds of the board (file and rank between 1 and 8). + - Use [`canMoveHere`](#canMoveHere) to determine if the piece can legally move to the new square, considering the presence of other pieces. + - If the move is valid, add it to the move list using [`moveListAdd`](movelist.c.md#moveListAdd). + - Return the populated move list containing all valid moves for the piece. +- **Output**: A pointer to a `moveList` structure containing all valid moves for the leaper piece from the given position. +- **Functions called**: + - [`moveListCreate`](movelist.c.md#moveListCreate) + - [`boardGetPiece`](board.c.md#boardGetPiece) + - [`pieceGetType`](piece.c.md#pieceGetType) + - [`pieceGetColor`](piece.c.md#pieceGetColor) + - [`canMoveHere`](#canMoveHere) + - [`moveListAdd`](movelist.c.md#moveListAdd) + - [`moveSq`](move.c.md#moveSq) + + +--- +### pmRiderMoveList +The `pmRiderMoveList` function generates a list of all possible moves for a rider-type chess piece (like a rook, bishop, or queen) from a given position on the board, considering the piece's movement directions and the board's current state. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chess board. + - `s`: The starting square (`sq` type) from which the piece will attempt to move. + - `pt`: The type of the piece (`pieceType`) that is expected to be at the starting square. + - `dirs`: A 2D array of integers representing the possible movement directions for the piece. + - `numDirs`: The number of directions available in the `dirs` array. +- **Control Flow**: + - Create a new move list using `moveListCreate()` to store possible moves. + - Retrieve the piece at the starting square `s` using `boardGetPiece()` and check if its type matches `pt`; if not, return the empty move list. + - Determine the color of the piece at the starting square. + - Iterate over each direction in `dirs` to explore potential moves. + - For each direction, repeatedly move the piece in that direction until it goes off the board or encounters another piece. + - If the new square is within bounds and the piece can move there (checked using `canMoveHere()`), add the move to the list using `moveListAdd()`. + - If a piece is encountered that is not empty, stop further movement in that direction. +- **Output**: A pointer to a `moveList` structure containing all valid moves for the rider piece from the starting square. +- **Functions called**: + - [`moveListCreate`](movelist.c.md#moveListCreate) + - [`boardGetPiece`](board.c.md#boardGetPiece) + - [`pieceGetType`](piece.c.md#pieceGetType) + - [`pieceGetColor`](piece.c.md#pieceGetColor) + - [`canMoveHere`](#canMoveHere) + - [`moveListAdd`](movelist.c.md#moveListAdd) + - [`moveSq`](move.c.md#moveSq) + + +--- +### addPawnMoveToMoveList +The `addPawnMoveToMoveList` function adds a pawn move to a move list, handling promotions if the move reaches the first or eighth rank. +- **Inputs**: + - `list`: A pointer to a `moveList` structure where the move will be added. + - `oldSq`: The starting square of the pawn, represented as a `sq` structure. + - `newSq`: The destination square of the pawn, represented as a `sq` structure. +- **Control Flow**: + - Check if the destination square `newSq` is on the first or eighth rank, indicating a promotion opportunity. + - If it is a promotion, add four moves to the list, each promoting the pawn to a different piece type: Queen, Rook, Bishop, and Knight. + - If it is not a promotion, add a regular move from `oldSq` to `newSq` to the list. +- **Output**: The function does not return a value; it modifies the `moveList` pointed to by `list` by adding the appropriate move(s). +- **Functions called**: + - [`moveListAdd`](movelist.c.md#moveListAdd) + - [`movePromote`](move.c.md#movePromote) + - [`moveSq`](move.c.md#moveSq) + + +--- +### pmGetPawnMoves +The `pmGetPawnMoves` function generates a list of all possible legal moves for a pawn located at a given square on a chess board. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chess board. + - `s`: A `sq` structure representing the current position of the pawn on the board. +- **Control Flow**: + - Create an empty move list using [`moveListCreate`](movelist.c.md#moveListCreate). + - Retrieve the piece at the given square `s` using [`boardGetPiece`](board.c.md#boardGetPiece). + - Check if the piece is a pawn; if not, return the empty move list. + - Determine the pawn's color and set the movement direction (`delta`) based on the color. + - Calculate the square directly in front of the pawn and check if it is empty; if so, add this move to the list. + - Check if the pawn is in its initial position and can move two squares forward; if so, add this move to the list. + - Check for possible captures to the left and right of the pawn's current position, including en passant captures, and add these moves to the list if valid. + - Return the populated move list. +- **Output**: A pointer to a `moveList` structure containing all possible legal moves for the pawn at the given position. +- **Functions called**: + - [`moveListCreate`](movelist.c.md#moveListCreate) + - [`boardGetPiece`](board.c.md#boardGetPiece) + - [`pieceGetType`](piece.c.md#pieceGetType) + - [`pieceGetColor`](piece.c.md#pieceGetColor) + - [`sqI`](square.c.md#sqI) + - [`addPawnMoveToMoveList`](#addPawnMoveToMoveList) + - [`canMoveHere`](#canMoveHere) + - [`sqEq`](square.c.md#sqEq) + + +--- +### pmGetPawnAttacks +The function `pmGetPawnAttacks` generates a list of potential attack moves for a pawn on a chessboard, considering only diagonal squares where it could attack if an opponent's piece were present. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chessboard. + - `s`: A `sq` structure representing the current position of the pawn on the board. +- **Control Flow**: + - Create an empty move list using `moveListCreate()`. + - Retrieve the piece at the given square `s` using `boardGetPiece(b, s)`. + - Check if the piece is a pawn using `pieceGetType(p) != ptPawn`; if not, return the empty move list. + - Determine the pawn's color using `pieceGetColor(p)` and set `delta` to 1 for white pawns and -1 for black pawns. + - Check if the pawn can attack diagonally to the left (file > 1); if so, calculate the new square and add the move to the list if it's a valid attack square using `canMoveHere(b, newSq, color)`. + - Check if the pawn can attack diagonally to the right (file < 8); if so, calculate the new square and add the move to the list if it's a valid attack square using `canMoveHere(b, newSq, color)`. + - Return the move list containing potential attack moves. +- **Output**: A pointer to a `moveList` structure containing potential attack moves for the pawn from its current position. +- **Functions called**: + - [`moveListCreate`](movelist.c.md#moveListCreate) + - [`boardGetPiece`](board.c.md#boardGetPiece) + - [`pieceGetType`](piece.c.md#pieceGetType) + - [`pieceGetColor`](piece.c.md#pieceGetColor) + - [`sqI`](square.c.md#sqI) + - [`canMoveHere`](#canMoveHere) + - [`moveListAdd`](movelist.c.md#moveListAdd) + - [`moveSq`](move.c.md#moveSq) + + +--- +### pmGetKnightMoves +The function `pmGetKnightMoves` generates a list of all possible legal moves for a knight located at a given square on a chessboard. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chessboard. + - `s`: A `sq` structure representing the current position of the knight on the board. +- **Control Flow**: + - The function calls [`pmLeaperMoveList`](#pmLeaperMoveList) with the board, the knight's current square, the piece type `ptKnight`, the predefined `knightOffsets` array, and the number of directions (8). + - [`pmLeaperMoveList`](#pmLeaperMoveList) processes these inputs to determine all valid moves for the knight based on its unique movement pattern. +- **Output**: A pointer to a `moveList` structure containing all valid moves for the knight from the given position. +- **Functions called**: + - [`pmLeaperMoveList`](#pmLeaperMoveList) + + +--- +### pmGetBishopMoves +The `pmGetBishopMoves` function generates a list of all possible moves for a bishop located at a given square on a chessboard. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chessboard. + - `s`: A `sq` structure representing the current position of the bishop on the board. +- **Control Flow**: + - The function calls [`pmRiderMoveList`](#pmRiderMoveList) with the board, the bishop's current square, the piece type `ptBishop`, the `bishopOffsets` array, and the number 4 as arguments. + - The [`pmRiderMoveList`](#pmRiderMoveList) function processes the bishop's movement by iterating over the diagonal directions specified in `bishopOffsets`. + - For each direction, it continues moving the bishop in that direction until it either reaches the edge of the board or encounters another piece. + - If the encountered piece is of the opposite color, the move is added to the list and the iteration for that direction stops. +- **Output**: A pointer to a `moveList` structure containing all valid moves for the bishop from the given square. +- **Functions called**: + - [`pmRiderMoveList`](#pmRiderMoveList) + + +--- +### pmGetRookMoves +The function `pmGetRookMoves` generates a list of all possible legal moves for a rook located at a given square on a chess board. +- **Inputs**: + - `b`: A pointer to the chess board structure representing the current state of the game. + - `s`: A structure representing the square on the board where the rook is currently located. +- **Control Flow**: + - The function calls [`pmRiderMoveList`](#pmRiderMoveList) with the board, square, piece type for rook, rook movement offsets, and the number of directions (4) as arguments. + - [`pmRiderMoveList`](#pmRiderMoveList) handles the logic for generating moves for pieces that can move multiple squares in a straight line, like the rook. +- **Output**: A pointer to a `moveList` structure containing all possible legal moves for the rook from the given square. +- **Functions called**: + - [`pmRiderMoveList`](#pmRiderMoveList) + + +--- +### pmGetQueenMoves +The function `pmGetQueenMoves` generates a list of all possible legal moves for a queen located at a given square on a chessboard. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chessboard. + - `s`: A `sq` structure representing the current position of the queen on the board. +- **Control Flow**: + - The function calls [`pmRiderMoveList`](#pmRiderMoveList) with the board, the queen's current position, the piece type `ptQueen`, the direction offsets for a queen (`royalOffsets`), and the number of directions (8). + - [`pmRiderMoveList`](#pmRiderMoveList) iterates over each direction in `royalOffsets`, moving the queen in that direction until it either reaches the edge of the board or encounters another piece. + - If the square is within bounds and either empty or occupied by an opponent's piece, the move is added to the move list. + - The iteration stops in a direction if a piece is encountered, as the queen cannot move past it. +- **Output**: A pointer to a `moveList` structure containing all possible legal moves for the queen from the given position. +- **Functions called**: + - [`pmRiderMoveList`](#pmRiderMoveList) + + +--- +### pmGetKingMoves +The `pmGetKingMoves` function generates a list of all possible legal moves for a king piece from a given position on a chess board. +- **Inputs**: + - `b`: A pointer to the `board` structure representing the current state of the chess board. + - `s`: A `sq` structure representing the current position of the king on the board. +- **Control Flow**: + - The function calls [`pmLeaperMoveList`](#pmLeaperMoveList) with the board, the king's current position, the piece type `ptKing`, the array `royalOffsets` representing the king's possible move directions, and the number of directions (8). + - [`pmLeaperMoveList`](#pmLeaperMoveList) processes these inputs to generate a list of valid moves for the king based on its leaping movement pattern. +- **Output**: A pointer to a `moveList` structure containing all valid moves for the king from the specified position. +- **Functions called**: + - [`pmLeaperMoveList`](#pmLeaperMoveList) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/chesslib/square.c.md b/driver_docs/c_cpp_export_test/src/chesslib/square.c.md new file mode 100644 index 0000000..1b6cbec --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/chesslib/square.c.md @@ -0,0 +1,127 @@ + + + + + +The `square.c` file in the `c_cpp_export_test` codebase provides functions for creating and manipulating chessboard squares, including conversion between different representations and checking square properties. + +# Purpose +This C source code file provides functionality for handling chessboard squares, encapsulating operations related to the representation and manipulation of squares on a chessboard. The code defines several functions that allow for the creation and manipulation of square objects, which are represented by a custom data type `sq`. The primary operations include creating a square from file and rank integers ([`sqI`](#sqI)), from a Standard Algebraic Notation (SAN) string ([`sqS`](#sqS)), and from an index ([`sqIndex`](#sqIndex)). Additionally, the code provides utility functions to retrieve the index of a square ([`sqGetIndex`](#sqGetIndex)), convert a square to its SAN string representation ([`sqGetStr`](#sqGetStr)), determine if a square is dark or light ([`sqIsDark`](#sqIsDark)), and compare two squares for equality ([`sqEq`](#sqEq)). + +The file is part of a larger library, as indicated by the inclusion of the header file "chesslib/square.h", suggesting that it is intended to be used as part of a chess-related software system. The code does not define a public API directly but provides essential internal functions that likely support higher-level operations within the library. The use of constants and checks ensures that the operations are constrained within the valid range of a standard 8x8 chessboard, enhancing the robustness of the library. The array `SQ_STRS` provides a mapping of indices to SAN strings, facilitating conversions between different square representations. +# Imports and Dependencies + +--- +- `chesslib/square.h` + + +# Global Variables + +--- +### SQ\_STRS +- **Type**: `const char*[]` +- **Description**: `SQ_STRS` is a global constant array of strings, where each string represents a square on a chessboard using standard algebraic notation (SAN). The array contains 64 elements, corresponding to the 64 squares on a chessboard, with each element being a string like "a1", "b1", etc., representing the file and rank of the square. +- **Use**: This array is used to map indices to their corresponding SAN strings for chessboard squares. + + +# Functions + +--- +### sqI +The `sqI` function creates a chessboard square from given file and rank values, ensuring they are within valid bounds. +- **Inputs**: + - `file`: An unsigned 8-bit integer representing the file (column) of the chessboard square, expected to be between 1 and 8. + - `rank`: An unsigned 8-bit integer representing the rank (row) of the chessboard square, expected to be between 1 and 8. +- **Control Flow**: + - Check if the file is less than 1 or greater than 8, or if the rank is less than 1 or greater than 8. + - If any of the above conditions are true, return `SQ_INVALID`. + - If the file and rank are within valid bounds, create a `sq` structure. + - Assign the file and rank values to the `sq` structure's `file` and `rank` fields, respectively. + - Return the `sq` structure. +- **Output**: A `sq` structure representing the chessboard square with the specified file and rank, or `SQ_INVALID` if the inputs are out of bounds. + + +--- +### sqS +The function `sqS` converts a string representing a chessboard square in SAN format to a `sq` structure with file and rank values. +- **Inputs**: + - `str`: A pointer to a constant character string representing a chessboard square in SAN format, such as "e4". +- **Control Flow**: + - Extract the first character `c1` from the input string `str`. + - Check if `c1` is a valid file character (between 'a' and 'h'); if not, return `SQ_INVALID`. + - Extract the second character `c2` from the input string `str`. + - Check if `c2` is a valid rank character (between '1' and '8'); if not, return `SQ_INVALID`. + - Create a `sq` structure `s` and set its `file` field to the numeric value corresponding to `c1` (1 for 'a', 2 for 'b', etc.). + - Set the `rank` field of `s` to the numeric value of `c2`. + - Return the `sq` structure `s`. +- **Output**: A `sq` structure representing the chessboard square with file and rank values, or `SQ_INVALID` if the input string is not a valid SAN square. + + +--- +### sqIndex +The `sqIndex` function converts an index into a chessboard square using a predefined string array. +- **Inputs**: + - `index`: An unsigned 8-bit integer representing the index of the square, expected to be between 0 and 63 inclusive. +- **Control Flow**: + - Check if the input index is less than 0 or greater than 63. + - If the index is out of bounds, return `SQ_INVALID`. + - If the index is valid, use it to access the `SQ_STRS` array to get the corresponding square string. + - Call the [`sqS`](#sqS) function with the retrieved string to convert it into a `sq` type and return it. +- **Output**: Returns a `sq` type representing the chessboard square corresponding to the given index, or `SQ_INVALID` if the index is out of bounds. +- **Functions called**: + - [`sqS`](#sqS) + + +--- +### sqGetIndex +The function `sqGetIndex` calculates the zero-based index of a chessboard square given its file and rank. +- **Inputs**: + - `s`: A structure representing a square on a chessboard, containing two fields: `file` and `rank`, both of which are integers. +- **Control Flow**: + - Check if the `file` or `rank` of the square `s` is outside the valid range (1 to 8); if so, return -1 indicating an invalid square. + - Calculate the index using the formula `(8 * (s.rank - 1)) + (s.file - 1)` which converts the 2D file and rank into a 1D index. +- **Output**: Returns a `uint8_t` representing the zero-based index of the square on a chessboard, or -1 if the square is invalid. + + +--- +### sqGetStr +The function `sqGetStr` returns the Standard Algebraic Notation (SAN) string representation of a given chess square. +- **Inputs**: + - `s`: A chess square represented by the custom type `sq`, which contains file and rank information. +- **Control Flow**: + - Call the helper function [`sqGetIndex`](#sqGetIndex) with the input square `s` to get its index. + - Check if the index is greater than 63, which indicates an invalid square, and return the string '##' if true. + - If the index is valid (0 to 63), return the corresponding SAN string from the `SQ_STRS` array. +- **Output**: A constant character pointer to the SAN string representing the square, or '##' if the square is invalid. +- **Functions called**: + - [`sqGetIndex`](#sqGetIndex) + + +--- +### sqIsDark +The function `sqIsDark` determines if a given chessboard square is dark-colored based on its rank and file. +- **Inputs**: + - `s`: A `sq` structure representing a square on a chessboard, containing `rank` and `file` fields. +- **Control Flow**: + - The function uses bitwise AND to check the least significant bit of both the `rank` and `file` fields of the square `s`. + - It performs an XOR operation on these bits to determine if they are different. + - The result of the XOR operation is negated to return 1 if the square is dark and 0 if it is light. +- **Output**: Returns 1 if the square is dark-colored, otherwise returns 0. + + +--- +### sqEq +The `sqEq` function checks if two chessboard squares are equal by comparing their file and rank values, after validating their boundaries. +- **Inputs**: + - `s1`: The first square to be compared, represented by a structure with file and rank attributes. + - `s2`: The second square to be compared, also represented by a structure with file and rank attributes. +- **Control Flow**: + - Check if the file or rank of the first square `s1` is out of the valid range (1 to 8); if so, set `s1` to `SQ_INVALID`. + - Check if the file or rank of the second square `s2` is out of the valid range (1 to 8); if so, set `s2` to `SQ_INVALID`. + - Compare the file and rank of `s1` and `s2` to determine if they are equal. +- **Output**: Returns 1 (true) if both squares have the same file and rank values, otherwise returns 0 (false). + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/chesslib/squareset.c.md b/driver_docs/c_cpp_export_test/src/chesslib/squareset.c.md new file mode 100644 index 0000000..5e65d8a --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/chesslib/squareset.c.md @@ -0,0 +1,57 @@ + + + + + +The `squareset.c` file implements functions for setting and getting values in a square set, which is part of a chess library. + +# Purpose +This C source code file implements a simple set of functions to manipulate a "square set," likely used in a chess-related application. The file includes two primary functions: [`sqSetSet`](#sqSetSet) and [`sqSetGet`](#sqSetGet). The [`sqSetSet`](#sqSetSet) function modifies a bit within a `sqSet` data structure, setting or clearing it based on the provided `value`, while ensuring the square is valid. The [`sqSetGet`](#sqSetGet) function retrieves the value of a specific bit from the `sqSet`, again checking for validity. This code is part of a larger library, as indicated by the inclusion of "chesslib/squareset.h", and it uses bitwise operations to efficiently manage the state of chessboard squares. +# Imports and Dependencies + +--- +- `stdlib.h` +- `chesslib/squareset.h` + + +# Functions + +--- +### sqSetSet +The function `sqSetSet` modifies a bit in a `sqSet` based on the index of a square and a given value. +- **Inputs**: + - `ss`: A pointer to a `sqSet`, which is a data structure representing a set of squares. + - `s`: A square `s` of type `sq`, which is used to determine the bit position to modify in the `sqSet`. + - `value`: A `uint8_t` value indicating whether to set (1) or clear (0) the bit corresponding to the square `s` in the `sqSet`. +- **Control Flow**: + - Check if the square `s` is invalid using `sqEq(s, SQ_INVALID)`, and return immediately if it is. + - Calculate the bit position by shifting 1 left by the index of the square `s` obtained from `sqGetIndex(s)`. + - If `value` is non-zero, set the bit in `sqSet` at the calculated position using bitwise OR. + - If `value` is zero, clear the bit in `sqSet` at the calculated position using bitwise AND with the negated bit. +- **Output**: The function does not return a value; it modifies the `sqSet` in place. +- **Functions called**: + - [`sqEq`](square.c.md#sqEq) + - [`sqGetIndex`](square.c.md#sqGetIndex) + + +--- +### sqSetGet +The function `sqSetGet` retrieves the value of a specific square from a square set, returning 0 if the square is invalid or the bit value at the square's index otherwise. +- **Inputs**: + - `ss`: A pointer to a `sqSet`, which is a data structure representing a set of squares. + - `s`: A `sq` type representing a specific square whose value is to be retrieved. +- **Control Flow**: + - Check if the square `s` is invalid using `sqEq(s, SQ_INVALID)`; if true, return 0. + - Calculate the index of the square `s` using `sqGetIndex(s)`. + - Shift the bits of the square set `*ss` right by the index of the square. + - Perform a bitwise AND operation with 1 to isolate the bit at the square's index. + - Return the result of the bitwise operation, which is either 0 or 1. +- **Output**: The function returns a `uint8_t` value, which is 0 if the square is invalid or the bit value (0 or 1) at the specified square's index in the square set. +- **Functions called**: + - [`sqEq`](square.c.md#sqEq) + - [`sqGetIndex`](square.c.md#sqGetIndex) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/tests.c.md b/driver_docs/c_cpp_export_test/src/tests.c.md new file mode 100644 index 0000000..6d27136 --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/tests.c.md @@ -0,0 +1,794 @@ + + + + + +The `tests.c` file in the `c_cpp_export_test` codebase contains a comprehensive suite of unit tests for various components of a chess implementation in C, including tests for squares, moves, move lists, boards, piece moves, attacked squares, move generation, FEN generation, and draw conditions. + +# Purpose +This C source code file is a comprehensive test suite for a chess implementation. It is designed to validate the functionality of various components of a chess library, including squares, moves, move lists, boards, piece movements, and more. The file includes a [`main`](#main) function that sequentially runs a series of test functions, each of which is responsible for testing specific aspects of the chess library. The tests cover a wide range of scenarios, such as move creation, board setup from FEN strings, move generation, castling, en passant, and draw conditions due to insufficient material. + +The file imports several headers from the chess library, indicating that it is intended to be used as a standalone executable to verify the correctness of the library's functionality. The test functions utilize helper functions like [`failTest`](#failTest) and [`validateString`](#validateString) to assert expected outcomes and halt execution upon failure. The code is structured to ensure that each component of the chess library behaves as expected, providing a robust framework for regression testing and quality assurance of the chess implementation. +# Imports and Dependencies + +--- +- `stdio.h` +- `stdlib.h` +- `string.h` +- `tests.h` +- `chesslib/squareset.h` +- `chesslib/movelist.h` +- `chesslib/board.h` +- `chesslib/piecemoves.h` +- `chesslib/boardlist.h` + + +# Global Variables + +--- +### currTest +- **Type**: `const char*` +- **Description**: `currTest` is a global variable of type `const char*` that holds the name of the currently running test as a string. It is used to track which test is being executed at any given time during the test suite execution. +- **Use**: This variable is used to store the name of the test currently being executed, allowing for error messages to specify which test failed. + + +# Functions + +--- +### main +The `main` function runs a series of predefined tests for various components of a chess implementation and reports success if all tests pass. +- **Inputs**: + - `argc`: The number of command-line arguments passed to the program. + - `argv`: An array of strings representing the command-line arguments. +- **Control Flow**: + - The function begins by running a series of test functions related to chess squares using the `RUN_TEST` macro. + - It continues by running test functions related to chess moves, move lists, and board creation and manipulation. + - The function then tests piece-specific move generation for pawns, knights, bishops, rooks, queens, and kings. + - It proceeds to test functions related to checking if squares are attacked and if a player is in check. + - The function tests the ability to play moves on the board, including special moves like castling and en passant. + - It generates and verifies moves for the board, including castling conditions. + - The function tests the generation of FEN strings from board states and checks for draw conditions due to insufficient material. + - It tests the functionality of board lists and square sets. + - Finally, if all tests pass, it prints a success message and returns 0. +- **Output**: The function returns an integer, 0, indicating successful execution if all tests pass. + + +--- +### failTest +The `failTest` function logs a failure message for the current test and terminates the program. +- **Inputs**: + - `msg`: A constant character pointer to a message string that provides additional information about the test failure; it can be NULL if no additional message is needed. +- **Control Flow**: + - Check if the input message `msg` is NULL. + - If `msg` is NULL, print a failure message to the standard error stream with the current test name. + - If `msg` is not NULL, print a failure message to the standard error stream with the current test name and the provided message. + - Terminate the program with an exit status of 1. +- **Output**: The function does not return a value; it exits the program with a status code of 1. + + +--- +### validateString +The `validateString` function compares two strings and triggers a test failure if they are not identical. +- **Inputs**: + - `actual`: A pointer to the actual string that needs to be validated. + - `expected`: A pointer to the expected string that the actual string is compared against. +- **Control Flow**: + - The function begins by comparing the `actual` and `expected` strings using `strcmp`. + - If the strings are not equal, it calculates the lengths of both strings using `strlen`. + - It allocates memory for a new string that will hold a formatted error message. + - The error message is created using `sprintf`, indicating the mismatch between the actual and expected strings. + - The [`failTest`](#failTest) function is called with the error message, which exits the program, so the subsequent `free` call is not executed. +- **Output**: The function does not return a value; it exits the program if the strings do not match. +- **Functions called**: + - [`failTest`](#failTest) + + +--- +### testSqI +The `testSqI` function verifies that the [`sqI`](chesslib/square.c.md#sqI) function correctly maps file and rank inputs to a square structure with matching file and rank values. +- **Inputs**: None +- **Control Flow**: + - Iterates over ranks from 1 to 8. + - For each rank, iterates over files from 1 to 8. + - Calls [`sqI`](chesslib/square.c.md#sqI) with the current file and rank to get a square `s`. + - Checks if the file and rank of `s` match the current file and rank. + - If they do not match, constructs an error message and calls [`failTest`](#failTest) with this message. +- **Output**: The function does not return a value; it either completes successfully or calls [`failTest`](#failTest) to indicate a failure. +- **Functions called**: + - [`sqI`](chesslib/square.c.md#sqI) + - [`failTest`](#failTest) + + +--- +### testSqS +The `testSqS` function tests the conversion of chess square strings to square structures and verifies their correctness. +- **Inputs**: None +- **Control Flow**: + - Iterates over ranks from 1 to 8. + - For each rank, iterates over files from 1 to 8. + - Constructs a string representation of the square using the file and rank. + - Calls the [`sqS`](chesslib/square.c.md#sqS) function to convert the string to a square structure. + - Checks if the converted square's file and rank match the expected values. + - If there is a mismatch, constructs an error message and calls [`failTest`](#failTest) to halt the test. +- **Output**: The function does not return a value; it halts the program if a test fails. +- **Functions called**: + - [`sqS`](chesslib/square.c.md#sqS) + - [`failTest`](#failTest) + + +--- +### testSqGetStr +The `testSqGetStr` function tests the conversion of chessboard square coordinates to their string representation and validates the output against expected values. +- **Inputs**: None +- **Control Flow**: + - Iterates over all possible ranks (1 to 8) and files (1 to 8) on a chessboard. + - For each combination of rank and file, it creates a square using the [`sqI`](chesslib/square.c.md#sqI) function. + - Generates the expected string representation of the square using the file and rank values. + - Calls [`sqGetStr`](chesslib/square.c.md#sqGetStr) to get the actual string representation of the square. + - Validates the actual string against the expected string using [`validateString`](#validateString). +- **Output**: The function does not return any value; it validates the correctness of the [`sqGetStr`](chesslib/square.c.md#sqGetStr) function by comparing its output to expected values. +- **Functions called**: + - [`sqI`](chesslib/square.c.md#sqI) + - [`validateString`](#validateString) + - [`sqGetStr`](chesslib/square.c.md#sqGetStr) + + +--- +### testSqIsDark +The `testSqIsDark` function verifies that each square on a chessboard is correctly identified as dark or light by the [`sqIsDark`](chesslib/square.c.md#sqIsDark) function. +- **Inputs**: None +- **Control Flow**: + - Initialize `expectedIsDark` to 1, assuming the square a1 is dark. + - Iterate over each rank from 1 to 8. + - For each rank, iterate over each file from 1 to 8. + - For each square, create a square object `s` using `sqI(file, rank)`. + - Determine if the square `s` is dark using `sqIsDark(s)` and store the result in `actualIsDark`. + - If `actualIsDark` does not match `expectedIsDark`, construct an error message and call [`failTest`](#failTest) with this message. + - Toggle `expectedIsDark` after each file iteration to alternate between dark and light squares. + - Toggle `expectedIsDark` after each rank iteration to maintain the checkerboard pattern. +- **Output**: The function does not return a value but will terminate the program with an error message if a test fails. +- **Functions called**: + - [`sqI`](chesslib/square.c.md#sqI) + - [`sqIsDark`](chesslib/square.c.md#sqIsDark) + - [`sqGetStr`](chesslib/square.c.md#sqGetStr) + - [`failTest`](#failTest) + + +--- +### validateMove +The `validateMove` function checks if a given chess move matches expected parameters and triggers a test failure if it does not. +- **Inputs**: + - `m`: A `move` structure representing the actual move to be validated. + - `expectedFrom`: A `sq` structure representing the expected starting square of the move. + - `expectedTo`: A `sq` structure representing the expected ending square of the move. + - `expectedPromotion`: A `pieceType` representing the expected promotion piece type, if any. +- **Control Flow**: + - The function checks if the actual move's starting square, ending square, and promotion type match the expected values using logical OR to combine the conditions. + - If any of these conditions are not met, a message is formatted with the actual and expected values using `sprintf`. + - The [`failTest`](#failTest) function is called with the formatted message, which halts the program and indicates a test failure. +- **Output**: The function does not return a value; it either completes silently if the move is valid or halts the program with an error message if the move is invalid. +- **Functions called**: + - [`sqEq`](chesslib/square.c.md#sqEq) + - [`sqGetStr`](chesslib/square.c.md#sqGetStr) + - [`failTest`](#failTest) + + +--- +### testMoveCreate +The `testMoveCreate` function tests the creation and validation of chess moves, including normal and promotion moves. +- **Inputs**: None +- **Control Flow**: + - A move `m` is created using [`moveSq`](chesslib/move.c.md#moveSq) from square (5, 8) to square (5, 7). + - The move `m` is validated using [`validateMove`](#validateMove) to ensure it matches the expected from and to squares and has no promotion. + - A promotion move `m` is created using [`movePromote`](chesslib/move.c.md#movePromote) from square (3, 2) to square (2, 1) with a promotion to a queen. + - The promotion move `m` is validated using [`validateMove`](#validateMove) to ensure it matches the expected from and to squares and the promotion to a queen. +- **Output**: The function does not return any output; it performs validation checks and may halt execution if a test fails. +- **Functions called**: + - [`moveSq`](chesslib/move.c.md#moveSq) + - [`sqI`](chesslib/square.c.md#sqI) + - [`validateMove`](#validateMove) + - [`movePromote`](chesslib/move.c.md#movePromote) + + +--- +### testMoveGetUci +The `testMoveGetUci` function tests the conversion of chess moves to UCI (Universal Chess Interface) format strings and validates the output against expected results. +- **Inputs**: None +- **Control Flow**: + - A move `m` is created from square e8 to e7 using [`moveSq`](chesslib/move.c.md#moveSq) and converted to UCI format using [`moveGetUci`](chesslib/move.c.md#moveGetUci), then validated against the expected string "e8e7" using [`validateString`](#validateString). + - Another move `m` is created from square c2 to b1 with a promotion to a queen using [`movePromote`](chesslib/move.c.md#movePromote), converted to UCI format, and validated against the expected string "c2b1q". +- **Output**: The function does not return any value; it validates the correctness of UCI string conversion for specific chess moves. +- **Functions called**: + - [`moveSq`](chesslib/move.c.md#moveSq) + - [`sqI`](chesslib/square.c.md#sqI) + - [`validateString`](#validateString) + - [`moveGetUci`](chesslib/move.c.md#moveGetUci) + - [`movePromote`](chesslib/move.c.md#movePromote) + + +--- +### testMoveFromUci +The `testMoveFromUci` function tests the conversion of UCI (Universal Chess Interface) strings into move objects and validates their correctness. +- **Inputs**: None +- **Control Flow**: + - The function begins by calling [`moveFromUci`](chesslib/move.c.md#moveFromUci) with the string "e8e7" to create a move object `m`. + - It then calls [`validateMove`](#validateMove) to check if the move `m` corresponds to moving from square e8 to e7 with no promotion (indicated by `ptEmpty`). + - Next, it calls [`moveFromUci`](chesslib/move.c.md#moveFromUci) with the string "c2b1q" to create another move object `m`. + - It calls [`validateMove`](#validateMove) again to check if this move `m` corresponds to moving from square c2 to b1 with a promotion to a queen (indicated by `ptQueen`). +- **Output**: The function does not return any value; it performs validation checks and may halt the program if a test fails. +- **Functions called**: + - [`moveFromUci`](chesslib/move.c.md#moveFromUci) + - [`validateMove`](#validateMove) + - [`sqI`](chesslib/square.c.md#sqI) + + +--- +### testMoveList +The `testMoveList` function tests the functionality of creating, adding, retrieving, and validating moves in a move list for a chess game. +- **Inputs**: None +- **Control Flow**: + - Create three moves using [`moveFromUci`](chesslib/move.c.md#moveFromUci) with UCI strings 'e2e4', 'e7e5', and 'e1e2'. + - Create a new move list using [`moveListCreate`](chesslib/movelist.c.md#moveListCreate). + - Add the three moves to the move list using [`moveListAdd`](chesslib/movelist.c.md#moveListAdd). + - Retrieve the moves from the move list using [`moveListGet`](chesslib/movelist.c.md#moveListGet) at indices 0, 1, and 2. + - Convert each retrieved move to its UCI string using [`moveGetUci`](chesslib/move.c.md#moveGetUci). + - Compare each UCI string with the expected string ('e2e4', 'e7e5', 'e1e2') using `strcmp`. + - If any comparison fails, call [`failTest`](#failTest) with a formatted error message. + - Free the UCI strings after comparison. + - Free the move list using [`moveListFree`](chesslib/movelist.c.md#moveListFree). +- **Output**: The function does not return any value; it performs assertions to validate the correctness of move list operations and may terminate the program if a test fails. +- **Functions called**: + - [`moveFromUci`](chesslib/move.c.md#moveFromUci) + - [`moveListCreate`](chesslib/movelist.c.md#moveListCreate) + - [`moveListAdd`](chesslib/movelist.c.md#moveListAdd) + - [`moveListGet`](chesslib/movelist.c.md#moveListGet) + - [`moveGetUci`](chesslib/move.c.md#moveGetUci) + - [`failTest`](#failTest) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + + +--- +### assertPiece +The `assertPiece` function checks if two chess pieces are equal and reports an error if they are not. +- **Inputs**: + - `actual`: The actual piece to be compared. + - `expected`: The expected piece to be compared against. +- **Control Flow**: + - The function compares the `actual` piece with the `expected` piece using the `!=` operator. + - If the pieces are not equal, it retrieves the letter representation of both pieces using [`pieceGetLetter`](chesslib/piece.c.md#pieceGetLetter). + - It formats a message indicating the mismatch using `sprintf`. + - The function then calls [`failTest`](#failTest) with the formatted message to report the error and halt the program. +- **Output**: The function does not return a value; it exits the program if the pieces do not match. +- **Functions called**: + - [`pieceGetLetter`](chesslib/piece.c.md#pieceGetLetter) + - [`failTest`](#failTest) + + +--- +### testBoardCreate +The `testBoardCreate` function verifies the correct initialization of a chess board by checking the placement of pieces, the current player, castling rights, en passant target, half-move clock, and move number. +- **Inputs**: None +- **Control Flow**: + - Create a new board using `boardCreate()` and store it in `b`. + - Check if the board `b` is `NULL` and fail the test if it is. + - Verify the initial positions of white pieces on the board using [`assertPiece`](#assertPiece). + - Verify the initial positions of white pawns on the board using a loop and [`assertPiece`](#assertPiece). + - Verify that the middle squares are empty using a loop and [`assertPiece`](#assertPiece). + - Verify the initial positions of black pawns on the board using a loop and [`assertPiece`](#assertPiece). + - Verify the initial positions of black pieces on the board using [`assertPiece`](#assertPiece). + - Check if the current player is white and fail the test if it is not. + - Check if all castling rights are enabled and fail the test if they are not. + - Check if the en passant target square is `SQ_INVALID` and fail the test if it is not. + - Check if the half-move clock is 0 and fail the test if it is not, providing a detailed message. + - Check if the move number is 1 and fail the test if it is not, providing a detailed message. + - Free the allocated memory for the board `b`. +- **Output**: The function does not return any value; it performs assertions and may terminate the program if any test fails. +- **Functions called**: + - [`boardCreate`](chesslib/board.c.md#boardCreate) + - [`failTest`](#failTest) + - [`assertPiece`](#assertPiece) + - [`sqEq`](chesslib/square.c.md#sqEq) + + +--- +### testBoardCreateFromFen +The function `testBoardCreateFromFen` tests the creation of a chess board from a FEN string and verifies the board's state against expected values. +- **Inputs**: None +- **Control Flow**: + - Create a board using [`boardCreateFromFen`](chesslib/board.c.md#boardCreateFromFen) with a specific FEN string. + - Check if the board creation returned a NULL pointer and fail the test if it did. + - Iterate over all 64 squares of the board, asserting that only specific squares contain pieces, while others are empty. + - Assert the presence of specific pieces at designated squares based on the FEN string. + - Verify that the current player is set to black as expected. + - Check that all castling flags are disabled. + - Validate that the en passant target square is correctly set to e3. + - Ensure the half-move clock is set to 0. + - Confirm the full move number is set to 46. + - Free the allocated board memory. +- **Output**: The function does not return any value; it performs assertions to validate the board state and fails the test if any assertion is incorrect. +- **Functions called**: + - [`boardCreateFromFen`](chesslib/board.c.md#boardCreateFromFen) + - [`failTest`](#failTest) + - [`assertPiece`](#assertPiece) + - [`sqEq`](chesslib/square.c.md#sqEq) + - [`sqI`](chesslib/square.c.md#sqI) + - [`sqGetStr`](chesslib/square.c.md#sqGetStr) + + +--- +### testBoardEq +The `testBoardEq` function is a placeholder for a test that checks if two chess boards are equal, but it is not yet implemented. +- **Inputs**: None +- **Control Flow**: + - The function calls [`failTest`](#failTest) with the message 'Not yet implemented', which causes the test to fail and the program to exit. + - There is a commented-out section indicating a plan to create a board from a FEN string, but it is not executed. +- **Output**: The function does not return any value as it is a void function, and it currently only causes the program to exit with a failure message. +- **Functions called**: + - [`failTest`](#failTest) + + +--- +### validateUciIsInMovelist +The `validateUciIsInMovelist` function checks if a given UCI move string is present in a move list and fails the test if it is not found. +- **Inputs**: + - `list`: A pointer to a `moveList` structure representing the list of moves to be checked. + - `expectedUci`: A string representing the expected UCI move that should be present in the move list. +- **Control Flow**: + - Iterate over each node in the move list starting from the head. + - For each node, retrieve the UCI string of the move using [`moveGetUci`](chesslib/move.c.md#moveGetUci). + - Compare the retrieved UCI string with the expected UCI string using `strcmp`. + - If a match is found (comparison result is 0), return from the function, indicating the move is present. + - If the loop completes without finding a match, format an error message indicating the expected UCI was absent. + - Call [`failTest`](#failTest) with the error message to fail the test. +- **Output**: The function does not return a value; it either returns normally if the UCI is found or calls [`failTest`](#failTest) to terminate the program if the UCI is not found. +- **Functions called**: + - [`moveGetUci`](chesslib/move.c.md#moveGetUci) + - [`failTest`](#failTest) + + +--- +### validateListSize +The `validateListSize` function checks if a move list's size matches an expected size and triggers a test failure if they do not match. +- **Inputs**: + - `list`: A pointer to a `moveList` structure, which contains a list of chess moves and its current size. + - `expectedSize`: A `size_t` value representing the expected number of elements in the move list. +- **Control Flow**: + - The function compares the `size` attribute of the `list` with `expectedSize`. + - If the sizes do not match, it formats an error message indicating the actual and expected sizes. + - The function then calls [`failTest`](#failTest) with the formatted message to indicate a test failure and halt execution. +- **Output**: The function does not return a value; it either completes without issue or halts the program if the list size does not match the expected size. +- **Functions called**: + - [`failTest`](#failTest) + + +--- +### testPawnMoves +The `testPawnMoves` function tests various scenarios of pawn movements on a chessboard, including normal moves, captures, promotions, and special moves like en passant, using a series of assertions to validate the correctness of the move generation logic. +- **Inputs**: None +- **Control Flow**: + - Initialize a board with a lone white pawn on its starting rank and generate its possible moves, validating that it can move one or two squares forward. + - Set up a board where a pawn can capture enemy pieces and validate that the move list includes both forward moves and captures. + - Test a scenario where a pawn is blocked by another piece, ensuring no moves are generated. + - Check a pawn not on its starting rank, validating it can only move one square forward. + - Test a white pawn about to promote, ensuring all promotion options are included in the move list. + - Set up a black pawn on its starting rank and validate it can move one or two squares forward. + - Test a scenario where a pawn is blocked with one free spot, ensuring only the free move is generated. + - Check a black pawn about to promote with capturing ability, validating all promotion and capture options are included. + - Test en passant capture opportunities for both white and black pawns, ensuring the special capture move is included. + - Free the move list and board resources after each test case. +- **Output**: The function does not return any value; it uses assertions to validate the correctness of pawn move generation logic. +- **Functions called**: + - [`boardCreateFromFen`](chesslib/board.c.md#boardCreateFromFen) + - [`pmGetPawnMoves`](chesslib/piecemoves.c.md#pmGetPawnMoves) + - [`sqS`](chesslib/square.c.md#sqS) + - [`validateListSize`](#validateListSize) + - [`validateUciIsInMovelist`](#validateUciIsInMovelist) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + + +--- +### testKnightMoves +The `testKnightMoves` function tests the generation of legal moves for a knight in various board positions. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board with a lone knight at c3 and generate its moves. + - Validate that the move list contains 8 moves and specific expected moves like 'c3d5', 'c3e4', etc. + - Free the move list memory. + - Initialize a chess board with a knight near the edge at h7 and generate its moves. + - Validate that the move list contains 3 moves and specific expected moves like 'h7g5', 'h7f6', etc. + - Free the move list memory. + - Initialize a chess board with a knight at f6 surrounded by other pieces and generate its moves. + - Validate that the move list contains 6 moves and specific expected moves like 'f6g8', 'f6h5', etc. + - Free the move list memory. +- **Output**: The function does not return any value; it validates the correctness of knight move generation through assertions. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`pmGetKnightMoves`](chesslib/piecemoves.c.md#pmGetKnightMoves) + - [`sqS`](chesslib/square.c.md#sqS) + - [`validateListSize`](#validateListSize) + - [`validateUciIsInMovelist`](#validateUciIsInMovelist) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + + +--- +### testBishopMoves +The `testBishopMoves` function tests the move generation for a bishop in different board scenarios to ensure correctness. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board with a lone bishop on e7 using FEN notation. + - Generate all possible moves for the bishop on e7 and store them in a move list. + - Validate that the move list contains exactly 9 moves and includes specific expected moves. + - Free the move list to release memory. + - Initialize a new board position with a bishop on c3 and some blocking pieces using FEN notation. + - Generate all possible moves for the bishop on c3 and store them in a move list. + - Validate that the move list contains exactly 5 moves and includes specific expected moves. + - Free the move list to release memory. +- **Output**: The function does not return any value; it performs assertions to validate the correctness of bishop move generation. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`pmGetBishopMoves`](chesslib/piecemoves.c.md#pmGetBishopMoves) + - [`sqS`](chesslib/square.c.md#sqS) + - [`validateListSize`](#validateListSize) + - [`validateUciIsInMovelist`](#validateUciIsInMovelist) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + + +--- +### testRookMoves +The `testRookMoves` function tests the generation and validation of legal moves for a rook in different board scenarios. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board with a lone rook on d7 using FEN notation. + - Generate all possible moves for the rook on d7 and store them in a move list. + - Validate that the move list contains exactly 14 moves and includes specific expected moves like 'd7d8', 'd7e7', etc. + - Free the move list to release memory. + - Reinitialize the board with a more complex setup including a rook on e5 surrounded by other pieces. + - Generate all possible moves for the rook on e5 and store them in a move list. + - Validate that the move list contains exactly 9 moves and includes specific expected moves like 'e5e6', 'e5e7', etc. + - Free the move list to release memory. +- **Output**: The function does not return any value; it performs assertions to validate the correctness of rook move generation and will halt execution if any test fails. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`pmGetRookMoves`](chesslib/piecemoves.c.md#pmGetRookMoves) + - [`sqS`](chesslib/square.c.md#sqS) + - [`validateListSize`](#validateListSize) + - [`validateUciIsInMovelist`](#validateUciIsInMovelist) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + + +--- +### testQueenMoves +The `testQueenMoves` function tests the move generation for a queen piece on a chessboard in different scenarios. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board with a lone queen at position b2 using FEN notation. + - Generate all possible moves for the queen at b2 and store them in a move list. + - Validate that the move list contains exactly 23 moves and specific expected moves like b2b3, b2b4, etc. + - Free the move list to release memory. + - Initialize another chess board with a queen at d5 surrounded by other pieces using FEN notation. + - Generate all possible moves for the queen at d5 and store them in a move list. + - Validate that the move list contains exactly 11 moves and specific expected moves like d5e6, d5f7, etc. + - Free the move list to release memory. +- **Output**: The function does not return any value; it validates the correctness of queen move generation through assertions. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`pmGetQueenMoves`](chesslib/piecemoves.c.md#pmGetQueenMoves) + - [`sqS`](chesslib/square.c.md#sqS) + - [`validateListSize`](#validateListSize) + - [`validateUciIsInMovelist`](#validateUciIsInMovelist) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + + +--- +### testKingMoves +The `testKingMoves` function tests the movement generation of a king piece on a chessboard in various scenarios without considering check conditions. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board with a lone king at position c7 and generate possible king moves using [`pmGetKingMoves`](chesslib/piecemoves.c.md#pmGetKingMoves). + - Validate that the generated move list contains 8 moves and includes specific moves like c7c8, c7d8, etc. + - Free the move list memory after validation. + - Initialize a chess board with a king in the corner at position a1 and generate possible king moves. + - Validate that the generated move list contains 3 moves and includes specific moves like a1a2, a1b2, etc. + - Free the move list memory after validation. + - Initialize a chess board with a king surrounded by other pieces at position d5 and generate possible king moves. + - Validate that the generated move list contains 5 moves and includes specific moves like d5e5, d5d4, etc. + - Free the move list memory after validation. +- **Output**: The function does not return any value; it performs assertions to validate the correctness of king move generation. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`pmGetKingMoves`](chesslib/piecemoves.c.md#pmGetKingMoves) + - [`sqS`](chesslib/square.c.md#sqS) + - [`validateListSize`](#validateListSize) + - [`validateUciIsInMovelist`](#validateUciIsInMovelist) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + + +--- +### testIsSquareAttacked +The `testIsSquareAttacked` function tests whether specific squares on a chess board are correctly identified as being attacked by certain pieces. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board with a knight and a pawn using FEN notation and iterate over all 64 squares to check if they are attacked by white pieces, comparing expected and actual results. + - Initialize a chess board with a lone rook using FEN notation and iterate over all 64 squares to check if they are attacked by black pieces, comparing expected and actual results. + - Initialize a chess board with a rook and blocking pieces using FEN notation and iterate over all 64 squares to check if they are attacked by black pieces, comparing expected and actual results. + - If any square's expected attacked status does not match the actual attacked status, a failure message is generated and the test is failed. +- **Output**: The function does not return any value but will halt execution and print an error message if any test fails. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`sqIndex`](chesslib/square.c.md#sqIndex) + - [`sqEq`](chesslib/square.c.md#sqEq) + - [`sqS`](chesslib/square.c.md#sqS) + - [`boardIsSquareAttacked`](chesslib/board.c.md#boardIsSquareAttacked) + - [`sqGetStr`](chesslib/square.c.md#sqGetStr) + - [`failTest`](#failTest) + + +--- +### testIsInCheck +The `testIsInCheck` function tests various chess board configurations to verify if the [`boardIsInCheck`](chesslib/board.c.md#boardIsInCheck) and [`boardIsPlayerInCheck`](chesslib/board.c.md#boardIsPlayerInCheck) functions correctly identify when a king is in check. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board `b` using [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) with a FEN string representing a board where the white king is in check by a black rook. + - Check if [`boardIsInCheck`](chesslib/board.c.md#boardIsInCheck) returns true for the board `b`; if not, call [`failTest`](#failTest) with an error message. + - Check if [`boardIsPlayerInCheck`](chesslib/board.c.md#boardIsPlayerInCheck) returns false for the black player; if not, call [`failTest`](#failTest) with an error message. + - Initialize the board `b` with a FEN string representing the Scholar's mate position where the black king is in check. + - Check if [`boardIsInCheck`](chesslib/board.c.md#boardIsInCheck) returns true for the board `b`; if not, call [`failTest`](#failTest) with an error message. + - Check if [`boardIsPlayerInCheck`](chesslib/board.c.md#boardIsPlayerInCheck) returns false for the white player; if not, call [`failTest`](#failTest) with an error message. + - Initialize the board `b` with a FEN string where checks are blocked by knights, ensuring no king is in check. + - Check if [`boardIsInCheck`](chesslib/board.c.md#boardIsInCheck) returns false for the board `b`; if not, call [`failTest`](#failTest) with an error message. + - Check if [`boardIsPlayerInCheck`](chesslib/board.c.md#boardIsPlayerInCheck) returns false for the black player; if not, call [`failTest`](#failTest) with an error message. +- **Output**: The function does not return any value; it uses [`failTest`](#failTest) to halt execution if any test fails. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`boardIsInCheck`](chesslib/board.c.md#boardIsInCheck) + - [`failTest`](#failTest) + - [`boardIsPlayerInCheck`](chesslib/board.c.md#boardIsPlayerInCheck) + + +--- +### validateBoardEq +The `validateBoardEq` function checks if two chess boards are identical and fails the test with a message if they are not. +- **Inputs**: + - `name`: A string representing the name or description of the test being performed. + - `b1`: A pointer to the first board structure to be compared. + - `b2`: A pointer to the second board structure to be compared. +- **Control Flow**: + - The function calls [`boardEq`](chesslib/board.c.md#boardEq) to compare the two boards `b1` and `b2` for equality. + - If the boards are not equal, it formats a message indicating the test name and that the boards were not the same. + - The function then calls [`failTest`](#failTest) with the formatted message to indicate the test failure and halt execution. +- **Output**: The function does not return a value; it either continues execution if the boards are equal or halts the program with a failure message if they are not. +- **Functions called**: + - [`boardEq`](chesslib/board.c.md#boardEq) + - [`failTest`](#failTest) + + +--- +### testBoardPlayMove +The `testBoardPlayMove` function tests various chess move scenarios on a board to ensure the [`boardPlayMoveInPlace`](chesslib/board.c.md#boardPlayMoveInPlace) function correctly updates the board state. +- **Inputs**: None +- **Control Flow**: + - Create a new chess board `b` using [`boardCreate`](chesslib/board.c.md#boardCreate) and a check board `bCheck`. + - Play the move 1. e4 on `b` and create a board `bCheck` from the FEN string representing the expected board state after the move. + - Validate that `b` and `bCheck` are equal using [`validateBoardEq`](#validateBoardEq). + - Check for fuzziness by comparing `b` with a slightly different board `bCheckFuzzy` and ensure they are not exactly equal but contextually the same. + - Play the move 1... Nf6 on `b` and update `bCheck` to the expected state after the move, then validate equality. + - Test capturing by setting up a board where a rook captures another rook, play the move, and validate the board state. + - Test a bishop capturing a pawn in the opening, play the move, and validate the board state. + - Test a series of moves leading to a draw, play each move, and validate the board state after each move. + - Test castling moves (White O-O, Black O-O, White O-O-O, Black O-O-O), play each move, and validate the board state after each move. + - Test en passant captures for both White and Black, play each move, and validate the board state after each move. + - Free the memory allocated for `b` and `bCheck`. +- **Output**: The function does not return any value; it performs assertions to validate board states and will terminate the program with an error message if any test fails. +- **Functions called**: + - [`boardCreate`](chesslib/board.c.md#boardCreate) + - [`boardPlayMoveInPlace`](chesslib/board.c.md#boardPlayMoveInPlace) + - [`moveSq`](chesslib/move.c.md#moveSq) + - [`sqS`](chesslib/square.c.md#sqS) + - [`boardCreateFromFen`](chesslib/board.c.md#boardCreateFromFen) + - [`validateBoardEq`](#validateBoardEq) + - [`boardEq`](chesslib/board.c.md#boardEq) + - [`failTest`](#failTest) + - [`boardEqContext`](chesslib/board.c.md#boardEqContext) + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`moveFromUci`](chesslib/move.c.md#moveFromUci) + + +--- +### validateUciIsNotInMovelist +The function `validateUciIsNotInMovelist` checks if a given UCI string is absent from a list of moves and fails the test if it is present. +- **Inputs**: + - `list`: A pointer to a `moveList` structure representing the list of moves to be checked. + - `expectedUci`: A character pointer to the UCI string that is expected to be absent from the move list. +- **Control Flow**: + - Iterate over each node in the move list starting from the head. + - For each node, retrieve the UCI string of the move using [`moveGetUci`](chesslib/move.c.md#moveGetUci). + - Compare the retrieved UCI string with the expected UCI string using `strcmp`. + - Free the memory allocated for the retrieved UCI string. + - If the strings match (comparison result is 0), construct an error message indicating the UCI string was found in the list. + - Call [`failTest`](#failTest) with the constructed message to indicate the test failure and exit the function. + - If the loop completes without finding a match, the function ends without any action, indicating the UCI string is not in the list. +- **Output**: The function does not return a value; it either completes silently if the UCI string is not found or calls [`failTest`](#failTest) to terminate the program if the UCI string is found. +- **Functions called**: + - [`moveGetUci`](chesslib/move.c.md#moveGetUci) + - [`failTest`](#failTest) + + +--- +### testBoardGenerateMoves +The `testBoardGenerateMoves` function tests the move generation functionality of a chess board implementation by validating the generated moves against expected moves for various board states. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board to the starting position and generate all possible moves. + - Validate that the generated move list contains 20 moves, including all possible pawn and knight moves from the initial position. + - Free the move list memory after validation. + - Set up a board with a specific FEN string and generate moves, validating the expected number of moves and specific pawn, knight, bishop, queen, and king moves. + - Free the move list memory after validation. + - Set up a board with fewer pieces and generate moves, validating the expected number of moves and specific knight and king moves. + - Free the move list memory after validation. + - Set up a board with a pinned knight and generate moves, validating that only king moves are possible and the knight cannot move. + - Free the move list memory after validation. + - Set up a board where the king is in check and generate moves, validating that only moves that block the check are possible. + - Free the move list memory after validation. +- **Output**: The function does not return any value; it performs assertions to validate the correctness of move generation and will terminate the program if any test fails. +- **Functions called**: + - [`boardInitInPlace`](chesslib/board.c.md#boardInitInPlace) + - [`boardGenerateMoves`](chesslib/board.c.md#boardGenerateMoves) + - [`validateListSize`](#validateListSize) + - [`validateUciIsInMovelist`](#validateUciIsInMovelist) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`validateUciIsNotInMovelist`](#validateUciIsNotInMovelist) + + +--- +### testBoardGenerateMovesCastling +The function `testBoardGenerateMovesCastling` tests the generation of castling moves in a chess game under various board conditions. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board with a specific FEN string and generate possible moves. + - Validate that the expected castling move (e.g., 'e1g1' for white king-side castling) is present in the generated move list. + - Modify the board state to remove castling rights and regenerate moves, then validate that the castling move is absent. + - Repeat the process for black king-side castling, white queen-side castling, and black queen-side castling. + - Test scenarios where castling is not allowed due to the king being in check or squares being attacked. + - Free the move list after each test case to prevent memory leaks. +- **Output**: The function does not return any value; it validates the presence or absence of castling moves in the generated move list and fails the test if the validation does not meet expectations. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`boardGenerateMoves`](chesslib/board.c.md#boardGenerateMoves) + - [`validateUciIsInMovelist`](#validateUciIsInMovelist) + - [`moveListFree`](chesslib/movelist.c.md#moveListFree) + - [`validateUciIsNotInMovelist`](#validateUciIsNotInMovelist) + + +--- +### validateBoardFen +The `validateBoardFen` function checks if a given FEN string correctly represents a chess board state by comparing it to the FEN string generated from the board initialized with the given FEN. +- **Inputs**: + - `fen`: A string representing the Forsyth-Edwards Notation (FEN) of a chess board state. +- **Control Flow**: + - Initialize a `board` structure `b`. + - Call [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) to set up the board `b` using the provided FEN string. + - Generate a FEN string `actualFen` from the board `b` using [`boardGetFen`](chesslib/board.c.md#boardGetFen). + - Call [`validateString`](#validateString) to compare `actualFen` with the input `fen` to ensure they match. + - Free the memory allocated for `actualFen`. +- **Output**: The function does not return a value; it validates the FEN string and may terminate the program if the validation fails. +- **Functions called**: + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + - [`boardGetFen`](chesslib/board.c.md#boardGetFen) + - [`validateString`](#validateString) + + +--- +### testBoardGetFen +The function `testBoardGetFen` validates the correctness of FEN (Forsyth-Edwards Notation) string generation for various chess board states. +- **Inputs**: None +- **Control Flow**: + - The function calls [`validateBoardFen`](#validateBoardFen) with the initial FEN string and several other FEN strings representing different chess positions. + - Each call to [`validateBoardFen`](#validateBoardFen) checks if the FEN string generated from a board matches the expected FEN string. +- **Output**: The function does not return any value; it performs validation checks and may halt the program if a test fails. +- **Functions called**: + - [`validateBoardFen`](#validateBoardFen) + + +--- +### validateBoardIsInsufficientMaterial +The function `validateBoardIsInsufficientMaterial` checks if a chess board has insufficient material for a draw and compares the result with an expected value, failing the test if they do not match. +- **Inputs**: + - `b`: A pointer to a `board` structure representing the current state of the chess board. + - `expected`: A `uint8_t` value representing the expected result of whether the board is a draw by insufficient material (1 for true, 0 for false). +- **Control Flow**: + - Call the function [`boardIsInsufficientMaterial`](chesslib/board.c.md#boardIsInsufficientMaterial) with the board `b` to determine if the board is a draw by insufficient material, storing the result in `actual`. + - Compare `actual` with `expected`. + - If `actual` does not equal `expected`, format a message indicating the discrepancy and call [`failTest`](#failTest) with this message to halt the test. +- **Output**: The function does not return a value; it either completes successfully or calls [`failTest`](#failTest) to indicate a test failure. +- **Functions called**: + - [`boardIsInsufficientMaterial`](chesslib/board.c.md#boardIsInsufficientMaterial) + - [`failTest`](#failTest) + + +--- +### testBoardIsInsufficientMaterial +The function `testBoardIsInsufficientMaterial` tests various chess board configurations to determine if they result in a draw due to insufficient material. +- **Inputs**: None +- **Control Flow**: + - Initialize a chess board `b` using [`boardInitInPlace`](chesslib/board.c.md#boardInitInPlace) and validate it is not insufficient material using [`validateBoardIsInsufficientMaterial`](#validateBoardIsInsufficientMaterial). + - Set up a board with only kings using [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) and validate it is insufficient material. + - Set up a board with a king versus a king and knight, and validate it is insufficient material. + - Set up a board with a king versus a king and two knights, and validate it is not insufficient material. + - Set up a board with a king and bishop versus a king and bishop on different colors, and validate it is not insufficient material. + - Set up a board with a king and bishop versus a king and bishop on the same color, and validate it is insufficient material. + - Set up a board with multiple bishops on the same color versus a king and bishops, and validate it is insufficient material. +- **Output**: The function does not return a value; it uses assertions to validate the test cases. +- **Functions called**: + - [`boardInitInPlace`](chesslib/board.c.md#boardInitInPlace) + - [`validateBoardIsInsufficientMaterial`](#validateBoardIsInsufficientMaterial) + - [`boardInitFromFenInPlace`](chesslib/board.c.md#boardInitFromFenInPlace) + + +--- +### testBoardList +The `testBoardList` function tests the functionality of creating, adding to, retrieving from, and freeing a list of chess boards. +- **Inputs**: None +- **Control Flow**: + - Create a new chess board `b1` using `boardCreate()`. + - Create a new board `b2` by playing a move on `b1` using `boardPlayMove()` with the move 'e2e4'. + - Create another board `b3` by playing a different move on `b1` using `boardPlayMove()` with the move 'c7c5'. + - Create a new board list `l` using `boardListCreate()`. + - Add boards `b1`, `b2`, and `b3` to the list `l` using `boardListAdd()`. + - Check if the first board in the list `l` is `b1` using `boardListGet()`, and call `failTest()` if it is not. + - Check if the second board in the list `l` is `b2` using `boardListGet()`, and call `failTest()` if it is not. + - Check if the third board in the list `l` is `b3` using `boardListGet()`, and call `failTest()` if it is not. + - Free the board list `l` using `boardListFree()`, which also frees all boards in the list. +- **Output**: The function does not return any value; it performs assertions to ensure the board list operations are correct and calls `failTest()` if any assertion fails. +- **Functions called**: + - [`boardCreate`](chesslib/board.c.md#boardCreate) + - [`boardPlayMove`](chesslib/board.c.md#boardPlayMove) + - [`moveFromUci`](chesslib/move.c.md#moveFromUci) + - [`boardListCreate`](chesslib/boardlist.c.md#boardListCreate) + - [`boardListAdd`](chesslib/boardlist.c.md#boardListAdd) + - [`boardListGet`](chesslib/boardlist.c.md#boardListGet) + - [`failTest`](#failTest) + - [`boardListFree`](chesslib/boardlist.c.md#boardListFree) + + +--- +### testSqSetSet +The function `testSqSetSet` tests the functionality of setting specific squares in a bitboard representation of a chessboard using the [`sqSetSet`](chesslib/squareset.c.md#sqSetSet) function. +- **Inputs**: None +- **Control Flow**: + - Initialize a 64-bit unsigned integer `ss` to 0, representing an empty bitboard. + - Call [`sqSetSet`](chesslib/squareset.c.md#sqSetSet) to set the bit corresponding to square 'e4' in `ss` to 1, and check if `ss` equals `0x0000000010000000`; if not, call [`failTest`](#failTest) with an error message. + - Call [`sqSetSet`](chesslib/squareset.c.md#sqSetSet) to set the bit corresponding to square 'd5' in `ss` to 1, and check if `ss` equals `0x0000000810000000`; if not, call [`failTest`](#failTest) with an error message. + - Call [`sqSetSet`](chesslib/squareset.c.md#sqSetSet) to set the bit corresponding to square 'a1' in `ss` to 1, and check if `ss` equals `0x0000000810000001`; if not, call [`failTest`](#failTest) with an error message. + - Call [`sqSetSet`](chesslib/squareset.c.md#sqSetSet) to set the bit corresponding to square 'h8' in `ss` to 1, and check if `ss` equals `0x8000000810000001`; if not, call [`failTest`](#failTest) with an error message. +- **Output**: The function does not return any value; it either completes successfully or calls [`failTest`](#failTest) to indicate a failure in setting the expected bits. +- **Functions called**: + - [`sqSetSet`](chesslib/squareset.c.md#sqSetSet) + - [`sqS`](chesslib/square.c.md#sqS) + - [`failTest`](#failTest) + + +--- +### testSqSetGet +The `testSqSetGet` function tests the correctness of the [`sqSetGet`](chesslib/squareset.c.md#sqSetGet) function by verifying if specific squares in a bitboard are set as expected. +- **Inputs**: None +- **Control Flow**: + - Initialize a bitboard `ss` with a diagonal pattern from a1 to h8. + - Iterate over all 64 squares on the board. + - For each square, calculate the expected value based on whether the square is on the diagonal (file equals rank). + - Retrieve the actual value from the bitboard using [`sqSetGet`](chesslib/squareset.c.md#sqSetGet). + - If the expected and actual values differ, construct an error message and call [`failTest`](#failTest) to indicate a test failure. + - Reinitialize the bitboard `ss` to represent specific files and ranks (c file, f file, 3 rank, and 6 rank). + - Repeat the iteration and comparison process for the new bitboard configuration. +- **Output**: The function does not return a value; it calls [`failTest`](#failTest) if any discrepancies are found between expected and actual values, which halts the program. +- **Functions called**: + - [`sqIndex`](chesslib/square.c.md#sqIndex) + - [`sqSetGet`](chesslib/squareset.c.md#sqSetGet) + - [`sqGetStr`](chesslib/square.c.md#sqGetStr) + - [`failTest`](#failTest) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/c_cpp_export_test/src/tests.h.md b/driver_docs/c_cpp_export_test/src/tests.h.md new file mode 100644 index 0000000..899ecd4 --- /dev/null +++ b/driver_docs/c_cpp_export_test/src/tests.h.md @@ -0,0 +1,278 @@ + + + + + +The `tests.h` file defines function prototypes for various test cases related to a Chess implementation in C, including tests for squares, moves, boards, and FEN generation. + +# Purpose +This C header file defines a series of function prototypes for testing various components of a chess game implementation. It is designed to facilitate unit testing by providing declarations for functions that test different aspects of the chess program, such as board creation, move generation, and piece movement. The file includes functions for testing specific chess functionalities, including square properties, move creation and validation, board state management, and special conditions like castling and insufficient material for a draw. The [`failTest`](#failTest) function is particularly notable as it is intended to halt the program when a test fails, optionally providing a message. Overall, this file serves as a blueprint for implementing comprehensive tests to ensure the correctness and reliability of a chess game coded in C. +# Function Declarations (Public API) + +--- +### failTest +Fails the current test and terminates the program. +- **Description**: This function is used to indicate a failure in the currently running test by printing a failure message to the standard error stream and then terminating the program. It should be called when a test condition fails and the test cannot continue. The function can optionally include a custom message to provide additional context about the failure. It is important to note that this function will halt the entire program, so it should be used judiciously within a testing framework. +- **Inputs**: + - `msg`: A pointer to a null-terminated string containing a custom failure message. If this parameter is NULL, no additional message is printed beyond the default failure notification. The caller retains ownership of the string, and it must be a valid pointer or NULL. +- **Output**: None +- **See also**: [`failTest`](tests.c.md#failTest) (Implementation) + + +--- +### validateString +Compares two strings and fails the test if they are not equal. +- **Description**: Use this function to verify that two strings are identical during a test. It is intended for use in a testing environment where the program should halt if the strings do not match. The function compares the provided strings and, if they differ, it constructs a detailed error message and calls `failTest` to terminate the test. This function should be used when exact string matching is critical for the test's success. +- **Inputs**: + - `actual`: A pointer to the actual string to be compared. Must not be null, as passing a null pointer will result in undefined behavior. + - `expected`: A pointer to the expected string to be compared against. Must not be null, as passing a null pointer will result in undefined behavior. +- **Output**: None +- **See also**: [`validateString`](tests.c.md#validateString) (Implementation) + + +--- +### testSqI +Tests the square indexing function for correctness. +- **Description**: This function is used to verify the correctness of the square indexing function `sqI` by iterating over all possible chessboard squares and checking if the function returns the expected file and rank. It is intended to be used in a testing environment to ensure that the `sqI` function behaves as expected for all valid chessboard positions. The function will call `failTest` with an appropriate message if any discrepancy is found, halting the test execution. This function should be used when validating the implementation of square indexing in a chess program. +- **Inputs**: None +- **Output**: None +- **See also**: [`testSqI`](tests.c.md#testSqI) (Implementation) + + +--- +### testSqS +Tests the conversion of chess square strings to square objects. +- **Description**: This function is used to verify that the conversion from chess square notation strings (e.g., "a1", "h8") to square objects is functioning correctly. It iterates over all possible squares on a chessboard, converts each square's string representation to a square object, and checks if the resulting object's file and rank match the expected values. If any conversion does not match the expected result, the test fails and halts execution with an error message. This function is typically used during development to ensure the correctness of the square conversion logic. +- **Inputs**: None +- **Output**: None +- **See also**: [`testSqS`](tests.c.md#testSqS) (Implementation) + + +--- +### testSqGetStr +Tests the string representation of chessboard squares. +- **Description**: This function is used to verify that the string representation of each square on a chessboard is correctly generated. It iterates over all possible squares on an 8x8 chessboard, constructs the expected string representation for each square, and validates it against the actual string returned by the `sqGetStr` function. This function is typically used in a testing context to ensure the correctness of the `sqGetStr` function, and it assumes that the chessboard is indexed from 1 to 8 for both ranks and files. +- **Inputs**: None +- **Output**: None +- **See also**: [`testSqGetStr`](tests.c.md#testSqGetStr) (Implementation) + + +--- +### testSqIsDark +Tests if the function correctly identifies dark squares on a chessboard. +- **Description**: This function is used to verify the correctness of the `sqIsDark` function, which determines if a given square on a chessboard is dark. It iterates over all squares on a standard 8x8 chessboard, checking if each square is correctly identified as dark or light. The function expects the `sqIsDark` function to return 1 for dark squares and 0 for light squares, starting with a1 as dark. If a discrepancy is found, it calls `failTest` with a descriptive message. This function is typically used in a testing environment to ensure the accuracy of the chessboard square color identification logic. +- **Inputs**: None +- **Output**: None +- **See also**: [`testSqIsDark`](tests.c.md#testSqIsDark) (Implementation) + + +--- +### testMoveCreate +Tests the creation of chess moves. +- **Description**: This function is used to verify the correct creation of chess moves within the testing framework. It should be called to ensure that moves are generated accurately according to the expected parameters. This function is part of a suite of tests for a chess implementation and is intended to validate the move creation logic by comparing the generated moves against expected values. It is typically used during development to catch errors in move generation logic. +- **Inputs**: None +- **Output**: None +- **See also**: [`testMoveCreate`](tests.c.md#testMoveCreate) (Implementation) + + +--- +### testMoveFromUci +Test the conversion of UCI strings to move objects. +- **Description**: This function is used to verify that UCI (Universal Chess Interface) strings are correctly converted into move objects within the chess implementation. It should be called during the testing phase to ensure that the move conversion logic is functioning as expected. The function does not take any parameters and does not return a value. It is intended to be used as part of a suite of tests to validate the chess engine's move handling capabilities. +- **Inputs**: None +- **Output**: None +- **See also**: [`testMoveFromUci`](tests.c.md#testMoveFromUci) (Implementation) + + +--- +### testMoveGetUci +Tests the conversion of chess moves to UCI notation. +- **Description**: This function is used to verify that the conversion of chess moves to UCI (Universal Chess Interface) notation is performed correctly. It is a part of a suite of tests for a chess implementation in C. The function checks specific move scenarios, including normal moves and promotion moves, to ensure that the UCI strings generated match the expected values. This function is intended for use in a testing environment and should be called when validating the correctness of move-to-UCI conversion functionality. +- **Inputs**: None +- **Output**: None +- **See also**: [`testMoveGetUci`](tests.c.md#testMoveGetUci) (Implementation) + + +--- +### testMoveList +Tests the functionality of move list operations. +- **Description**: This function is designed to test the creation, addition, retrieval, and validation of moves within a move list in a chess implementation. It creates a move list, adds several moves to it, retrieves them, and checks their correctness by comparing their UCI (Universal Chess Interface) string representations against expected values. This function is useful for ensuring that the move list operations are functioning correctly and that moves are stored and retrieved accurately. It should be used in a testing environment where the correctness of move handling is critical. The function will halt the program if any discrepancies are found, indicating a failure in the move list operations. +- **Inputs**: None +- **Output**: None +- **See also**: [`testMoveList`](tests.c.md#testMoveList) (Implementation) + + +--- +### testBoardCreate +Validates the initial state of a newly created chess board. +- **Description**: This function is used to verify that a newly created chess board is initialized correctly according to standard chess rules. It checks that all pieces are in their correct starting positions, the current player is set to white, all castling rights are enabled, the en passant target square is invalid, the half-move clock is set to zero, and the move number is set to one. This function is typically used in a testing context to ensure that the board creation logic is functioning as expected. It will halt the program if any of these conditions are not met. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardCreate`](tests.c.md#testBoardCreate) (Implementation) + + +--- +### testBoardCreateFromFen +Tests the creation of a chess board from a FEN string. +- **Description**: This function is used to verify that a chess board can be correctly initialized from a given FEN (Forsyth-Edwards Notation) string. It checks that the board's pieces, current player, castling rights, en passant target square, half-move clock, and full move number are set as expected. This function is typically used in a testing context to ensure that the board creation logic is functioning correctly. It is important to note that this function will halt the program if the board is not created correctly or if any of the assertions fail. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardCreateFromFen`](tests.c.md#testBoardCreateFromFen) (Implementation) + + +--- +### testBoardEq +Fails the test for board equality. +- **Description**: This function is intended to test the equality of two chess boards, but it currently fails the test and halts the program with a message indicating that it is not yet implemented. It is a placeholder for future implementation and should not be used in its current state for any testing purposes. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardEq`](tests.c.md#testBoardEq) (Implementation) + + +--- +### testPawnMoves +Tests the functionality of pawn move generation in various board scenarios. +- **Description**: This function is used to verify the correctness of pawn move generation in a chess game implementation. It sets up different board scenarios using the Forsyth-Edwards Notation (FEN) and checks the generated pawn moves against expected results. The function covers scenarios such as pawns on their starting rank, pawns with capture opportunities, blocked pawns, promotion possibilities, and en passant captures. It is intended to be used in a testing environment to ensure that the pawn move generation logic is functioning as expected. The function does not return any value and is expected to halt the program if any test fails. +- **Inputs**: None +- **Output**: None +- **See also**: [`testPawnMoves`](tests.c.md#testPawnMoves) (Implementation) + + +--- +### testKnightMoves +Tests the generation of legal knight moves on a chessboard. +- **Description**: This function is used to verify the correctness of knight move generation in a chess implementation. It sets up various board positions with knights and checks if the generated moves match the expected legal moves for those positions. This function is typically used in a testing environment to ensure that the knight move generation logic is functioning correctly. It assumes that the board and move list management functions are working as expected and does not return any value or modify any input parameters. +- **Inputs**: None +- **Output**: None +- **See also**: [`testKnightMoves`](tests.c.md#testKnightMoves) (Implementation) + + +--- +### testBishopMoves +Tests the move generation for bishops on a chessboard. +- **Description**: This function is used to verify the correctness of bishop move generation in a chess implementation. It sets up specific board positions and checks that the generated moves for a bishop match the expected set of moves. This function is typically used during development to ensure that the bishop move generation logic is functioning correctly. It is expected to be called in a testing environment where the program can be halted if the test fails. The function does not return any value or modify any input parameters. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBishopMoves`](tests.c.md#testBishopMoves) (Implementation) + + +--- +### testRookMoves +Tests the move generation for rooks on a chessboard. +- **Description**: This function is used to verify the correctness of rook move generation in a chess implementation. It sets up specific board positions and checks that the generated moves for a rook match the expected legal moves. This function is typically used during development to ensure that the move generation logic for rooks is functioning correctly. It is not intended for use in production code, but rather as part of a test suite to validate the chess engine's behavior. +- **Inputs**: None +- **Output**: None +- **See also**: [`testRookMoves`](tests.c.md#testRookMoves) (Implementation) + + +--- +### testQueenMoves +Tests the move generation for a queen on a chessboard. +- **Description**: This function is used to verify the correctness of move generation for a queen piece on a chessboard. It sets up specific board positions and checks that the generated moves for a queen match the expected set of moves. This function is typically used in a testing context to ensure that the move generation logic for queens is functioning correctly. It assumes that the board and move generation functions are correctly implemented and available. The function does not return any value but will halt the program if the test conditions are not met. +- **Inputs**: None +- **Output**: None +- **See also**: [`testQueenMoves`](tests.c.md#testQueenMoves) (Implementation) + + +--- +### testKingMoves +Tests the generation of king moves on a chess board. +- **Description**: This function is used to verify the correctness of king move generation in a chess game implementation. It sets up various board positions and checks if the generated moves for the king are as expected. This function is useful for ensuring that the move generation logic for the king is functioning correctly, including edge cases such as the king being in a corner or surrounded by other pieces. It is important to note that the function does not consider whether the king's moves place it in check, as the underlying move generation function does not account for move legality in terms of check. +- **Inputs**: None +- **Output**: None +- **See also**: [`testKingMoves`](tests.c.md#testKingMoves) (Implementation) + + +--- +### testIsSquareAttacked +Tests if squares on a chess board are correctly identified as attacked. +- **Description**: This function is used to verify the correctness of the boardIsSquareAttacked function by setting up specific board positions and checking if the function correctly identifies attacked squares. It is intended for use in a testing environment to ensure that the logic for determining attacked squares is functioning as expected. The function sets up various board scenarios using the Forsyth-Edwards Notation (FEN) and compares the actual results of boardIsSquareAttacked against expected outcomes. It is crucial for validating the accuracy of attack detection in a chess engine. +- **Inputs**: None +- **Output**: None +- **See also**: [`testIsSquareAttacked`](tests.c.md#testIsSquareAttacked) (Implementation) + + +--- +### testIsInCheck +Tests if a chess board is correctly identified as being in check. +- **Description**: This function is used to verify the correctness of check detection logic in a chess board implementation. It sets up various board states using the Forsyth-Edwards Notation (FEN) and checks if the board is correctly identified as being in check or not. This function is intended for use in a testing environment to ensure that the check detection functions, such as `boardIsInCheck` and `boardIsPlayerInCheck`, behave as expected under different scenarios. It is crucial for validating the integrity of the chess engine's check detection capabilities. +- **Inputs**: None +- **Output**: None +- **See also**: [`testIsInCheck`](tests.c.md#testIsInCheck) (Implementation) + + +--- +### testBoardPlayMove +Tests the functionality of playing moves on a chess board. +- **Description**: This function is used to verify the correctness of move execution on a chess board by simulating various chess scenarios, including standard moves, captures, castling, and en passant. It ensures that the board state after each move matches the expected state, as represented by FEN strings. This function is typically called during the testing phase to validate the move execution logic of a chess engine. It is important to ensure that the board is correctly initialized and that the move logic is implemented accurately before using this function. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardPlayMove`](tests.c.md#testBoardPlayMove) (Implementation) + + +--- +### testBoardGenerateMoves +Tests the move generation functionality of a chess board. +- **Description**: This function is used to verify the correctness of move generation in a chess board implementation. It performs a series of tests on different board states to ensure that the generated moves match expected results. This function is typically used during development to validate that the move generation logic is functioning correctly. It is important to run this test after any changes to the move generation code to ensure no regressions have been introduced. The function does not take any parameters and does not return a value, as it is intended solely for testing purposes. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardGenerateMoves`](tests.c.md#testBoardGenerateMoves) (Implementation) + + +--- +### testBoardGenerateMovesCastling +Tests castling move generation in various board scenarios. +- **Description**: This function is used to verify the correct generation of castling moves under different board conditions in a chess game. It should be called to ensure that the move generation logic correctly handles castling rights, checks, and other constraints that affect castling. The function simulates various board states and checks if the expected castling moves are present or absent in the generated move list. It is intended for use in a testing environment to validate the chess engine's handling of castling rules. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardGenerateMovesCastling`](tests.c.md#testBoardGenerateMovesCastling) (Implementation) + + +--- +### testBoardGetFen +Tests the FEN string generation functionality of the chess board. +- **Description**: This function is used to verify that the chess board's FEN (Forsyth-Edwards Notation) string generation is functioning correctly. It is intended for use in a testing environment to ensure that the board can accurately represent its state in FEN format. The function does not take any parameters and does not return a value. It is expected to be called within a test suite where the board's FEN generation is being validated against known FEN strings. The function will halt the program if the FEN generation does not match the expected values, indicating a failure in the test. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardGetFen`](tests.c.md#testBoardGetFen) (Implementation) + + +--- +### testBoardIsInsufficientMaterial +Tests the board state for draw conditions due to insufficient material. +- **Description**: This function is used to verify that a chess board state is correctly identified as a draw due to insufficient material. It sets up various board configurations and checks if the function responsible for detecting insufficient material correctly identifies these scenarios. This function is typically used in a testing environment to ensure the accuracy of the insufficient material detection logic. It should be called when validating the draw detection capabilities of a chess engine or application. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardIsInsufficientMaterial`](tests.c.md#testBoardIsInsufficientMaterial) (Implementation) + + +--- +### testBoardList +Tests the functionality of board list operations. +- **Description**: This function is used to verify the correct behavior of board list operations, including creation, addition, retrieval, and freeing of board objects within a list. It ensures that boards can be added to a list and retrieved in the correct order, and that the list and its contents are properly freed. This function is typically used in a testing environment to validate the integrity of board list management in a chess application. +- **Inputs**: None +- **Output**: None +- **See also**: [`testBoardList`](tests.c.md#testBoardList) (Implementation) + + +--- +### testSqSetSet +Tests the functionality of setting squares in a square set. +- **Description**: This function is used to verify that the `sqSetSet` function correctly sets specific squares in a square set represented by a 64-bit integer. It is intended for use in a testing environment to ensure that the `sqSetSet` function behaves as expected when setting various squares. The function checks multiple scenarios by setting different squares and comparing the resulting square set against expected values. If any of the checks fail, the function calls `failTest` to indicate a failure in the test. +- **Inputs**: None +- **Output**: None +- **See also**: [`testSqSetSet`](tests.c.md#testSqSetSet) (Implementation) + + +--- +### testSqSetGet +Tests the functionality of retrieving square set values. +- **Description**: This function is used to verify the correctness of the square set retrieval logic in a chess implementation. It checks whether specific squares on a chessboard, represented by a bitboard, are correctly identified as being set or not. The function is intended to be used in a testing context to ensure that the square set retrieval function, `sqSetGet`, behaves as expected for various board configurations. It is important to call this function in a controlled test environment where the results can be validated and any discrepancies can be addressed. +- **Inputs**: None +- **Output**: None +- **See also**: [`testSqSetGet`](tests.c.md#testSqSetGet) (Implementation) + + + +--- +Made with ❤️ by [Driver](https://www.driver.ai/) \ No newline at end of file diff --git a/driver_docs/cpp_src.driver.md b/driver_docs/cpp_src.driver.md deleted file mode 100644 index c5fa884..0000000 --- a/driver_docs/cpp_src.driver.md +++ /dev/null @@ -1,27 +0,0 @@ - -## Files -- **[bishop.cpp](cpp_src/bishop.cpp.driver.md)**: The `bishop.cpp` file implements the Bishop class for a chess game, defining its movement rules, value, and display representation. -- **[bishop.h](cpp_src/bishop.h.driver.md)**: The `bishop.h` file defines a class representing a chess bishop piece, including methods for creating a bishop, determining its value, checking legal moves, and displaying the piece. -- **[board.cpp](cpp_src/board.cpp.driver.md)**: The `board.cpp` file implements a chess board for the ChessProject, including methods to check if paths are clear for vertical, horizontal, and diagonal movements, as well as displaying the board state. -- **[board.h](cpp_src/board.h.driver.md)**: The `board.h` file defines a `Board` class representing an 8x8 game board, including methods for accessing squares, checking clear paths, and displaying the board. -- **[game.cpp](cpp_src/game.cpp.driver.md)**: The `game.cpp` file in the `c_cpp_export_test` codebase implements the setup and management of a chess game, including initializing pieces and players, and determining the next player to move. -- **[game.h](cpp_src/game.h.driver.md)**: The `game.h` file defines a class for representing a game of chess, including methods for initializing the game and managing player turns. -- **[king.cpp](cpp_src/king.cpp.driver.md)**: The `king.cpp` file implements the behavior of a King piece in a chess game, including its movement rules and display functionality. -- **[king.h](cpp_src/king.h.driver.md)**: The `king.h` file defines a `King` class representing a chess king piece, including methods for creating the piece, determining its value, checking legal moves, and displaying it. -- **[knight.cpp](cpp_src/knight.cpp.driver.md)**: The `knight.cpp` file implements the behavior of a Knight piece in a chess game, including its movement rules and display representation. -- **[knight.h](cpp_src/knight.h.driver.md)**: The `knight.h` file defines a `Knight` class representing a chess knight piece, including methods for determining legal moves, getting its point value, and displaying the piece. -- **[main.cpp](cpp_src/main.cpp.driver.md)**: The `main.cpp` file contains the main program logic for playing a chess game, including initializing the game, displaying the board, and handling player moves. -- **[pawn.cpp](cpp_src/pawn.cpp.driver.md)**: The `pawn.cpp` file implements the behavior of a pawn piece in a chess game, including movement, promotion to a queen, and display functionality. -- **[pawn.h](cpp_src/pawn.h.driver.md)**: The `pawn.h` file defines a `Pawn` class representing a chess pawn piece, including methods for setting its location, determining legal moves, and displaying the piece. -- **[piece.cpp](cpp_src/piece.cpp.driver.md)**: The `piece.cpp` file implements the behavior of a chess piece, including movement validation and capturing logic, within a chess game project. -- **[piece.h](cpp_src/piece.h.driver.md)**: The `piece.h` file defines an abstract class for a game piece, including methods for movement, location, and color attributes. -- **[player.cpp](cpp_src/player.cpp.driver.md)**: The `player.cpp` file implements the `Player` class for a chess game, handling player actions such as making moves, checking for check status, capturing pieces, and calculating scores. -- **[player.h](cpp_src/player.h.driver.md)**: The `player.h` file defines a `Player` class for a chess game, including methods for making moves, checking if the player is in check, capturing pieces, and accessing player attributes like name, color, and score. -- **[queen.cpp](cpp_src/queen.cpp.driver.md)**: The `queen.cpp` file implements the Queen chess piece, including its movement logic and display functionality, for a chess project. -- **[queen.h](cpp_src/queen.h.driver.md)**: The `queen.h` file defines a `Queen` class representing a chess queen piece, including methods for determining legal moves, getting its point value, and displaying the piece. -- **[restrictedPiece.cpp](cpp_src/restrictedPiece.cpp.driver.md)**: The `restrictedPiece.cpp` file defines the `RestrictedPiece` class for a chess project, which extends the `Piece` class to include functionality for tracking whether the piece has moved. -- **[restrictedPiece.h](cpp_src/restrictedPiece.h.driver.md)**: The `restrictedPiece.h` file defines a `RestrictedPiece` class for a chess piece that tracks whether it has been moved, inheriting from the `Piece` class. -- **[rook.cpp](cpp_src/rook.cpp.driver.md)**: The `rook.cpp` file implements the behavior of a Rook chess piece, including its movement validation and display, within the `ChessProject`. -- **[rook.h](cpp_src/rook.h.driver.md)**: The `rook.h` file defines a class representing a chess rook piece, including methods for determining legal moves, getting its point value, and displaying the piece. -- **[square.cpp](cpp_src/square.cpp.driver.md)**: The `square.cpp` file implements the `Square` class for a chess project, managing the position and occupancy of a chessboard square. -- **[square.h](cpp_src/square.h.driver.md)**: The `square.h` file defines a `Square` class for a game board, including methods to manage its position and the piece occupying it. diff --git a/driver_docs/cpp_src/bishop.cpp.driver.md b/driver_docs/cpp_src/bishop.cpp.driver.md deleted file mode 100644 index 0870f18..0000000 --- a/driver_docs/cpp_src/bishop.cpp.driver.md +++ /dev/null @@ -1,91 +0,0 @@ -# Purpose -This C++ code defines the implementation of a [`Bishop`](#BishopBishop) class, which is part of a chess game project. The code provides narrow functionality specific to the behavior and characteristics of a bishop piece in chess. It is a C++ source file intended to be compiled as part of a larger chess application, likely alongside other piece classes. The [`Bishop`](#BishopBishop) class inherits from a `Piece` class, indicating a class hierarchy for different chess pieces. It includes methods to determine the bishop's value, check if a move is valid based on diagonal movement, and display the bishop's representation. The code relies on external components such as a `Board` class and a `Square` class, suggesting it is part of a modular design where each piece type has its own implementation file. -# Imports and Dependencies - ---- -- `bishop.h` - - -# Data Structures - ---- -### Bishop -- **Description**: [See definition](bishop.h.driver.md#Bishop) -- **Member Functions**: - - [`Bishop::Bishop`](#BishopBishop) - - [`Bishop::~Bishop`](#BishopBishop) - - [`Bishop::value`](#Bishopvalue) - - [`Bishop::canMoveTo`](#BishopcanMoveTo) - - [`Bishop::display`](#Bishopdisplay) -- **Inherits from**: - - `Piece` - -**Methods** - ---- -#### Bishop::Bishop -The `Bishop` constructor initializes a Bishop object with a specified color by calling the base class `Piece` constructor. -- **Inputs**: - - `isWhite`: A boolean indicating whether the Bishop is white (true) or black (false). -- **Control Flow**: - - The constructor `Bishop::Bishop(bool isWhite)` is called with a boolean parameter `isWhite`. - - The constructor initializes the Bishop object by calling the base class `Piece` constructor with the `isWhite` parameter. -- **Output**: - - There is no return value as this is a constructor for initializing a Bishop object. -- **See also**: [`Bishop`](bishop.h.driver.md#Bishop) (Data Structure) - - ---- -#### Bishop::\~Bishop -The destructor for the Bishop class is a default destructor that performs no specific actions. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is called when a Bishop object is destroyed. - - No specific actions or resource deallocations are performed within the destructor. -- **Output**: - - There is no output or return value from the destructor. -- **See also**: [`Bishop`](bishop.h.driver.md#Bishop) (Data Structure) - - ---- -#### Bishop::value -The `value` function returns the point value of a Bishop piece in a chess game. -- **Inputs**: - - None -- **Control Flow**: - - The function is a constant member function of the `Bishop` class, indicating it does not modify the state of the object. - - It directly returns the integer value `3`, which represents the point value of a Bishop in chess. -- **Output**: - - The function returns an integer value of `3`, representing the point value of a Bishop piece. -- **See also**: [`Bishop`](bishop.h.driver.md#Bishop) (Data Structure) - - ---- -#### Bishop::canMoveTo -The `canMoveTo` function determines if a Bishop can legally move to a specified square by checking if the path is a clear diagonal. -- **Inputs**: - - `location`: A reference to a `Square` object representing the target location to which the Bishop intends to move. -- **Control Flow**: - - Initialize a boolean variable `validMove` to `false`. - - Check if the path from the Bishop's current location to the target `location` is a clear diagonal using `Board::getBoard()->isClearDiagonal`. - - If the path is clear, set `validMove` to `true`. - - Return the value of `validMove`. -- **Output**: - - A boolean value indicating whether the Bishop can legally move to the specified square. -- **See also**: [`Bishop`](bishop.h.driver.md#Bishop) (Data Structure) - - ---- -#### Bishop::display -The `display` function outputs the color and type of the Bishop piece to the console. -- **Inputs**: - - None -- **Control Flow**: - - The function uses the `cout` stream to output the Bishop's color followed by the letter 'B'. -- **Output**: - - The function outputs a string to the console that represents the Bishop piece, consisting of its color and the letter 'B'. -- **See also**: [`Bishop`](bishop.h.driver.md#Bishop) (Data Structure) - - - diff --git a/driver_docs/cpp_src/bishop.h.driver.md b/driver_docs/cpp_src/bishop.h.driver.md deleted file mode 100644 index 5f3a51f..0000000 --- a/driver_docs/cpp_src/bishop.h.driver.md +++ /dev/null @@ -1,26 +0,0 @@ -# Purpose -The provided code is a C++ header file (`bishop.h`) that defines a class representing a chess bishop piece, indicating narrow functionality specific to chess game logic. This class, `Bishop`, inherits from a base class `Piece`, suggesting it is part of a larger chess application or library. The class includes a constructor to initialize the bishop with a color, a destructor, and several member functions: `value()` to return the bishop's point value, `canMoveTo()` to determine if a move to a specified square is legal, and `display()` to output the bishop's representation. The inclusion of other headers like `piece.h` and `square.h` implies dependencies on other components of the chess game, such as the general piece behavior and board squares. -# Imports and Dependencies - ---- -- `iostream` -- `piece.h` -- `square.h` - - -# Data Structures - ---- -### Bishop -- **Type**: `class` -- **Description**: The `Bishop` class represents a chess bishop piece in a chess game, inheriting from the `Piece` class. It includes a constructor to initialize the bishop with a specified color, a destructor, and methods to determine the bishop's point value, check if a move to a specific square is legal based on diagonal movement, and display the bishop's representation. The class encapsulates the behavior specific to a bishop piece, such as its movement rules and display format. -- **Member Functions**: - - [`Bishop::Bishop`](bishop.cpp.driver.md#BishopBishop) - - [`Bishop::~Bishop`](bishop.cpp.driver.md#BishopBishop) - - [`Bishop::value`](bishop.cpp.driver.md#Bishopvalue) - - [`Bishop::canMoveTo`](bishop.cpp.driver.md#BishopcanMoveTo) - - [`Bishop::display`](bishop.cpp.driver.md#Bishopdisplay) -- **Inherits from**: - - [`Piece`](piece.h.driver.md#Piece) - - diff --git a/driver_docs/cpp_src/board.cpp.driver.md b/driver_docs/cpp_src/board.cpp.driver.md deleted file mode 100644 index adfecf4..0000000 --- a/driver_docs/cpp_src/board.cpp.driver.md +++ /dev/null @@ -1,188 +0,0 @@ -# Purpose -The `board.cpp` file is part of a Chess project and is responsible for implementing the [`Board`](#BoardBoard) class, which models the chessboard. This file provides the core functionality for managing the board's state, including the setup and teardown of the board's squares, checking the clarity of paths (vertical, horizontal, and diagonal) between squares, and displaying the board's current state. The [`Board`](#BoardBoard) class uses a singleton pattern, as evidenced by the `getBoard()` method, which ensures that only one instance of the board exists throughout the application. This is achieved by maintaining a static pointer `_theBoard` to the single instance of the [`Board`](#BoardBoard). - -The file includes several key methods that facilitate chess gameplay. The constructor initializes the board by creating a grid of `Square` objects, while the destructor ensures proper memory management by deleting these objects. The [`isClearVertical`](#BoardisClearVertical), [`isClearHorizontal`](#BoardisClearHorizontal), and [`isClearDiagonal`](#BoardisClearDiagonal) methods are crucial for determining if a path between two squares is unobstructed, which is essential for validating moves in chess. The [`isEndRow`](#BoardisEndRow) method checks if a square is in the first or last row, which can be important for pawn promotion. Finally, the [`display`](#Boarddisplay) method outputs the current state of the board to a given output stream, showing the position of pieces and the board's layout. This file is integral to the chess game's functionality, providing both the data structure and the logic needed to manage the board's state and interactions. -# Imports and Dependencies - ---- -- `board.h` -- `piece.h` - - -# Global Variables - ---- -### \_theBoard -- **Type**: `Board*` -- **Description**: `_theBoard` is a static pointer to a `Board` object, used to implement the singleton pattern for the `Board` class. It is initialized to `NULL` and is intended to ensure that only one instance of the `Board` class exists throughout the program. -- **Use**: This variable is used to store and provide access to the single instance of the `Board` class, ensuring that all operations on the board are performed on the same instance. - - -# Data Structures - ---- -### Board -- **Description**: [See definition](board.h.driver.md#Board) -- **Member Functions**: - - [`Board::Board`](#BoardBoard) - - [`Board::~Board`](#BoardBoard) - - [`Board::getBoard`](#BoardgetBoard) - - [`Board::squareAt`](#BoardsquareAt) - - [`Board::isClearVertical`](#BoardisClearVertical) - - [`Board::isClearHorizontal`](#BoardisClearHorizontal) - - [`Board::isClearDiagonal`](#BoardisClearDiagonal) - - [`Board::isEndRow`](#BoardisEndRow) - - [`Board::display`](#Boarddisplay) - -**Methods** - ---- -#### Board::Board -The `Board` constructor initializes an 8x8 chess board by creating `Square` objects for each position on the board. -- **Inputs**: - - None -- **Control Flow**: - - The constructor iterates over a fixed dimension (8x8) using two nested loops. - - For each pair of indices (i, j), it creates a new `Square` object with coordinates (i, j). - - The newly created `Square` object is assigned to the corresponding position in the `_squares` array. -- **Output**: - - The function does not return any value as it is a constructor. -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - ---- -#### Board::\~Board -The destructor `~Board` deallocates memory for the 2D array of `Square` objects in the `Board` class. -- **Inputs**: - - None -- **Control Flow**: - - Iterates over each row of the `_squares` 2D array using a loop with index `i`. - - For each row, iterates over each column using a loop with index `j` and deletes the `Square` object at `_squares[i][j]`. - - After deleting all `Square` objects in a row, deletes the row itself using `delete[] _squares[i]`. - - Finally, deletes the entire `_squares` array using `delete[] _squares`. -- **Output**: - - The function does not return any value as it is a destructor. -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - ---- -#### Board::getBoard -The `getBoard` function implements the singleton pattern to ensure only one instance of the `Board` class is created and returned. -- **Inputs**: - - None -- **Control Flow**: - - Check if the static member `_theBoard` is `NULL`. - - If `_theBoard` is `NULL`, create a new instance of `Board` and assign it to `_theBoard`. - - Return the `_theBoard` instance. -- **Output**: - - Returns a pointer to the single instance of the `Board` class. -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - ---- -#### Board::squareAt -The `squareAt` function retrieves a pointer to a `Square` object located at the specified coordinates on the board. -- **Inputs**: - - `x`: The x-coordinate of the square on the board, representing the column index. - - `y`: The y-coordinate of the square on the board, representing the row index. -- **Control Flow**: - - Access the 2D array `_squares` using the provided x and y coordinates. - - Return the `Square` pointer located at `_squares[x][y]`. -- **Output**: - - A pointer to the `Square` object located at the specified (x, y) coordinates on the board. -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - ---- -#### Board::isClearVertical -The `isClearVertical` function checks if the vertical path between two squares on a chess board is clear of any occupied squares. -- **Inputs**: - - `from`: A reference to the starting `Square` object. - - `to`: A reference to the ending `Square` object. -- **Control Flow**: - - Initialize pointers `start` and `end` to determine the order of squares based on their y-values. - - Assign `start` to the square with the smaller y-value and `end` to the other square. - - Check if the x-values of `start` and `end` are equal to ensure no horizontal movement; if not, set `valid` to false. - - If the x-values are equal, iterate over the y-values between `start` and `end`. - - For each square in the vertical path, check if it is occupied using the [`squareAt`](#BoardsquareAt) method. - - If any square is occupied, set `valid` to false. - - Return the boolean `valid` indicating if the path is clear. -- **Output**: - - A boolean value indicating whether the vertical path between the two squares is clear (true) or not (false). -- **Functions called**: - - [`Board::squareAt`](#BoardsquareAt) -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - ---- -#### Board::isClearHorizontal -The `isClearHorizontal` function checks if the horizontal path between two squares on a chess board is clear of any occupied squares. -- **Inputs**: - - `from`: A reference to the starting `Square` object. - - `to`: A reference to the ending `Square` object. -- **Control Flow**: - - Initialize pointers `start` and `end` to determine the direction of horizontal traversal based on the x-values of `from` and `to`. - - Check if there is any vertical movement by comparing the y-values of `start` and `end`; if they differ, set `valid` to false. - - If there is no vertical movement, iterate over the horizontal path between `start` and `end` (excluding the endpoints) to check if any square is occupied. - - If any square in the path is occupied, set `valid` to false. - - Return the value of `valid`, which indicates whether the path is clear. -- **Output**: - - A boolean value indicating whether the horizontal path between the two squares is clear (true) or not (false). -- **Functions called**: - - [`Board::squareAt`](#BoardsquareAt) -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - ---- -#### Board::isClearDiagonal -The `isClearDiagonal` function checks if the path between two squares on a chess board is a clear diagonal, meaning no pieces are blocking the path. -- **Inputs**: - - `from`: A reference to the starting Square object on the board. - - `to`: A reference to the ending Square object on the board. -- **Control Flow**: - - Initialize a boolean variable `valid` to true, which will be used to determine if the diagonal path is clear. - - Calculate the translation in the x and y directions between the `from` and `to` squares. - - Determine the direction of movement in both x and y directions by setting `xDir` and `yDir` to 1 or -1 based on the sign of the translations. - - Check if the absolute values of the x and y translations are equal; if not, set `valid` to false as the path is not diagonal. - - If the path is diagonal, iterate over each square along the diagonal path (excluding the starting and ending squares). - - For each square along the path, check if it is occupied using the [`squareAt`](#BoardsquareAt) method; if any square is occupied, set `valid` to false. - - Return the value of `valid`, indicating whether the diagonal path is clear. -- **Output**: - - A boolean value indicating whether the diagonal path between the two squares is clear (true) or blocked (false). -- **Functions called**: - - [`Board::squareAt`](#BoardsquareAt) -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - ---- -#### Board::isEndRow -The `isEndRow` function checks if a given square is located on the first or last row of the board. -- **Inputs**: - - `location`: A reference to a `Square` object representing the location on the board to be checked. -- **Control Flow**: - - Retrieve the Y-coordinate of the `location` square using `location.getY()`. - - Check if the Y-coordinate is equal to 0 or `_DIMENSION - 1` (indicating the first or last row of the board). - - Return `true` if the Y-coordinate matches either condition, otherwise return `false`. -- **Output**: - - A boolean value indicating whether the square is on the first or last row of the board. -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - ---- -#### Board::display -The `display` function outputs the current state of the chess board to a given output stream, showing the position of pieces on an 8x8 grid. -- **Inputs**: - - `outStream`: An output stream (such as `std::cout`) where the board's display will be printed. -- **Control Flow**: - - The function begins by printing the column labels (a to h) and a separator line to the output stream. - - It then iterates over each row of the board from top to bottom (black pieces at the top, white at the bottom). - - For each row, it prints the row number, followed by the contents of each square in that row, separated by vertical bars. - - If a square is occupied by a piece, it calls the `display` method of the piece to print its representation; otherwise, it prints two spaces to indicate an empty square. - - After printing all squares in a row, it prints the row number again and a separator line. - - Finally, it prints the column labels again at the bottom of the board. -- **Output**: - - The function does not return a value; it outputs the board's state to the provided output stream. -- **See also**: [`Board`](board.h.driver.md#Board) (Data Structure) - - - diff --git a/driver_docs/cpp_src/board.h.driver.md b/driver_docs/cpp_src/board.h.driver.md deleted file mode 100644 index 03f426d..0000000 --- a/driver_docs/cpp_src/board.h.driver.md +++ /dev/null @@ -1,33 +0,0 @@ -# Purpose -The provided code is a C++ header file, `board.h`, which defines the `Board` class. This class represents a game board, specifically an 8x8 grid, which is a common size for games like chess or checkers. The `Board` class provides a narrow but essential functionality focused on managing and interacting with the game board's squares. It includes methods to access specific squares, check for clear paths between squares in vertical, horizontal, and diagonal directions, and determine if a square is on an ending row. These functionalities are crucial for implementing game logic that involves movement and positioning on the board. - -The `Board` class is designed as a singleton, indicated by the private constructor and the static method `getBoard()`, which ensures that only one instance of the board exists. The class also includes a destructor and a method to display the board's current state to an output stream. The private attributes include a static pointer `_theBoard` to hold the singleton instance and a 2D array `_squares` to represent the board's squares. The class relies on the `Square` class, which is included via the `square.h` header, suggesting that each square on the board is an instance of the `Square` class. This header file is intended to be included in other parts of the program where board functionality is required, and it defines a public API for interacting with the board. -# Imports and Dependencies - ---- -- `ostream` -- `square.h` - - -# Data Structures - ---- -### Board -- **Type**: `class` -- **Members**: - - `_theBoard`: A static pointer to the singleton instance of the Board class. - - `_DIMENSION`: A constant integer representing the dimension of the board, set to 8. - - `_squares`: A 2D array of pointers to Square objects representing the board's squares. -- **Description**: The `Board` class represents a game board, specifically an 8x8 grid, typically used for games like chess or checkers. It is implemented as a singleton, ensuring only one instance of the board exists. The board is composed of `Square` objects, each of which can be accessed via the `squareAt` method. The class provides methods to check if paths between squares are clear in vertical, horizontal, or diagonal directions, and to determine if a square is on an end row. The board can be displayed using the `display` method, which outputs the current state of the board to a given output stream. -- **Member Functions**: - - [`Board::Board`](board.cpp.driver.md#BoardBoard) - - [`Board::~Board`](board.cpp.driver.md#BoardBoard) - - [`Board::getBoard`](board.cpp.driver.md#BoardgetBoard) - - [`Board::squareAt`](board.cpp.driver.md#BoardsquareAt) - - [`Board::isClearVertical`](board.cpp.driver.md#BoardisClearVertical) - - [`Board::isClearHorizontal`](board.cpp.driver.md#BoardisClearHorizontal) - - [`Board::isClearDiagonal`](board.cpp.driver.md#BoardisClearDiagonal) - - [`Board::isEndRow`](board.cpp.driver.md#BoardisEndRow) - - [`Board::display`](board.cpp.driver.md#Boarddisplay) - - diff --git a/driver_docs/cpp_src/game.cpp.driver.md b/driver_docs/cpp_src/game.cpp.driver.md deleted file mode 100644 index 90c9c81..0000000 --- a/driver_docs/cpp_src/game.cpp.driver.md +++ /dev/null @@ -1,133 +0,0 @@ -# Purpose -The `game.cpp` file is a core component of a chess application, specifically responsible for managing the overall game state and the interactions between players and pieces on the board. This file defines the [`Game`](#GameGame) class, which encapsulates the initialization and management of chess pieces and players. The [`Game`](#GameGame) class constructor and destructor handle the creation and cleanup of game resources, such as dynamically allocated chess pieces and player objects. The [`initialize`](#Gameinitialize) method sets up the chessboard by placing all pieces in their starting positions and associating them with their respective players, ensuring that the game is ready to begin. - -The file includes several headers for different chess piece types, such as `queen.h`, `bishop.h`, `knight.h`, `rook.h`, `pawn.h`, and `king.h`, indicating that it relies on these classes to represent the various chess pieces. The [`Game`](#GameGame) class also manages the turn-based logic of the game through methods like [`getNextPlayer`](#GamegetNextPlayer) and [`opponentOf`](#GameopponentOf), which determine the current and opposing players. The use of static member variables for players and piece collections suggests that the [`Game`](#GameGame) class maintains a single instance of the game state, which is shared across the application. Overall, this file provides a focused implementation of the chess game's core mechanics, serving as a central point for game initialization and player management. -# Imports and Dependencies - ---- -- `game.h` -- `queen.h` -- `bishop.h` -- `knight.h` -- `rook.h` -- `pawn.h` -- `king.h` -- `square.h` - - -# Global Variables - ---- -### player1 -- **Type**: `Player*` -- **Description**: `player1` is a global pointer variable of type `Player*` that is part of the `Game` class. It is used to represent the first player in the chess game, typically the player controlling the white pieces. -- **Use**: `player1` is initialized in the `initialize` method to point to a new `Player` object representing the white player, and it is used to determine the current player and their opponent during the game. - - ---- -### player2 -- **Type**: `Player*` -- **Description**: The `player2` variable is a global pointer to a `Player` object representing the second player in the game, typically the player controlling the black pieces in a chess game. It is initialized to `NULL` and later assigned a `Player` object in the `initialize` method of the `Game` class. -- **Use**: `player2` is used to store and manage the state and actions of the second player in the chess game. - - ---- -### nextPlayer -- **Type**: `Player*` -- **Description**: The `nextPlayer` variable is a pointer to a `Player` object, which represents the player who is to make the next move in the game. It is initialized to `NULL` and later set to point to one of the two players in the game, either `player1` or `player2`. The variable is used to keep track of whose turn it is to play. -- **Use**: This variable is used to determine and update the current player whose turn it is to make a move in the chess game. - - -# Data Structures - ---- -### Game -- **Description**: [See definition](game.h.driver.md#Game) -- **Member Functions**: - - [`Game::Game`](#GameGame) - - [`Game::~Game`](#GameGame) - - [`Game::initialize`](#Gameinitialize) - - [`Game::getNextPlayer`](#GamegetNextPlayer) - - [`Game::opponentOf`](#GameopponentOf) - -**Methods** - ---- -#### Game::Game -The `Game` constructor initializes a new instance of the `Game` class without performing any specific actions. -- **Inputs**: - - None -- **Control Flow**: - - The constructor is defined but does not contain any code or logic, indicating it performs no operations when a `Game` object is instantiated. -- **Output**: - - There is no output or return value from this constructor as it is a default constructor with an empty body. -- **See also**: [`Game`](game.h.driver.md#Game) (Data Structure) - - ---- -#### Game::\~Game -The destructor `~Game` cleans up dynamically allocated memory for chess pieces and players when a `Game` object is destroyed. -- **Inputs**: - - None -- **Control Flow**: - - Iterates over the `whitePieces` set, deleting each `Piece` pointer and then clears the set. - - Iterates over the `blackPieces` set, deleting each `Piece` pointer and then clears the set. - - Deletes the `player1` and `player2` objects. -- **Output**: - - This function does not return any value as it is a destructor. -- **See also**: [`Game`](game.h.driver.md#Game) (Data Structure) - - ---- -#### Game::initialize -The `initialize` function sets up a new chess game by creating and positioning all pieces on the board, assigning them to players, and determining the starting player. -- **Inputs**: - - None -- **Control Flow**: - - Initialize two sets to hold white and black pieces. - - Create and position a white Queen at (3, 0) and a black Queen at (3, 7), then add them to their respective sets. - - Create and position two white Bishops at (2, 0) and (5, 0) and two black Bishops at (2, 7) and (5, 7), then add them to their respective sets. - - Create and position two white Knights at (1, 0) and (6, 0) and two black Knights at (1, 7) and (6, 7), then add them to their respective sets. - - Create and position two white Rooks at (0, 0) and (7, 0) and two black Rooks at (0, 7) and (7, 7), then add them to their respective sets. - - Create and position eight white Pawns on row 1 and eight black Pawns on row 6, then add them to their respective sets. - - Create and position a white King at (4, 0) and a black King at (4, 7), then add them to their respective sets. - - Create a white player with the white King and white pieces, and a black player with the black King and black pieces. - - Set the next player to be the black player. -- **Output**: - - The function does not return any value; it initializes the game state by setting up the board and players. -- **See also**: [`Game`](game.h.driver.md#Game) (Data Structure) - - ---- -#### Game::getNextPlayer -The `getNextPlayer` function updates and returns the player whose turn is next in the game. -- **Inputs**: - - None -- **Control Flow**: - - The function calls [`opponentOf`](#GameopponentOf) with the current `nextPlayer` to determine the opponent player. - - The `nextPlayer` is updated to the opponent player returned by [`opponentOf`](#GameopponentOf). - - The updated `nextPlayer` is returned. -- **Output**: - - The function returns a pointer to the `Player` object representing the next player whose turn it is. -- **Functions called**: - - [`Game::opponentOf`](#GameopponentOf) -- **See also**: [`Game`](game.h.driver.md#Game) (Data Structure) - - ---- -#### Game::opponentOf -The `opponentOf` function returns the opponent player of the given player in a chess game. -- **Inputs**: - - `player`: A reference to a Player object for whom the opponent is to be determined. -- **Control Flow**: - - Declare a pointer to Player named `opponent`. - - Check if the name of the input player matches the name of `player1`. - - If the names match, set `opponent` to `player2`. - - If the names do not match, set `opponent` to `player1`. - - Return the `opponent` pointer. -- **Output**: - - A pointer to the Player object representing the opponent of the given player. -- **See also**: [`Game`](game.h.driver.md#Game) (Data Structure) - - - diff --git a/driver_docs/cpp_src/game.h.driver.md b/driver_docs/cpp_src/game.h.driver.md deleted file mode 100644 index 478b475..0000000 --- a/driver_docs/cpp_src/game.h.driver.md +++ /dev/null @@ -1,34 +0,0 @@ -# Purpose -The provided code is a C++ header file named `game.h`, which defines a class `Game` that represents a game of chess. This file is part of a broader chess application, as indicated by its inclusion of other headers such as `board.h`, `piece.h`, and `player.h`. The `Game` class encapsulates the core functionality required to manage a chess game, including initializing the game, determining the next player to move, and identifying the opponent of a given player. The class is designed with both public and private members, where the public interface provides essential methods for game management, and the private section contains attributes that maintain the state of the game, such as the players and the sets of pieces for each side. - -The `Game` class is structured to be used as a singleton, as suggested by its static methods and attributes, which implies that only one instance of the game is intended to be active at any time. The static methods `initialize`, `getNextPlayer`, and `opponentOf` provide the primary interface for interacting with the game state, while the private constructor prevents direct instantiation of the class. This design pattern ensures controlled access to the game state and enforces the logic necessary for managing a chess game. The use of static attributes like `player1`, `player2`, `nextPlayer`, and the sets of pieces (`whitePieces` and `blackPieces`) further supports this singleton approach, centralizing the game state within the class itself. -# Imports and Dependencies - ---- -- `set` -- `iostream` -- `board.h` -- `piece.h` -- `player.h` - - -# Data Structures - ---- -### Game -- **Type**: `class` -- **Members**: - - `player1`: A static pointer to the first player, representing the white player in the game. - - `player2`: A static pointer to the second player, representing the black player in the game. - - `nextPlayer`: A static pointer to the player whose turn is next. - - `whitePieces`: A static set containing pointers to all the white pieces in the game. - - `blackPieces`: A static set containing pointers to all the black pieces in the game. -- **Description**: The `Game` class represents a game of chess, managing the players and their respective pieces. It includes static methods to initialize the game, determine the next player, and find the opponent of a given player. The class maintains static attributes for the two players, the next player to move, and sets of pieces for both white and black sides. The destructor ensures proper cleanup of dynamically allocated pieces and players. -- **Member Functions**: - - [`Game::Game`](game.cpp.driver.md#GameGame) - - [`Game::~Game`](game.cpp.driver.md#GameGame) - - [`Game::initialize`](game.cpp.driver.md#Gameinitialize) - - [`Game::getNextPlayer`](game.cpp.driver.md#GamegetNextPlayer) - - [`Game::opponentOf`](game.cpp.driver.md#GameopponentOf) - - diff --git a/driver_docs/cpp_src/king.cpp.driver.md b/driver_docs/cpp_src/king.cpp.driver.md deleted file mode 100644 index aede0c8..0000000 --- a/driver_docs/cpp_src/king.cpp.driver.md +++ /dev/null @@ -1,94 +0,0 @@ -# Purpose -The `king.cpp` file is part of a chess game project, specifically implementing the behavior and characteristics of the King chess piece. This file provides a narrow functionality focused on defining the movement rules and display characteristics of the King piece within the game. The class [`King`](#KingKing) inherits from `RestrictedPiece`, indicating that it is a specialized type of chess piece with specific movement restrictions. The constructor initializes the King with a color attribute, and the destructor is defined but does not perform any specific actions. - -The most important technical components of this file include the [`canMoveTo`](#KingcanMoveTo) method, which encapsulates the logic for determining valid moves for the King piece. This method checks if the King can move one square in any direction—forward, backward, sideways, or diagonally—consistent with the rules of chess. The [`value`](#Kingvalue) method returns a constant value of 0, which might be used in the context of the game to represent the King's value in terms of gameplay strategy. The [`display`](#Kingdisplay) method outputs the King's representation on the board, using the color attribute to distinguish between white and black pieces. This file is intended to be part of a larger chess application, likely interacting with other components such as the board and other piece classes. -# Imports and Dependencies - ---- -- `king.h` - - -# Data Structures - ---- -### King -- **Description**: [See definition](king.h.driver.md#King) -- **Member Functions**: - - [`King::King`](#KingKing) - - [`King::~King`](#KingKing) - - [`King::value`](#Kingvalue) - - [`King::canMoveTo`](#KingcanMoveTo) - - [`King::display`](#Kingdisplay) -- **Inherits from**: - - `RestrictedPiece` - -**Methods** - ---- -#### King::King -The King constructor initializes a King object by calling the constructor of its parent class, RestrictedPiece, with a boolean indicating the piece's color. -- **Inputs**: - - `isWhite`: A boolean value indicating whether the King piece is white (true) or black (false). -- **Control Flow**: - - The constructor takes a boolean parameter 'isWhite'. - - It calls the constructor of the parent class, RestrictedPiece, passing 'isWhite' to it. -- **Output**: - - There is no return value as this is a constructor for the King class. -- **See also**: [`King`](king.h.driver.md#King) (Data Structure) - - ---- -#### King::\~King -The destructor for the King class is a default destructor that performs no specific actions. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is defined but contains no code, indicating it performs no operations when a King object is destroyed. -- **Output**: - - There is no output or return value from this destructor. -- **See also**: [`King`](king.h.driver.md#King) (Data Structure) - - ---- -#### King::value -The `value` function returns the point value of the King piece, which is 0. -- **Inputs**: - - None -- **Control Flow**: - - The function simply returns the integer value 0. -- **Output**: - - The function returns an integer value representing the point value of the King piece, which is 0. -- **See also**: [`King`](king.h.driver.md#King) (Data Structure) - - ---- -#### King::canMoveTo -The `canMoveTo` function determines if a King chess piece can legally move to a specified square based on standard chess rules for a King's movement. -- **Inputs**: - - `location`: A reference to a `Square` object representing the target location to which the King is attempting to move. -- **Control Flow**: - - Initialize `validMove` to `false` to track if the move is valid. - - Calculate `translationX` as the difference between the target square's x-coordinate and the King's current x-coordinate. - - Calculate `translationY` as the difference between the target square's y-coordinate and the King's current y-coordinate. - - Check if the move is one square forward or backward by verifying if `abs(translationY) == 1` and `translationX == 0`; if true, set `validMove` to `true`. - - Check if the move is one square sideways by verifying if `abs(translationX) == 1` and `translationY == 0`; if true, set `validMove` to `true`. - - Check if the move is one square diagonally by verifying if `abs(translationX) == 1` and `abs(translationY) == 1`; if true, set `validMove` to `true`. - - Return the value of `validMove`, indicating whether the move is valid. -- **Output**: - - A boolean value indicating whether the King can legally move to the specified square. -- **See also**: [`King`](king.h.driver.md#King) (Data Structure) - - ---- -#### King::display -The `display` function outputs the color and symbol of the King piece to the console. -- **Inputs**: - - None -- **Control Flow**: - - The function uses the `cout` stream to output the color of the King piece followed by the character 'K'. -- **Output**: - - The function outputs a string to the console, which is the color of the King piece concatenated with the letter 'K'. -- **See also**: [`King`](king.h.driver.md#King) (Data Structure) - - - diff --git a/driver_docs/cpp_src/king.h.driver.md b/driver_docs/cpp_src/king.h.driver.md deleted file mode 100644 index e6fcca7..0000000 --- a/driver_docs/cpp_src/king.h.driver.md +++ /dev/null @@ -1,27 +0,0 @@ -# Purpose -The provided code is a C++ header file, `king.h`, which defines a class representing a chess king piece. This class, `King`, inherits from a base class `RestrictedPiece`, suggesting that it is part of a larger chess game application where different types of chess pieces are modeled. The `King` class encapsulates the behavior and characteristics specific to a king piece in chess, such as its ability to move and its point value. The class provides a constructor to initialize a king piece with a specified color, a destructor, and several member functions that define its functionality. - -The `King` class includes methods such as `value()`, which returns the point value of the king piece, and `canMoveTo(Square& location)`, which determines if the king can legally move to a specified square on the chessboard. Additionally, the `display()` method is provided to output the representation of the king piece, likely for visualization purposes in the game. This header file is intended to be included in other parts of the application, where the functionality of the king piece is required, and it defines a public API for interacting with king objects within the chess game. -# Imports and Dependencies - ---- -- `iostream` -- `restrictedPiece.h` - - -# Data Structures - ---- -### King -- **Type**: `class` -- **Description**: The `King` class represents a chess king piece and inherits from the `RestrictedPiece` class. It includes a constructor to initialize the king with a specified color, a destructor, and several member functions. The `value` function returns the point value of the king, which is set to 0 in this implementation. The `canMoveTo` function determines if the king can legally move to a specified square, allowing moves one square in any direction (forward, backward, sideways, or diagonally). The `display` function outputs the king's representation, which includes its color and the letter 'K'. -- **Member Functions**: - - [`King::King`](king.cpp.driver.md#KingKing) - - [`King::~King`](king.cpp.driver.md#KingKing) - - [`King::value`](king.cpp.driver.md#Kingvalue) - - [`King::canMoveTo`](king.cpp.driver.md#KingcanMoveTo) - - [`King::display`](king.cpp.driver.md#Kingdisplay) -- **Inherits from**: - - [`RestrictedPiece`](restrictedPiece.h.driver.md#RestrictedPiece) - - diff --git a/driver_docs/cpp_src/knight.cpp.driver.md b/driver_docs/cpp_src/knight.cpp.driver.md deleted file mode 100644 index 1062b74..0000000 --- a/driver_docs/cpp_src/knight.cpp.driver.md +++ /dev/null @@ -1,95 +0,0 @@ -# Purpose -The provided C++ source code file, `knight.cpp`, is part of a larger project, likely a chess game, as indicated by the file name and the project name `ChessProject`. This file specifically implements the behavior of the Knight piece in a chess game. It defines the [`Knight`](#KnightKnight) class, which inherits from a base class `Piece`, suggesting a class hierarchy where different chess pieces share common functionality. The [`Knight`](#KnightKnight) class constructor initializes the piece with a color, and the destructor is defined but does not perform any specific actions, which is typical when no dynamic memory or resources need to be released. - -The [`Knight`](#KnightKnight) class provides several key functionalities. The `value()` method returns the integer value `3`, which is a common convention in chess programming to represent the relative strength of a Knight. The `canMoveTo(Square& location)` method implements the unique movement logic of the Knight, which can move in an "L" shape: two squares in one direction and one square perpendicular, or vice versa. This method checks the validity of a move based on these rules. The `display()` method outputs the Knight's representation, which includes its color and the letter "N", typically used to denote a Knight in chess notation. This file is likely part of a broader collection of files, each implementing different chess pieces, and it does not define a public API or external interface, as it is intended to be used internally within the chess game application. -# Imports and Dependencies - ---- -- `knight.h` - - -# Data Structures - ---- -### Knight -- **Description**: [See definition](knight.h.driver.md#Knight) -- **Member Functions**: - - [`Knight::Knight`](#KnightKnight) - - [`Knight::~Knight`](#KnightKnight) - - [`Knight::value`](#Knightvalue) - - [`Knight::canMoveTo`](#KnightcanMoveTo) - - [`Knight::display`](#Knightdisplay) -- **Inherits from**: - - `Piece` - -**Methods** - ---- -#### Knight::Knight -The `Knight` constructor initializes a `Knight` object by calling the `Piece` constructor with a boolean indicating the piece's color. -- **Inputs**: - - `isWhite`: A boolean value indicating whether the knight is white (true) or black (false). -- **Control Flow**: - - The constructor `Knight::Knight(bool isWhite)` is called with a boolean parameter `isWhite`. - - The constructor initializes the `Knight` object by invoking the constructor of its base class `Piece` with the `isWhite` parameter. -- **Output**: - - There is no return value as this is a constructor for initializing a `Knight` object. -- **See also**: [`Knight`](knight.h.driver.md#Knight) (Data Structure) - - ---- -#### Knight::\~Knight -The destructor for the Knight class is a default destructor that performs no specific actions. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is defined but contains no code, indicating it performs no operations when a Knight object is destroyed. -- **Output**: - - There is no output or return value from this destructor. -- **See also**: [`Knight`](knight.h.driver.md#Knight) (Data Structure) - - ---- -#### Knight::value -The `value` function returns the fixed point value of a Knight piece in chess. -- **Inputs**: - - None -- **Control Flow**: - - The function directly returns the integer value 3, representing the point value of a Knight in chess. -- **Output**: - - The function returns an integer value of 3, which is the standard point value assigned to a Knight in chess. -- **See also**: [`Knight`](knight.h.driver.md#Knight) (Data Structure) - - ---- -#### Knight::canMoveTo -The `canMoveTo` function determines if a Knight piece can legally move to a specified square based on chess movement rules for a Knight. -- **Inputs**: - - `location`: A reference to a `Square` object representing the target location to which the Knight is attempting to move. -- **Control Flow**: - - Initialize `validMove` to `false`. - - Calculate `translationX` as the difference between the target square's x-coordinate and the Knight's current x-coordinate. - - Calculate `translationY` as the difference between the target square's y-coordinate and the Knight's current y-coordinate. - - Check if the move is valid by verifying if the absolute values of `translationY` and `translationX` match the Knight's L-shaped movement pattern (1 square in one direction and 2 squares in the perpendicular direction). - - If either of the conditions for a valid Knight move is met, set `validMove` to `true`. - - Return the value of `validMove`. -- **Output**: - - A boolean value indicating whether the Knight can legally move to the specified square. -- **See also**: [`Knight`](knight.h.driver.md#Knight) (Data Structure) - - ---- -#### Knight::display -The `display` function outputs the color and type of the Knight piece to the console. -- **Inputs**: - - None -- **Control Flow**: - - The function accesses the `_color` attribute of the Knight object, which indicates the color of the piece (e.g., 'W' for white or 'B' for black). - - It concatenates the color with the character 'N', which represents the Knight piece in chess notation. - - The concatenated string is then output to the console using `cout`. -- **Output**: - - The function outputs a string to the console that represents the Knight piece, including its color and type. -- **See also**: [`Knight`](knight.h.driver.md#Knight) (Data Structure) - - - diff --git a/driver_docs/cpp_src/knight.h.driver.md b/driver_docs/cpp_src/knight.h.driver.md deleted file mode 100644 index db63ecb..0000000 --- a/driver_docs/cpp_src/knight.h.driver.md +++ /dev/null @@ -1,26 +0,0 @@ -# Purpose -The provided code is a C++ header file (`knight.h`) that defines a class representing a chess knight piece, indicating narrow functionality specific to chess game logic. This class, `Knight`, inherits from a base class `Piece`, suggesting it is part of a larger chess game framework. The header file declares several member functions: a constructor to initialize the knight with a color, a destructor, a method to return the knight's point value, a method to check if a move to a specified square is legal, and a method to display the knight. The inclusion of other headers, `square.h` and `piece.h`, implies dependencies on other components of the chess game, such as board squares and general piece behavior. -# Imports and Dependencies - ---- -- `iostream` -- `square.h` -- `piece.h` - - -# Data Structures - ---- -### Knight -- **Type**: `class` -- **Description**: The `Knight` class represents a chess knight piece and inherits from the `Piece` class. It includes a constructor to initialize the knight with a specified color, a destructor, and several member functions. The `value` function returns the point value of the knight, which is 3. The `canMoveTo` function determines if the knight can legally move to a given square based on the unique L-shaped movement pattern of a knight in chess. The `display` function outputs the knight's representation, which includes its color and the letter 'N' for knight. -- **Member Functions**: - - [`Knight::Knight`](knight.cpp.driver.md#KnightKnight) - - [`Knight::~Knight`](knight.cpp.driver.md#KnightKnight) - - [`Knight::value`](knight.cpp.driver.md#Knightvalue) - - [`Knight::canMoveTo`](knight.cpp.driver.md#KnightcanMoveTo) - - [`Knight::display`](knight.cpp.driver.md#Knightdisplay) -- **Inherits from**: - - [`Piece`](piece.h.driver.md#Piece) - - diff --git a/driver_docs/cpp_src/main.cpp.driver.md b/driver_docs/cpp_src/main.cpp.driver.md deleted file mode 100644 index 51db3f3..0000000 --- a/driver_docs/cpp_src/main.cpp.driver.md +++ /dev/null @@ -1,30 +0,0 @@ -# Purpose -This code is a C++ executable, specifically the main entry point for a chess game application. It provides narrow functionality focused on initializing and managing the flow of a chess game. The code includes headers for "game.h" and "board.h," suggesting that it relies on external classes or functions defined in these files to handle game logic and board representation. The main function initializes the game, displays the initial board state, and enters a loop where players alternate making moves. It ensures that only valid moves are accepted, prompting the player to try again if an invalid move is attempted, and updates the board display after each move. This code is designed to be run as a standalone application, facilitating a text-based chess game experience. -# Imports and Dependencies - ---- -- `iostream` -- `game.h` -- `board.h` - - -# Functions - ---- -### main -The `main` function initializes and runs a continuous loop for a chess game where players alternate making moves until a valid move is made. -- **Inputs**: - - `argc`: The number of command-line arguments passed to the program. - - `argv`: An array of C-style strings representing the command-line arguments. -- **Control Flow**: - - Initialize a pointer to `Player` as `currentPlayer` to keep track of the current player. - - Call `Game::initialize()` to set up the initial state of the chess game. - - Display the initial state of the board using `Board::getBoard()->display(cout)`. - - Enter an infinite loop to alternate between players making moves. - - Within the loop, get the next player using `Game::getNextPlayer()` and assign it to `currentPlayer`. - - Attempt to make a move with `currentPlayer->makeMove()`, and if the move is invalid, output an error message and prompt the player to try again. - - After a valid move, display the updated state of the board using `Board::getBoard()->display(cout)`. -- **Output**: - - The function returns an integer value of 0, indicating successful execution of the program. - - diff --git a/driver_docs/cpp_src/pawn.cpp.driver.md b/driver_docs/cpp_src/pawn.cpp.driver.md deleted file mode 100644 index d23c62e..0000000 --- a/driver_docs/cpp_src/pawn.cpp.driver.md +++ /dev/null @@ -1,136 +0,0 @@ -# Purpose -The provided C++ source code file, `pawn.cpp`, is part of a chess game implementation, specifically handling the behavior and rules associated with the pawn piece. This file defines the [`Pawn`](#PawnPawn) class, which inherits from a `RestrictedPiece` class, indicating that it has specific movement constraints. The [`Pawn`](#PawnPawn) class encapsulates the unique movement and promotion rules of a pawn in chess, such as moving forward one square, capturing diagonally, and the special two-square initial move. A significant feature of this class is its ability to promote a pawn to a queen when it reaches the opponent's end of the board, achieved through a delegate pattern where the pawn delegates its behavior to a `Queen` object upon promotion. - -The [`Pawn`](#PawnPawn) class includes several key methods: [`moveTo`](#PawnmoveTo), which handles the logic for moving the pawn and promoting it if necessary; [`canMoveTo`](#PawncanMoveTo), which checks if a move is valid according to pawn movement rules; and [`display`](#Pawndisplay), which outputs the pawn's representation on the board. The class also manages its location on the board and interacts with other components like `Square` and `Board` to determine valid moves and promotions. This file is part of a broader chess project, and it provides specific functionality for the pawn piece, integrating with other components like `queen.h` and `board.h` to ensure cohesive gameplay mechanics. -# Imports and Dependencies - ---- -- `pawn.h` -- `queen.h` -- `board.h` - - -# Data Structures - ---- -### Pawn -- **Description**: [See definition](pawn.h.driver.md#Pawn) -- **Member Functions**: - - [`Pawn::Pawn`](#PawnPawn) - - [`Pawn::~Pawn`](#PawnPawn) - - [`Pawn::setLocation`](#PawnsetLocation) - - [`Pawn::value`](#Pawnvalue) - - [`Pawn::moveTo`](#PawnmoveTo) - - [`Pawn::canMoveTo`](#PawncanMoveTo) - - [`Pawn::display`](#Pawndisplay) -- **Inherits from**: - - `RestrictedPiece` - -**Methods** - ---- -#### Pawn::Pawn -The `Pawn` constructor initializes a `Pawn` object, setting its color and initializing its delegate to NULL. -- **Inputs**: - - `isWhite`: A boolean indicating whether the pawn is white (true) or black (false). -- **Control Flow**: - - The constructor initializes the `Pawn` object by calling the constructor of its parent class `RestrictedPiece` with the `isWhite` parameter. - - It sets the private member `_delegate` to `NULL`, indicating that the pawn has not been promoted to another piece. -- **Output**: - - The function does not return any value as it is a constructor. -- **See also**: [`Pawn`](pawn.h.driver.md#Pawn) (Data Structure) - - ---- -#### Pawn::\~Pawn -The destructor for the Pawn class deallocates memory for the delegate piece if it exists. -- **Inputs**: - - None -- **Control Flow**: - - Check if the _delegate pointer is not null. - - If _delegate is not null, delete the memory allocated for _delegate. -- **Output**: - - This destructor does not return any value as it is responsible for cleaning up resources when a Pawn object is destroyed. -- **See also**: [`Pawn`](pawn.h.driver.md#Pawn) (Data Structure) - - ---- -#### Pawn::setLocation -The `setLocation` function sets the location of a `Pawn` object by calling the `setLocation` method of its base class `Piece`. -- **Inputs**: - - `location`: A pointer to a `Square` object representing the new location for the `Pawn`. -- **Control Flow**: - - The function takes a `Square*` as an argument, which represents the new location for the `Pawn`. - - It calls the `setLocation` method of the base class `Piece` with the provided `location` argument. -- **Output**: - - The function does not return any value. -- **See also**: [`Pawn`](pawn.h.driver.md#Pawn) (Data Structure) - - ---- -#### Pawn::value -The `value` function returns the point value of a Pawn piece in a chess game. -- **Inputs**: - - None -- **Control Flow**: - - The function is a constant member function of the `Pawn` class, indicating it does not modify any member variables. - - It simply returns the integer value `1`, representing the point value of a Pawn in chess. -- **Output**: - - The function returns an integer value of `1`, representing the point value of a Pawn. -- **See also**: [`Pawn`](pawn.h.driver.md#Pawn) (Data Structure) - - ---- -#### Pawn::moveTo -The `moveTo` function attempts to move a pawn to a specified square, handling both normal pawn movement and promotion to a queen if applicable. -- **Inputs**: - - `byPlayer`: A reference to the Player object attempting to move the pawn. - - `to`: A reference to the Square object representing the destination square for the pawn. -- **Control Flow**: - - Initialize a boolean variable `valid` to false to track the validity of the move. - - Check if the pawn has been promoted by verifying if `_delegate` is not null. - - If promoted, use the delegate piece's `moveTo` method to determine move validity. - - If the move is valid, update the pawn's current and new square occupiers and set the new location. - - If not promoted, use the `RestrictedPiece`'s `moveTo` method to attempt a normal pawn move. - - If the move is valid and the pawn reaches the opponent's end row, promote the pawn to a queen by creating a new `Queen` object and setting it as the delegate. - - Return the boolean `valid` indicating whether the move was successful. -- **Output**: - - Returns a boolean value indicating whether the move was successful. -- **Functions called**: - - [`Pawn::setLocation`](#PawnsetLocation) -- **See also**: [`Pawn`](pawn.h.driver.md#Pawn) (Data Structure) - - ---- -#### Pawn::canMoveTo -The `canMoveTo` function determines if a pawn can legally move to a specified square based on its current position, movement rules, and whether it has been promoted. -- **Inputs**: - - `location`: A reference to a `Square` object representing the target location to which the pawn is attempting to move. -- **Control Flow**: - - Initialize `validMove` to false and calculate the translation in x and y directions from the current location to the target location. - - Check if the pawn has been promoted to another piece (delegate); if so, use the delegate's movement rules to determine if the move is valid. - - If the pawn is not promoted, adjust the translation values for black pieces to account for their movement direction on the board. - - Check if the move is a valid one-square forward move to an unoccupied square and set `validMove` to true if so. - - Check if the move is a valid two-square forward move from the starting position to an unoccupied square along a clear vertical path and set `validMove` to true if so. - - Check if the move is a valid capture move to an occupied square on an adjacent diagonal and set `validMove` to true if so. - - Return the value of `validMove`. -- **Output**: - - A boolean value indicating whether the pawn can legally move to the specified square. -- **See also**: [`Pawn`](pawn.h.driver.md#Pawn) (Data Structure) - - ---- -#### Pawn::display -The `display` function outputs the visual representation of a Pawn, either by delegating to another piece or displaying its own symbol. -- **Inputs**: - - None -- **Control Flow**: - - Check if the `_delegate` pointer is not null. - - If `_delegate` is not null, call the `display` method on the `_delegate` object. - - If `_delegate` is null, output the Pawn's color followed by the letter 'P' to represent the Pawn. -- **Output**: - - The function outputs the Pawn's representation to the standard output stream. -- **See also**: [`Pawn`](pawn.h.driver.md#Pawn) (Data Structure) - - - diff --git a/driver_docs/cpp_src/pawn.h.driver.md b/driver_docs/cpp_src/pawn.h.driver.md deleted file mode 100644 index 25b4d61..0000000 --- a/driver_docs/cpp_src/pawn.h.driver.md +++ /dev/null @@ -1,30 +0,0 @@ -# Purpose -The provided code is a C++ header file (`pawn.h`) that defines a class representing a chess pawn piece, which is a specific type of chess piece with restricted movement capabilities. This class, `Pawn`, inherits from a base class `RestrictedPiece`, suggesting that it is part of a broader chess game implementation where different pieces have varying movement rules. The class offers narrow functionality specific to the pawn's behavior, including methods for setting its location, determining its point value, moving to a new square, checking the legality of a move, and displaying the piece. The header file is intended to be included in other parts of a chess program, as indicated by the inclusion guards (`#ifndef PAWN_H` and `#define PAWN_H`) and the inclusion of other headers like `square.h` and `restrictedPiece.h`. -# Imports and Dependencies - ---- -- `iostream` -- `square.h` -- `restrictedPiece.h` - - -# Data Structures - ---- -### Pawn -- **Type**: `class` -- **Members**: - - `_delegate`: A pointer to a Piece object used for delegation when the pawn is promoted. -- **Description**: The Pawn class represents a pawn piece in a chess game, inheriting from the RestrictedPiece class. It encapsulates the behavior and attributes specific to a pawn, including its movement rules and promotion to a queen when reaching the opponent's end of the board. The class uses a delegate pattern to handle the pawn's behavior after promotion, allowing it to adopt the movement rules of a queen. The Pawn class provides methods to set its location, determine its point value, move to a new square, check if a move is legal, and display itself. -- **Member Functions**: - - [`Pawn::Pawn`](pawn.cpp.driver.md#PawnPawn) - - [`Pawn::~Pawn`](pawn.cpp.driver.md#PawnPawn) - - [`Pawn::setLocation`](pawn.cpp.driver.md#PawnsetLocation) - - [`Pawn::value`](pawn.cpp.driver.md#Pawnvalue) - - [`Pawn::moveTo`](pawn.cpp.driver.md#PawnmoveTo) - - [`Pawn::canMoveTo`](pawn.cpp.driver.md#PawncanMoveTo) - - [`Pawn::display`](pawn.cpp.driver.md#Pawndisplay) -- **Inherits from**: - - [`RestrictedPiece`](restrictedPiece.h.driver.md#RestrictedPiece) - - diff --git a/driver_docs/cpp_src/piece.cpp.driver.md b/driver_docs/cpp_src/piece.cpp.driver.md deleted file mode 100644 index 9245c02..0000000 --- a/driver_docs/cpp_src/piece.cpp.driver.md +++ /dev/null @@ -1,138 +0,0 @@ -# Purpose -The provided C++ source file, `piece.cpp`, is part of a larger chess application, as indicated by its inclusion in the "ChessProject". This file implements the [`Piece`](#PiecePiece) class, which represents a chess piece in the game. The class provides functionality to manage the piece's color, location, and movement on the chessboard. The constructor initializes the piece's color based on whether it is white or black, and the destructor is defined but does not perform any specific actions. The [`moveTo`](#PiecemoveTo) method is a critical component of this class, handling the logic for moving a piece from one square to another, including capturing opponent pieces and ensuring that moves do not leave the player's king in check. This method encapsulates the rules of chess regarding piece movement and captures, making it a central part of the game's mechanics. - -The [`Piece`](#PiecePiece) class also includes several utility methods, such as [`setLocation`](#PiecesetLocation), [`isWhite`](#PieceisWhite), [`color`](#Piececolor), [`isOnSquare`](#PieceisOnSquare), and [`location`](#Piecelocation), which provide access to the piece's attributes and state. These methods facilitate interaction with the piece's properties, such as determining its color, checking its current position, and updating its location on the board. The file imports two headers, `piece.h` and `player.h`, suggesting that it relies on definitions from these files, likely for the [`Piece`](#PiecePiece) and `Player` classes, respectively. Overall, `piece.cpp` is a focused implementation that provides essential functionality for managing chess pieces within the broader context of a chess game application. -# Imports and Dependencies - ---- -- `string` -- `piece.h` -- `player.h` - - -# Data Structures - ---- -### Piece -- **Description**: [See definition](piece.h.driver.md#Piece) -- **Member Functions**: - - [`Piece::Piece`](#PiecePiece) - - [`Piece::~Piece`](#PiecePiece) - - [`Piece::moveTo`](#PiecemoveTo) - - [`Piece::setLocation`](#PiecesetLocation) - - [`Piece::isWhite`](#PieceisWhite) - - [`Piece::color`](#Piececolor) - - [`Piece::isOnSquare`](#PieceisOnSquare) - - [`Piece::location`](#Piecelocation) - -**Methods** - ---- -#### Piece::Piece -The `Piece` constructor initializes a chess piece with a specified color and sets its initial square to null. -- **Inputs**: - - `isWhite`: A boolean indicating whether the piece is white (true) or black (false). -- **Control Flow**: - - The constructor initializes the `_isWhite` member variable with the value of `isWhite`. - - The `_square` member variable is initialized to `NULL`, indicating that the piece is not on any square initially. - - A conditional check is performed on `isWhite` to set the `_color` member variable to "W" if `isWhite` is true, otherwise to "B". -- **Output**: - - The constructor does not return a value as it is used to initialize an object of the `Piece` class. -- **See also**: [`Piece`](piece.h.driver.md#Piece) (Data Structure) - - ---- -#### Piece::\~Piece -The destructor for the `Piece` class is a default destructor that performs no specific actions. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is called when a `Piece` object is destroyed. - - No specific actions or resource deallocations are performed within the destructor. -- **Output**: - - There is no output or return value from the destructor. -- **See also**: [`Piece`](piece.h.driver.md#Piece) (Data Structure) - - ---- -#### Piece::moveTo -The `moveTo` function attempts to move a chess piece to a specified square, ensuring the move is legal according to chess rules and does not leave the player's king in check. -- **Inputs**: - - `byPlayer`: A reference to the Player object attempting to move the piece, used to verify the move's legality and color. - - `toSquare`: A reference to the Square object representing the destination square for the piece. -- **Control Flow**: - - Initialize `validMove` to false and `toCapture` to NULL, and store the current square in `fromSquare`. - - Check if the piece is being moved by its owner by comparing the piece's color with the player's color. - - Verify if the piece can move to the target square using the `canMoveTo` method. - - If the target square is occupied, check if the occupying piece can be captured (i.e., it is of a different color). - - If the move is valid, tentatively move the piece by updating the square occupancies and check if the move leaves the player's king in check. - - If the move results in the king being in check, revert the move and restore the original state. - - If the move does not leave the king in check, finalize the move and capture the opponent's piece if applicable. - - Return `validMove` indicating whether the move was successfully executed. -- **Output**: - - A boolean value indicating whether the move was valid and successfully executed. -- **See also**: [`Piece`](piece.h.driver.md#Piece) (Data Structure) - - ---- -#### Piece::setLocation -The `setLocation` function assigns a new square location to a chess piece. -- **Inputs**: - - `location`: A pointer to a `Square` object representing the new location for the piece. -- **Control Flow**: - - The function takes a pointer to a `Square` object as an argument. - - It assigns this pointer to the private member variable `_square`, effectively updating the piece's current location. -- **Output**: - - The function does not return any value. -- **See also**: [`Piece`](piece.h.driver.md#Piece) (Data Structure) - - ---- -#### Piece::isWhite -The `isWhite` function checks if a chess piece is white. -- **Inputs**: - - None -- **Control Flow**: - - The function directly returns the value of the private member variable `_isWhite`. -- **Output**: - - A boolean value indicating whether the piece is white (`true`) or not (`false`). -- **See also**: [`Piece`](piece.h.driver.md#Piece) (Data Structure) - - ---- -#### Piece::color -The `color` function returns the color of a chess piece as a string. -- **Inputs**: - - None -- **Control Flow**: - - The function simply returns the value of the private member variable `_color`. -- **Output**: - - The function returns a `string` representing the color of the piece, which is either "W" for white or "B" for black. -- **See also**: [`Piece`](piece.h.driver.md#Piece) (Data Structure) - - ---- -#### Piece::isOnSquare -The `isOnSquare` function checks if a chess piece is currently located on a square. -- **Inputs**: - - None -- **Control Flow**: - - The function returns the value of the private member variable `_square`. -- **Output**: - - A boolean value indicating whether the piece is on a square (true if `_square` is not null, false otherwise). -- **See also**: [`Piece`](piece.h.driver.md#Piece) (Data Structure) - - ---- -#### Piece::location -The `location` function returns the current square on which the piece is located. -- **Inputs**: - - None -- **Control Flow**: - - The function directly returns the private member variable `_square`. -- **Output**: - - A pointer to a `Square` object representing the current location of the piece. -- **See also**: [`Piece`](piece.h.driver.md#Piece) (Data Structure) - - - diff --git a/driver_docs/cpp_src/piece.h.driver.md b/driver_docs/cpp_src/piece.h.driver.md deleted file mode 100644 index 57eefd0..0000000 --- a/driver_docs/cpp_src/piece.h.driver.md +++ /dev/null @@ -1,33 +0,0 @@ -# Purpose -The provided code is a C++ header file, `piece.h`, which defines an abstract class `Piece` representing a game piece, likely for a board game such as chess. This class provides a broad functionality as it serves as a base class for different types of game pieces, encapsulating common attributes and behaviors that all pieces share. The class includes several virtual functions, indicating that it is designed to be subclassed, with derived classes implementing specific behaviors for different types of pieces. Key functionalities include moving a piece to a new square, determining if a move is legal, setting and getting the piece's location, and displaying the piece. The class also provides methods to check the piece's color and whether it is currently on a square. - -The `Piece` class interfaces with other components such as `Square`, `Board`, and `Player`, suggesting it is part of a larger game framework. It includes public APIs for interacting with these components, such as `moveTo`, `setLocation`, and `canMoveTo`, which are essential for game logic. The use of pure virtual functions like `value`, `display`, and `canMoveTo` enforces that derived classes must provide specific implementations, allowing for polymorphic behavior. The class also manages internal state with attributes like `_isWhite`, `_color`, and `_square`, which are used to track the piece's color and current position on the board. Overall, this header file is a crucial part of a game engine, providing a flexible and extensible foundation for implementing various game pieces. -# Imports and Dependencies - ---- -- `ostream` -- `square.h` -- `board.h` - - -# Data Structures - ---- -### Piece -- **Type**: `class` -- **Members**: - - `_isWhite`: A boolean indicating if the piece is white. - - `_color`: A string representing the color of the piece, either 'W' for white or 'B' for black. - - `_square`: A pointer to the Square object where the piece is currently located. -- **Description**: The `Piece` class represents a generic game piece in a board game, such as chess. It includes attributes to store the piece's color and its current location on the board. The class provides methods to move the piece, check if a move is legal, and determine the piece's value, among other functionalities. It serves as a base class for specific types of pieces, requiring derived classes to implement certain virtual functions like `value`, `display`, and `canMoveTo`. The class ensures that moves are legal and handles capturing opponent pieces while maintaining the integrity of the game state. -- **Member Functions**: - - [`Piece::Piece`](piece.cpp.driver.md#PiecePiece) - - [`Piece::~Piece`](piece.cpp.driver.md#PiecePiece) - - [`Piece::moveTo`](piece.cpp.driver.md#PiecemoveTo) - - [`Piece::setLocation`](piece.cpp.driver.md#PiecesetLocation) - - [`Piece::isWhite`](piece.cpp.driver.md#PieceisWhite) - - [`Piece::color`](piece.cpp.driver.md#Piececolor) - - [`Piece::isOnSquare`](piece.cpp.driver.md#PieceisOnSquare) - - [`Piece::location`](piece.cpp.driver.md#Piecelocation) - - diff --git a/driver_docs/cpp_src/player.cpp.driver.md b/driver_docs/cpp_src/player.cpp.driver.md deleted file mode 100644 index e645c43..0000000 --- a/driver_docs/cpp_src/player.cpp.driver.md +++ /dev/null @@ -1,175 +0,0 @@ -# Purpose -The `player.cpp` file is part of a Chess game project and implements the [`Player`](#PlayerPlayer) class, which encapsulates the behavior and attributes of a chess player. This file provides functionality specific to managing a player's actions and state within a game, such as making moves, checking if the player is in check, capturing pieces, and calculating the player's score based on captured pieces. The class constructor initializes a player with a name, color, a reference to their king, and a set of pieces they control. The [`makeMove`](#PlayermakeMove) function handles player input for moves, ensuring they are valid and in algebraic notation, and then executes the move on the board. The [`inCheck`](#PlayerinCheck) function determines if the player's king is under threat from any of the opponent's pieces, while the [`capture`](#Playercapture) function updates the state of a captured piece and adds it to the player's collection of captured pieces. - -The file includes several key components such as the [`makeMove`](#PlayermakeMove), [`inCheck`](#PlayerinCheck), [`capture`](#Playercapture), and [`score`](#Playerscore) methods, which are central to the player's interaction with the game. The [`makeMove`](#PlayermakeMove) method is particularly important as it interfaces with the board to execute moves, while [`inCheck`](#PlayerinCheck) and [`capture`](#Playercapture) manage game state and player strategy. The file also defines accessors like [`getName`](#PlayergetName), [`isWhite`](#PlayerisWhite), [`myPieces`](#PlayermyPieces), and [`myKing`](#PlayermyKing), which provide information about the player's identity and current game status. This file is a C++ source file that is likely part of a larger application, interacting with other components such as `board.h`, `game.h`, and `player.h`, and does not define a standalone executable. Instead, it contributes to the broader functionality of the Chess game by managing player-specific logic and interactions. -# Imports and Dependencies - ---- -- `iostream` -- `player.h` -- `board.h` -- `game.h` - - -# Data Structures - ---- -### Player -- **Description**: [See definition](player.h.driver.md#Player) -- **Member Functions**: - - [`Player::Player`](#PlayerPlayer) - - [`Player::~Player`](#PlayerPlayer) - - [`Player::makeMove`](#PlayermakeMove) - - [`Player::inCheck`](#PlayerinCheck) - - [`Player::capture`](#Playercapture) - - [`Player::getName`](#PlayergetName) - - [`Player::isWhite`](#PlayerisWhite) - - [`Player::score`](#Playerscore) - - [`Player::myPieces`](#PlayermyPieces) - - [`Player::myKing`](#PlayermyKing) - -**Methods** - ---- -#### Player::Player -The Player constructor initializes a Player object with a name, color, a reference to their King, and a set of their pieces. -- **Inputs**: - - `name`: A string representing the player's name. - - `isWhite`: A boolean indicating whether the player is playing with the white pieces. - - `myKing`: A reference to the player's King object. - - `myPieces`: A reference to a set of pointers to the player's Piece objects. -- **Control Flow**: - - The constructor initializes the private member variables _name, _isWhite, _myPieces, and _myKing with the provided arguments. -- **Output**: - - The function does not return any value as it is a constructor. -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::\~Player -The `~Player` function is the default destructor for the `Player` class, responsible for cleaning up resources when a `Player` object is destroyed. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is defined but does not contain any specific logic or resource deallocation code. - - It is implicitly called when a `Player` object goes out of scope or is explicitly deleted. -- **Output**: - - The destructor does not return any value or perform any specific actions, as it is currently empty. -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::makeMove -The `makeMove` function allows a player to input and execute a move in a chess game, ensuring the move is valid and in the correct format. -- **Inputs**: - - `none`: The function does not take any parameters; it relies on user input for the move. -- **Control Flow**: - - Check if the player is currently in check and announce it if true. - - Prompt the player to enter a move in algebraic notation (e.g., 'a2 a4'). - - Validate the input to ensure it is in the correct format and the starting square is occupied. - - If the input is invalid, prompt the player to enter a move again until a valid move is provided. - - Translate the valid input from algebraic notation to board coordinates. - - Execute the move by moving the piece from the starting square to the destination square. -- **Output**: - - Returns a boolean indicating whether the move was successfully executed. -- **Functions called**: - - [`Player::inCheck`](#PlayerinCheck) -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::inCheck -The `inCheck` function determines if the current player's king is in check by checking if any opponent's piece can move to the king's location. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a boolean variable `check` to `false`. - - Iterate over each piece in the opponent's set of pieces. - - For each piece, check if it is located on the board and can move to the current player's king's location. - - If such a piece is found, set `check` to `true`. - - Return the value of `check`. -- **Output**: - - A boolean value indicating whether the player's king is in check (true if in check, false otherwise). -- **Functions called**: - - [`Player::myKing`](#PlayermyKing) -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::capture -The `capture` function removes a piece from the board and adds it to the player's set of captured pieces. -- **Inputs**: - - `aPiece`: A pointer to the Piece object that is to be captured. -- **Control Flow**: - - The function first calls `setLocation(NULL)` on the `aPiece` to unset its location on the board, effectively removing it from play. - - The function then inserts `aPiece` into the player's `_capturedPieces` set, indicating that the piece has been captured by this player. -- **Output**: - - The function does not return any value. -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::getName -The `getName` function returns the name of the player. -- **Inputs**: - - None -- **Control Flow**: - - The function accesses the private member variable `_name` of the `Player` class. - - It returns the value of `_name`. -- **Output**: - - The function returns a `string` representing the player's name. -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::isWhite -The `isWhite` function checks if the player is the white player in a chess game. -- **Inputs**: - - None -- **Control Flow**: - - The function directly returns the value of the private member variable `_isWhite`. -- **Output**: - - A boolean value indicating whether the player is the white player (`true` if white, `false` otherwise). -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::score -The `score` function calculates the total score of a player's captured pieces by summing their values. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a local variable `score` to 0 to hold the total score. - - Iterate over each piece in the `_capturedPieces` set using an iterator. - - For each piece, retrieve its value using the `value()` method and add it to the `score`. - - Return the total `score` after iterating through all captured pieces. -- **Output**: - - The function returns an integer representing the total score of the player's captured pieces. -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::myPieces -The `myPieces` function returns a pointer to the set of pieces owned by the player. -- **Inputs**: - - None -- **Control Flow**: - - The function simply returns the address of the `_myPieces` member variable, which is a reference to a set of `Piece` pointers. -- **Output**: - - A pointer to a `set` representing the player's pieces. -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - ---- -#### Player::myKing -The `myKing` function returns a pointer to the `King` object associated with the `Player` instance. -- **Inputs**: - - None -- **Control Flow**: - - The function simply returns the address of the `_myKing` member variable, which is a reference to a `King` object. -- **Output**: - - A pointer to the `King` object associated with the `Player` instance. -- **See also**: [`Player`](player.h.driver.md#Player) (Data Structure) - - - diff --git a/driver_docs/cpp_src/player.h.driver.md b/driver_docs/cpp_src/player.h.driver.md deleted file mode 100644 index b51eaad..0000000 --- a/driver_docs/cpp_src/player.h.driver.md +++ /dev/null @@ -1,37 +0,0 @@ -# Purpose -The provided code is a C++ header file, `player.h`, which defines the `Player` class for a chess game application. This class encapsulates the attributes and behaviors of a chess player, including their name, color (white or black), their king, and the set of pieces they control. The class provides a range of functionalities that are essential for managing a player's state and actions during a chess game. These functionalities include making moves, checking if the player is in check, capturing opponent pieces, and calculating the player's score based on captured pieces. The class also provides accessors to retrieve the player's name, color, set of pieces, and their king. - -The `Player` class is designed to be a part of a larger chess game system, as indicated by its dependencies on other components like `Piece` and `King`, which are likely defined in the included headers `piece.h` and `king.h`. The class defines a public API with methods that allow interaction with a player's state and actions, making it a crucial component for the game's logic. The use of standard C++ libraries, such as ``, suggests that the class leverages efficient data structures to manage collections of pieces. The class is structured to be instantiated with specific attributes, such as the player's name and color, and it maintains private attributes to encapsulate the player's state, ensuring that the internal data is protected and only accessible through the defined public methods. -# Imports and Dependencies - ---- -- `set` -- `piece.h` -- `king.h` - - -# Data Structures - ---- -### Player -- **Type**: `class` -- **Members**: - - `_name`: Stores the name of the player. - - `_isWhite`: Indicates whether the player is playing with the white pieces. - - `_myPieces`: References the set of pieces currently controlled by the player. - - `_capturedPieces`: Holds the set of pieces captured by the player. - - `_myKing`: References the player's king piece. -- **Description**: The `Player` class represents a chess player in a game, encapsulating the player's name, color (white or black), and the pieces they control. It provides functionality to make moves, check if the player is in check, capture opponent pieces, and calculate the score based on captured pieces. The class maintains references to the player's king and the set of pieces they control, as well as a set of captured pieces. This structure is essential for managing the state and actions of a player within a chess game. -- **Member Functions**: - - [`Player::Player`](player.cpp.driver.md#PlayerPlayer) - - [`Player::~Player`](player.cpp.driver.md#PlayerPlayer) - - [`Player::makeMove`](player.cpp.driver.md#PlayermakeMove) - - [`Player::inCheck`](player.cpp.driver.md#PlayerinCheck) - - [`Player::capture`](player.cpp.driver.md#Playercapture) - - [`Player::getName`](player.cpp.driver.md#PlayergetName) - - [`Player::isWhite`](player.cpp.driver.md#PlayerisWhite) - - [`Player::score`](player.cpp.driver.md#Playerscore) - - [`Player::myPieces`](player.cpp.driver.md#PlayermyPieces) - - [`Player::myKing`](player.cpp.driver.md#PlayermyKing) - - diff --git a/driver_docs/cpp_src/queen.cpp.driver.md b/driver_docs/cpp_src/queen.cpp.driver.md deleted file mode 100644 index c4116b1..0000000 --- a/driver_docs/cpp_src/queen.cpp.driver.md +++ /dev/null @@ -1,92 +0,0 @@ -# Purpose -The `queen.cpp` file is part of a chess software project, specifically implementing the behavior and characteristics of the Queen piece in a game of chess. This file defines the [`Queen`](#QueenQueen) class, which inherits from a base class `Piece`, indicating that it is part of a larger object-oriented design for representing chess pieces. The primary functionality provided by this file includes the construction and destruction of a [`Queen`](#QueenQueen) object, determining the value of the Queen piece, checking the validity of its moves, and displaying the piece on the board. - -The [`Queen`](#QueenQueen) class encapsulates the specific movement rules of a Queen in chess, allowing it to move vertically, horizontally, or diagonally across the board, as long as the path is clear. This is achieved through the [`canMoveTo`](#QueencanMoveTo) method, which utilizes methods from a `Board` class to verify if the path is unobstructed. The [`value`](#Queenvalue) method returns the standard chess value of a Queen, which is 9, reflecting its importance in the game. The [`display`](#Queendisplay) method outputs the Queen's representation, which includes its color and the letter "Q". This file is likely part of a larger system where each chess piece is implemented in a similar manner, contributing to a comprehensive simulation of a chess game. -# Imports and Dependencies - ---- -- `queen.h` - - -# Data Structures - ---- -### Queen -- **Description**: [See definition](queen.h.driver.md#Queen) -- **Member Functions**: - - [`Queen::Queen`](#QueenQueen) - - [`Queen::~Queen`](#QueenQueen) - - [`Queen::value`](#Queenvalue) - - [`Queen::canMoveTo`](#QueencanMoveTo) - - [`Queen::display`](#Queendisplay) -- **Inherits from**: - - `Piece` - -**Methods** - ---- -#### Queen::Queen -The `Queen` constructor initializes a Queen object by setting its color through the base class `Piece` constructor. -- **Inputs**: - - `isWhite`: A boolean indicating whether the Queen is white (true) or black (false). -- **Control Flow**: - - The constructor `Queen::Queen(bool isWhite)` is called with a boolean parameter `isWhite`. - - The constructor initializes the `Queen` object by calling the base class `Piece` constructor with the `isWhite` parameter. -- **Output**: - - There is no return value as this is a constructor for the `Queen` class. -- **See also**: [`Queen`](queen.h.driver.md#Queen) (Data Structure) - - ---- -#### Queen::\~Queen -The destructor for the Queen class is a default destructor that performs no specific actions. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is defined but contains no code, indicating it performs no operations when a Queen object is destroyed. -- **Output**: - - There is no output or return value from this destructor. -- **See also**: [`Queen`](queen.h.driver.md#Queen) (Data Structure) - - ---- -#### Queen::value -The `value` function returns the fixed point value of a Queen piece in chess. -- **Inputs**: - - None -- **Control Flow**: - - The function simply returns the integer value 9, which represents the point value of a Queen in chess. -- **Output**: - - The function returns an integer value of 9, representing the point value of a Queen piece. -- **See also**: [`Queen`](queen.h.driver.md#Queen) (Data Structure) - - ---- -#### Queen::canMoveTo -The `canMoveTo` function determines if a Queen chess piece can legally move to a specified square based on clear vertical, horizontal, or diagonal paths. -- **Inputs**: - - `location`: A reference to a `Square` object representing the target location to which the Queen is attempting to move. -- **Control Flow**: - - Initialize a boolean variable `validMove` to `false`. - - Check if the path to the target location is clear vertically using `Board::getBoard()->isClearVertical`; if true, set `validMove` to `true`. - - If not vertical, check if the path is clear horizontally using `Board::getBoard()->isClearHorizontal`; if true, set `validMove` to `true`. - - If not horizontal, check if the path is clear diagonally using `Board::getBoard()->isClearDiagonal`; if true, set `validMove` to `true`. - - Return the value of `validMove`. -- **Output**: - - A boolean value indicating whether the Queen can legally move to the specified square. -- **See also**: [`Queen`](queen.h.driver.md#Queen) (Data Structure) - - ---- -#### Queen::display -The `display` function outputs the Queen's color and the letter 'Q' to represent the Queen piece on the console. -- **Inputs**: - - None -- **Control Flow**: - - The function uses the `cout` stream to output the Queen's color concatenated with the letter 'Q'. -- **Output**: - - The function outputs a string to the console, representing the Queen piece with its color and the letter 'Q'. -- **See also**: [`Queen`](queen.h.driver.md#Queen) (Data Structure) - - - diff --git a/driver_docs/cpp_src/queen.h.driver.md b/driver_docs/cpp_src/queen.h.driver.md deleted file mode 100644 index 8d3ca10..0000000 --- a/driver_docs/cpp_src/queen.h.driver.md +++ /dev/null @@ -1,26 +0,0 @@ -# Purpose -The provided code is a C++ header file (`queen.h`) that defines a class representing a chess queen piece, offering narrow functionality specific to chess game logic. This class, `Queen`, inherits from a base class `Piece`, suggesting a broader chess game framework where different pieces share common characteristics. The header file declares several member functions: a constructor to initialize the queen with a color, a destructor, a method to return the queen's point value, a method to check if a move to a specified square is legal, and a method to display the piece. This file is intended to be included in other parts of a chess application, where the implementation of these methods would be defined, likely in a corresponding `.cpp` file. -# Imports and Dependencies - ---- -- `iostream` -- `square.h` -- `piece.h` - - -# Data Structures - ---- -### Queen -- **Type**: `class` -- **Description**: The `Queen` class represents a chess queen piece and inherits from the `Piece` class. It encapsulates the behavior and characteristics of a queen in a chess game, including its color, point value, and movement capabilities. The class provides methods to determine the point value of the queen, check if a move to a specific square is legal based on chess rules, and display the queen on the board. The queen can move vertically, horizontally, or diagonally as long as the path is clear, reflecting its powerful and versatile movement in chess. -- **Member Functions**: - - [`Queen::Queen`](queen.cpp.driver.md#QueenQueen) - - [`Queen::~Queen`](queen.cpp.driver.md#QueenQueen) - - [`Queen::value`](queen.cpp.driver.md#Queenvalue) - - [`Queen::canMoveTo`](queen.cpp.driver.md#QueencanMoveTo) - - [`Queen::display`](queen.cpp.driver.md#Queendisplay) -- **Inherits from**: - - [`Piece`](piece.h.driver.md#Piece) - - diff --git a/driver_docs/cpp_src/restrictedPiece.cpp.driver.md b/driver_docs/cpp_src/restrictedPiece.cpp.driver.md deleted file mode 100644 index ab919fb..0000000 --- a/driver_docs/cpp_src/restrictedPiece.cpp.driver.md +++ /dev/null @@ -1,80 +0,0 @@ -# Purpose -The `restrictedPiece.cpp` file is part of a larger chess application, as indicated by its inclusion in the "ChessProject." This file defines the implementation of the [`RestrictedPiece`](#RestrictedPieceRestrictedPiece) class, which inherits from a base class `Piece`. The primary purpose of this class is to represent a chess piece with movement restrictions, specifically tracking whether the piece has moved from its initial position. This functionality is crucial for implementing chess rules that depend on a piece's movement history, such as castling for rooks and pawns' initial double-step move. - -The file includes two header files, `player.h` and `restrictedPiece.h`, suggesting that it interacts with player-related functionality and defines its own interface in `restrictedPiece.h`. The class constructor initializes the piece's color and sets a private member `_moved` to `false`, indicating that the piece has not yet moved. The [`moveTo`](#RestrictedPiecemoveTo) method overrides a similar method in the base class to update the `_moved` status only if a valid move is executed and the piece has not moved before. The [`hasMoved`](#RestrictedPiecehasMoved) method provides a public interface to check the movement status of the piece. This file is a focused implementation, providing specific functionality related to movement restrictions within the broader context of a chess game. -# Imports and Dependencies - ---- -- `player.h` -- `restrictedPiece.h` - - -# Data Structures - ---- -### RestrictedPiece -- **Description**: [See definition](restrictedPiece.h.driver.md#RestrictedPiece) -- **Member Functions**: - - [`RestrictedPiece::RestrictedPiece`](#RestrictedPieceRestrictedPiece) - - [`RestrictedPiece::~RestrictedPiece`](#RestrictedPieceRestrictedPiece) - - [`RestrictedPiece::moveTo`](#RestrictedPiecemoveTo) - - [`RestrictedPiece::hasMoved`](#RestrictedPiecehasMoved) -- **Inherits from**: - - `Piece` - -**Methods** - ---- -#### RestrictedPiece::RestrictedPiece -The `RestrictedPiece` constructor initializes a chess piece with a specified color and sets its moved status to false. -- **Inputs**: - - `isWhite`: A boolean indicating whether the piece is white (true) or black (false). -- **Control Flow**: - - The constructor initializes the base class `Piece` with the `isWhite` parameter to set the color of the piece. - - It sets the private member variable `_moved` to `false`, indicating that the piece has not been moved yet. -- **Output**: - - There is no return value as this is a constructor for the `RestrictedPiece` class. -- **See also**: [`RestrictedPiece`](restrictedPiece.h.driver.md#RestrictedPiece) (Data Structure) - - ---- -#### RestrictedPiece::\~RestrictedPiece -The destructor for the RestrictedPiece class performs no specific actions upon object destruction. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is defined but contains no code, indicating no special cleanup or resource management is needed for this class. -- **Output**: - - There is no output or return value from a destructor. -- **See also**: [`RestrictedPiece`](restrictedPiece.h.driver.md#RestrictedPiece) (Data Structure) - - ---- -#### RestrictedPiece::moveTo -The `moveTo` function attempts to move a `RestrictedPiece` to a specified square and updates its moved status if the move is valid and the piece hasn't been moved before. -- **Inputs**: - - `byPlayer`: A reference to the `Player` object attempting to move the piece. - - `to`: A reference to the `Square` object representing the destination square for the move. -- **Control Flow**: - - Call the `moveTo` method of the base class `Piece` to determine if the move is valid, storing the result in `validMove`. - - Check if `validMove` is true and the `_moved` attribute is false, indicating a valid move and that the piece hasn't been moved before. - - If both conditions are met, set `_moved` to true to indicate the piece has been moved. - - Return the value of `validMove` to indicate whether the move was successful. -- **Output**: - - A boolean value indicating whether the move was successful. -- **See also**: [`RestrictedPiece`](restrictedPiece.h.driver.md#RestrictedPiece) (Data Structure) - - ---- -#### RestrictedPiece::hasMoved -The `hasMoved` function checks if a `RestrictedPiece` has been moved from its initial position. -- **Inputs**: - - None -- **Control Flow**: - - The function simply returns the value of the private member variable `_moved`. -- **Output**: - - A boolean value indicating whether the `RestrictedPiece` has been moved (`true`) or not (`false`). -- **See also**: [`RestrictedPiece`](restrictedPiece.h.driver.md#RestrictedPiece) (Data Structure) - - - diff --git a/driver_docs/cpp_src/restrictedPiece.h.driver.md b/driver_docs/cpp_src/restrictedPiece.h.driver.md deleted file mode 100644 index 080829b..0000000 --- a/driver_docs/cpp_src/restrictedPiece.h.driver.md +++ /dev/null @@ -1,25 +0,0 @@ -# Purpose -The provided code is a C++ header file (`restrictedPiece.h`) that defines a class `RestrictedPiece`, which inherits from a base class `Piece`. This class is designed to represent a chess piece with the additional functionality of tracking whether it has been moved, which is a narrow and specific functionality useful in chess game implementations. The class includes a constructor to initialize the piece with a color, a destructor, a method `moveTo` to attempt moving the piece to a new square, and a method `hasMoved` to check if the piece has been moved previously. The `_moved` attribute is a private member variable used to store the state of whether the piece has been moved. This header file is intended to be included in other C++ source files where the `RestrictedPiece` class functionality is required. -# Imports and Dependencies - ---- -- `piece.h` - - -# Data Structures - ---- -### RestrictedPiece -- **Type**: `class` -- **Members**: - - `_moved`: A boolean attribute that indicates whether the piece has been moved. -- **Description**: The `RestrictedPiece` class is a specialized type of chess piece that extends the `Piece` class, adding functionality to track whether the piece has been moved. This is achieved through a private boolean attribute `_moved`, which is initially set to `false` and updated to `true` upon a successful move. The class provides methods to move the piece and check if it has been moved, thus allowing for game logic that depends on whether a piece has been moved, such as castling in chess. -- **Member Functions**: - - [`RestrictedPiece::RestrictedPiece`](restrictedPiece.cpp.driver.md#RestrictedPieceRestrictedPiece) - - [`RestrictedPiece::~RestrictedPiece`](restrictedPiece.cpp.driver.md#RestrictedPieceRestrictedPiece) - - [`RestrictedPiece::moveTo`](restrictedPiece.cpp.driver.md#RestrictedPiecemoveTo) - - [`RestrictedPiece::hasMoved`](restrictedPiece.cpp.driver.md#RestrictedPiecehasMoved) -- **Inherits from**: - - [`Piece`](piece.h.driver.md#Piece) - - diff --git a/driver_docs/cpp_src/rook.cpp.driver.md b/driver_docs/cpp_src/rook.cpp.driver.md deleted file mode 100644 index ed9b55c..0000000 --- a/driver_docs/cpp_src/rook.cpp.driver.md +++ /dev/null @@ -1,94 +0,0 @@ -# Purpose -The provided C++ source code file, `rook.cpp`, is part of a larger chess application, as indicated by its inclusion in the "ChessProject". This file specifically implements the behavior and characteristics of the Rook chess piece. The class [`Rook`](#RookRook) inherits from a base class `RestrictedPiece`, which likely encapsulates common functionality for chess pieces with restricted movement patterns. The constructor initializes the Rook with a color, indicating whether it is a white or black piece, and the destructor is defined but does not perform any specific actions, suggesting that no special cleanup is required for this class. - -The [`Rook`](#RookRook) class defines several key methods that encapsulate its functionality. The `value()` method returns an integer value of 5, which is a common convention in chess programming to represent the relative strength of a Rook compared to other pieces. The `canMoveTo()` method determines if the Rook can legally move to a specified `Square` on the chessboard, checking for clear paths either vertically or horizontally, which aligns with the Rook's movement rules in chess. The `display()` method outputs the Rook's representation, which includes its color and the letter "R", to the console. This file is not a standalone executable but rather a component of a larger system, likely intended to be used in conjunction with other chess piece classes and a chessboard management system. -# Imports and Dependencies - ---- -- `rook.h` - - -# Data Structures - ---- -### Rook -- **Description**: [See definition](rook.h.driver.md#Rook) -- **Member Functions**: - - [`Rook::Rook`](#RookRook) - - [`Rook::~Rook`](#RookRook) - - [`Rook::value`](#Rookvalue) - - [`Rook::canMoveTo`](#RookcanMoveTo) - - [`Rook::display`](#Rookdisplay) -- **Inherits from**: - - `RestrictedPiece` - -**Methods** - ---- -#### Rook::Rook -The Rook constructor initializes a Rook object by calling the constructor of its parent class, RestrictedPiece, with a boolean indicating the piece's color. -- **Inputs**: - - `isWhite`: A boolean value indicating whether the Rook is white (true) or black (false). -- **Control Flow**: - - The constructor of the Rook class is called with a boolean parameter 'isWhite'. - - The constructor of the parent class, RestrictedPiece, is invoked with the 'isWhite' parameter to initialize the Rook object. -- **Output**: - - There is no output from this constructor function as it is used to initialize an object of the Rook class. -- **See also**: [`Rook`](rook.h.driver.md#Rook) (Data Structure) - - ---- -#### Rook::\~Rook -The destructor for the Rook class is a default destructor that performs no specific actions. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is called when a Rook object is destroyed. - - No specific actions or resource deallocations are performed within the destructor. -- **Output**: - - There is no output or return value from the destructor. -- **See also**: [`Rook`](rook.h.driver.md#Rook) (Data Structure) - - ---- -#### Rook::value -The `value` function returns the point value of a Rook piece in a chess game. -- **Inputs**: - - None -- **Control Flow**: - - The function is a simple getter that directly returns the integer value 5, representing the point value of a Rook in chess. -- **Output**: - - The function returns an integer value of 5, which is the standard point value assigned to a Rook in chess. -- **See also**: [`Rook`](rook.h.driver.md#Rook) (Data Structure) - - ---- -#### Rook::canMoveTo -The `canMoveTo` function determines if a Rook can legally move to a specified square on a chessboard by checking for clear vertical or horizontal paths. -- **Inputs**: - - `location`: A reference to a `Square` object representing the target location to which the Rook is attempting to move. -- **Control Flow**: - - Initialize a boolean variable `validMove` to `false`. - - Check if the path from the Rook's current location to the target location is clear vertically using `Board::getBoard()->isClearVertical`. - - If the vertical path is clear, set `validMove` to `true`. - - If the vertical path is not clear, check if the path is clear horizontally using `Board::getBoard()->isClearHorizontal`. - - If the horizontal path is clear, set `validMove` to `true`. - - Return the value of `validMove`. -- **Output**: - - Returns a boolean value indicating whether the Rook can legally move to the specified square, based on clear vertical or horizontal paths. -- **See also**: [`Rook`](rook.h.driver.md#Rook) (Data Structure) - - ---- -#### Rook::display -The `display` function outputs the color and type of the Rook piece to the console. -- **Inputs**: - - None -- **Control Flow**: - - The function uses the `cout` stream to output the Rook's color followed by the letter 'R'. -- **Output**: - - The function does not return any value; it outputs directly to the console. -- **See also**: [`Rook`](rook.h.driver.md#Rook) (Data Structure) - - - diff --git a/driver_docs/cpp_src/rook.h.driver.md b/driver_docs/cpp_src/rook.h.driver.md deleted file mode 100644 index 58e0484..0000000 --- a/driver_docs/cpp_src/rook.h.driver.md +++ /dev/null @@ -1,28 +0,0 @@ -# Purpose -The provided code is a C++ header file, `rook.h`, which defines the interface for a `Rook` class, representing a rook piece in a chess game. This class inherits from `RestrictedPiece`, suggesting that it is part of a larger chess game framework where different types of chess pieces are implemented as subclasses of a more general piece class. The `Rook` class encapsulates the behavior and characteristics specific to a rook, such as its point value and movement capabilities on a chessboard. - -The `Rook` class includes several public member functions that define its core functionality. The constructor `Rook(bool isWhite)` initializes a rook with a specified color, while the destructor `~Rook()` handles any necessary cleanup. The `value()` function returns the point value of the rook, which is a standard feature in chess to evaluate the strength of a piece. The `canMoveTo(Square& location)` function determines if a move to a specified square is legal, adhering to the rook's movement rules in chess. Lastly, the `display()` function outputs a representation of the rook, likely for visualization purposes in a console-based or graphical chess application. This header file is intended to be included in other parts of the program where the `Rook` class functionality is required, and it defines a clear public API for interacting with rook objects. -# Imports and Dependencies - ---- -- `iostream` -- `restrictedPiece.h` -- `square.h` - - -# Data Structures - ---- -### Rook -- **Type**: `class` -- **Description**: The `Rook` class represents a chess rook piece and is derived from the `RestrictedPiece` class. It encapsulates the behavior and characteristics of a rook, including its ability to move vertically or horizontally across the board, as determined by the `canMoveTo` method. The class provides a constructor to initialize the rook with a specific color, a destructor, a method to return the point value of the rook (which is 5), and a method to display the rook on the board. The `Rook` class does not have any additional member variables beyond those inherited from `RestrictedPiece`. -- **Member Functions**: - - [`Rook::Rook`](rook.cpp.driver.md#RookRook) - - [`Rook::~Rook`](rook.cpp.driver.md#RookRook) - - [`Rook::value`](rook.cpp.driver.md#Rookvalue) - - [`Rook::canMoveTo`](rook.cpp.driver.md#RookcanMoveTo) - - [`Rook::display`](rook.cpp.driver.md#Rookdisplay) -- **Inherits from**: - - [`RestrictedPiece`](restrictedPiece.h.driver.md#RestrictedPiece) - - diff --git a/driver_docs/cpp_src/square.cpp.driver.md b/driver_docs/cpp_src/square.cpp.driver.md deleted file mode 100644 index a64457c..0000000 --- a/driver_docs/cpp_src/square.cpp.driver.md +++ /dev/null @@ -1,118 +0,0 @@ -# Purpose -The provided code is a C++ source file, likely part of a larger chess application, that defines the implementation of a [`Square`](#SquareSquare) class. This class offers narrow functionality, specifically managing the state of a square on a chessboard, including its coordinates and the piece occupying it. The class constructor initializes the square's position and sets the occupying piece to `NULL`, while the destructor is defined but does not perform any specific actions. The class provides methods to set and retrieve the piece occupying the square, check if the square is occupied, and access the square's coordinates. This file is intended to be compiled and linked with other parts of the ChessProject, as it includes headers for dependencies like `piece.h` and `square.h`. -# Imports and Dependencies - ---- -- `piece.h` -- `square.h` - - -# Data Structures - ---- -### Square -- **Description**: [See definition](square.h.driver.md#Square) -- **Member Functions**: - - [`Square::Square`](#SquareSquare) - - [`Square::~Square`](#SquareSquare) - - [`Square::setOccupier`](#SquaresetOccupier) - - [`Square::getX`](#SquaregetX) - - [`Square::getY`](#SquaregetY) - - [`Square::occupied`](#Squareoccupied) - - [`Square::occupiedBy`](#SquareoccupiedBy) - -**Methods** - ---- -#### Square::Square -The `Square` constructor initializes a `Square` object with specified x and y coordinates and sets the occupying piece to NULL. -- **Inputs**: - - `x`: The x-coordinate of the square on the board. - - `y`: The y-coordinate of the square on the board. -- **Control Flow**: - - The constructor initializes the private member variable `_x` with the value of the input parameter `x`. - - The constructor initializes the private member variable `_y` with the value of the input parameter `y`. - - The constructor sets the private member variable `_piece` to `NULL`, indicating that the square is initially unoccupied. -- **Output**: - - The function does not return any value as it is a constructor for the `Square` class. -- **See also**: [`Square`](square.h.driver.md#Square) (Data Structure) - - ---- -#### Square::\~Square -The destructor for the Square class, `~Square`, is a default destructor that performs no specific actions. -- **Inputs**: - - None -- **Control Flow**: - - The destructor is called when a Square object is destroyed. - - No specific actions or resource deallocations are performed within the destructor. -- **Output**: - - There is no output or return value from the destructor. -- **See also**: [`Square`](square.h.driver.md#Square) (Data Structure) - - ---- -#### Square::setOccupier -The `setOccupier` function assigns a `Piece` object to a `Square` object, indicating that the square is occupied by that piece. -- **Inputs**: - - `piece`: A pointer to a `Piece` object that is to be set as the occupier of the square. -- **Control Flow**: - - The function takes a pointer to a `Piece` object as an argument. - - It assigns this pointer to the private member variable `_piece` of the `Square` class, effectively setting the piece that occupies the square. -- **Output**: - - The function does not return any value. -- **See also**: [`Square`](square.h.driver.md#Square) (Data Structure) - - ---- -#### Square::getX -The `getX` function returns the x-coordinate of a `Square` object. -- **Inputs**: - - None -- **Control Flow**: - - The function accesses the private member variable `_x` of the `Square` class. - - It returns the value of `_x`. -- **Output**: - - The function returns an integer representing the x-coordinate of the `Square`. -- **See also**: [`Square`](square.h.driver.md#Square) (Data Structure) - - ---- -#### Square::getY -The `getY` function returns the Y-coordinate of a `Square` object. -- **Inputs**: - - None -- **Control Flow**: - - The function accesses the private member variable `_y` of the `Square` class. - - It returns the value of `_y`. -- **Output**: - - The function returns an integer representing the Y-coordinate of the square. -- **See also**: [`Square`](square.h.driver.md#Square) (Data Structure) - - ---- -#### Square::occupied -The `occupied` function checks if a `Square` object is occupied by a `Piece`. -- **Inputs**: - - None -- **Control Flow**: - - The function accesses the private member `_piece` of the `Square` class. - - It returns the boolean value of `_piece`, which is `true` if `_piece` is not `NULL` (indicating the square is occupied) and `false` if `_piece` is `NULL` (indicating the square is not occupied). -- **Output**: - - A boolean value indicating whether the square is occupied by a piece. -- **See also**: [`Square`](square.h.driver.md#Square) (Data Structure) - - ---- -#### Square::occupiedBy -The `occupiedBy` function returns the `Piece` object that currently occupies the `Square`. -- **Inputs**: - - None -- **Control Flow**: - - The function directly returns the private member variable `_piece`, which is a pointer to a `Piece` object. -- **Output**: - - A pointer to the `Piece` object that occupies the `Square`, or `NULL` if the square is unoccupied. -- **See also**: [`Square`](square.h.driver.md#Square) (Data Structure) - - - diff --git a/driver_docs/cpp_src/square.h.driver.md b/driver_docs/cpp_src/square.h.driver.md deleted file mode 100644 index 78c0a98..0000000 --- a/driver_docs/cpp_src/square.h.driver.md +++ /dev/null @@ -1,22 +0,0 @@ -# Purpose -The provided code is a C++ header file (`square.h`) that defines a class `Square`, which represents a square on a game board. This code offers narrow functionality, specifically tailored for managing the state and properties of a single square, such as its position on the board and the piece occupying it. The class includes constructors, a destructor, and member functions to set and retrieve the position and occupancy status of the square. It also uses a forward declaration for the `Piece` class, indicating that `Square` interacts with another class, likely representing game pieces. This header file is intended to be included in other C++ source files where the `Square` class functionality is required. -# Data Structures - ---- -### Square -- **Type**: `class` -- **Members**: - - `_x`: Stores the X-coordinate of the square on the board. - - `_y`: Stores the Y-coordinate of the square on the board. - - `_piece`: Pointer to the Piece object that occupies the square, or NULL if unoccupied. -- **Description**: The `Square` class represents a single square on a game board, characterized by its X and Y coordinates. It can hold a reference to a `Piece` object, indicating whether the square is occupied. The class provides methods to set and retrieve the piece occupying the square, as well as to check if the square is occupied. It encapsulates the position and occupancy state of a square, making it a fundamental component for board-based games. -- **Member Functions**: - - [`Square::Square`](square.cpp.driver.md#SquareSquare) - - [`Square::~Square`](square.cpp.driver.md#SquareSquare) - - [`Square::setOccupier`](square.cpp.driver.md#SquaresetOccupier) - - [`Square::getX`](square.cpp.driver.md#SquaregetX) - - [`Square::getY`](square.cpp.driver.md#SquaregetY) - - [`Square::occupied`](square.cpp.driver.md#Squareoccupied) - - [`Square::occupiedBy`](square.cpp.driver.md#SquareoccupiedBy) - - diff --git a/driver_docs/include.driver.md b/driver_docs/include.driver.md deleted file mode 100644 index 1f46d94..0000000 --- a/driver_docs/include.driver.md +++ /dev/null @@ -1,3 +0,0 @@ -## Folders -- **[chesslib](include/chesslib.driver.md)**: The `chesslib` folder in the `c_cpp_export_test` codebase contains header files that define structures and functions for managing various aspects of a chess game, including the board, pieces, moves, and game state. - diff --git a/driver_docs/include/chesslib.driver.md b/driver_docs/include/chesslib.driver.md deleted file mode 100644 index 04dbebe..0000000 --- a/driver_docs/include/chesslib.driver.md +++ /dev/null @@ -1,11 +0,0 @@ - -## Files -- **[board.h](chesslib/board.h.driver.md)**: The `board.h` file defines the structure and functions for managing a chess board, including initialization, move generation, and state comparison, within the `c_cpp_export_test` codebase. -- **[boardlist.h](chesslib/boardlist.h.driver.md)**: The `boardlist.h` file defines a linked list structure and operations for managing a list of chess boards, including creation, addition, retrieval, undo, and memory deallocation. -- **[chess.h](chesslib/chess.h.driver.md)**: The `chess.h` file defines the structure and functions for managing a chess game, including game initialization, move handling, and draw claims, within the `c_cpp_export_test` codebase. -- **[move.h](chesslib/move.h.driver.md)**: The `move.h` file defines a structure and functions for representing and manipulating chess moves, including conversion to and from UCI notation. -- **[movelist.h](chesslib/movelist.h.driver.md)**: The `movelist.h` file defines data structures and functions for managing a list of chess moves, including creation, addition, retrieval, and conversion to UCI string format. -- **[piece.h](chesslib/piece.h.driver.md)**: The `piece.h` file defines enumerations and functions for representing and manipulating chess pieces, including their types, colors, and corresponding letters. -- **[piecemoves.h](chesslib/piecemoves.h.driver.md)**: The `piecemoves.h` file defines functions for generating potential move lists for different chess pieces, including leapers, riders, and specific pieces like pawns, knights, bishops, rooks, queens, and kings. -- **[square.h](chesslib/square.h.driver.md)**: The `square.h` file defines a `sq` struct for representing chessboard squares, along with functions for creating, indexing, and comparing these squares, as well as determining their color. -- **[squareset.h](chesslib/squareset.h.driver.md)**: The `squareset.h` file defines a 64-bit representation for a set of chessboard squares and provides functions to set and get the state of individual squares. diff --git a/driver_docs/include/chesslib/board.h.driver.md b/driver_docs/include/chesslib/board.h.driver.md deleted file mode 100644 index 2ba28be..0000000 --- a/driver_docs/include/chesslib/board.h.driver.md +++ /dev/null @@ -1,237 +0,0 @@ -# Purpose -This C header file defines the structure and functionality for managing a chess board within a chess application. It provides a comprehensive set of functions and data structures to represent the state of a chess game, including the positions of pieces, the current player, castling rights, and other game-specific details. The file includes definitions for creating and initializing a board, either from scratch or from a Forsyth-Edwards Notation (FEN) string, which is a standard notation for describing a particular board position. The header also includes functions for manipulating the board, such as setting and getting pieces, generating possible moves, and checking for conditions like check or insufficient material. - -The file is designed to be a part of a larger chess library, as indicated by the inclusion of other headers like "square.h", "piece.h", and "movelist.h". It defines a public API for interacting with the board, allowing other parts of the program to create and manipulate board states. The use of bitmasks for castling rights and functions for comparing board states suggest a focus on efficiency and precise control over game state management. This header file is essential for any chess application that requires detailed and accurate representation and manipulation of the game board. -# Imports and Dependencies - ---- -- `chesslib/square.h` -- `chesslib/piece.h` -- `chesslib/movelist.h` - - -# Global Variables - ---- -### boardCreate -- **Type**: `function` -- **Description**: The `boardCreate` function is a global function that allocates and initializes a new chess board structure, returning a pointer to this newly created board. It is designed to set up a board with the initial chess position and must be freed after use to avoid memory leaks. -- **Use**: This function is used to create a new chess board instance, initialized to the standard starting position, for use in a chess game application. - - ---- -### boardCreateFromFen -- **Type**: `function` -- **Description**: The `boardCreateFromFen` function is a global function that allocates and initializes a chess board based on a given FEN (Forsyth-Edwards Notation) string. It returns a pointer to a `board` structure, which represents the state of a chess game, or NULL if the initialization fails. -- **Use**: This function is used to create a new chess board from a FEN string, allowing the game state to be set up from a specific position. - - ---- -### boardGenerateMoves -- **Type**: `function pointer` -- **Description**: The `boardGenerateMoves` is a function that takes a pointer to a `board` structure as an argument and returns a pointer to a `moveList` structure. This function is responsible for generating all possible legal moves for the current player on the given chess board. -- **Use**: This function is used to calculate and retrieve all potential moves for the current player based on the current state of the chess board. - - ---- -### boardPlayMove -- **Type**: `function` -- **Description**: The `boardPlayMove` function is a global function that takes a pointer to a `board` structure and a `move` as parameters. It returns a new `board` structure where the specified move has been applied to the given board. This function is part of a chess library and is used to simulate the effect of a move on a chess board, creating a new board state as a result. -- **Use**: This function is used to apply a move to a chess board and return the resulting board state. - - ---- -### boardGetFen -- **Type**: `function` -- **Description**: The `boardGetFen` function is a global function that takes a pointer to a `board` structure as its parameter and returns a string representing the board's state in Forsyth-Edwards Notation (FEN). FEN is a standard notation for describing a particular board position of a chess game. This function is essential for serializing the board state into a human-readable format that can be used for saving, sharing, or analyzing the game state. -- **Use**: This function is used to convert the current state of a chess board into a FEN string for external use or storage. - - -# Data Structures - ---- -### board -- **Type**: `struct` -- **Members**: - - `pieces`: An array of 64 `piece` elements representing the chess pieces on the board. - - `currentPlayer`: A `pieceColor` indicating which player's turn it is to move. - - `castleState`: A `uint8_t` bitmask that describes the castling rights for both players. - - `epTarget`: A `sq` representing the en passant target square, if applicable. - - `halfMoveClock`: An `unsigned int` tracking the number of half-moves since the last capture or pawn move. - - `moveNumber`: An `unsigned int` indicating the current move number in the game. -- **Description**: The `board` structure is a comprehensive representation of a chess game state, encapsulating the positions of all pieces on the board, the current player's turn, castling rights, en passant target square, and move counters. It is designed to facilitate the management and manipulation of a chess game, providing the necessary data to track game progress and enforce rules such as castling and en passant. The structure is integral to functions that initialize, modify, and evaluate the board state, supporting operations like move generation and validation. - - -# Function Declarations (Public API) - ---- -### boardCreate -Allocates and initializes a chess board to the standard starting position. -- **Description**: This function creates a new chess board initialized to the standard starting position, as defined by the Forsyth-Edwards Notation (FEN) string for the initial setup of a chess game. It returns a pointer to the newly allocated board structure. The caller is responsible for freeing the allocated memory when it is no longer needed. This function is useful for setting up a new game of chess with the standard initial configuration. It is expected to be called when a new game is started, and it handles any necessary memory allocation internally. -- **Inputs**: - - None -- **Output**: A pointer to a newly allocated and initialized board structure, or NULL if the allocation fails. -- **See also**: [`boardCreate`](../../src/chesslib/board.c.driver.md#boardCreate) (Implementation) - - ---- -### boardCreateFromFen -Creates a chess board from a FEN string. -- **Description**: This function allocates memory for a new chess board and initializes it using the provided FEN (Forsyth-Edwards Notation) string, which describes a particular board position. It is useful for setting up a board to a specific state as described by the FEN. The function returns a pointer to the newly created board, or NULL if the initialization fails. The caller is responsible for freeing the allocated memory when the board is no longer needed. This function should be used when a specific board setup is required, and it is important to ensure that the FEN string is valid to avoid initialization failure. -- **Inputs**: - - `fen`: A null-terminated string representing the board position in Forsyth-Edwards Notation. The string must be valid and correctly formatted, as invalid FEN strings will cause the function to return NULL. -- **Output**: Returns a pointer to a newly allocated and initialized board, or NULL if the FEN string is invalid or initialization fails. -- **See also**: [`boardCreateFromFen`](../../src/chesslib/board.c.driver.md#boardCreateFromFen) (Implementation) - - ---- -### boardInitInPlace -Initializes a chess board to the standard starting position. -- **Description**: This function sets up the provided chess board structure to represent the initial position of a standard chess game. It should be used when you want to reset or initialize a board to the starting configuration. The function must be called with a valid pointer to a `board` structure, which it will modify in place. Ensure that the board structure is properly allocated before calling this function. -- **Inputs**: - - `b`: A pointer to a `board` structure that will be initialized. Must not be null, and the caller retains ownership of the memory. The function modifies the board in place to represent the initial chess position. -- **Output**: None -- **See also**: [`boardInitInPlace`](../../src/chesslib/board.c.driver.md#boardInitInPlace) (Implementation) - - ---- -### boardInitFromFenInPlace -Initializes a chess board from a FEN string in place. -- **Description**: This function sets up a chess board based on the provided FEN (Forsyth-Edwards Notation) string, directly modifying the given board structure. It should be used when you want to initialize or reset a board to a specific state described by a FEN string. The function expects a valid FEN string and a pre-allocated board structure. It returns an error code if the FEN string is malformed or if any part of the board setup fails. The function modifies the board's pieces, current player, castling rights, en passant target square, half-move clock, and full move number based on the FEN data. -- **Inputs**: - - `b`: A pointer to a pre-allocated board structure that will be initialized. The caller retains ownership and must ensure it is valid and properly allocated. - - `fen`: A null-terminated string containing the FEN representation of the board state. It must not be null and should be a valid FEN string. Invalid FEN strings will result in an error code being returned. -- **Output**: Returns 0 on successful initialization, or 1 if an error occurs due to an invalid FEN string. -- **See also**: [`boardInitFromFenInPlace`](../../src/chesslib/board.c.driver.md#boardInitFromFenInPlace) (Implementation) - - ---- -### boardSetPiece -Sets a piece on the specified square of the board. -- **Description**: This function places a specified chess piece on a given square of the board. It is typically used to update the board state during gameplay or setup. The board must be properly initialized before calling this function. The function does not perform any validation on the square or piece, so it is the caller's responsibility to ensure that the square is within valid bounds and the piece is a valid chess piece. This function directly modifies the board's state. -- **Inputs**: - - `b`: A pointer to the board structure where the piece will be placed. Must not be null and should point to a valid, initialized board. - - `s`: The square on the board where the piece will be placed. It should be a valid square within the board's bounds. - - `p`: The chess piece to place on the specified square. It should be a valid piece as defined in the chess library. -- **Output**: None -- **See also**: [`boardSetPiece`](../../src/chesslib/board.c.driver.md#boardSetPiece) (Implementation) - - ---- -### boardGetPiece -Retrieve the piece located at a specific square on the board. -- **Description**: Use this function to obtain the piece that is currently positioned on a specified square of the chess board. This function is useful when you need to inspect the board's state or validate moves. It requires a valid board pointer and a square identifier. Ensure that the board has been properly initialized before calling this function to avoid undefined behavior. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should point to a valid, initialized board. - - `s`: An identifier for the square on the board from which to retrieve the piece. Must be a valid square within the board's boundaries. -- **Output**: The piece located at the specified square on the board. -- **See also**: [`boardGetPiece`](../../src/chesslib/board.c.driver.md#boardGetPiece) (Implementation) - - ---- -### boardGenerateMoves -Generates all legal moves for the current player on the board. -- **Description**: This function generates a list of all legal moves available to the current player on the given chess board. It should be called when you need to determine the possible actions a player can take in their turn. The function considers all pieces of the current player, including special moves like castling, and excludes moves that would leave the player in check. The caller is responsible for freeing the returned move list to avoid memory leaks. -- **Inputs**: - - `b`: A pointer to a 'board' structure representing the current state of the chess game. Must not be null. The board should be properly initialized and represent a valid game state. -- **Output**: A pointer to a 'moveList' structure containing all legal moves for the current player. The list is dynamically allocated and must be freed by the caller. -- **See also**: [`boardGenerateMoves`](../../src/chesslib/board.c.driver.md#boardGenerateMoves) (Implementation) - - ---- -### boardIsSquareAttacked -Determines if a square is attacked by a specified color. -- **Description**: Use this function to check if a specific square on the chess board is under attack by any piece of a given color. This is useful for determining threats and planning moves in a chess game. The function requires a valid board state and a square to check, along with the color of the potential attacker. It returns a non-zero value if the square is attacked, and zero if it is not. Ensure that the board is properly initialized before calling this function. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should be properly initialized. - - `s`: The square to check for attacks. It should be a valid square on the board. - - `attacker`: The color of the pieces to check for attacks. Must be a valid pieceColor value representing either white or black. -- **Output**: Returns a non-zero value if the square is attacked by the specified color, otherwise returns zero. -- **See also**: [`boardIsSquareAttacked`](../../src/chesslib/board.c.driver.md#boardIsSquareAttacked) (Implementation) - - ---- -### boardIsInCheck -Checks if the current player is in check. -- **Description**: Use this function to determine if the player whose turn it is currently is in check on the given chess board. This function is useful for validating game states and ensuring that moves do not leave the player's king in check. It should be called after the board has been properly initialized and set up for a game. The function assumes that the board structure is correctly populated and that the currentPlayer field accurately reflects the player whose turn it is. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. The board must be properly initialized and must not be null. The function does not modify the board. -- **Output**: Returns a non-zero value if the current player is in check, and zero if not. -- **See also**: [`boardIsInCheck`](../../src/chesslib/board.c.driver.md#boardIsInCheck) (Implementation) - - ---- -### boardIsPlayerInCheck -Determines if the specified player is in check on the given board. -- **Description**: This function checks whether the player of the specified color is currently in check on the provided chess board. It should be used when you need to verify the check status of a player during a game. The function requires a valid board pointer and a player color as inputs. It iterates over the board to find the player's king and checks if it is under attack by any opposing pieces. The function assumes that the board is correctly set up and that the player color is valid. It returns a non-zero value if the player is in check, and zero otherwise. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null, and should be properly initialized. - - `player`: The color of the player to check, either pcWhite or pcBlack. Must be a valid pieceColor value. -- **Output**: Returns 1 if the specified player is in check, otherwise returns 0. -- **See also**: [`boardIsPlayerInCheck`](../../src/chesslib/board.c.driver.md#boardIsPlayerInCheck) (Implementation) - - ---- -### boardIsInsufficientMaterial -Determines if a chess board position has insufficient material to checkmate. -- **Description**: This function checks whether the given chess board position is such that neither player has enough material to force a checkmate, resulting in a draw. It should be used when you need to determine if the game can be declared a draw due to insufficient material. The function assumes that the board is correctly initialized and contains valid chess pieces. It handles standard cases of insufficient material, such as only kings remaining, or a king with a single minor piece (knight or bishop), or only bishops on the same color. The function does not handle more complex scenarios beyond these standard cases. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should be properly initialized with valid chess pieces. The function does not modify the board. -- **Output**: Returns 1 if the position is a draw due to insufficient material, otherwise returns 0. -- **See also**: [`boardIsInsufficientMaterial`](../../src/chesslib/board.c.driver.md#boardIsInsufficientMaterial) (Implementation) - - ---- -### boardPlayMove -Returns a new board with the specified move applied. -- **Description**: Use this function to create a new board state by applying a move to an existing board. This function is useful when you need to preserve the original board state and work with a modified version. It allocates memory for a new board, copies the current board state, applies the move, and returns the new board. The caller is responsible for freeing the allocated memory for the new board to avoid memory leaks. Ensure that the input board is valid and the move is legal within the context of the game rules. -- **Inputs**: - - `b`: A pointer to the current board state. Must not be null and should represent a valid game state. - - `m`: The move to be applied to the board. It should be a legal move according to the game rules. -- **Output**: A pointer to a new board with the move applied. The caller is responsible for freeing this memory. -- **See also**: [`boardPlayMove`](../../src/chesslib/board.c.driver.md#boardPlayMove) (Implementation) - - ---- -### boardPlayMoveInPlace -Executes a chess move on the given board, updating its state in place. -- **Description**: This function applies a specified chess move to an existing board, directly modifying the board's state to reflect the move. It should be used when you want to update the board without creating a new instance. The function handles special moves such as castling, en passant, and pawn promotion, and updates relevant game state variables like the half-move clock, move number, and castling rights. It assumes the board is in a valid state and the move is legal. The function does not return a value, so it is important to ensure the board and move are correctly set up before calling this function. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null, and the board should be properly initialized before calling this function. The function modifies this board in place. - - `m`: A move structure representing the chess move to be played. The move should be valid and legal according to the current state of the board. -- **Output**: None -- **See also**: [`boardPlayMoveInPlace`](../../src/chesslib/board.c.driver.md#boardPlayMoveInPlace) (Implementation) - - ---- -### boardEq -Determine if two chess boards are identical in all aspects. -- **Description**: Use this function to check if two chess board states are completely identical, including the current player, castle state, en passant target square, half-move clock, move number, and the arrangement of pieces on the board. This function is useful for validating board states in applications such as chess engines or game state verification. It is important to ensure that both board pointers are valid and point to properly initialized board structures before calling this function. The function returns a boolean-like value indicating equality. -- **Inputs**: - - `b1`: A pointer to the first board structure to compare. Must not be null and should point to a valid, initialized board. - - `b2`: A pointer to the second board structure to compare. Must not be null and should point to a valid, initialized board. -- **Output**: Returns 1 if the boards are identical in all aspects, otherwise returns 0. -- **See also**: [`boardEq`](../../src/chesslib/board.c.driver.md#boardEq) (Implementation) - - ---- -### boardEqContext -Compares two chess boards for equality, ignoring move counters and filtering en passant target squares. -- **Description**: Use this function to determine if two chess board states are equivalent in terms of player turn, castling rights, piece positions, and valid en passant targets, while ignoring move counters. This function is useful when you need to compare board states for game logic purposes, such as detecting repeated positions or validating moves, without considering the half-move clock or move number. Ensure that both board pointers are valid and initialized before calling this function. The function returns a non-zero value if the boards are considered equal under these conditions, and zero otherwise. -- **Inputs**: - - `b1`: A pointer to the first board structure to compare. Must not be null and should be properly initialized. - - `b2`: A pointer to the second board structure to compare. Must not be null and should be properly initialized. -- **Output**: Returns 1 if the boards are equal in terms of player turn, castling rights, piece positions, and valid en passant targets; returns 0 otherwise. -- **See also**: [`boardEqContext`](../../src/chesslib/board.c.driver.md#boardEqContext) (Implementation) - - ---- -### boardGetFen -Generates a FEN string representing the current state of the chess board. -- **Description**: This function creates a Forsyth-Edwards Notation (FEN) string that describes the current state of the given chess board. It is useful for saving the board state or for interoperability with other chess software that uses FEN. The function allocates memory for the FEN string, which the caller is responsible for freeing. It assumes that the input board is properly initialized and contains valid game state information. The function handles all aspects of the FEN format, including piece placement, active color, castling availability, en passant target square, halfmove clock, and fullmove number. -- **Inputs**: - - `b`: A pointer to a 'board' structure representing the current state of the chess game. Must not be null and should be properly initialized with valid game state data. -- **Output**: A dynamically allocated string containing the FEN representation of the board. The caller is responsible for freeing this string. -- **See also**: [`boardGetFen`](../../src/chesslib/board.c.driver.md#boardGetFen) (Implementation) - - diff --git a/driver_docs/include/chesslib/boardlist.h.driver.md b/driver_docs/include/chesslib/boardlist.h.driver.md deleted file mode 100644 index 458fbfa..0000000 --- a/driver_docs/include/chesslib/boardlist.h.driver.md +++ /dev/null @@ -1,117 +0,0 @@ -# Purpose -This C header file defines a data structure and associated operations for managing a linked list of chess boards, likely as part of a larger chess application. It includes the definition of two structures: `boardListNode`, which represents a node in the linked list containing a pointer to a `board` and a pointer to the next node, and `boardList`, which maintains the list's head, tail, and size. The file declares functions for creating and managing these lists, including [`boardListCreate`](#boardListCreate) and [`boardListNodeCreate`](#boardListNodeCreate) for initialization, [`boardListAdd`](#boardListAdd) for adding a board to the list, [`boardListGet`](#boardListGet) for retrieving a board by index, [`boardListUndo`](#boardListUndo) for removing the last added board, and [`boardListFree`](#boardListFree) for deallocating the list and its nodes. This header file is essential for handling dynamic collections of chess boards, facilitating operations such as move history management in a chess game. -# Imports and Dependencies - ---- -- `stddef.h` -- `chesslib/board.h` - - -# Global Variables - ---- -### boardListCreate -- **Type**: `function` -- **Description**: The `boardListCreate` function is a global function that is responsible for creating and initializing a new instance of the `boardList` data structure. This function sets up an empty list with no nodes and a size of zero, preparing it for further operations such as adding or retrieving board nodes. -- **Use**: This function is used to initialize a new `boardList` structure, which can then be used to manage a collection of `board` instances in a linked list format. - - ---- -### boardListNodeCreate -- **Type**: `function pointer` -- **Description**: The `boardListNodeCreate` is a function that creates a new `boardListNode` structure, which is a node in a linked list containing a pointer to a `board` and a pointer to the next node in the list. This function is used to initialize a new node with a given `board` pointer, setting up the basic structure for a linked list of boards. -- **Use**: This function is used to create and initialize a new node in a linked list of boards, facilitating the management of a sequence of board states. - - ---- -### boardListGet -- **Type**: `function` -- **Description**: The `boardListGet` function is a global function that retrieves a pointer to a `board` from a `boardList` at a specified index. It is part of a set of operations that manage a linked list of chess boards. -- **Use**: This function is used to access a specific board within a `boardList` by providing the list and the desired index. - - -# Data Structures - ---- -### boardListNode -- **Type**: `struct` -- **Members**: - - `board`: A pointer to a `board` structure, representing a chess board. - - `next`: A pointer to the next `boardListNode` in the linked list. -- **Description**: The `boardListNode` is a node structure used in a linked list to store a sequence of chess boards. Each node contains a pointer to a `board` structure, which represents a chess board, and a pointer to the next node in the list, allowing for traversal through the list. This structure is part of a larger system for managing a list of chess boards, enabling operations such as adding new boards, retrieving boards by index, and undoing moves by removing boards from the list. - - ---- -### boardList -- **Type**: `struct` -- **Members**: - - `head`: A pointer to the first node in the board list. - - `tail`: A pointer to the last node in the board list. - - `size`: The number of nodes currently in the board list. -- **Description**: The `boardList` structure is a linked list designed to manage a sequence of `board` objects, where each node in the list is represented by a `boardListNode`. It maintains pointers to the head and tail of the list for efficient insertion and removal operations, and tracks the total number of nodes with the `size` member. This structure is useful for applications that require dynamic management of chess board states, such as implementing undo functionality in a chess game. - - -# Function Declarations (Public API) - ---- -### boardListCreate -Create and initialize an empty board list. -- **Description**: This function allocates and initializes a new boardList structure, setting up an empty list ready for use. It should be called when a new board list is needed, typically at the start of operations involving board management. The function returns a pointer to the newly created boardList, which initially has no nodes and a size of zero. The caller is responsible for managing the memory of the returned boardList, including eventually freeing it with boardListFree to avoid memory leaks. -- **Inputs**: - - None -- **Output**: A pointer to a newly allocated and initialized boardList structure. -- **See also**: [`boardListCreate`](../../src/chesslib/boardlist.c.driver.md#boardListCreate) (Implementation) - - ---- -### boardListNodeCreate -Creates a new board list node with the specified board. -- **Description**: This function is used to create a new node for a linked list of boards, encapsulating the provided board pointer within a newly allocated node. It is typically used when constructing or modifying a linked list of boards, such as when implementing a history of board states in a chess game. The function allocates memory for the node, initializes it with the given board, and sets the next pointer to NULL. It is the caller's responsibility to ensure that the provided board pointer is valid and to manage the memory of the created node, including freeing it when it is no longer needed. -- **Inputs**: - - `b`: A pointer to a board structure that the new node will encapsulate. The pointer must be valid, and the caller retains ownership of the board. The function does not check for nullity, so passing a null pointer will result in undefined behavior. -- **Output**: A pointer to the newly created boardListNode, or NULL if memory allocation fails. -- **See also**: [`boardListNodeCreate`](../../src/chesslib/boardlist.c.driver.md#boardListNodeCreate) (Implementation) - - ---- -### boardListAdd -Adds a board to the end of a board list. -- **Description**: This function appends a new board to the end of the specified board list. It should be used when you want to maintain a sequence of boards, such as in a game history. The function assumes that the list has been properly initialized and is not null. It updates the list's head and tail pointers as necessary and increments the size of the list. The function does not handle invalid input, so the caller must ensure that the list and board are valid and properly initialized before calling this function. -- **Inputs**: - - `list`: A pointer to a boardList structure where the board will be added. Must not be null and should be initialized before use. The caller retains ownership. - - `b`: A pointer to a board structure to be added to the list. Must not be null and should be a valid board. The caller retains ownership. -- **Output**: None -- **See also**: [`boardListAdd`](../../src/chesslib/boardlist.c.driver.md#boardListAdd) (Implementation) - - ---- -### boardListGet -Retrieve a board from the board list at a specified index. -- **Description**: Use this function to access a specific board from a board list by providing the index of the desired board. The function assumes that the index is within the bounds of the list, meaning it should be less than the size of the list. It is important to ensure that the list is not empty and that the index is valid to avoid undefined behavior. This function does not modify the list or the boards within it. -- **Inputs**: - - `list`: A pointer to a boardList from which a board is to be retrieved. Must not be null, and the list should be properly initialized and populated with boards. - - `index`: An unsigned integer representing the position of the board to retrieve. Must be less than the size of the list to ensure valid access. -- **Output**: A pointer to the board at the specified index in the list. If the index is out of bounds, the behavior is undefined. -- **See also**: [`boardListGet`](../../src/chesslib/boardlist.c.driver.md#boardListGet) (Implementation) - - ---- -### boardListUndo -Removes the last board from the board list. -- **Description**: This function is used to remove the last board from a given board list, effectively undoing the last addition. It should be called when you want to revert the most recent change to the list. The function safely handles cases where the list is empty or contains only one element, ensuring no operation is performed if the list is already empty. It decrements the size of the list and updates the tail pointer accordingly. This function must be called with a valid boardList pointer, and the list should have been previously initialized. -- **Inputs**: - - `list`: A pointer to a boardList structure. Must not be null. The function will handle the case where the list is empty or has only one node, performing no operation if the list is empty. -- **Output**: None -- **See also**: [`boardListUndo`](../../src/chesslib/boardlist.c.driver.md#boardListUndo) (Implementation) - - ---- -### boardListFree -Frees all memory associated with a board list. -- **Description**: This function is used to release all memory allocated for a boardList and its associated nodes. It should be called when the board list is no longer needed to prevent memory leaks. The function traverses the list, freeing each board and node, and finally frees the list itself. It is important to ensure that the list is not used after this function is called, as it will be in an undefined state. -- **Inputs**: - - `list`: A pointer to the boardList to be freed. Must not be null. The function will free all nodes and boards within the list, as well as the list structure itself. The caller should not use the list after this function is called. -- **Output**: None -- **See also**: [`boardListFree`](../../src/chesslib/boardlist.c.driver.md#boardListFree) (Implementation) - - diff --git a/driver_docs/include/chesslib/chess.h.driver.md b/driver_docs/include/chesslib/chess.h.driver.md deleted file mode 100644 index aa2c36e..0000000 --- a/driver_docs/include/chesslib/chess.h.driver.md +++ /dev/null @@ -1,385 +0,0 @@ -# Purpose -This C source code file defines a set of functions and data structures for managing and interacting with a chess game. It provides a comprehensive interface for creating, initializing, and manipulating a chess game, including tracking the game's state, history, and legal moves. The code is structured around a `chess` struct, which encapsulates the current legal moves, terminal state, board history, move history, and repetition count. The file includes functions for creating a new chess game, either from scratch or from a specific FEN (Forsyth-Edwards Notation) string, and for freeing the resources associated with a game. - -The file also defines a variety of utility functions for interacting with the chess game, such as retrieving the current board, legal moves, and terminal state, as well as playing and undoing moves. Additionally, it provides functions to check for specific game conditions, such as whether a draw can be claimed under certain rules. The code is designed to be used as part of a larger chess library, as indicated by the inclusion of headers like "chesslib/boardlist.h" and "chesslib/movelist.h". It does not define a main function, suggesting that it is intended to be used as a library rather than an executable. The file provides a public API for managing chess games, with functions that mirror those in the `board` struct for convenience, allowing for easy integration into other software components that require chess game functionality. -# Imports and Dependencies - ---- -- `chesslib/boardlist.h` -- `chesslib/movelist.h` -- `chesslib/squareset.h` - - -# Global Variables - ---- -### chessCreate -- **Type**: `function pointer` -- **Description**: The `chessCreate` function is a global function that returns a pointer to a `chess` structure, which represents a chess game. This function is responsible for creating and initializing a new chess game instance, which must be freed after use to prevent memory leaks. -- **Use**: The `chessCreate` function is used to instantiate a new chess game, setting up the initial state and allocating necessary resources. - - ---- -### chessCreateFen -- **Type**: `function pointer` -- **Description**: The `chessCreateFen` is a function that creates and initializes a chess game from a given FEN (Forsyth-Edwards Notation) string. It returns a pointer to a `chess` structure, which represents the state of the chess game. If the provided FEN string is invalid, the function returns `NULL`. This function is part of a chess library that manages the state and rules of a chess game. -- **Use**: This function is used to initialize a chess game state from a FEN string, allowing users to start a game from a specific position. - - ---- -### chessGetBoard -- **Type**: `function pointer` -- **Description**: `chessGetBoard` is a function that returns a pointer to a `board` structure, which represents the current state of the chess board in a given chess game. It takes a pointer to a `chess` structure as an argument, which contains the game's state and history. -- **Use**: This function is used to retrieve the current board state from a `chess` game instance. - - ---- -### chessGetLegalMoves -- **Type**: `function` -- **Description**: The `chessGetLegalMoves` function is a global function that returns a pointer to a `moveList` structure, which contains all the legal moves available for the current state of a chess game. It takes a pointer to a `chess` structure as its parameter, which represents the current game state. -- **Use**: This function is used to retrieve the list of legal moves for the current position in a chess game, allowing the game logic to determine possible actions. - - ---- -### chessGetBoardHistory -- **Type**: `function pointer` -- **Description**: `chessGetBoardHistory` is a function that returns a pointer to a `boardList`, which represents the history of board states in a chess game. It takes a pointer to a `chess` structure as an argument, allowing it to access the board history associated with that particular game instance. -- **Use**: This function is used to retrieve the sequence of board states that have occurred throughout the game, enabling analysis or review of the game's progression. - - ---- -### chessGetMoveHistory -- **Type**: `function` -- **Description**: The `chessGetMoveHistory` function is a global function that returns a pointer to a `moveList` structure, which represents the history of moves made in a chess game. It takes a pointer to a `chess` structure as its parameter, allowing it to access the move history of the specific game instance. -- **Use**: This function is used to retrieve the list of moves that have been played in a given chess game. - - ---- -### chessGetMoveHistoryUci -- **Type**: `function` -- **Description**: The `chessGetMoveHistoryUci` function returns a string that represents the history of all moves made in a chess game in the Universal Chess Interface (UCI) format. This function is part of a chess game management system and is used to retrieve the move history for analysis or display purposes. -- **Use**: This function is used to obtain a UCI-formatted string of the move history from a chess game instance. - - ---- -### chessGetFen -- **Type**: `function` -- **Description**: The `chessGetFen` function is a global function that returns a string representing the current state of a chess game in Forsyth-Edwards Notation (FEN). This string must be freed by the caller to avoid memory leaks. -- **Use**: This function is used to obtain a FEN string that describes the current position of the chess game, which can be useful for saving the game state or for analysis purposes. - - -# Data Structures - ---- -### terminalState -- **Type**: `enum` -- **Members**: - - `tsOngoing`: Represents a game state where the game is still in progress. - - `tsCheckmate`: Indicates that the game has ended in checkmate. - - `tsDrawStalemate`: Represents a draw due to stalemate. - - `tsDrawClaimed50MoveRule`: Indicates a draw claimed by the 50-move rule. - - `tsDraw75MoveRule`: Represents a draw automatically enforced by the 75-move rule. - - `tsDrawClaimedThreefold`: Indicates a draw claimed by threefold repetition. - - `tsDrawFivefold`: Represents a draw automatically enforced by fivefold repetition. - - `tsDrawInsufficient`: Indicates a draw due to insufficient material to checkmate. -- **Description**: The `terminalState` enum defines the possible end states of a chess game, including ongoing play, checkmate, and various types of draws such as stalemate, 50-move rule, threefold repetition, and insufficient material. Each enumerator represents a specific condition under which a chess game can be concluded, providing a comprehensive set of outcomes for game termination. - - ---- -### chess -- **Type**: `struct` -- **Members**: - - `currentLegalMoves`: A pointer to a moveList structure containing the current legal moves available in the game. - - `terminal`: An enum value representing the terminal state of the game, such as ongoing, checkmate, or various draw conditions. - - `boardHistory`: A pointer to a boardList structure that keeps track of the history of board states throughout the game. - - `moveHistory`: A pointer to a moveList structure that records the history of moves made during the game. - - `repetitions`: A uint8_t value indicating how many times the current board position has been repeated. -- **Description**: The 'chess' structure is a comprehensive representation of a chess game state, encapsulating the current legal moves, the terminal state of the game, the history of board states and moves, and the number of repetitions of the current position. It is designed to manage and track the progression of a chess game, providing functionality to initialize, update, and query the game state, as well as to handle special conditions like draw claims and move legality. - - -# Function Declarations (Public API) - ---- -### chessCreate -Creates and initializes a new chess game instance. -- **Description**: This function is used to create and initialize a new chess game instance with the standard initial position. It is suitable for starting a new game of chess from the default setup. The function allocates memory for the chess game structure, and the caller is responsible for freeing this memory using `chessFree` when the game is no longer needed. This function does not require any parameters and will return a pointer to the initialized chess game structure. If the initialization fails, it will return NULL. -- **Inputs**: - - None -- **Output**: Returns a pointer to a newly created chess game instance, or NULL if initialization fails. -- **See also**: [`chessCreate`](../../src/chesslib/chess.c.driver.md#chessCreate) (Implementation) - - ---- -### chessCreateFen -Creates and initializes a chess game from a FEN string. -- **Description**: This function allocates and initializes a new chess game structure based on the provided FEN (Forsyth-Edwards Notation) string, which describes a specific board position. It is useful for setting up a game from a known position. The function returns a pointer to the initialized chess game structure if the FEN string is valid. If the FEN string is invalid, the function returns NULL, and no memory is allocated for the chess game. The caller is responsible for freeing the returned chess game structure using `chessFree` when it is no longer needed. -- **Inputs**: - - `fen`: A null-terminated string representing the board position in Forsyth-Edwards Notation. The string must be valid FEN; otherwise, the function will return NULL. The caller retains ownership of this string, and it must not be null. -- **Output**: A pointer to a newly allocated and initialized chess game structure if the FEN is valid, or NULL if the FEN is invalid. -- **See also**: [`chessCreateFen`](../../src/chesslib/chess.c.driver.md#chessCreateFen) (Implementation) - - ---- -### chessInitInPlace -Initializes a chess game to the standard starting position. -- **Description**: This function sets up a chess game represented by the `chess` structure to the standard initial position, ready for play. It should be used when you want to start a new game from the traditional starting setup. The function must be called with a valid `chess` structure that has been properly allocated. It does not return any value and assumes that the input structure is not null. This function is typically used when resetting a game or starting a new one without needing to specify a custom position using FEN notation. -- **Inputs**: - - `c`: A pointer to a `chess` structure that will be initialized to the standard starting position. The structure must be allocated before calling this function and must not be null. The caller retains ownership of the structure. -- **Output**: None -- **See also**: [`chessInitInPlace`](../../src/chesslib/chess.c.driver.md#chessInitInPlace) (Implementation) - - ---- -### chessInitFenInPlace -Initializes a chess game state from a FEN string in place. -- **Description**: This function initializes an existing chess game structure using a given FEN (Forsyth-Edwards Notation) string, which describes a specific board position. It should be used when you want to set up a chess game to a specific state as described by the FEN string. The function must be called with a valid chess structure that has been properly allocated. If the FEN string is invalid, the function will not modify the chess structure and will return an error code. This function is useful for setting up specific board positions for analysis or testing. -- **Inputs**: - - `c`: A pointer to a chess structure that must be pre-allocated and will be initialized to the state described by the FEN string. The caller retains ownership and must ensure it is not null. - - `fen`: A pointer to a null-terminated string containing the FEN representation of the desired board state. The string must be valid and correctly formatted; otherwise, the function will return an error code. -- **Output**: Returns 0 if the initialization is successful, or 1 if the FEN string is invalid, in which case the chess structure remains unmodified. -- **See also**: [`chessInitFenInPlace`](../../src/chesslib/chess.c.driver.md#chessInitFenInPlace) (Implementation) - - ---- -### chessFree -Frees a chess game and all its components. -- **Description**: Use this function to release all memory associated with a chess game when it is no longer needed. It should be called to prevent memory leaks after a chess game has been created using `chessCreate` or `chessCreateFen`. Ensure that the pointer `c` is valid and was previously allocated by one of the creation functions. After calling this function, the pointer `c` should not be used again unless it is reinitialized. -- **Inputs**: - - `c`: A pointer to a `chess` structure that must have been previously allocated by `chessCreate` or `chessCreateFen`. The pointer must not be null, and the function will free all associated resources. Passing an invalid or null pointer results in undefined behavior. -- **Output**: None -- **See also**: [`chessFree`](../../src/chesslib/chess.c.driver.md#chessFree) (Implementation) - - ---- -### chessGetBoard -Retrieves the current board state from a chess game. -- **Description**: Use this function to obtain the current board state of a chess game represented by the `chess` structure. This function is useful when you need to analyze or display the current position of pieces on the board. It is expected that the `chess` structure has been properly initialized and is in a valid state before calling this function. The function does not modify the state of the game or the board. -- **Inputs**: - - `c`: A pointer to a `chess` structure representing the current game. Must not be null and should point to a valid, initialized chess game. If the pointer is invalid, the behavior is undefined. -- **Output**: A pointer to a `board` structure representing the current board state. The caller should not modify the returned board directly. -- **See also**: [`chessGetBoard`](../../src/chesslib/chess.c.driver.md#chessGetBoard) (Implementation) - - ---- -### chessGetLegalMoves -Retrieves the list of legal moves for the current game state. -- **Description**: Use this function to obtain the current list of legal moves available in the ongoing chess game. This function is useful for determining the possible actions a player can take at any given point in the game. It is important to ensure that the chess game has been properly initialized and is in a valid state before calling this function. The returned list reflects the legal moves based on the current board configuration and game rules. -- **Inputs**: - - `c`: A pointer to a chess structure representing the current game state. Must not be null. The chess game should be initialized and in a valid state before calling this function. -- **Output**: A pointer to a moveList structure containing the legal moves for the current game state. The caller should not modify or free this list directly. -- **See also**: [`chessGetLegalMoves`](../../src/chesslib/chess.c.driver.md#chessGetLegalMoves) (Implementation) - - ---- -### chessGetTerminalState -Retrieves the current terminal state of a chess game. -- **Description**: Use this function to determine the current terminal state of a chess game, which indicates whether the game is ongoing, in checkmate, or drawn under various conditions. This function is useful for checking the game's status after moves have been played. It should be called on a valid chess game object that has been properly initialized. The function does not modify the game state and is safe to call at any time after initialization. -- **Inputs**: - - `c`: A pointer to a chess game object. Must not be null and should point to a valid, initialized chess game structure. The function does not modify the object. -- **Output**: The function returns the current terminal state of the chess game, which is an enumeration value of type `terminalState`. -- **See also**: [`chessGetTerminalState`](../../src/chesslib/chess.c.driver.md#chessGetTerminalState) (Implementation) - - ---- -### chessGetBoardHistory -Retrieve the history of board states in a chess game. -- **Description**: Use this function to access the sequence of board states that have occurred throughout the course of a chess game. This can be useful for analyzing the progression of the game or for implementing features that require knowledge of past board configurations. The function should be called on a valid `chess` object that has been properly initialized. It does not modify the state of the game or the `chess` object. -- **Inputs**: - - `c`: A pointer to a `chess` object representing the current game state. Must not be null and should point to a valid, initialized `chess` structure. If the pointer is invalid, behavior is undefined. -- **Output**: Returns a pointer to a `boardList` object representing the history of board states. The caller should not modify or free this list directly. -- **See also**: [`chessGetBoardHistory`](../../src/chesslib/chess.c.driver.md#chessGetBoardHistory) (Implementation) - - ---- -### chessGetMoveHistory -Retrieves the history of moves made in a chess game. -- **Description**: This function is used to obtain the list of all moves that have been played in a given chess game. It is useful for analyzing the progression of the game or for displaying the move history to users. The function should be called on a valid chess game object, and it assumes that the game has been properly initialized. The returned move list reflects the current state of the game's move history and should not be modified by the caller. -- **Inputs**: - - `c`: A pointer to a chess game object. It must not be null and should point to a valid, initialized chess game structure. If the pointer is invalid, the behavior is undefined. -- **Output**: A pointer to a moveList structure representing the history of moves made in the game. The caller should not modify this list. -- **See also**: [`chessGetMoveHistory`](../../src/chesslib/chess.c.driver.md#chessGetMoveHistory) (Implementation) - - ---- -### chessGetRepetitions -Retrieve the number of times the current board position has been repeated. -- **Description**: Use this function to determine how many times the current board position has been encountered during the game. This information is useful for detecting draw conditions such as the threefold repetition rule. The function should be called on a valid `chess` object that has been properly initialized. It does not modify the state of the game or the `chess` object. -- **Inputs**: - - `c`: A pointer to a `chess` object representing the current game state. Must not be null and should be a valid, initialized `chess` object. -- **Output**: Returns the number of times the current board position has been repeated as a `uint8_t` value. -- **See also**: [`chessGetRepetitions`](../../src/chesslib/chess.c.driver.md#chessGetRepetitions) (Implementation) - - ---- -### chessPlayMove -Attempts to play a specified move in a chess game. -- **Description**: This function attempts to play a given move in the context of an ongoing chess game. It should be called when you want to execute a move that has been determined to be legal. The function checks if the game is still ongoing and if the move is among the current legal moves. If the move is valid and the game is ongoing, it updates the game state by applying the move, adding it to the move history, and recalculating the game's fields. If the move is illegal or the game is not ongoing, the function returns an error code. This function should be used only when the game is in progress and the move is expected to be legal. -- **Inputs**: - - `c`: A pointer to a chess structure representing the current game state. Must not be null and the game must be ongoing (i.e., terminal state is tsOngoing). - - `m`: A move structure representing the move to be played. It should be a legal move within the current game state. -- **Output**: Returns 0 if the move was successfully played, or 1 if the move was illegal or the game is not ongoing. -- **See also**: [`chessPlayMove`](../../src/chesslib/chess.c.driver.md#chessPlayMove) (Implementation) - - ---- -### chessUndo -Undoes the last move or draw claim in a chess game. -- **Description**: Use this function to revert the most recent move or draw claim in a chess game, effectively stepping back one turn. It is useful for implementing undo functionality in a chess application. The function must be called on a valid chess game object that has been initialized and has at least one move in its history. If there are no moves to undo, the function will return an error code. Additionally, if the game is in a draw state due to a claimed draw, the draw state will be reset to ongoing. -- **Inputs**: - - `c`: A pointer to a chess game object. This object must be initialized and must not be null. The function will fail if there are no moves in the game's history to undo. -- **Output**: Returns 0 if the undo operation is successful, or 1 if unsuccessful (e.g., no moves left to undo). -- **See also**: [`chessUndo`](../../src/chesslib/chess.c.driver.md#chessUndo) (Implementation) - - ---- -### chessGetPiece -Retrieves the piece located at a specific square on the chessboard. -- **Description**: This function is used to obtain the piece present at a given square on the chessboard within a chess game. It is useful for checking the current state of the board, such as determining which piece occupies a particular position. The function should be called with a valid chess game instance and a valid square identifier. It is important to ensure that the chess game has been properly initialized before calling this function to avoid undefined behavior. -- **Inputs**: - - `c`: A pointer to a chess game instance. Must not be null and should point to a valid, initialized chess game structure. - - `s`: An identifier for a square on the chessboard. Must be a valid square within the board's range. -- **Output**: The function returns the piece located at the specified square. If the square is empty, it returns a value indicating no piece is present. -- **See also**: [`chessGetPiece`](../../src/chesslib/chess.c.driver.md#chessGetPiece) (Implementation) - - ---- -### chessGetPlayer -Returns the current player's color in the chess game. -- **Description**: Use this function to determine which player's turn it is in the current state of the chess game. This function is useful for game logic that depends on knowing the active player, such as determining legal moves or enforcing turn-based rules. It must be called with a valid pointer to a chess game structure that has been properly initialized. The function does not modify the game state or any input parameters. -- **Inputs**: - - `c`: A pointer to a chess structure representing the current game state. Must not be null and should point to a valid, initialized chess game. -- **Output**: The function returns a value of type pieceColor, indicating the color of the player whose turn it is. -- **See also**: [`chessGetPlayer`](../../src/chesslib/chess.c.driver.md#chessGetPlayer) (Implementation) - - ---- -### chessGetCastleState -Retrieve the current castling rights state of the chess game. -- **Description**: This function is used to obtain the current castling rights state from a chess game instance. It is useful for determining which castling moves are still available in the ongoing game. The function should be called with a valid pointer to a chess game structure that has been properly initialized. The castling state is represented as an 8-bit unsigned integer, where each bit may represent a specific castling right. Ensure that the chess game instance is not null before calling this function to avoid undefined behavior. -- **Inputs**: - - `c`: A pointer to a chess structure representing the current state of the game. Must not be null and should be properly initialized before calling this function. -- **Output**: An 8-bit unsigned integer representing the current castling rights state of the game. -- **See also**: [`chessGetCastleState`](../../src/chesslib/chess.c.driver.md#chessGetCastleState) (Implementation) - - ---- -### chessGetEpTarget -Retrieves the en passant target square from the chess game state. -- **Description**: This function is used to obtain the en passant target square from the current state of a chess game. It is useful when you need to determine if an en passant capture is possible in the current position. The function should be called on a valid chess game object that has been properly initialized. It does not modify the state of the game or any of its components. -- **Inputs**: - - `c`: A pointer to a chess game object. It must not be null and should point to a valid, initialized chess game structure. If the pointer is invalid, the behavior is undefined. -- **Output**: The function returns the en passant target square as a value of type 'sq'. If there is no en passant target, the return value will indicate this (typically as a special value or null square, depending on the 'sq' type definition). -- **See also**: [`chessGetEpTarget`](../../src/chesslib/chess.c.driver.md#chessGetEpTarget) (Implementation) - - ---- -### chessGetHalfMoveClock -Retrieve the half-move clock from the chess game state. -- **Description**: This function is used to obtain the current half-move clock value from a chess game, which is part of the game's state. The half-move clock counts the number of half-moves (or ply) since the last capture or pawn advance, and is used in determining draw conditions such as the fifty-move rule. This function should be called when you need to check the progress towards a draw by the fifty-move rule. It is expected that the chess game has been properly initialized before calling this function. -- **Inputs**: - - `c`: A pointer to a chess structure representing the current state of the chess game. Must not be null, and the chess game should be properly initialized before calling this function. -- **Output**: Returns the current half-move clock as an unsigned integer, indicating the number of half-moves since the last capture or pawn move. -- **See also**: [`chessGetHalfMoveClock`](../../src/chesslib/chess.c.driver.md#chessGetHalfMoveClock) (Implementation) - - ---- -### chessGetMoveNumber -Retrieve the current move number of the chess game. -- **Description**: Use this function to obtain the current move number in a chess game, which is useful for tracking the progress of the game or for display purposes. This function should be called on a valid chess game object that has been properly initialized. It is important to ensure that the chess game object is not null before calling this function to avoid undefined behavior. -- **Inputs**: - - `c`: A pointer to a chess game object. This must be a valid, non-null pointer to a chess structure that has been initialized using one of the provided initialization functions. If the pointer is null, the behavior is undefined. -- **Output**: Returns the current move number as an unsigned integer, representing the number of moves made in the game so far. -- **See also**: [`chessGetMoveNumber`](../../src/chesslib/chess.c.driver.md#chessGetMoveNumber) (Implementation) - - ---- -### chessGetMoveHistoryUci -Returns a string of all moves in the game's history in UCI format. -- **Description**: Use this function to obtain a string representation of all moves made in a chess game, formatted according to the Universal Chess Interface (UCI) standard. This is useful for logging, analysis, or exporting the game's move history. The returned string must be freed by the caller to avoid memory leaks. Ensure that the chess game object is properly initialized and contains a valid move history before calling this function. -- **Inputs**: - - `c`: A pointer to a chess game object. Must not be null and should be a valid, initialized chess game instance. The function assumes that the game has a move history to convert to UCI format. -- **Output**: A dynamically allocated string containing the UCI representation of the game's move history. The caller is responsible for freeing this string. -- **See also**: [`chessGetMoveHistoryUci`](../../src/chesslib/chess.c.driver.md#chessGetMoveHistoryUci) (Implementation) - - ---- -### chessIsInCheck -Checks if the current player is in check. -- **Description**: This function determines whether the current player in a chess game is in a state of check, meaning their king is under threat of capture on the next move. It should be called when you need to verify the check status of the game, typically after a move has been made. The function requires a valid chess game object that has been properly initialized. It does not modify the game state or any of its components. -- **Inputs**: - - `c`: A pointer to a chess game object. This must be a valid, initialized chess object and must not be null. If the pointer is invalid or null, the behavior is undefined. -- **Output**: Returns 1 if the current player is in check, and 0 otherwise. -- **See also**: [`chessIsInCheck`](../../src/chesslib/chess.c.driver.md#chessIsInCheck) (Implementation) - - ---- -### chessIsSquareAttacked -Determines if a specific square is attacked by the opponent. -- **Description**: This function checks whether a given square on the chessboard is under attack by the opponent's pieces. It is useful for determining threats to specific squares, which can be critical for making strategic decisions in a chess game. The function should be called with a valid chess game state and a valid square identifier. It assumes that the chess game has been properly initialized and is in a valid state. The function does not modify the game state or any of its components. -- **Inputs**: - - `c`: A pointer to a chess structure representing the current state of the chess game. Must not be null and should point to a valid, initialized chess game. - - `s`: An identifier for the square to be checked. It should be a valid square within the bounds of the chessboard. -- **Output**: Returns 1 if the square is attacked by the opponent, otherwise returns 0. -- **See also**: [`chessIsSquareAttacked`](../../src/chesslib/chess.c.driver.md#chessIsSquareAttacked) (Implementation) - - ---- -### chessGetFen -Returns a string containing the current board position in FEN format. -- **Description**: This function provides the current state of the chess board in the Forsyth-Edwards Notation (FEN) format, which is useful for saving the game state or for interoperability with other chess software. It must be called with a valid `chess` object that has been properly initialized. The returned string must be freed by the caller to avoid memory leaks. This function is typically used when you need to export the current game state or analyze it using external tools that accept FEN strings. -- **Inputs**: - - `c`: A pointer to a `chess` structure representing the current game state. It must not be null and should be properly initialized before calling this function. If the pointer is invalid, the behavior is undefined. -- **Output**: A dynamically allocated string containing the FEN representation of the current board state. The caller is responsible for freeing this string. -- **See also**: [`chessGetFen`](../../src/chesslib/chess.c.driver.md#chessGetFen) (Implementation) - - ---- -### chessCanClaimDraw50 -Determines if a draw can be claimed under the 50-move rule. -- **Description**: This function checks whether a draw can be claimed in a chess game based on the 50-move rule, which allows a player to claim a draw if no pawn has been moved and no capture has been made in the last 50 moves by each player. It should be called when a player wants to verify if they can claim a draw under this rule. The function requires that the game is ongoing and will return a positive result if the conditions for the 50-move rule are met. -- **Inputs**: - - `c`: A pointer to a chess game structure. Must not be null. The game must be in an ongoing state for the function to return a meaningful result. -- **Output**: Returns 1 if a draw can be claimed under the 50-move rule, otherwise returns 0. -- **See also**: [`chessCanClaimDraw50`](../../src/chesslib/chess.c.driver.md#chessCanClaimDraw50) (Implementation) - - ---- -### chessCanClaimDrawThreefold -Determines if a draw can be claimed due to threefold repetition. -- **Description**: Use this function to check if the current game state allows a player to claim a draw based on the threefold repetition rule. This function should be called when you want to verify if the same board position has occurred at least three times during the game, which is a condition for claiming a draw in chess. The function requires that the game is still ongoing and will return a non-zero value if the draw can be claimed. Ensure that the chess game structure is properly initialized and represents an ongoing game before calling this function. -- **Inputs**: - - `c`: A pointer to a chess structure representing the current game state. Must not be null and should be properly initialized. The game must be ongoing for the function to return a meaningful result. -- **Output**: Returns a non-zero value if a draw can be claimed due to threefold repetition, otherwise returns zero. -- **See also**: [`chessCanClaimDrawThreefold`](../../src/chesslib/chess.c.driver.md#chessCanClaimDrawThreefold) (Implementation) - - ---- -### chessClaimDraw50 -Claims a draw under the 50-move rule if applicable. -- **Description**: This function is used to claim a draw in a chess game when the 50-move rule condition is met. The 50-move rule states that a player can claim a draw if no pawn has been moved and no capture has been made in the last 50 moves by each player. This function should be called when a player wishes to claim such a draw. It checks if the draw can be claimed and, if so, updates the game's terminal state to reflect the draw claim. It is important to ensure that the game state is correctly initialized and that the function `chessCanClaimDraw50` returns true before calling this function. -- **Inputs**: - - `c`: A pointer to a `chess` structure representing the current game state. Must not be null. The function assumes that the game state is valid and properly initialized. If the draw cannot be claimed, the game state remains unchanged. -- **Output**: None -- **See also**: [`chessClaimDraw50`](../../src/chesslib/chess.c.driver.md#chessClaimDraw50) (Implementation) - - ---- -### chessClaimDrawThreefold -Claims a draw by threefold repetition if possible. -- **Description**: This function is used to claim a draw in a chess game when the same board position has occurred three times, which is a condition for a draw by threefold repetition. It should be called when a player believes the current position has been repeated three times during the game. The function checks if the draw can be claimed using the current game state and updates the game's terminal state to indicate a draw if the condition is met. It is important to ensure that the game state is up-to-date before calling this function, as it relies on the current board history to determine eligibility for the draw claim. -- **Inputs**: - - `c`: A pointer to a chess game structure. Must not be null. The function assumes that the game state is correctly maintained and up-to-date, as it uses the board history to determine if a draw can be claimed. -- **Output**: None -- **See also**: [`chessClaimDrawThreefold`](../../src/chesslib/chess.c.driver.md#chessClaimDrawThreefold) (Implementation) - - ---- -### chessCalculateFields -Updates the legal moves, repetition count, and terminal state of a chess game. -- **Description**: This function updates the state of a chess game by recalculating the list of legal moves, counting the number of times the current board position has been repeated, and determining the terminal state of the game. It should be called internally after each move to ensure the game state is accurate. The function handles various terminal conditions such as checkmate, stalemate, and draw scenarios based on repetition, move count, or insufficient material. It assumes that the chess game structure is properly initialized and that the current board state is valid. -- **Inputs**: - - `c`: A pointer to a chess structure representing the current game state. Must not be null and should be properly initialized before calling this function. The function will update the fields within this structure. -- **Output**: None -- **See also**: [`chessCalculateFields`](../../src/chesslib/chess.c.driver.md#chessCalculateFields) (Implementation) - - diff --git a/driver_docs/include/chesslib/move.h.driver.md b/driver_docs/include/chesslib/move.h.driver.md deleted file mode 100644 index edcd383..0000000 --- a/driver_docs/include/chesslib/move.h.driver.md +++ /dev/null @@ -1,86 +0,0 @@ -# Purpose -This C header file defines structures and functions related to chess moves, likely as part of a larger chess application. It includes necessary headers for square and piece definitions, indicating that it builds upon existing chess-related data types. The `move` structure encapsulates a chess move, including the starting and ending squares and an optional promotion piece type. The file declares functions for creating moves ([`moveSq`](#moveSq) and [`movePromote`](#movePromote)), comparing moves ([`moveEq`](#moveEq)), and converting moves to and from UCI (Universal Chess Interface) notation ([`moveGetUci`](#moveGetUci) and [`moveFromUci`](#moveFromUci)). This header is designed to facilitate the manipulation and representation of chess moves within a program, providing essential operations for move creation, comparison, and notation conversion. -# Imports and Dependencies - ---- -- `chesslib/square.h` -- `chesslib/piece.h` - - -# Global Variables - ---- -### moveGetUci -- **Type**: `function` -- **Description**: The `moveGetUci` function is a global function that takes a `move` structure as an argument and returns a string representing the move in UCI (Universal Chess Interface) notation. The returned string must be freed by the caller to avoid memory leaks. -- **Use**: This function is used to convert a move structure into its UCI notation string representation. - - -# Data Structures - ---- -### move -- **Type**: `struct` -- **Members**: - - `from`: The starting square of the move. - - `to`: The destination square of the move. - - `promotion`: The type of piece to promote to, if applicable. -- **Description**: The `move` structure represents a chess move, encapsulating the starting and ending squares on the board, as well as an optional promotion piece type for pawn promotions. This structure is fundamental for representing and manipulating moves in a chess game, allowing for operations such as move creation, comparison, and conversion to and from UCI notation. - - -# Function Declarations (Public API) - ---- -### moveSq -Creates a move from one square to another without promotion. -- **Description**: This function is used to create a move structure representing a chess move from one square to another without any piece promotion. It is typically used when a piece is moved on the board without changing its type, such as moving a pawn forward without reaching the promotion rank. The function returns a move structure that can be used in further operations, such as comparing moves or converting to UCI notation. Ensure that the squares provided are valid within the context of the chessboard. -- **Inputs**: - - `from`: The starting square of the move. Must be a valid square on the chessboard. - - `to`: The destination square of the move. Must be a valid square on the chessboard. -- **Output**: A move structure representing the move from the starting square to the destination square without promotion. -- **See also**: [`moveSq`](../../src/chesslib/move.c.driver.md#moveSq) (Implementation) - - ---- -### movePromote -Creates a move with a promotion from one square to another. -- **Description**: This function constructs a chess move that includes a promotion, specifying the starting square, the destination square, and the type of piece to promote to. It is typically used when a pawn reaches the opposite end of the board and is promoted to another piece. The function returns a move structure encapsulating these details. Ensure that the 'from' and 'to' squares are valid board positions and that the promotion piece type is appropriate for a promotion (e.g., not a pawn or king). -- **Inputs**: - - `from`: The starting square of the move. Must be a valid square on the chessboard. - - `to`: The destination square of the move. Must be a valid square on the chessboard. - - `promotion`: The type of piece to promote to. Should be a valid piece type for promotion, typically a queen, rook, bishop, or knight. -- **Output**: Returns a move structure representing the move from the starting square to the destination square with the specified promotion. -- **See also**: [`movePromote`](../../src/chesslib/move.c.driver.md#movePromote) (Implementation) - - ---- -### moveEq -Compares two chess moves for equality. -- **Description**: Use this function to determine if two chess moves are identical in terms of their starting and ending squares, as well as any promotion involved. This function is useful when you need to check if two moves are the same in a chess game context. It requires both moves to be fully specified, including the promotion piece type if applicable. The function returns a non-zero value if the moves are equal and zero if they are not. -- **Inputs**: - - `m1`: The first move to compare. It must be a valid move structure with defined 'from', 'to', and 'promotion' fields. - - `m2`: The second move to compare. It must also be a valid move structure with defined 'from', 'to', and 'promotion' fields. -- **Output**: Returns a non-zero value if the moves are equal, otherwise returns zero. -- **See also**: [`moveEq`](../../src/chesslib/move.c.driver.md#moveEq) (Implementation) - - ---- -### moveGetUci -Converts a chess move to its UCI notation string. -- **Description**: This function generates a string representing a chess move in UCI (Universal Chess Interface) notation. It should be used when you need a textual representation of a move for logging, communication, or analysis purposes. The function allocates memory for the resulting string, which includes the starting and ending squares of the move, and appends the promotion piece type if applicable. The caller is responsible for freeing the allocated memory to avoid memory leaks. Ensure that the move structure is properly initialized before calling this function. -- **Inputs**: - - `m`: A move structure containing the starting square, ending square, and an optional promotion piece type. The move must be valid and properly initialized. If the promotion field is non-zero, it indicates a pawn promotion, and the corresponding piece type will be included in the UCI string. -- **Output**: A dynamically allocated string containing the UCI notation of the move. The caller must free this string after use. -- **See also**: [`moveGetUci`](../../src/chesslib/move.c.driver.md#moveGetUci) (Implementation) - - ---- -### moveFromUci -Converts a UCI string to a move structure. -- **Description**: This function is used to convert a move represented in UCI (Universal Chess Interface) notation into a `move` structure, which includes the starting and ending squares and any promotion piece type. It is typically called when parsing moves from a UCI-compliant input, such as a chess engine or GUI. The input string must be at least four characters long, representing the starting and ending squares in algebraic notation, and may include an optional fifth character for promotion. The function handles standard promotion characters ('n', 'b', 'r', 'q', 'k') and defaults to no promotion if the character is absent or unrecognized. The caller must ensure the input string is valid and properly formatted. -- **Inputs**: - - `uci`: A string representing a move in UCI notation. It must be at least four characters long, with the first two characters representing the starting square and the next two representing the ending square. An optional fifth character can specify a promotion piece ('n', 'b', 'r', 'q', 'k'). The string must not be null, and the caller retains ownership. -- **Output**: A `move` structure containing the parsed starting and ending squares and the promotion piece type, if applicable. -- **See also**: [`moveFromUci`](../../src/chesslib/move.c.driver.md#moveFromUci) (Implementation) - - diff --git a/driver_docs/include/chesslib/movelist.h.driver.md b/driver_docs/include/chesslib/movelist.h.driver.md deleted file mode 100644 index 67e1eb4..0000000 --- a/driver_docs/include/chesslib/movelist.h.driver.md +++ /dev/null @@ -1,127 +0,0 @@ -# Purpose -This C header file defines a data structure and associated operations for managing a list of chess moves, likely as part of a larger chess application. It includes the definition of two structures: `moveListNode`, which represents a single node in the list containing a chess move and a pointer to the next node, and `moveList`, which represents the entire list with pointers to the head and tail nodes and a size indicator. The file declares several functions for creating and manipulating these lists, such as adding moves, retrieving moves by index, undoing the last move, and converting the list to a UCI (Universal Chess Interface) string format. Additionally, it provides a function to free the memory allocated for the list and its nodes, ensuring proper resource management. This header file is essential for managing sequences of moves in a chess game, facilitating operations like move tracking and conversion to standard formats. -# Imports and Dependencies - ---- -- `stddef.h` -- `chesslib/move.h` - - -# Global Variables - ---- -### moveListCreate -- **Type**: `function` -- **Description**: The `moveListCreate` function is a global function that is responsible for creating and initializing a new instance of a `moveList` structure. This structure is used to manage a list of moves, typically in a chess game context, and includes a head and tail pointer to `moveListNode` structures, as well as a size to track the number of moves. -- **Use**: This function is used to create an empty `moveList` that can be populated with moves using other functions like `moveListAdd`. - - ---- -### moveListNodeCreate -- **Type**: `function` -- **Description**: The `moveListNodeCreate` function is a constructor for creating a new node in a linked list of moves, specifically for a chess game. It takes a `move` as an argument and returns a pointer to a newly allocated `moveListNode` structure, which contains the move and a pointer to the next node in the list. -- **Use**: This function is used to initialize and allocate memory for a new node in a move list, which is part of a linked list structure representing a sequence of chess moves. - - ---- -### moveListGetUciString -- **Type**: `function pointer` -- **Description**: The `moveListGetUciString` is a function that takes a pointer to a `moveList` structure and returns a dynamically allocated string representing the moves in the list in UCI (Universal Chess Interface) format. The returned string must be freed by the caller to avoid memory leaks. -- **Use**: This function is used to convert a list of chess moves into a UCI-compliant string representation. - - -# Data Structures - ---- -### moveListNode -- **Type**: `struct` -- **Members**: - - `move`: A `move` object representing a single move in a chess game. - - `next`: A pointer to the next `moveListNode` in the linked list. -- **Description**: The `moveListNode` is a structure used to represent a node in a singly linked list of chess moves. Each node contains a `move` object, which holds the details of a single chess move, and a pointer to the next node in the list, allowing for traversal through the sequence of moves. This structure is part of a larger system for managing and manipulating lists of chess moves, facilitating operations such as adding, retrieving, and undoing moves. - - ---- -### moveList -- **Type**: `struct` -- **Members**: - - `head`: A pointer to the first node in the move list. - - `tail`: A pointer to the last node in the move list. - - `size`: The number of nodes currently in the move list. -- **Description**: The `moveList` structure is a linked list designed to store a sequence of chess moves. It maintains pointers to the head and tail of the list for efficient insertion and removal of moves, and it tracks the total number of moves with the `size` member. This structure is used to manage and manipulate a list of moves in a chess game, allowing operations such as adding new moves, retrieving moves by index, undoing the last move, and converting the list to a UCI string format. - - -# Function Declarations (Public API) - ---- -### moveListCreate -Create an empty move list. -- **Description**: This function initializes and returns a new, empty move list, which is a data structure used to store a sequence of chess moves. It allocates memory for the move list and sets its initial state with no moves. This function should be called when a new move list is needed, and the returned pointer must be managed by the caller, who is responsible for freeing it using `moveListFree` to avoid memory leaks. -- **Inputs**: - - None -- **Output**: A pointer to a newly allocated `moveList` structure, initialized to be empty. -- **See also**: [`moveListCreate`](../../src/chesslib/movelist.c.driver.md#moveListCreate) (Implementation) - - ---- -### moveListNodeCreate -Creates a new move list node with the specified move. -- **Description**: This function is used to create a new node for a move list, initializing it with a specified move. It allocates memory for the node and sets its move field to the provided move, while the next pointer is initialized to NULL. This function is typically used when constructing or modifying a move list in a chess application. The caller is responsible for managing the memory of the created node, including freeing it when it is no longer needed. -- **Inputs**: - - `move`: The move to be stored in the new node. It is expected to be a valid move as defined by the chess library. The function does not validate the move, so the caller must ensure its correctness. -- **Output**: A pointer to the newly created moveListNode containing the specified move, or NULL if memory allocation fails. -- **See also**: [`moveListNodeCreate`](../../src/chesslib/movelist.c.driver.md#moveListNodeCreate) (Implementation) - - ---- -### moveListAdd -Adds a move to the end of a move list. -- **Description**: This function appends a new move to the end of the specified move list, updating the list's size and maintaining the correct order of moves. It should be used when you need to record a new move in a sequence of moves, such as in a chess game. The function assumes that the move list has been properly initialized before calling. It handles the case where the list is initially empty by setting both the head and tail to the new node. The function does not handle invalid input and assumes that the provided move list pointer is valid and non-null. -- **Inputs**: - - `list`: A pointer to a moveList structure where the move will be added. Must not be null and should be properly initialized before calling this function. The caller retains ownership. - - `move`: A move to be added to the list. The function does not impose any specific constraints on the move's value. -- **Output**: None -- **See also**: [`moveListAdd`](../../src/chesslib/movelist.c.driver.md#moveListAdd) (Implementation) - - ---- -### moveListGet -Retrieve a move from the move list at a specified index. -- **Description**: This function is used to access a specific move from a move list by providing an index. It is useful when you need to retrieve a move at a particular position in the list. The function assumes that the index is within the bounds of the list, so it should only be called with a valid index that is less than the size of the list. The move list must be properly initialized and populated with moves before calling this function. -- **Inputs**: - - `list`: A pointer to a moveList structure from which the move is to be retrieved. Must not be null and should be properly initialized. - - `index`: An unsigned integer representing the position of the move to retrieve. Must be less than the size of the list to avoid undefined behavior. -- **Output**: The move located at the specified index in the move list. -- **See also**: [`moveListGet`](../../src/chesslib/movelist.c.driver.md#moveListGet) (Implementation) - - ---- -### moveListUndo -Removes the last move from the move list. -- **Description**: This function is used to remove the last move from a move list, effectively undoing the most recent move. It should be called when you need to backtrack or reverse the last action in a sequence of moves. The function safely handles cases where the list is empty or contains only one move, ensuring no operations are performed on a null or invalid list. It decrements the size of the list accordingly and updates the list's tail pointer. -- **Inputs**: - - `list`: A pointer to a moveList structure representing the list of moves. Must not be null. If the list is empty or null, the function performs no action. The caller retains ownership of the list. -- **Output**: None -- **See also**: [`moveListUndo`](../../src/chesslib/movelist.c.driver.md#moveListUndo) (Implementation) - - ---- -### moveListGetUciString -Creates a UCI string representation of the moves in the list. -- **Description**: This function generates a string in UCI (Universal Chess Interface) format representing all the moves contained in the provided move list. It is useful for exporting or displaying the sequence of moves in a standardized format. The function allocates memory for the resulting string, which the caller is responsible for freeing. If the list is empty, the function returns an empty string. If the list contains only one move, the string will represent that single move without any trailing space. The function handles promotion moves by including the promotion character in the string. -- **Inputs**: - - `list`: A pointer to a moveList structure containing the moves to be converted to a UCI string. Must not be null. The function assumes the list is properly initialized and populated with valid moves. -- **Output**: A dynamically allocated string containing the UCI representation of the moves in the list. The caller is responsible for freeing this string. If the list is empty, an empty string is returned. -- **See also**: [`moveListGetUciString`](../../src/chesslib/movelist.c.driver.md#moveListGetUciString) (Implementation) - - ---- -### moveListFree -Frees a move list and all its nodes. -- **Description**: Use this function to release all memory associated with a move list, including all its nodes. It should be called when the move list is no longer needed to prevent memory leaks. Ensure that the list pointer is valid and was previously allocated by moveListCreate. After calling this function, the list pointer should not be used unless it is reinitialized. -- **Inputs**: - - `list`: A pointer to a moveList structure that must have been created by moveListCreate. The pointer must not be null, and the function will free all nodes within the list as well as the list itself. Passing a null pointer will result in undefined behavior. -- **Output**: None -- **See also**: [`moveListFree`](../../src/chesslib/movelist.c.driver.md#moveListFree) (Implementation) - - diff --git a/driver_docs/include/chesslib/piece.h.driver.md b/driver_docs/include/chesslib/piece.h.driver.md deleted file mode 100644 index e6188e7..0000000 --- a/driver_docs/include/chesslib/piece.h.driver.md +++ /dev/null @@ -1,101 +0,0 @@ -# Purpose -This C header file defines enumerations and function prototypes related to chess pieces, serving as a foundational component for a chess program. It includes three enumerations: `pieceType`, which categorizes the types of chess pieces (e.g., pawn, knight, bishop); `piece`, which represents specific pieces with color differentiation (e.g., white pawn, black knight); and `pieceColor`, which specifies the color of a piece (white or black). The file also declares several functions that operate on these enumerations, such as [`pieceGetType`](#pieceGetType) and [`pieceGetColor`](#pieceGetColor), which extract the type and color from a `piece`, and [`pieceMake`](#pieceMake), which constructs a `piece` from a given type and color. This header file is essential for managing and manipulating chess pieces within a larger chess application. -# Data Structures - ---- -### pieceType -- **Type**: `enum` -- **Members**: - - `ptEmpty`: Represents an empty square or no piece. - - `ptPawn`: Represents a pawn piece. - - `ptKnight`: Represents a knight piece. - - `ptBishop`: Represents a bishop piece. - - `ptRook`: Represents a rook piece. - - `ptQueen`: Represents a queen piece. - - `ptKing`: Represents a king piece. -- **Description**: The `pieceType` enumeration defines the different types of chess pieces that can exist on a chessboard, including an empty square. Each enumerator corresponds to a specific type of piece, such as a pawn, knight, bishop, rook, queen, or king, allowing for easy identification and manipulation of chess pieces within a program. - - ---- -### piece -- **Type**: `enum` -- **Members**: - - `pEmpty`: Represents an empty square on the chessboard. - - `pWPawn`: Represents a white pawn piece. - - `pWKnight`: Represents a white knight piece. - - `pWBishop`: Represents a white bishop piece. - - `pWRook`: Represents a white rook piece. - - `pWQueen`: Represents a white queen piece. - - `pWKing`: Represents a white king piece. - - `pBPawn`: Represents a black pawn piece. - - `pBKnight`: Represents a black knight piece. - - `pBBishop`: Represents a black bishop piece. - - `pBRook`: Represents a black rook piece. - - `pBQueen`: Represents a black queen piece. - - `pBKing`: Represents a black king piece. -- **Description**: The `piece` enum defines constants for each type of chess piece, including both white and black pieces, as well as an empty square. It is used to represent the state of a chessboard in a program, allowing for easy identification and manipulation of chess pieces based on their type and color. - - ---- -### pieceColor -- **Type**: `enum` -- **Members**: - - `pcNoColor`: Represents a piece with no color. - - `pcWhite`: Represents a white-colored piece. - - `pcBlack`: Represents a black-colored piece. -- **Description**: The `pieceColor` enum is used to define the color of a chess piece, with possible values indicating no color, white, or black. This enumeration is part of a chess program and helps in distinguishing between different colored pieces on the board. - - -# Function Declarations (Public API) - ---- -### pieceGetType -Returns the type of a given chess piece. -- **Description**: This function determines the type of a chess piece based on its enumeration value. It is useful for identifying the kind of piece (e.g., pawn, knight) from a given piece enumeration, which includes both white and black pieces. The function expects a valid piece enumeration value as input, and it correctly maps black pieces to their corresponding type by adjusting their enumeration value. It should be used when the specific type of a piece is needed, regardless of its color. -- **Inputs**: - - `p`: An enumeration value of type `piece` representing a chess piece. It must be a valid value from the `piece` enum, including both white and black pieces. Invalid values may lead to undefined behavior. -- **Output**: The function returns a `pieceType` enumeration value corresponding to the type of the input piece, such as `ptPawn`, `ptKnight`, etc. -- **See also**: [`pieceGetType`](../../src/chesslib/piece.c.driver.md#pieceGetType) (Implementation) - - ---- -### pieceGetColor -Returns the color of a given chess piece. -- **Description**: Use this function to determine the color of a specified chess piece. It is useful when you need to differentiate between white and black pieces in a chess game. The function expects a valid piece enumeration value as input and returns the corresponding color. If the piece is not recognized as either white or black, the function returns a value indicating no color. This function is typically used in chess game logic to handle piece-specific operations based on color. -- **Inputs**: - - `p`: A value of type `piece` representing a chess piece. It must be a valid enumeration value within the defined range of pieces. If the value does not correspond to a recognized piece, the function will return `pcNoColor`. -- **Output**: Returns a `pieceColor` value indicating the color of the piece: `pcWhite` for white pieces, `pcBlack` for black pieces, and `pcNoColor` if the piece does not have a recognized color. -- **See also**: [`pieceGetColor`](../../src/chesslib/piece.c.driver.md#pieceGetColor) (Implementation) - - ---- -### pieceTypeGetLetter -Returns the character representation of a chess piece type. -- **Description**: This function provides a character representation for a given chess piece type, which can be useful for displaying or logging purposes. It maps each piece type to a specific character: 'P' for pawn, 'N' for knight, 'B' for bishop, 'R' for rook, 'Q' for queen, 'K' for king, and a space character for an empty piece type. If the input does not match any defined piece type, the function returns a null character. This function should be used when a textual representation of a piece type is needed, and it assumes that the input is a valid `pieceType` enumeration value. -- **Inputs**: - - `pe`: The chess piece type to be converted to a character. It must be a valid `pieceType` enumeration value. If the value is not recognized, the function returns a null character. -- **Output**: Returns a character corresponding to the given piece type, or a null character if the piece type is not recognized. -- **See also**: [`pieceTypeGetLetter`](../../src/chesslib/piece.c.driver.md#pieceTypeGetLetter) (Implementation) - - ---- -### pieceGetLetter -Returns the character representation of a chess piece. -- **Description**: This function provides the character representation of a given chess piece, which is useful for displaying the piece in a user interface or for debugging purposes. The character returned corresponds to the type of the piece, with uppercase letters representing white pieces and lowercase letters representing black pieces. The function assumes that the input is a valid piece enumeration value. It should be used in contexts where the piece's type and color need to be represented as a single character. -- **Inputs**: - - `p`: A piece enumeration value representing a chess piece. It must be a valid value from the 'piece' enum, and the function does not handle invalid values. -- **Output**: A character representing the piece, with uppercase for white pieces and lowercase for black pieces. -- **See also**: [`pieceGetLetter`](../../src/chesslib/piece.c.driver.md#pieceGetLetter) (Implementation) - - ---- -### pieceMake -Create a chess piece of a specified type and color. -- **Description**: This function constructs a chess piece based on the specified type and color. It is used to initialize or create a piece for a chess game, ensuring that the piece is valid by checking the color and type. If the color is not valid (neither white nor black), or if the type is not recognized, the function returns an empty piece. This function is useful for setting up a chessboard or managing game state where specific pieces need to be instantiated. -- **Inputs**: - - `type`: Specifies the type of the chess piece to create. Must be one of the defined pieceType values (e.g., ptPawn, ptKnight). If an unrecognized type is provided, the function returns an empty piece. - - `color`: Specifies the color of the chess piece. Must be either pcWhite or pcBlack. If an invalid color is provided, the function returns an empty piece. -- **Output**: Returns a piece of the specified type and color, or pEmpty if the inputs are invalid. -- **See also**: [`pieceMake`](../../src/chesslib/piece.c.driver.md#pieceMake) (Implementation) - - diff --git a/driver_docs/include/chesslib/piecemoves.h.driver.md b/driver_docs/include/chesslib/piecemoves.h.driver.md deleted file mode 100644 index e6cd113..0000000 --- a/driver_docs/include/chesslib/piecemoves.h.driver.md +++ /dev/null @@ -1,183 +0,0 @@ -# Purpose -This C source code file is part of a chess engine, specifically focusing on defining the movement logic for various chess pieces. It provides a set of functions that generate potential moves for each type of chess piece, including pawns, knights, bishops, rooks, queens, and kings. The file includes functions for both "leaper" pieces, which can move to specific squares based on predefined offsets (such as knights), and "rider" pieces, which can continue moving in a direction until they encounter an obstacle (such as bishops, rooks, and queens). The functions return a `moveList`, which is presumably a data structure that holds potential moves for a piece on a given board state. This file is intended to be included in other parts of the chess engine, as indicated by the `#pragma once` directive, which prevents multiple inclusions. - -The code is organized around the concept of generating potential moves, which are not necessarily legal moves, as they might leave the player in check. This suggests that the file is part of a larger system where move validation and game rules are handled elsewhere. The inclusion of headers like "chesslib/board.h" and "chesslib/movelist.h" indicates that this file relies on external data structures and functions defined in those headers, likely for representing the chessboard and managing lists of moves. The file does not define public APIs or external interfaces directly but provides essential internal functionality for the chess engine's move generation subsystem. -# Imports and Dependencies - ---- -- `chesslib/board.h` -- `chesslib/movelist.h` - - -# Global Variables - ---- -### pmLeaperMoveList -- **Type**: `function` -- **Description**: The `pmLeaperMoveList` function is designed to generate a list of potential moves for a leaper piece on a chessboard. It takes a board, a starting square, a piece type, an array of directional offsets, and the number of directions as parameters. The function returns a moveList, which contains all possible moves for the leaper based on the given directions. -- **Use**: This function is used to calculate and return all potential moves for leaper-type chess pieces, such as knights, based on specified directional offsets. - - ---- -### pmRiderMoveList -- **Type**: `function pointer` -- **Description**: The `pmRiderMoveList` is a function pointer that returns a pointer to a `moveList` structure. It is used to generate a list of potential moves for a rider piece on a chessboard, which can move in a fixed direction any number of times until it encounters an obstacle. The function takes a board pointer, a square, a piece type, an array of direction offsets, and the number of directions as parameters. -- **Use**: This function is used to calculate and return a list of potential moves for rider pieces like bishops, rooks, and queens in a chess game. - - ---- -### pmGetPawnMoves -- **Type**: `function pointer` -- **Description**: The `pmGetPawnMoves` is a function pointer that returns a pointer to a `moveList` structure. It takes two parameters: a pointer to a `board` structure and a `sq` type, which likely represents a square on the chessboard. This function is designed to calculate and return a list of potential moves for a pawn located at a specific square on the given board. -- **Use**: This function is used to determine all possible moves a pawn can make from a given position on the chessboard. - - ---- -### pmGetKnightMoves -- **Type**: `function pointer` -- **Description**: The `pmGetKnightMoves` is a function pointer that returns a pointer to a `moveList` structure. It is designed to calculate and return all potential moves for a knight piece on a chessboard, given the current state of the board and the position of the knight. The function does not account for moves that might leave the player in check. -- **Use**: This function is used to generate a list of all possible moves for a knight piece from a given position on the chessboard. - - ---- -### pmGetBishopMoves -- **Type**: `function pointer` -- **Description**: The `pmGetBishopMoves` is a function pointer that returns a pointer to a `moveList` structure, which represents a list of potential moves for a bishop on a chessboard. It takes two parameters: a pointer to a `board` structure and a `sq` type representing the square on the board where the bishop is located. -- **Use**: This function is used to calculate and return all possible moves for a bishop from a given position on the chessboard. - - ---- -### pmGetRookMoves -- **Type**: `function pointer` -- **Description**: The `pmGetRookMoves` is a function that returns a pointer to a `moveList`, which represents potential moves for a rook piece on a chess board. It takes two parameters: a pointer to a `board` structure and a `sq` type representing the square from which the rook is moving. -- **Use**: This function is used to calculate and return all possible moves for a rook from a given position on the chess board. - - ---- -### pmGetQueenMoves -- **Type**: `function pointer` -- **Description**: The `pmGetQueenMoves` is a function pointer that returns a pointer to a `moveList` structure. It takes two parameters: a pointer to a `board` structure and a `sq` type, which likely represents a square on the chessboard. This function is designed to generate a list of potential moves for a queen piece on a given board position. -- **Use**: This function is used to calculate and return all possible moves for a queen from a specific square on the chessboard. - - ---- -### pmGetKingMoves -- **Type**: `function pointer` -- **Description**: The `pmGetKingMoves` is a function pointer that returns a pointer to a `moveList` structure. It takes two parameters: a pointer to a `board` structure and a `sq` type, which likely represents a square on the chessboard. This function is designed to calculate and return all potential moves for a king piece on a given board position. -- **Use**: This function is used to determine the possible moves for a king piece on a chessboard, which can then be evaluated for legality and strategic value. - - ---- -### pmGetPawnAttacks -- **Type**: `function pointer` -- **Description**: The `pmGetPawnAttacks` is a function that returns a pointer to a `moveList`, which represents potential attack moves for a pawn on a chessboard. It takes a pointer to a `board` structure and a square `s` as parameters, indicating the current state of the board and the position of the pawn, respectively. -- **Use**: This function is used to determine and return the possible attack moves for a pawn from a given position on the chessboard. - - -# Function Declarations (Public API) - ---- -### pmLeaperMoveList -Generates a list of potential moves for a leaper piece on a chessboard. -- **Description**: This function is used to determine all potential moves for a leaper piece, such as a knight, on a given chessboard. It requires the current state of the board, the position of the piece, the type of the piece, and an array of directional offsets that define how the piece can move. The function returns a list of potential moves, which may include moves that leave the player in check. It is important to ensure that the piece at the specified position matches the provided piece type before calling this function. The function handles out-of-bounds moves by ignoring them. -- **Inputs**: - - `b`: A pointer to the board structure representing the current state of the chessboard. Must not be null. - - `s`: The current position of the piece on the board, represented as a square structure. Must be a valid position on the board. - - `pt`: The type of the piece for which moves are being generated. Must match the type of the piece at the given position. - - `dirs`: An array of integer pairs representing the directional offsets for the leaper's movement. Each pair defines a possible move direction. - - `numDirs`: The number of directional offsets provided in the dirs array. Must be greater than zero. -- **Output**: A pointer to a moveList structure containing the potential moves for the leaper piece. The list may be empty if no valid moves are found. -- **See also**: [`pmLeaperMoveList`](../../src/chesslib/piecemoves.c.driver.md#pmLeaperMoveList) (Implementation) - - ---- -### pmRiderMoveList -Generates a list of potential moves for a rider piece from a given position. -- **Description**: This function is used to determine all potential moves for a rider-type chess piece (such as a rook, bishop, or queen) from a specified position on the board. It calculates moves in all specified directions until an obstruction is encountered or the edge of the board is reached. The function should be called when you need to evaluate possible moves for a rider piece, taking into account the current board state. It returns a list of potential moves, which may include moves that leave the player in check, so further validation may be necessary. -- **Inputs**: - - `b`: A pointer to the board structure representing the current state of the chess game. Must not be null. - - `s`: The starting square from which the rider piece will attempt to move. It should be a valid square on the board. - - `pt`: The type of the piece expected at the starting square. This is used to verify that the piece at the square matches the expected type. - - `dirs`: An array of direction offsets, where each direction is represented as a pair of integers indicating file and rank changes. This array defines the directions in which the rider can move. - - `numDirs`: The number of directions provided in the dirs array. It must be a positive integer that does not exceed the actual size of the dirs array. -- **Output**: A pointer to a moveList structure containing all potential moves for the rider piece from the given position. -- **See also**: [`pmRiderMoveList`](../../src/chesslib/piecemoves.c.driver.md#pmRiderMoveList) (Implementation) - - ---- -### pmGetPawnMoves -Generates a list of potential moves for a pawn on a given board square. -- **Description**: This function is used to determine all potential moves for a pawn located at a specific square on a chess board. It should be called when you need to evaluate the possible actions a pawn can take, including forward moves and captures. The function assumes that the board and square are valid and that the square contains a pawn. It returns a move list that may include moves that leave the player in check, so further validation is required to ensure legality in a game context. The function handles both single and double forward moves, as well as diagonal captures, including en passant. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null, and should be properly initialized before calling this function. - - `s`: A square structure representing the position of the pawn on the board. Must be a valid square on the board and should contain a pawn piece. -- **Output**: A pointer to a moveList structure containing potential moves for the pawn. The list may be empty if no moves are possible. -- **See also**: [`pmGetPawnMoves`](../../src/chesslib/piecemoves.c.driver.md#pmGetPawnMoves) (Implementation) - - ---- -### pmGetKnightMoves -Returns a list of potential knight moves from a given square on the board. -- **Description**: This function generates and returns a list of all potential moves for a knight piece located at a specified square on the chess board. It is useful for determining the possible moves a knight can make, regardless of whether these moves would leave the player in check. The function should be called when you need to evaluate the knight's movement options from a specific position on the board. Ensure that the board is properly initialized before calling this function. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess board. Must not be null, and should be a valid, initialized board. - - `s`: The square from which the knight's potential moves are to be calculated. It should be a valid square on the board, typically represented by an integer or an enumeration. -- **Output**: A pointer to a moveList structure containing the potential moves for the knight. The caller is responsible for managing the memory of the returned moveList. -- **See also**: [`pmGetKnightMoves`](../../src/chesslib/piecemoves.c.driver.md#pmGetKnightMoves) (Implementation) - - ---- -### pmGetBishopMoves -Generates potential bishop moves from a given square on the board. -- **Description**: This function is used to obtain a list of all potential moves for a bishop located at a specific square on a chess board. It should be called when you need to determine the possible moves a bishop can make, considering the current state of the board. The function returns a move list that includes all potential moves, but it does not account for whether these moves would leave the player's king in check. It is important to ensure that the board is properly initialized before calling this function. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null, and should be properly initialized before calling this function. - - `s`: The square from which the bishop's potential moves are to be calculated. It should be a valid square on the board, typically represented by an enumeration or integer within the bounds of the board. -- **Output**: A pointer to a moveList structure containing the potential moves for the bishop from the specified square. The caller is responsible for managing the memory of the returned moveList. -- **See also**: [`pmGetBishopMoves`](../../src/chesslib/piecemoves.c.driver.md#pmGetBishopMoves) (Implementation) - - ---- -### pmGetRookMoves -Generates a list of potential rook moves from a given board position. -- **Description**: This function is used to determine all potential moves for a rook piece located at a specific square on a chess board. It should be called when you need to evaluate the possible moves a rook can make from its current position. The function returns a list of moves that the rook can potentially make, but it does not account for whether these moves would leave the player's king in check. It is important to ensure that the board is properly initialized and that the square corresponds to a valid position on the board before calling this function. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null, and should be properly initialized before calling this function. - - `s`: The square on the board where the rook is currently located. It should be a valid square within the board's boundaries. -- **Output**: A pointer to a moveList structure containing all potential moves for the rook from the specified square. The caller is responsible for managing the memory of the returned moveList. -- **See also**: [`pmGetRookMoves`](../../src/chesslib/piecemoves.c.driver.md#pmGetRookMoves) (Implementation) - - ---- -### pmGetQueenMoves -Generates a list of potential moves for a queen on a chessboard. -- **Description**: This function is used to obtain a list of all potential moves for a queen piece located at a specific square on a given chessboard. It is useful in chess engines or applications that need to calculate possible moves for a queen, considering its ability to move any number of squares along a rank, file, or diagonal. The function does not account for whether the moves leave the current player in check, so additional validation may be necessary. It should be called with a valid board and a square that contains a queen piece. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chessboard. Must not be null, and should be properly initialized before calling this function. - - `s`: A square on the board where the queen is located. It should be a valid square index within the board's boundaries. -- **Output**: A pointer to a moveList structure containing potential moves for the queen. The caller is responsible for managing the memory of the returned moveList. -- **See also**: [`pmGetQueenMoves`](../../src/chesslib/piecemoves.c.driver.md#pmGetQueenMoves) (Implementation) - - ---- -### pmGetKingMoves -Generates a list of potential king moves from a given square on the board. -- **Description**: This function is used to determine all potential moves a king can make from a specified square on a chess board. It is useful for evaluating possible king movements during a game, but it does not account for moves that would leave the king in check. The function should be called with a valid board state and a square that contains a king. The caller is responsible for ensuring that the square is within the bounds of the board and that the board is properly initialized. -- **Inputs**: - - `b`: A pointer to a board structure representing the current state of the chess game. Must not be null and should be properly initialized before calling this function. - - `s`: The square from which to calculate the king's potential moves. It should be a valid square on the board, and ideally, it should contain a king piece. -- **Output**: A pointer to a moveList structure containing the potential moves for the king from the specified square. The list may include moves that place the king in check. -- **See also**: [`pmGetKingMoves`](../../src/chesslib/piecemoves.c.driver.md#pmGetKingMoves) (Implementation) - - ---- -### pmGetPawnAttacks -Generates a list of potential attack moves for a pawn on a given square. -- **Description**: This function is used to determine the potential attack moves for a pawn located at a specific square on the chess board. It should be called when you need to evaluate the attacking capabilities of a pawn, considering the pawn's color and position. The function returns a list of moves that represent possible attacks, which may not necessarily be legal in terms of leaving the player in check. It is important to ensure that the square provided contains a pawn, as the function will return an empty move list if the piece on the square is not a pawn. -- **Inputs**: - - `b`: A pointer to the board structure representing the current state of the chess game. Must not be null, and the board should be properly initialized before calling this function. - - `s`: The square on the board where the pawn is located. It should be a valid square within the board's boundaries, and ideally, it should contain a pawn piece. If the square does not contain a pawn, the function will return an empty move list. -- **Output**: Returns a pointer to a moveList structure containing potential attack moves for the pawn. The list may be empty if the square does not contain a pawn or if there are no valid attack moves. -- **See also**: [`pmGetPawnAttacks`](../../src/chesslib/piecemoves.c.driver.md#pmGetPawnAttacks) (Implementation) - - diff --git a/driver_docs/include/chesslib/square.h.driver.md b/driver_docs/include/chesslib/square.h.driver.md deleted file mode 100644 index a23f3d3..0000000 --- a/driver_docs/include/chesslib/square.h.driver.md +++ /dev/null @@ -1,102 +0,0 @@ -# Purpose -This C header file defines a structure and associated functions for handling chessboard squares. The `sq` struct represents a square on a chessboard using two `uint8_t` values for the file and rank, which are constrained to the range 1-8. The file provides utility functions for creating squares from integer coordinates or Standard Algebraic Notation (SAN) strings, converting squares to and from a linear index (0-63), and obtaining the SAN string representation of a square. Additionally, it includes functions to determine if a square is dark-colored and to compare two squares for equality. The `SQ_INVALID` macro defines an invalid square with both file and rank set to -1, which is useful for error handling or initialization. -# Imports and Dependencies - ---- -- `stdint.h` - - -# Global Variables - ---- -### sqGetStr -- **Type**: `function` -- **Description**: The `sqGetStr` function is a global function that takes a square `sq` as an argument and returns a constant character pointer. This pointer represents the SAN (Standard Algebraic Notation) string of the given square, which is a common notation used in chess to describe board positions. -- **Use**: This function is used to obtain the SAN string representation of a square without needing to free the returned string. - - -# Data Structures - ---- -### sq -- **Type**: `struct` -- **Members**: - - `file`: Represents the file (column) of a square on a chessboard, ranging from 1 to 8. - - `rank`: Represents the rank (row) of a square on a chessboard, ranging from 1 to 8. -- **Description**: The `sq` struct is a simple data structure used to represent a square on a chessboard, with `file` and `rank` as its members, both of which are 8-bit unsigned integers. The values for `file` and `rank` are expected to be in the range of 1 to 8, corresponding to the columns and rows of a standard chessboard. This struct is used in various functions to create, manipulate, and compare chessboard squares, as well as to convert between different representations of squares, such as index and SAN (Standard Algebraic Notation) strings. - - -# Function Declarations (Public API) - ---- -### sqI -Create a square from file and rank values. -- **Description**: This function constructs a square object using the provided file and rank values, which represent positions on a chessboard. It is useful when you need to create a square based on specific file and rank coordinates. The function expects both file and rank to be within the range of 1 to 8, inclusive, corresponding to valid chessboard positions. If either value is outside this range, the function returns a special invalid square constant, SQ_INVALID, indicating an error in the input values. -- **Inputs**: - - `file`: The file component of the square, representing the column on a chessboard. Valid values are from 1 to 8, inclusive. If the value is outside this range, the function returns SQ_INVALID. - - `rank`: The rank component of the square, representing the row on a chessboard. Valid values are from 1 to 8, inclusive. If the value is outside this range, the function returns SQ_INVALID. -- **Output**: Returns a square object with the specified file and rank if both are valid; otherwise, returns SQ_INVALID. -- **See also**: [`sqI`](../../src/chesslib/square.c.driver.md#sqI) (Implementation) - - ---- -### sqS -Creates a square from a SAN string representation. -- **Description**: This function converts a Standard Algebraic Notation (SAN) string, representing a chessboard square, into a `sq` struct. It expects a two-character string where the first character is a file ('a' to 'h') and the second character is a rank ('1' to '8'). If the input string does not conform to this format, the function returns `SQ_INVALID`. This function is useful for parsing chess moves or positions from SAN strings into a structured format for further processing. -- **Inputs**: - - `str`: A pointer to a null-terminated string representing a chessboard square in SAN format. The string must be exactly two characters long, with the first character being a file ('a' to 'h') and the second a rank ('1' to '8'). The caller retains ownership of the string, and it must not be null. If the string is invalid, the function returns `SQ_INVALID`. -- **Output**: Returns a `sq` struct representing the square if the input is valid, or `SQ_INVALID` if the input string is not a valid SAN square. -- **See also**: [`sqS`](../../src/chesslib/square.c.driver.md#sqS) (Implementation) - - ---- -### sqIndex -Converts an index to a square representation. -- **Description**: This function converts a given index, ranging from 0 to 63, into a square structure representing a position on a chessboard. It is useful for translating linear index values into two-dimensional board coordinates. The function returns a special invalid square if the provided index is outside the valid range, ensuring that invalid inputs are safely handled. -- **Inputs**: - - `index`: An unsigned 8-bit integer representing the index of the square, expected to be in the range 0 to 63. If the index is outside this range, the function returns an invalid square. -- **Output**: Returns a square structure corresponding to the given index, or an invalid square if the index is out of range. -- **See also**: [`sqIndex`](../../src/chesslib/square.c.driver.md#sqIndex) (Implementation) - - ---- -### sqGetIndex -Converts a square to its corresponding index on a chessboard. -- **Description**: This function calculates the zero-based index of a given square on a chessboard, where the index ranges from 0 to 63. It is useful for mapping a square's file and rank to a single linear index, which can be used in array representations of a chessboard. The function expects the square's file and rank to be within the range of 1 to 8, inclusive. If the square's file or rank is outside this range, the function returns -1, indicating an invalid square. -- **Inputs**: - - `s`: A square structure containing 'file' and 'rank' fields, both of which must be in the range 1 to 8. If either field is outside this range, the function returns -1. The caller retains ownership of the square structure. -- **Output**: Returns a uint8_t representing the zero-based index of the square on a chessboard, or -1 if the square is invalid. -- **See also**: [`sqGetIndex`](../../src/chesslib/square.c.driver.md#sqGetIndex) (Implementation) - - ---- -### sqGetStr -Returns the SAN string representation of a given square. -- **Description**: This function provides the Standard Algebraic Notation (SAN) string for a given square, which is useful for representing chessboard positions in a human-readable format. It should be used when you need to convert a square structure into its corresponding SAN string. The function expects a valid square structure as input, and if the square's index is out of the valid range (0-63), it returns a placeholder string "##". The returned string does not require deallocation by the caller. -- **Inputs**: - - `s`: A square structure representing a position on a chessboard. The square must be valid, with an index in the range 0-63. If the index is outside this range, the function returns "##". -- **Output**: A pointer to a constant character string representing the SAN notation of the square, or "##" if the square is invalid. -- **See also**: [`sqGetStr`](../../src/chesslib/square.c.driver.md#sqGetStr) (Implementation) - - ---- -### sqIsDark -Determine if a chessboard square is dark-colored. -- **Description**: This function checks whether a given chessboard square, represented by the `sq` structure, is dark-colored. It is useful for applications that need to differentiate between dark and light squares on a chessboard. The function expects the `sq` structure to have `file` and `rank` values within the range of 1 to 8, as these represent valid chessboard coordinates. The function returns 1 if the square is dark and 0 if it is light. It is important to ensure that the `sq` structure is properly initialized with valid values before calling this function. -- **Inputs**: - - `s`: A structure representing a chessboard square, with `file` and `rank` fields expected to be in the range 1-8. The caller must ensure these values are valid chessboard coordinates. -- **Output**: Returns 1 if the square is dark-colored, and 0 if it is light-colored. -- **See also**: [`sqIsDark`](../../src/chesslib/square.c.driver.md#sqIsDark) (Implementation) - - ---- -### sqEq -Compares two chessboard squares for equality. -- **Description**: Use this function to determine if two chessboard squares, represented by the `sq` struct, are equal in terms of their file and rank. The function checks if the file and rank of each square are within the valid range of 1 to 8, inclusive. If either square has a file or rank outside this range, it is considered invalid and set to `SQ_INVALID`. The function then compares the file and rank of the two squares and returns a result indicating whether they are equal. This function is useful in applications where you need to verify if two positions on a chessboard are the same. -- **Inputs**: - - `s1`: The first square to compare, represented by the `sq` struct. The `file` and `rank` must be in the range 1 to 8. If out of range, it is treated as `SQ_INVALID`. - - `s2`: The second square to compare, represented by the `sq` struct. The `file` and `rank` must be in the range 1 to 8. If out of range, it is treated as `SQ_INVALID`. -- **Output**: Returns 1 if the squares are equal (same file and rank), or 0 if they are not. -- **See also**: [`sqEq`](../../src/chesslib/square.c.driver.md#sqEq) (Implementation) - - diff --git a/driver_docs/include/chesslib/squareset.h.driver.md b/driver_docs/include/chesslib/squareset.h.driver.md deleted file mode 100644 index cacf726..0000000 --- a/driver_docs/include/chesslib/squareset.h.driver.md +++ /dev/null @@ -1,33 +0,0 @@ -# Purpose -This C header file defines a data structure and associated functions for managing a "square set" in a chess-related application. The square set is represented as a 64-bit integer (`uint64_t`), where each bit corresponds to a square on a chessboard, indicating whether it is "on" or "off." The file includes function prototypes for [`sqSetSet`](#sqSetSet) and [`sqSetGet`](#sqSetGet), which are used to modify and retrieve the state of a specific square within the set, respectively. The file also includes a note to potentially add conditional typedefs for systems that do not support `uint64_t`, suggesting a future enhancement for broader compatibility. This header is part of a larger library, as indicated by the inclusion of "chesslib/square.h". -# Imports and Dependencies - ---- -- `chesslib/square.h` - - -# Function Declarations (Public API) - ---- -### sqSetSet -Sets the state of a square in a square set. -- **Description**: This function modifies the state of a specific square within a square set, which is represented as a 64-bit integer. It should be used to mark a square as either 'on' or 'off' based on the provided value. The function does nothing if the square is invalid, ensuring that only valid squares are modified. This function is typically used in scenarios where you need to track the state of multiple squares on a chessboard, such as in board games or simulations. The square set must be properly initialized before calling this function. -- **Inputs**: - - `ss`: A pointer to the square set (sqSet) to be modified. Must not be null, and the caller retains ownership. - - `s`: The square (sq) whose state is to be set. Must be a valid square; otherwise, the function will not modify the square set. - - `value`: A uint8_t value indicating the desired state of the square: non-zero to set the square 'on', zero to set it 'off'. -- **Output**: None -- **See also**: [`sqSetSet`](../../src/chesslib/squareset.c.driver.md#sqSetSet) (Implementation) - - ---- -### sqSetGet -Retrieve the status of a square in a square set. -- **Description**: This function checks whether a specific square in a square set is marked as 'on' or 'off'. It is used to determine the current state of a square within a 64-bit representation of a chessboard. The function should be called with a valid square set and a valid square identifier. If the square identifier is invalid, the function returns 0, indicating the square is 'off'. This function is useful for querying the state of individual squares in board-related operations. -- **Inputs**: - - `ss`: A pointer to a sqSet, which is a 64-bit integer representing the state of each square on a chessboard. The pointer must not be null, and the caller retains ownership. - - `s`: A square identifier of type sq. It must represent a valid square on the board. If the square is invalid (e.g., SQ_INVALID), the function returns 0. -- **Output**: Returns 1 if the specified square is 'on' in the set, and 0 if it is 'off' or if the square is invalid. -- **See also**: [`sqSetGet`](../../src/chesslib/squareset.c.driver.md#sqSetGet) (Implementation) - - diff --git a/driver_docs/src.driver.md b/driver_docs/src.driver.md deleted file mode 100644 index 5d3fde2..0000000 --- a/driver_docs/src.driver.md +++ /dev/null @@ -1,6 +0,0 @@ -## Folders -- **[chesslib](src/chesslib.driver.md)**: The `chesslib` folder in the `c_cpp_export_test` codebase contains C source files that collectively implement a comprehensive chess library, including functionalities for board management, move handling, game state determination, and piece movement logic. - -## Files -- **[tests.c](src/tests.c.driver.md)**: The `tests.c` file in the `c_cpp_export_test` codebase contains a comprehensive suite of unit tests for various components of a chess implementation in C, including tests for squares, moves, move lists, boards, piece moves, attacked squares, move generation, FEN generation, draw conditions, board lists, and square sets. -- **[tests.h](src/tests.h.driver.md)**: The `tests.h` file defines a series of function prototypes for testing various aspects of a Chess implementation in C, including square, move, board, and piece move functionalities. diff --git a/driver_docs/src/chesslib.driver.md b/driver_docs/src/chesslib.driver.md deleted file mode 100644 index f246076..0000000 --- a/driver_docs/src/chesslib.driver.md +++ /dev/null @@ -1,11 +0,0 @@ - -## Files -- **[board.c](chesslib/board.c.driver.md)**: The `board.c` file in the `c_cpp_export_test` codebase implements a chess board, including functions for creating a board from a FEN string, generating legal moves, checking for check and checkmate, and converting the board state back to a FEN string. -- **[boardlist.c](chesslib/boardlist.c.driver.md)**: The `boardlist.c` file implements a singly linked list for managing a list of chess boards, including functions to create, add, retrieve, undo, and free the list. -- **[chess.c](chesslib/chess.c.driver.md)**: The `chess.c` file implements a chess game, providing functions for creating and managing chess games, handling moves, and determining game states such as checkmate and draw conditions. -- **[move.c](chesslib/move.c.driver.md)**: The `move.c` file in the `c_cpp_export_test` codebase implements functions for handling chess moves, including creating moves, comparing them, converting to and from UCI strings, and handling promotions. -- **[movelist.c](chesslib/movelist.c.driver.md)**: The `movelist.c` file implements a linked list structure for managing chess moves, including functions for creating, adding, retrieving, undoing moves, and generating a UCI string representation of the move list. -- **[piece.c](chesslib/piece.c.driver.md)**: The `piece.c` file in the `c_cpp_export_test` codebase implements functions for handling chess pieces, including determining their type, color, and corresponding letter representation. -- **[piecemoves.c](chesslib/piecemoves.c.driver.md)**: The `piecemoves.c` file in the `c_cpp_export_test` codebase implements the movement logic for chess pieces, including pawns, knights, bishops, rooks, queens, and kings, while avoiding circular dependencies. -- **[square.c](chesslib/square.c.driver.md)**: The `square.c` file in the `c_cpp_export_test` codebase provides functions for creating and manipulating chessboard squares, including conversion between different representations and determining square properties such as color. -- **[squareset.c](chesslib/squareset.c.driver.md)**: The `squareset.c` file implements functions for setting and getting values in a square set, which is part of a chess library. diff --git a/driver_docs/src/chesslib/board.c.driver.md b/driver_docs/src/chesslib/board.c.driver.md deleted file mode 100644 index cb0f7b5..0000000 --- a/driver_docs/src/chesslib/board.c.driver.md +++ /dev/null @@ -1,350 +0,0 @@ -# Purpose -This C source code file implements a chess board management system, providing functionality to create, manipulate, and evaluate chess board states. The code is designed to handle chess board operations using the Forsyth-Edwards Notation (FEN), which is a standard notation for describing a particular board position of a chess game. The file includes functions to initialize a board from a FEN string, generate legal moves, check for check conditions, and determine if a board state has insufficient material for a checkmate. It also provides utilities for playing moves, checking board equality, and converting board states back to FEN strings. - -The code is structured around a `board` data structure, which encapsulates the state of a chess game, including piece positions, current player, castling rights, en passant targets, and move counters. Key functions include [`boardCreateFromFen`](#boardCreateFromFen) for initializing a board from a FEN string, [`boardGenerateMoves`](#boardGenerateMoves) for generating all legal moves for the current player, and [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) for executing a move on the board. The file also includes error handling for invalid FEN strings and provides mechanisms to check for special conditions like check, checkmate, and insufficient material. This code is intended to be part of a larger chess library, as indicated by the inclusion of headers like "chesslib/board.h" and "chesslib/piecemoves.h", and it does not define a main function, suggesting it is not an executable but rather a component to be used within a chess application. -# Imports and Dependencies - ---- -- `stdio.h` -- `ctype.h` -- `stdlib.h` -- `string.h` -- `chesslib/board.h` -- `chesslib/piecemoves.h` - - -# Functions - ---- -### boardCreate -The `boardCreate` function initializes a new chess board using the standard initial position in FEN notation. -- **Inputs**: - - None -- **Control Flow**: - - The function calls [`boardCreateFromFen`](#boardCreateFromFen) with `INITIAL_FEN` as the argument, which represents the standard initial position of a chess game. - - It returns the result of the [`boardCreateFromFen`](#boardCreateFromFen) function call. -- **Output**: - - A pointer to a `board` structure initialized to the standard starting position, or `NULL` if initialization fails. -- **Functions called**: - - [`boardCreateFromFen`](#boardCreateFromFen) - - ---- -### boardCreateFromFen -The `boardCreateFromFen` function creates a new chess board initialized from a given FEN string. -- **Inputs**: - - `fen`: A string representing the board state in Forsyth-Edwards Notation (FEN). -- **Control Flow**: - - Allocate memory for a new `board` structure. - - Call [`boardInitFromFenInPlace`](#boardInitFromFenInPlace) to initialize the board with the FEN string. - - If initialization fails (returns non-zero), free the allocated memory and return `NULL`. - - If initialization succeeds, return the pointer to the newly created board. -- **Output**: - - Returns a pointer to a newly allocated and initialized `board` structure, or `NULL` if initialization fails. -- **Functions called**: - - [`boardInitFromFenInPlace`](#boardInitFromFenInPlace) - - ---- -### boardInitInPlace -The `boardInitInPlace` function initializes a chess board to the standard starting position using the FEN string for the initial setup. -- **Inputs**: - - `b`: A pointer to a `board` structure that will be initialized to the standard starting position. -- **Control Flow**: - - The function calls [`boardInitFromFenInPlace`](#boardInitFromFenInPlace) with the board pointer `b` and the constant `INITIAL_FEN` which represents the standard starting position in FEN notation. -- **Output**: - - The function does not return a value; it modifies the board in place to represent the initial chess position. -- **Functions called**: - - [`boardInitFromFenInPlace`](#boardInitFromFenInPlace) - - ---- -### boardInitFromFenInPlace -The function `boardInitFromFenInPlace` initializes a chess board structure from a given FEN (Forsyth-Edwards Notation) string, setting up the board's pieces, current player, castling rights, en passant target square, and move counters. -- **Inputs**: - - `b`: A pointer to a `board` structure that will be initialized based on the FEN string. - - `fen`: A constant character pointer representing the FEN string that describes the board state to be initialized. -- **Control Flow**: - - Initialize the starting square to the top-left of the board (file 1, rank 8). - - Iterate over the FEN string to read and set up the board pieces, handling numbers for empty squares, slashes for rank changes, and specific characters for different pieces. - - Check for errors in the FEN string format, such as misplaced slashes or characters beyond the end of a rank, and return an error code if found. - - After reading the piece placement, read the current player's turn ('w' or 'b') and validate it. - - Parse the castling rights from the FEN string, updating the board's castling state accordingly. - - Read the en passant target square from the FEN string, validating its format and updating the board's en passant target. - - Finally, read the half-move clock and full move number from the FEN string using `sscanf`. -- **Output**: - - Returns 0 on successful initialization, or 1 if an error is encountered in the FEN string. -- **Functions called**: - - [`sqI`](square.c.driver.md#sqI) - - [`boardSetPiece`](#boardSetPiece) - - [`boardGetPiece`](#boardGetPiece) - - [`sqS`](square.c.driver.md#sqS) - - ---- -### boardSetPiece -The `boardSetPiece` function sets a specific piece on a chess board at a given square. -- **Inputs**: - - `b`: A pointer to the `board` structure where the piece is to be set. - - `s`: The `sq` type representing the square on the board where the piece should be placed. - - `p`: The `piece` type representing the chess piece to be placed on the board. -- **Control Flow**: - - Calculate the index of the square `s` using the [`sqGetIndex`](square.c.driver.md#sqGetIndex) function. - - Set the piece `p` at the calculated index in the `pieces` array of the board `b`. -- **Output**: - - This function does not return any value; it modifies the board in place. -- **Functions called**: - - [`sqGetIndex`](square.c.driver.md#sqGetIndex) - - ---- -### boardGetPiece -The `boardGetPiece` function retrieves the chess piece located at a specific square on a given chess board. -- **Inputs**: - - `b`: A pointer to a `board` structure representing the current state of the chess board. - - `s`: A `sq` type representing the specific square on the board from which to retrieve the piece. -- **Control Flow**: - - The function calls [`sqGetIndex`](square.c.driver.md#sqGetIndex) with the square `s` to get the corresponding index in the board's piece array. - - It then accesses the `pieces` array of the board `b` using the calculated index to retrieve the piece located at that square. - - Finally, it returns the piece found at the specified index. -- **Output**: - - The function returns a `piece` type, which represents the chess piece located at the specified square on the board. -- **Functions called**: - - [`sqGetIndex`](square.c.driver.md#sqGetIndex) - - ---- -### boardGenerateMoves -The `boardGenerateMoves` function generates a list of all legal moves for the current player on a given chess board, including castling moves, and returns this list. -- **Inputs**: - - `b`: A pointer to a `board` structure representing the current state of the chess game. -- **Control Flow**: - - Create an empty move list using [`moveListCreate`](movelist.c.driver.md#moveListCreate). - - Iterate over each square on the board (64 squares total). - - For each square, retrieve the piece and check if it belongs to the current player; if not, continue to the next square. - - Determine the type of piece and generate potential moves for that piece using the appropriate function (e.g., [`pmGetPawnMoves`](piecemoves.c.driver.md#pmGetPawnMoves) for pawns). - - For each potential move, simulate the move on a copy of the board and check if the move results in the current player being in check; if not, add the move to the move list. - - Check if castling is possible for the current player by verifying the conditions for castling (e.g., no pieces between the king and rook, squares not attacked). - - Add valid castling moves to the move list if conditions are met. - - Return the list of legal moves. -- **Output**: - - A pointer to a `moveList` structure containing all legal moves for the current player, which must be freed after use. -- **Functions called**: - - [`moveListCreate`](movelist.c.driver.md#moveListCreate) - - [`sqIndex`](square.c.driver.md#sqIndex) - - [`boardGetPiece`](#boardGetPiece) - - [`pieceGetColor`](piece.c.driver.md#pieceGetColor) - - [`pieceGetType`](piece.c.driver.md#pieceGetType) - - [`pmGetPawnMoves`](piecemoves.c.driver.md#pmGetPawnMoves) - - [`pmGetKnightMoves`](piecemoves.c.driver.md#pmGetKnightMoves) - - [`pmGetBishopMoves`](piecemoves.c.driver.md#pmGetBishopMoves) - - [`pmGetRookMoves`](piecemoves.c.driver.md#pmGetRookMoves) - - [`pmGetQueenMoves`](piecemoves.c.driver.md#pmGetQueenMoves) - - [`pmGetKingMoves`](piecemoves.c.driver.md#pmGetKingMoves) - - [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) - - [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) - - [`moveListAdd`](movelist.c.driver.md#moveListAdd) - - [`moveListFree`](movelist.c.driver.md#moveListFree) - - [`sqI`](square.c.driver.md#sqI) - - [`boardIsSquareAttacked`](#boardIsSquareAttacked) - - [`moveSq`](move.c.driver.md#moveSq) - - ---- -### boardIsSquareAttacked -The function `boardIsSquareAttacked` checks if a specific square on a chess board is attacked by any piece of a given color. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chess board. - - `s`: The square (`sq` type) on the board to check for attacks. - - `attacker`: The color (`pieceColor` type) of the pieces that might be attacking the square. -- **Control Flow**: - - Iterate over all 64 squares on the board to find pieces of the specified attacker color. - - For each piece found, determine its type and generate a list of possible moves or attacks for that piece using the appropriate function (e.g., [`pmGetPawnAttacks`](piecemoves.c.driver.md#pmGetPawnAttacks), [`pmGetKnightMoves`](piecemoves.c.driver.md#pmGetKnightMoves), etc.). - - If a list of moves is generated, iterate through the moves to check if any move targets the specified square `s`. - - If a move is found that targets the square `s`, free the move list and return 1, indicating the square is attacked. - - If no attacking move is found after checking all pieces, return 0, indicating the square is not attacked. -- **Output**: - - Returns 1 if the square is attacked by a piece of the specified color, otherwise returns 0. -- **Functions called**: - - [`sqIndex`](square.c.driver.md#sqIndex) - - [`boardGetPiece`](#boardGetPiece) - - [`pieceGetColor`](piece.c.driver.md#pieceGetColor) - - [`pieceGetType`](piece.c.driver.md#pieceGetType) - - [`pmGetPawnAttacks`](piecemoves.c.driver.md#pmGetPawnAttacks) - - [`pmGetKnightMoves`](piecemoves.c.driver.md#pmGetKnightMoves) - - [`pmGetBishopMoves`](piecemoves.c.driver.md#pmGetBishopMoves) - - [`pmGetRookMoves`](piecemoves.c.driver.md#pmGetRookMoves) - - [`pmGetQueenMoves`](piecemoves.c.driver.md#pmGetQueenMoves) - - [`pmGetKingMoves`](piecemoves.c.driver.md#pmGetKingMoves) - - [`sqEq`](square.c.driver.md#sqEq) - - [`moveListFree`](movelist.c.driver.md#moveListFree) - - ---- -### boardIsInCheck -The `boardIsInCheck` function checks if the current player on a given chess board is in check. -- **Inputs**: - - `b`: A pointer to a `board` structure representing the current state of the chess game. -- **Control Flow**: - - The function calls [`boardIsPlayerInCheck`](#boardIsPlayerInCheck), passing the board `b` and the current player `b->currentPlayer` as arguments. - - It returns the result of the [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) function call, which determines if the current player's king is under attack. -- **Output**: - - Returns a `uint8_t` value, where 1 indicates the current player is in check, and 0 indicates they are not. -- **Functions called**: - - [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) - - ---- -### boardIsPlayerInCheck -The function `boardIsPlayerInCheck` checks if a player's king is currently in check on a given chess board. -- **Inputs**: - - `b`: A pointer to a `board` structure representing the current state of the chess board. - - `player`: A `pieceColor` value indicating the color of the player (either `pcWhite` or `pcBlack`) whose king's check status is being evaluated. -- **Control Flow**: - - Determine the type of the player's king (`pWKing` for white or `pBKing` for black) and the opponent's color (`pcBlack` for white player and `pcWhite` for black player). - - Iterate over all 64 squares of the board using a loop. - - For each square, check if the piece on that square is the player's king. - - If the player's king is found, check if the square is attacked by any piece of the opponent's color using [`boardIsSquareAttacked`](#boardIsSquareAttacked). - - If the square is attacked, return 1 indicating the player is in check. - - If the loop completes without finding the king in check, return 0 indicating the player is not in check. -- **Output**: - - Returns a `uint8_t` value: 1 if the player's king is in check, 0 otherwise. -- **Functions called**: - - [`sqIndex`](square.c.driver.md#sqIndex) - - [`boardGetPiece`](#boardGetPiece) - - [`boardIsSquareAttacked`](#boardIsSquareAttacked) - - ---- -### boardIsInsufficientMaterial -The function `boardIsInsufficientMaterial` checks if a chess board position is a draw due to insufficient material to checkmate. -- **Inputs**: - - `b`: A pointer to a `board` structure representing the current state of the chess board. -- **Control Flow**: - - Initialize counters for pieces, knights, bishops on dark squares, bishops on light squares, and kings. - - Iterate over all 64 squares of the board to count the number of each type of piece. - - Check if the board has only kings, which is always a draw, and return 1 if true. - - Check if there is one white king and one black king, and if the total number of pieces equals the sum of kings and minor pieces (knights and bishops). - - If there are only two kings and one minor piece, return 1 indicating a draw. - - If there are only two kings and bishops all on the same color, return 1 indicating a draw. - - If none of the draw conditions are met, return 0. -- **Output**: - - Returns 1 if the position is a draw due to insufficient material, otherwise returns 0. -- **Functions called**: - - [`sqIndex`](square.c.driver.md#sqIndex) - - [`boardGetPiece`](#boardGetPiece) - - [`pieceGetType`](piece.c.driver.md#pieceGetType) - - [`sqIsDark`](square.c.driver.md#sqIsDark) - - ---- -### boardPlayMove -The `boardPlayMove` function creates a new chess board state by applying a given move to an existing board. -- **Inputs**: - - `b`: A pointer to the current board structure representing the current state of the chess game. - - `m`: A move structure representing the move to be applied to the board. -- **Control Flow**: - - Allocate memory for a new board structure and copy the contents of the existing board into it. - - Call [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) to apply the move to the new board in place. - - Return the pointer to the newly created board with the move applied. -- **Output**: - - A pointer to a new board structure that represents the state of the board after the move has been applied. -- **Functions called**: - - [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) - - ---- -### boardPlayMoveInPlace -The `boardPlayMoveInPlace` function executes a given chess move on a board, updating the board's state accordingly. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chess board. - - `m`: A `move` structure representing the move to be played, including the starting and ending positions and any promotion details. -- **Control Flow**: - - If the current player is black, increment the move number. - - Determine if the move is irreversible (pawn move or capture) and reset or increment the half-move clock accordingly. - - Check if the move is a castling move and update the rook's position and castling rights. - - If a rook moves or is captured, update the castling rights by clearing the appropriate flags. - - Handle en passant captures by removing the captured pawn from the board. - - Move the piece from the source to the destination square, handling promotions if necessary. - - Set the en passant target square if a pawn moves two squares forward, otherwise invalidate it. - - Switch the current player to the other player. -- **Output**: - - The function does not return a value; it modifies the board in place to reflect the move played. -- **Functions called**: - - [`pieceGetType`](piece.c.driver.md#pieceGetType) - - [`boardGetPiece`](#boardGetPiece) - - [`boardSetPiece`](#boardSetPiece) - - [`sqI`](square.c.driver.md#sqI) - - [`sqEq`](square.c.driver.md#sqEq) - - [`pieceMake`](piece.c.driver.md#pieceMake) - - ---- -### boardEq -The `boardEq` function checks if two chess board states are fully equal by comparing various attributes and the board's memory. -- **Inputs**: - - `b1`: A pointer to the first board structure to be compared. - - `b2`: A pointer to the second board structure to be compared. -- **Control Flow**: - - Check if the current player of both boards is the same; if not, return 0. - - Check if the castling state of both boards is the same; if not, return 0. - - Check if the en passant target squares of both boards are equal using [`sqEq`](square.c.driver.md#sqEq); if not, return 0. - - Check if the half-move clock values of both boards are the same; if not, return 0. - - Check if the move numbers of both boards are the same; if not, return 0. - - Use `memcmp` to compare the memory of both boards for the first 64 pieces; if they differ, return 0. - - If all checks pass, return 1 indicating the boards are fully equal. -- **Output**: - - Returns 1 if the boards are fully equal, otherwise returns 0. -- **Functions called**: - - [`sqEq`](square.c.driver.md#sqEq) - - ---- -### boardEqContext -The `boardEqContext` function checks if two chess boards are contextually equal, ignoring move counters and filtering en passant target squares. -- **Inputs**: - - `b1`: A pointer to the first board structure to compare. - - `b2`: A pointer to the second board structure to compare. -- **Control Flow**: - - Check if the current player on both boards is the same; if not, return 0. - - Check if the castling state on both boards is the same; if not, return 0. - - Compare the memory of both boards for the first 64 pieces; if they differ, return 0. - - For each board, check if the en passant target square is valid and if any pawns can attack it; if not, set it to invalid. - - Compare the en passant target squares of both boards; if they differ, return 0. - - If all checks pass, return 1 indicating the boards are contextually equal. -- **Output**: - - Returns 1 if the boards are contextually equal, otherwise returns 0. -- **Functions called**: - - [`sqEq`](square.c.driver.md#sqEq) - - [`sqI`](square.c.driver.md#sqI) - - [`boardGetPiece`](#boardGetPiece) - - [`boardPlayMoveInPlace`](#boardPlayMoveInPlace) - - [`moveSq`](move.c.driver.md#moveSq) - - [`boardIsPlayerInCheck`](#boardIsPlayerInCheck) - - ---- -### boardGetFen -The `boardGetFen` function generates a FEN (Forsyth-Edwards Notation) string representing the current state of a chess board. -- **Inputs**: - - `b`: A pointer to a `board` structure representing the current state of the chess game. -- **Control Flow**: - - Initialize a buffer `buf` to store the FEN string and a pointer `c` to traverse the buffer. - - Iterate over each rank from 8 to 1 and each file from 1 to 8 to process each square on the board. - - For each square, check if it contains a piece; if so, append the piece's letter to the buffer, otherwise increment a blank counter. - - If there are blanks at the end of a rank, append the count to the buffer and add a '/' if not the last rank. - - Append the current player's turn ('w' or 'b') to the buffer. - - Determine the castling rights and append the appropriate characters ('K', 'Q', 'k', 'q') or '-' if none. - - Check the en passant target square and append its coordinates or '-' if invalid. - - Use `sprintf` to append the half-move clock and move number to the buffer. - - Allocate memory for the FEN string, copy the buffer content to it, and return the string. -- **Output**: - - A dynamically allocated string containing the FEN representation of the board, which must be freed by the caller. -- **Functions called**: - - [`sqI`](square.c.driver.md#sqI) - - [`boardGetPiece`](#boardGetPiece) - - [`pieceGetLetter`](piece.c.driver.md#pieceGetLetter) - - [`sqEq`](square.c.driver.md#sqEq) - - [`sqGetStr`](square.c.driver.md#sqGetStr) - - diff --git a/driver_docs/src/chesslib/move.c.driver.md b/driver_docs/src/chesslib/move.c.driver.md deleted file mode 100644 index d462b59..0000000 --- a/driver_docs/src/chesslib/move.c.driver.md +++ /dev/null @@ -1,101 +0,0 @@ -# Purpose -This C source code file is part of a chess-related software library, specifically handling the creation and manipulation of chess moves. The file provides functions to create moves, compare them, and convert them to and from the Universal Chess Interface (UCI) string format. The primary functions include [`moveSq`](#moveSq), which creates a basic move between two squares; [`movePromote`](#movePromote), which creates a move with an optional promotion piece; and [`moveEq`](#moveEq), which checks if two moves are equivalent. Additionally, the file includes [`moveGetUci`](#moveGetUci), which converts a move into its UCI string representation, and [`moveFromUci`](#moveFromUci), which parses a UCI string to create a move object. The code is designed to be part of a larger chess library, as indicated by the inclusion of "chesslib/move.h", and it provides essential functionality for handling chess moves in a programmatic way. - -The file is not a standalone executable but rather a component of a larger system, likely intended to be used in conjunction with other parts of a chess engine or application. It defines a narrow set of functionalities focused on move operations, which are crucial for any chess software that needs to process and validate moves, especially in formats compatible with UCI, a common protocol used in chess engines. The code does not include error checking for UCI string parsing, which suggests that it assumes valid input or that error handling is managed elsewhere in the system. -# Imports and Dependencies - ---- -- `stdio.h` -- `stdlib.h` -- `ctype.h` -- `chesslib/move.h` - - -# Functions - ---- -### moveSq -The `moveSq` function creates a move from one square to another without any promotion in a chess game. -- **Inputs**: - - `from`: The starting square of the move, represented by the type `sq`. - - `to`: The destination square of the move, represented by the type `sq`. -- **Control Flow**: - - The function calls [`movePromote`](#movePromote) with the `from` and `to` squares and `ptEmpty` as the promotion type. - - The [`movePromote`](#movePromote) function constructs a `move` structure with the given `from`, `to`, and `promotion` values. - - The constructed `move` is returned by [`movePromote`](#movePromote) and subsequently by `moveSq`. -- **Output**: - - A `move` structure representing a move from the `from` square to the `to` square with no promotion. -- **Functions called**: - - [`movePromote`](#movePromote) - - ---- -### movePromote -The `movePromote` function creates and returns a `move` structure initialized with the given starting square, destination square, and promotion piece type. -- **Inputs**: - - `from`: The starting square of the move, represented by the type `sq`. - - `to`: The destination square of the move, represented by the type `sq`. - - `promotion`: The type of piece to which a pawn is promoted, represented by the type `pieceType`. -- **Control Flow**: - - A `move` structure `m` is declared. - - The `from` field of `m` is set to the input `from`. - - The `to` field of `m` is set to the input `to`. - - The `promotion` field of `m` is set to the input `promotion`. - - The function returns the `move` structure `m`. -- **Output**: - - The function returns a `move` structure initialized with the specified `from`, `to`, and `promotion` values. - - ---- -### moveEq -The `moveEq` function checks if two chess moves are equivalent by comparing their starting and ending squares and promotion types. -- **Inputs**: - - `m1`: The first move to compare, represented as a `move` structure. - - `m2`: The second move to compare, represented as a `move` structure. -- **Control Flow**: - - The function calls [`sqEq`](square.c.driver.md#sqEq) to compare the `from` squares of `m1` and `m2`. - - It then calls [`sqEq`](square.c.driver.md#sqEq) to compare the `to` squares of `m1` and `m2`. - - Finally, it checks if the `promotion` fields of `m1` and `m2` are equal. - - The function returns the logical AND of these three comparisons. -- **Output**: - - The function returns a `uint8_t` value, which is `1` if the moves are equivalent and `0` otherwise. -- **Functions called**: - - [`sqEq`](square.c.driver.md#sqEq) - - ---- -### moveGetUci -The `moveGetUci` function generates a UCI (Universal Chess Interface) string representation of a given chess move, including promotion if applicable. -- **Inputs**: - - `m`: A `move` structure containing the source square, destination square, and optional promotion piece type. -- **Control Flow**: - - Initialize a character array `p` with two elements set to zero. - - Check if the move includes a promotion piece type. - - If there is a promotion, convert the promotion piece type to a lowercase letter and store it in `p[0]`, then allocate memory for a 6-character string. - - If there is no promotion, allocate memory for a 5-character string. - - Use `sprintf` to format the move's source square, destination square, and promotion letter into the allocated string. - - Return the formatted string. -- **Output**: - - A dynamically allocated string representing the UCI format of the move, which must be freed by the caller. -- **Functions called**: - - [`pieceTypeGetLetter`](piece.c.driver.md#pieceTypeGetLetter) - - [`sqGetStr`](square.c.driver.md#sqGetStr) - - ---- -### moveFromUci -The `moveFromUci` function converts a UCI (Universal Chess Interface) string into a `move` structure, representing a chess move with optional promotion. -- **Inputs**: - - `uci`: A string representing a chess move in UCI format, which typically consists of four characters for the starting and ending squares, and optionally a fifth character for promotion. -- **Control Flow**: - - Extracts the first two characters from the `uci` string to form the `from` square and the next two characters to form the `to` square. - - Initializes a `promotion` variable of type `pieceType` to determine if the move includes a promotion. - - Uses a `switch` statement to check the fifth character of the `uci` string to set the `promotion` type, defaulting to `ptEmpty` if no valid promotion character is found. - - Creates a `move` structure `m`, setting its `from` and `to` fields using the [`sqS`](square.c.driver.md#sqS) function to convert the square strings, and its `promotion` field to the determined promotion type. - - Returns the constructed `move` structure `m`. -- **Output**: - - The function returns a `move` structure representing the chess move described by the UCI string, including the starting and ending squares and any promotion type. -- **Functions called**: - - [`sqS`](square.c.driver.md#sqS) - - diff --git a/driver_docs/src/chesslib/piecemoves.c.driver.md b/driver_docs/src/chesslib/piecemoves.c.driver.md deleted file mode 100644 index 2a84330..0000000 --- a/driver_docs/src/chesslib/piecemoves.c.driver.md +++ /dev/null @@ -1,274 +0,0 @@ -# Purpose -This C source code file is part of a chess game implementation, specifically focusing on the movement logic for different chess pieces. The file defines functions that calculate possible moves for each type of chess piece, including pawns, knights, bishops, rooks, queens, and kings. The code is structured to handle the unique movement patterns of each piece, such as the leaping ability of knights and the linear movement of rooks and bishops. The file includes helper functions like [`canMoveHere`](#canMoveHere) to determine if a piece can move to a specific square, considering the presence of other pieces and their colors. - -The file is not a standalone executable but rather a component of a larger chess library, as indicated by the inclusion of "chesslib/piecemoves.h". It provides specific functionality related to chess piece movements, which can be utilized by other parts of the chess program. The functions return lists of possible moves (`moveList`) for each piece, taking into account the current state of the board and the rules of chess, such as pawn promotion and en passant captures. This file is crucial for implementing the core mechanics of chess piece movement within the game. -# Imports and Dependencies - ---- -- `chesslib/piecemoves.h` - - -# Global Variables - ---- -### knightOffsets -- **Type**: `int8_t[8][2]` -- **Description**: The `knightOffsets` variable is a two-dimensional array of integers that represents the possible moves a knight can make on a chessboard. Each sub-array contains two integers, where the first integer represents the change in the file (column) and the second integer represents the change in the rank (row) of the knight's position. -- **Use**: This variable is used to calculate the potential new positions a knight can move to from its current position on the chessboard. - - ---- -### bishopOffsets -- **Type**: `int8_t[4][2]` -- **Description**: The `bishopOffsets` variable is a two-dimensional array of integers that represents the possible movement directions for a bishop in a chess game. Each sub-array contains two integers, which correspond to the change in file and rank, respectively, for a bishop's diagonal movement on the chessboard. -- **Use**: This variable is used to determine the valid movement directions for a bishop piece when generating its possible moves on a chessboard. - - ---- -### rookOffsets -- **Type**: `int8_t[4][2]` -- **Description**: The `rookOffsets` variable is a two-dimensional array of integers that represents the possible movement directions for a rook in a chess game. Each sub-array contains two integers, where the first integer represents the change in the file (column) and the second integer represents the change in the rank (row). The four sub-arrays correspond to the rook's ability to move vertically and horizontally on the chessboard. -- **Use**: This variable is used to determine the possible movement directions for a rook when generating its move list in the `pmGetRookMoves` function. - - ---- -### royalOffsets -- **Type**: `int8_t[8][2]` -- **Description**: The `royalOffsets` variable is a two-dimensional array of 8 elements, each containing a pair of integers. These pairs represent the possible movement directions for the queen and king pieces on a chessboard, covering all eight surrounding squares in a grid pattern. -- **Use**: This variable is used to determine the valid movement directions for the queen and king pieces in chess, allowing them to move in any direction on the board. - - -# Functions - ---- -### canMoveHere -The `canMoveHere` function checks if a piece can move to a specified square on the board without encountering a piece of the same color. -- **Inputs**: - - `b`: A pointer to the board structure representing the current state of the chess board. - - `s`: The square on the board to which the piece is attempting to move. - - `ourColor`: The color of the piece attempting to move. -- **Control Flow**: - - Retrieve the piece located at the specified square `s` on the board `b` using [`boardGetPiece`](board.c.driver.md#boardGetPiece) function. - - Check if the retrieved piece is `pEmpty`, indicating the square is empty; if so, return 1 (true) to indicate the move is possible. - - If the square is not empty, retrieve the color of the piece at the square using [`pieceGetColor`](piece.c.driver.md#pieceGetColor). - - Compare the color of the piece at the square with `ourColor`; if they are different, return 1 (true) to indicate the move is possible, otherwise return 0 (false). -- **Output**: - - Returns 1 (true) if the square is empty or occupied by an opponent's piece, otherwise returns 0 (false) if occupied by a piece of the same color. -- **Functions called**: - - [`boardGetPiece`](board.c.driver.md#boardGetPiece) - - [`pieceGetColor`](piece.c.driver.md#pieceGetColor) - - ---- -### pmLeaperMoveList -The `pmLeaperMoveList` function generates a list of valid moves for leaper-type chess pieces from a given position on the board. -- **Inputs**: - - `b`: A pointer to the chess board structure, representing the current state of the game. - - `s`: The starting square (of type `sq`) from which the piece will attempt to move. - - `pt`: The type of the piece (of type `pieceType`) that is expected to be at the starting square. - - `dirs`: A 2D array of integers representing the possible directions the piece can move in terms of file and rank offsets. - - `numDirs`: The number of directions available in the `dirs` array. -- **Control Flow**: - - Create a new move list using `moveListCreate()` to store potential moves. - - Retrieve the piece located at the starting square `s` using `boardGetPiece(b, s)`. - - Check if the piece type matches the expected type `pt`; if not, return the empty move list. - - Determine the color of the piece at the starting square. - - Iterate over each direction in the `dirs` array. - - Calculate the new square by adding the direction offsets to the current square's file and rank. - - Check if the new square is within the bounds of the board (1 to 8 for both file and rank). - - If the new square is valid and can be moved to (using [`canMoveHere`](#canMoveHere)), add the move to the move list using [`moveListAdd`](movelist.c.driver.md#moveListAdd). - - Return the populated move list. -- **Output**: - - A pointer to a `moveList` structure containing all valid moves for the leaper piece from the given starting square. -- **Functions called**: - - [`moveListCreate`](movelist.c.driver.md#moveListCreate) - - [`boardGetPiece`](board.c.driver.md#boardGetPiece) - - [`pieceGetType`](piece.c.driver.md#pieceGetType) - - [`pieceGetColor`](piece.c.driver.md#pieceGetColor) - - [`canMoveHere`](#canMoveHere) - - [`moveListAdd`](movelist.c.driver.md#moveListAdd) - - [`moveSq`](move.c.driver.md#moveSq) - - ---- -### pmRiderMoveList -The `pmRiderMoveList` function generates a list of all possible moves for a rider-type chess piece (like a bishop, rook, or queen) from a given position on the board, considering the piece's movement directions and the board's current state. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chessboard. - - `s`: The `sq` structure representing the starting square of the piece on the board. - - `pt`: The `pieceType` enumeration value representing the type of the piece (e.g., bishop, rook, queen) for which moves are being generated. - - `dirs`: A 2D array of integers representing the possible movement directions for the piece, where each direction is a pair of integers indicating file and rank offsets. - - `numDirs`: The number of movement directions provided in the `dirs` array. -- **Control Flow**: - - Create an empty move list using `moveListCreate()`. - - Retrieve the piece located at the starting square `s` using `boardGetPiece()`. - - Check if the piece type matches the specified `pt`; if not, return the empty move list. - - Determine the color of the piece using `pieceGetColor()`. - - Iterate over each direction in the `dirs` array. - - For each direction, initialize `newSq` to the starting square `s`. - - In a loop, update `newSq` by adding the current direction offsets to its file and rank. - - Check if `newSq` is within the board boundaries (file and rank between 1 and 8); if not, break the loop. - - Retrieve the piece at `newSq` using `boardGetPiece()`. - - Check if the piece can move to `newSq` using `canMoveHere()`; if true, add the move to the list using `moveListAdd()`. - - If `newSq` contains a piece (not empty), break the loop to stop further movement in that direction. - - Return the populated move list. -- **Output**: - - A pointer to a `moveList` structure containing all valid moves for the rider piece from the starting square `s`. -- **Functions called**: - - [`moveListCreate`](movelist.c.driver.md#moveListCreate) - - [`boardGetPiece`](board.c.driver.md#boardGetPiece) - - [`pieceGetType`](piece.c.driver.md#pieceGetType) - - [`pieceGetColor`](piece.c.driver.md#pieceGetColor) - - [`canMoveHere`](#canMoveHere) - - [`moveListAdd`](movelist.c.driver.md#moveListAdd) - - [`moveSq`](move.c.driver.md#moveSq) - - ---- -### addPawnMoveToMoveList -The `addPawnMoveToMoveList` function adds a pawn move to a move list, including promotion moves if the pawn reaches the first or eighth rank. -- **Inputs**: - - `list`: A pointer to a `moveList` structure where the move will be added. - - `oldSq`: The starting square of the pawn, represented as a `sq` structure. - - `newSq`: The destination square of the pawn, represented as a `sq` structure. -- **Control Flow**: - - Check if the destination square `newSq` is on the first or eighth rank, indicating a promotion opportunity. - - If it is a promotion, add four promotion moves to the list: promoting the pawn to a queen, rook, bishop, and knight respectively. - - If it is not a promotion, add a regular pawn move from `oldSq` to `newSq` to the list. -- **Output**: - - The function does not return a value; it modifies the `moveList` pointed to by `list` by adding the appropriate move(s). -- **Functions called**: - - [`moveListAdd`](movelist.c.driver.md#moveListAdd) - - [`movePromote`](move.c.driver.md#movePromote) - - [`moveSq`](move.c.driver.md#moveSq) - - ---- -### pmGetPawnMoves -The `pmGetPawnMoves` function generates a list of all possible legal moves for a pawn located at a given square on a chess board. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chess board. - - `s`: A `sq` structure representing the square on the board where the pawn is located. -- **Control Flow**: - - Create an empty move list using `moveListCreate()`. - - Retrieve the piece at square `s` using `boardGetPiece()` and check if it is a pawn; if not, return the empty move list. - - Determine the pawn's color and set the movement direction (`delta`) based on whether the pawn is white or black. - - Calculate the square directly in front of the pawn and check if it is empty; if so, add this move to the list. - - Check if the pawn is on its starting rank and can move two squares forward; if so, add this move to the list if the square is empty. - - Check for possible captures to the left and right of the pawn's current position, including en passant captures, and add these moves to the list if valid. - - Return the populated move list. -- **Output**: - - A pointer to a `moveList` structure containing all legal moves for the pawn at the specified square. -- **Functions called**: - - [`moveListCreate`](movelist.c.driver.md#moveListCreate) - - [`boardGetPiece`](board.c.driver.md#boardGetPiece) - - [`pieceGetType`](piece.c.driver.md#pieceGetType) - - [`pieceGetColor`](piece.c.driver.md#pieceGetColor) - - [`sqI`](square.c.driver.md#sqI) - - [`addPawnMoveToMoveList`](#addPawnMoveToMoveList) - - [`canMoveHere`](#canMoveHere) - - [`sqEq`](square.c.driver.md#sqEq) - - ---- -### pmGetPawnAttacks -The `pmGetPawnAttacks` function generates a list of potential attack moves for a pawn on a chessboard, based on its current position and color. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chessboard. - - `s`: A `sq` structure representing the current position of the pawn on the board. -- **Control Flow**: - - Create a new move list using `moveListCreate()` to store potential attack moves. - - Retrieve the piece at the given square `s` using `boardGetPiece(b, s)`. - - Check if the piece is a pawn using `pieceGetType(p) != ptPawn`; if not, return the empty move list. - - Determine the pawn's color using `pieceGetColor(p)` and set `delta` to 1 for white pawns and -1 for black pawns. - - Check if the pawn can attack to the left (file > 1) by calculating the new square and using `canMoveHere()` to verify if the move is possible; if so, add the move to the list. - - Check if the pawn can attack to the right (file < 8) by calculating the new square and using `canMoveHere()` to verify if the move is possible; if so, add the move to the list. - - Return the list of potential attack moves. -- **Output**: - - A pointer to a `moveList` structure containing the potential attack moves for the pawn from its current position. -- **Functions called**: - - [`moveListCreate`](movelist.c.driver.md#moveListCreate) - - [`boardGetPiece`](board.c.driver.md#boardGetPiece) - - [`pieceGetType`](piece.c.driver.md#pieceGetType) - - [`pieceGetColor`](piece.c.driver.md#pieceGetColor) - - [`sqI`](square.c.driver.md#sqI) - - [`canMoveHere`](#canMoveHere) - - [`moveListAdd`](movelist.c.driver.md#moveListAdd) - - [`moveSq`](move.c.driver.md#moveSq) - - ---- -### pmGetKnightMoves -The `pmGetKnightMoves` function generates a list of all possible legal moves for a knight piece from a given position on a chess board. -- **Inputs**: - - `b`: A pointer to the chess board structure representing the current state of the game. - - `s`: The square structure representing the current position of the knight on the board. -- **Control Flow**: - - The function calls [`pmLeaperMoveList`](#pmLeaperMoveList) with the board, the knight's current position, the piece type for a knight, the predefined knight move offsets, and the number of possible knight moves (8). - - [`pmLeaperMoveList`](#pmLeaperMoveList) processes these inputs to generate a list of valid moves for the knight, considering the board boundaries and potential captures. -- **Output**: - - A pointer to a `moveList` structure containing all valid moves for the knight from the given position. -- **Functions called**: - - [`pmLeaperMoveList`](#pmLeaperMoveList) - - ---- -### pmGetBishopMoves -The `pmGetBishopMoves` function generates a list of all possible moves for a bishop located at a given square on a chess board. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chess board. - - `s`: A `sq` structure representing the current position of the bishop on the board. -- **Control Flow**: - - The function calls [`pmRiderMoveList`](#pmRiderMoveList) with the board, the bishop's current square, the piece type `ptBishop`, the direction offsets for a bishop, and the number of directions (4). - - [`pmRiderMoveList`](#pmRiderMoveList) handles the logic for generating moves for pieces that can move multiple squares in a straight line, like a bishop. -- **Output**: - - A pointer to a `moveList` structure containing all valid moves for the bishop from the given square. -- **Functions called**: - - [`pmRiderMoveList`](#pmRiderMoveList) - - ---- -### pmGetRookMoves -The `pmGetRookMoves` function generates a list of all possible legal moves for a rook located at a given square on a chess board. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chess board. - - `s`: A `sq` structure representing the current position of the rook on the board. -- **Control Flow**: - - The function calls [`pmRiderMoveList`](#pmRiderMoveList) with the board, the rook's current square, the piece type `ptRook`, the direction offsets for a rook, and the number of directions (4). - - [`pmRiderMoveList`](#pmRiderMoveList) processes these inputs to generate a list of all possible moves for the rook, considering the board boundaries and other pieces on the board. -- **Output**: - - A pointer to a `moveList` structure containing all possible legal moves for the rook from the given position. -- **Functions called**: - - [`pmRiderMoveList`](#pmRiderMoveList) - - ---- -### pmGetQueenMoves -The `pmGetQueenMoves` function generates a list of all possible moves for a queen piece from a given position on a chess board. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chess board. - - `s`: A `sq` structure representing the current position of the queen on the board. -- **Control Flow**: - - The function calls [`pmRiderMoveList`](#pmRiderMoveList) with the board, the queen's current position, the piece type `ptQueen`, the direction offsets for a queen (`royalOffsets`), and the number of directions (8). - - [`pmRiderMoveList`](#pmRiderMoveList) processes these inputs to generate all possible moves for the queen, considering the board boundaries and other pieces on the board. -- **Output**: - - A pointer to a `moveList` structure containing all valid moves for the queen from the given position. -- **Functions called**: - - [`pmRiderMoveList`](#pmRiderMoveList) - - ---- -### pmGetKingMoves -The `pmGetKingMoves` function generates a list of all possible legal moves for a king piece from a given position on a chess board. -- **Inputs**: - - `b`: A pointer to the `board` structure representing the current state of the chess board. - - `s`: A `sq` structure representing the current position of the king on the board. -- **Control Flow**: - - The function calls [`pmLeaperMoveList`](#pmLeaperMoveList) with the board, the king's current position, the piece type `ptKing`, the array `royalOffsets` defining the king's movement directions, and the number of directions (8). - - [`pmLeaperMoveList`](#pmLeaperMoveList) processes these inputs to generate a list of valid moves for the king based on its movement capabilities and the current board state. -- **Output**: - - A pointer to a `moveList` structure containing all valid moves for the king from the specified position. -- **Functions called**: - - [`pmLeaperMoveList`](#pmLeaperMoveList) - - diff --git a/driver_docs/src/chesslib/square.c.driver.md b/driver_docs/src/chesslib/square.c.driver.md deleted file mode 100644 index 17e54a4..0000000 --- a/driver_docs/src/chesslib/square.c.driver.md +++ /dev/null @@ -1,124 +0,0 @@ -# Purpose -This C source code file provides functionality for handling chessboard squares, encapsulating operations related to the representation and manipulation of squares on a standard 8x8 chessboard. The code defines several functions that allow for the creation and manipulation of square objects, which are represented by the `sq` type. The primary operations include creating a square from file and rank integers ([`sqI`](#sqI)), from a Standard Algebraic Notation (SAN) string ([`sqS`](#sqS)), and from an index ([`sqIndex`](#sqIndex)). Additionally, the code provides utility functions to retrieve the SAN string representation of a square ([`sqGetStr`](#sqGetStr)), determine if a square is dark or light ([`sqIsDark`](#sqIsDark)), and compare two squares for equality ([`sqEq`](#sqEq)). - -The file is part of a larger library, as indicated by the inclusion of the header file "chesslib/square.h", suggesting that it is intended to be used as part of a chess-related software system. The code defines a set of public APIs that facilitate the conversion between different representations of chessboard squares, ensuring that operations remain within the valid bounds of a chessboard. The use of constants and utility functions like `SQ_STRS` and [`sqGetIndex`](#sqGetIndex) further supports efficient and accurate square manipulation, making this file a focused and essential component for any chess application requiring square-based operations. -# Imports and Dependencies - ---- -- `chesslib/square.h` - - -# Global Variables - ---- -### SQ\_STRS -- **Type**: `const char *[64]` -- **Description**: `SQ_STRS` is a global constant array of 64 string literals, each representing a square on a standard 8x8 chessboard using algebraic notation. The array elements are ordered from 'a1' to 'h8', covering all possible squares on the board. -- **Use**: This array is used to map indices to their corresponding square names in algebraic notation, facilitating conversion between index-based and string-based square representations. - - -# Functions - ---- -### sqI -The function `sqI` creates a chessboard square object from given file and rank values, ensuring they are within valid bounds. -- **Inputs**: - - `file`: An unsigned 8-bit integer representing the file (column) of the chessboard square, expected to be between 1 and 8. - - `rank`: An unsigned 8-bit integer representing the rank (row) of the chessboard square, expected to be between 1 and 8. -- **Control Flow**: - - Check if the `file` is less than 1 or greater than 8, or if the `rank` is less than 1 or greater than 8. - - If any of the above conditions are true, return `SQ_INVALID`. - - If both `file` and `rank` are within valid bounds, create a `sq` object `s`. - - Assign the `file` value to `s.file` and the `rank` value to `s.rank`. - - Return the `sq` object `s`. -- **Output**: - - The function returns a `sq` object representing a valid chessboard square if the inputs are within bounds, otherwise it returns `SQ_INVALID`. - - ---- -### sqS -The function `sqS` converts a string representing a chessboard square in SAN format to a `sq` structure with file and rank values. -- **Inputs**: - - `str`: A pointer to a constant character string representing a chessboard square in SAN format (e.g., "e4"). -- **Control Flow**: - - Extract the first character `c1` from the input string `str`. - - Check if `c1` is a valid file character ('a' to 'h'); if not, return `SQ_INVALID`. - - Extract the second character `c2` from the input string `str`. - - Check if `c2` is a valid rank character ('1' to '8'); if not, return `SQ_INVALID`. - - Create a `sq` structure `s` and set its `file` field to the numeric value corresponding to `c1` ('a' = 1, ..., 'h' = 8). - - Set the `rank` field of `s` to the numeric value of `c2` ('1' = 1, ..., '8' = 8). - - Return the `sq` structure `s`. -- **Output**: - - The function returns a `sq` structure representing the file and rank of the chessboard square, or `SQ_INVALID` if the input string is not a valid SAN square. - - ---- -### sqIndex -The `sqIndex` function converts a given index into a chessboard square using a predefined array of square strings. -- **Inputs**: - - `index`: An unsigned 8-bit integer representing the index of the square, expected to be between 0 and 63 inclusive. -- **Control Flow**: - - Check if the input index is less than 0 or greater than 63. - - If the index is out of bounds, return `SQ_INVALID`. - - If the index is valid, use it to access the `SQ_STRS` array to get the corresponding square string. - - Call the [`sqS`](#sqS) function with the retrieved square string to convert it into a `sq` type and return it. -- **Output**: - - The function returns a `sq` type representing the chessboard square corresponding to the given index, or `SQ_INVALID` if the index is out of bounds. -- **Functions called**: - - [`sqS`](#sqS) - - ---- -### sqGetIndex -The function `sqGetIndex` calculates the zero-based index of a chessboard square given its file and rank. -- **Inputs**: - - `s`: A structure representing a square on a chessboard, containing two fields: `file` and `rank`, both of which are expected to be integers between 1 and 8 inclusive. -- **Control Flow**: - - Check if the `file` or `rank` of the square `s` is outside the valid range (1 to 8); if so, return -1 indicating an invalid square. - - Calculate the index using the formula `(8 * (s.rank - 1)) + (s.file - 1)` which maps the 2D coordinates to a 1D array index. -- **Output**: - - The function returns a `uint8_t` representing the zero-based index of the square on a chessboard, or -1 if the square is invalid. - - ---- -### sqGetStr -The `sqGetStr` function returns the Standard Algebraic Notation (SAN) string representation of a given chess square. -- **Inputs**: - - `s`: A chess square represented by the `sq` type, which contains file and rank information. -- **Control Flow**: - - Call the [`sqGetIndex`](#sqGetIndex) function with the input square `s` to get its index. - - Check if the index is greater than 63; if so, return the string '##' indicating an invalid square. - - If the index is valid (0 to 63), return the corresponding SAN string from the `SQ_STRS` array. -- **Output**: - - A constant character pointer to the SAN string representing the square, or '##' if the square is invalid. -- **Functions called**: - - [`sqGetIndex`](#sqGetIndex) - - ---- -### sqIsDark -The `sqIsDark` function determines if a given chessboard square is dark-colored based on its rank and file. -- **Inputs**: - - `s`: A `sq` structure representing a square on a chessboard, containing `rank` and `file` fields. -- **Control Flow**: - - The function uses bitwise AND to check the least significant bit of both the `rank` and `file` fields of the square `s`. - - It then applies the XOR operation to these bits to determine if they are different. - - The result of the XOR operation is negated to return 1 if the square is dark and 0 if it is light. -- **Output**: - - Returns 1 if the square is dark-colored, otherwise returns 0. - - ---- -### sqEq -The `sqEq` function checks if two chessboard squares are equal, considering invalid squares. -- **Inputs**: - - `s1`: The first square to compare, represented by a structure with 'file' and 'rank' attributes. - - `s2`: The second square to compare, also represented by a structure with 'file' and 'rank' attributes. -- **Control Flow**: - - Check if the 'file' or 'rank' of 's1' is outside the valid range (1 to 8); if so, set 's1' to 'SQ_INVALID'. - - Check if the 'file' or 'rank' of 's2' is outside the valid range (1 to 8); if so, set 's2' to 'SQ_INVALID'. - - Compare the 'file' and 'rank' of 's1' and 's2' to determine if they are equal. -- **Output**: - - Returns 1 if the squares are equal (both 'file' and 'rank' match), otherwise returns 0. - - diff --git a/driver_docs/src/chesslib/squareset.c.driver.md b/driver_docs/src/chesslib/squareset.c.driver.md deleted file mode 100644 index afd0883..0000000 --- a/driver_docs/src/chesslib/squareset.c.driver.md +++ /dev/null @@ -1,48 +0,0 @@ -# Purpose -This C source code file implements a simple set of functions for manipulating a "square set," which is likely a data structure used in a chess-related application. The file includes two primary functions: [`sqSetSet`](#sqSetSet) and [`sqSetGet`](#sqSetGet). The [`sqSetSet`](#sqSetSet) function modifies a bit within a `sqSet` data structure, setting or clearing it based on the provided `value`, while ensuring the square is valid. The [`sqSetGet`](#sqSetGet) function retrieves the value of a specific bit from the `sqSet`, again checking for validity. This code is part of a larger library, as indicated by the inclusion of "chesslib/squareset.h", and it uses bitwise operations to efficiently manage the state of chessboard squares. -# Imports and Dependencies - ---- -- `stdlib.h` -- `chesslib/squareset.h` - - -# Functions - ---- -### sqSetSet -The `sqSetSet` function modifies a bit in a square set based on the given square and value. -- **Inputs**: - - `ss`: A pointer to a `sqSet`, which is a data structure representing a set of squares. - - `s`: A `sq` type representing a specific square to be modified in the set. - - `value`: A `uint8_t` value indicating whether to set (1) or clear (0) the bit corresponding to the square `s`. -- **Control Flow**: - - Check if the square `s` is invalid using `sqEq(s, SQ_INVALID)`, and return immediately if it is. - - Calculate the bit position for the square `s` using `sqGetIndex(s)` and shift a 1 to that position to create a bitmask. - - If `value` is non-zero, set the bit in `ss` using the bitwise OR operation with the bitmask. - - If `value` is zero, clear the bit in `ss` using the bitwise AND operation with the negated bitmask. -- **Output**: - - The function does not return a value; it modifies the `sqSet` in place. -- **Functions called**: - - [`sqEq`](square.c.driver.md#sqEq) - - [`sqGetIndex`](square.c.driver.md#sqGetIndex) - - ---- -### sqSetGet -The function `sqSetGet` retrieves the bit value at a specific index in a square set, representing a chessboard state, based on the given square. -- **Inputs**: - - `ss`: A pointer to a `sqSet`, which is a data structure representing a set of squares on a chessboard. - - `s`: A `sq` type representing a specific square on the chessboard. -- **Control Flow**: - - Check if the square `s` is invalid using `sqEq(s, SQ_INVALID)`; if it is invalid, return 0. - - Calculate the index of the square `s` using `sqGetIndex(s)`. - - Shift the bits of `*ss` right by the calculated index and perform a bitwise AND with 1 to isolate the bit at that index. - - Return the isolated bit value, which is either 0 or 1. -- **Output**: - - The function returns a `uint8_t` value, which is 0 if the square is invalid or if the bit at the specified index is 0, and 1 if the bit at the specified index is 1. -- **Functions called**: - - [`sqEq`](square.c.driver.md#sqEq) - - [`sqGetIndex`](square.c.driver.md#sqGetIndex) - - diff --git a/driver_docs/src/tests.c.driver.md b/driver_docs/src/tests.c.driver.md deleted file mode 100644 index fbd6569..0000000 --- a/driver_docs/src/tests.c.driver.md +++ /dev/null @@ -1,847 +0,0 @@ -# Purpose -This C source code file is a comprehensive test suite for a chess implementation. It is designed to validate the functionality of various components of a chess library, including squares, moves, move lists, boards, piece movements, and more. The file includes a [`main`](#main) function that sequentially runs a series of test functions, each of which is responsible for testing specific aspects of the chess library. The tests cover a wide range of scenarios, such as move creation, board setup from FEN strings, move generation, castling, en passant, and draw conditions due to insufficient material. - -The file imports several headers from the chess library, indicating that it is intended to be used in conjunction with these components to ensure their correctness. The test functions utilize helper functions like [`failTest`](#failTest) and [`validateString`](#validateString) to assert expected outcomes and halt execution if a test fails. This file is not intended to be a reusable library or a public API; rather, it serves as an internal testing mechanism to verify the integrity and correctness of the chess library's functionality. The tests are thorough and cover both basic and complex chess scenarios, ensuring that the library behaves as expected under various conditions. -# Imports and Dependencies - ---- -- `stdio.h` -- `stdlib.h` -- `string.h` -- `tests.h` -- `chesslib/squareset.h` -- `chesslib/movelist.h` -- `chesslib/board.h` -- `chesslib/piecemoves.h` -- `chesslib/boardlist.h` - - -# Global Variables - ---- -### currTest -- **Type**: `const char*` -- **Description**: `currTest` is a global variable of type `const char*` that holds the name of the currently running test as a string. It is used to track which test is being executed at any given time during the test suite execution. -- **Use**: This variable is used to store the name of the test currently being executed, allowing for error messages to specify which test failed. - - -# Functions - ---- -### main -The `main` function runs a series of predefined tests for a chess implementation and reports success if all tests pass. -- **Inputs**: - - `argc`: The number of command-line arguments passed to the program. - - `argv`: An array of strings representing the command-line arguments passed to the program. -- **Control Flow**: - - The function begins by running a series of test functions using the `RUN_TEST` macro, which sets the current test name and executes the test function. - - Tests are grouped by functionality, such as square tests, move tests, board tests, piece move tests, attacked square tests, move generation tests, FEN generation tests, draw condition tests, board list tests, and square set tests. - - Each test function is executed sequentially, and if any test fails, the program will terminate with an error message indicating the failed test. - - If all tests pass, a success message is printed to the console. - - The function returns 0 to indicate successful execution. -- **Output**: - - The function returns an integer value of 0, indicating successful execution if all tests pass. - - ---- -### failTest -The `failTest` function logs a failure message for the current test and terminates the program. -- **Inputs**: - - `msg`: A constant character pointer to a message string that provides additional context for the test failure; it can be NULL if no additional message is needed. -- **Control Flow**: - - Check if the input message `msg` is NULL. - - If `msg` is NULL, print a failure message to the standard error stream with the current test name. - - If `msg` is not NULL, print a failure message to the standard error stream with the current test name and the provided message. - - Terminate the program with an exit status of 1. -- **Output**: - - The function does not return any value as it terminates the program execution. - - ---- -### validateString -The `validateString` function compares two strings and triggers a test failure if they are not identical. -- **Inputs**: - - `actual`: A pointer to the actual string that needs to be validated. - - `expected`: A pointer to the expected string that the actual string is compared against. -- **Control Flow**: - - The function begins by comparing the `actual` and `expected` strings using `strcmp`. - - If the strings are not equal, it calculates the lengths of both strings using `strlen`. - - It allocates memory for a new string that will hold the error message, which includes both the actual and expected strings. - - The error message is formatted and stored in the allocated memory using `sprintf`. - - The [`failTest`](#failTest) function is called with the error message, which causes the program to exit. - - The `free` function is called to deallocate the memory for the error message, although this line is not executed because [`failTest`](#failTest) exits the program. -- **Output**: - - The function does not return a value; it exits the program if the strings do not match. -- **Functions called**: - - [`failTest`](#failTest) - - ---- -### testSqI -The `testSqI` function tests the [`sqI`](chesslib/square.c.driver.md#sqI) function to ensure it correctly maps file and rank inputs to a square structure with matching file and rank values. -- **Inputs**: - - None -- **Control Flow**: - - Iterates over ranks from 1 to 8. - - For each rank, iterates over files from 1 to 8. - - Calls [`sqI`](chesslib/square.c.driver.md#sqI) with the current file and rank to get a square `s`. - - Checks if the file and rank of `s` match the current file and rank. - - If they do not match, constructs an error message and calls [`failTest`](#failTest) with the message. -- **Output**: - - The function does not return a value; it will exit the program with an error message if a test fails. -- **Functions called**: - - [`sqI`](chesslib/square.c.driver.md#sqI) - - [`failTest`](#failTest) - - ---- -### testSqS -The `testSqS` function verifies that the [`sqS`](chesslib/square.c.driver.md#sqS) function correctly converts chess square strings to their corresponding `sq` structure representation. -- **Inputs**: - - None -- **Control Flow**: - - Iterates over all possible ranks (1 to 8) and files (1 to 8) of a chessboard. - - For each rank and file, constructs a string representation of the square (e.g., 'a1', 'b2'). - - Calls the [`sqS`](chesslib/square.c.driver.md#sqS) function to convert the string to an `sq` structure. - - Checks if the `sq` structure's file and rank match the expected file and rank. - - If there is a mismatch, constructs an error message and calls [`failTest`](#failTest) to halt the test. -- **Output**: - - The function does not return a value; it halts the program with an error message if a test fails. -- **Functions called**: - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`failTest`](#failTest) - - ---- -### testSqGetStr -The `testSqGetStr` function tests the conversion of chessboard square coordinates to their string representation and validates the output against expected values. -- **Inputs**: - - None -- **Control Flow**: - - Iterates over ranks from 1 to 8. - - For each rank, iterates over files from 1 to 8. - - For each file and rank combination, creates a square using `sqI(file, rank)`. - - Generates a string representation of the square using the file and rank values. - - Validates the string representation obtained from `sqGetStr(s)` against the expected string using [`validateString`](#validateString). -- **Output**: - - The function does not return a value; it validates the correctness of the [`sqGetStr`](chesslib/square.c.driver.md#sqGetStr) function by comparing its output to expected string representations of chessboard squares. -- **Functions called**: - - [`sqI`](chesslib/square.c.driver.md#sqI) - - [`validateString`](#validateString) - - [`sqGetStr`](chesslib/square.c.driver.md#sqGetStr) - - ---- -### testSqIsDark -The `testSqIsDark` function verifies that each square on a chessboard is correctly identified as dark or light according to the expected pattern. -- **Inputs**: - - None -- **Control Flow**: - - Initialize `expectedIsDark` to 1, indicating that the first square (a1) is expected to be dark. - - Iterate over each rank from 1 to 8. - - For each rank, iterate over each file from 1 to 8. - - For each square, create a square object `s` using `sqI(file, rank)`. - - Determine if the square `s` is dark using `sqIsDark(s)` and store the result in `actualIsDark`. - - If `actualIsDark` does not match `expectedIsDark`, construct an error message and call [`failTest`](#failTest) with this message to indicate a test failure. - - Toggle `expectedIsDark` after each file iteration to alternate the expected color for the next square. - - Toggle `expectedIsDark` after each rank iteration to maintain the checkerboard pattern. -- **Output**: - - The function does not return a value but will terminate the program with an error message if a square's darkness does not match the expected pattern. -- **Functions called**: - - [`sqI`](chesslib/square.c.driver.md#sqI) - - [`sqIsDark`](chesslib/square.c.driver.md#sqIsDark) - - [`sqGetStr`](chesslib/square.c.driver.md#sqGetStr) - - [`failTest`](#failTest) - - ---- -### validateMove -The `validateMove` function checks if a given move matches expected parameters and fails the test if it does not. -- **Inputs**: - - `m`: The move to be validated, containing the starting square, ending square, and promotion type. - - `expectedFrom`: The expected starting square of the move. - - `expectedTo`: The expected ending square of the move. - - `expectedPromotion`: The expected promotion type of the move. -- **Control Flow**: - - Check if the starting square of the move `m` is not equal to `expectedFrom` using [`sqEq`](chesslib/square.c.driver.md#sqEq) function. - - Check if the ending square of the move `m` is not equal to `expectedTo` using [`sqEq`](chesslib/square.c.driver.md#sqEq) function. - - Check if the promotion type of the move `m` is not equal to `expectedPromotion`. - - If any of the above checks fail, format a message with the actual and expected move details using `sprintf`. - - Call [`failTest`](#failTest) with the formatted message to indicate the test failure. -- **Output**: - - The function does not return a value; it either passes silently or calls [`failTest`](#failTest) to indicate a test failure. -- **Functions called**: - - [`sqEq`](chesslib/square.c.driver.md#sqEq) - - [`sqGetStr`](chesslib/square.c.driver.md#sqGetStr) - - [`failTest`](#failTest) - - ---- -### testMoveCreate -The `testMoveCreate` function tests the creation and validation of chess moves, including normal and promotion moves. -- **Inputs**: - - None -- **Control Flow**: - - Create a move `m` using [`moveSq`](chesslib/move.c.driver.md#moveSq) from square (5, 8) to square (5, 7). - - Validate the move `m` using [`validateMove`](#validateMove) to ensure it matches the expected from and to squares and has no promotion. - - Create a move `m` using [`movePromote`](chesslib/move.c.driver.md#movePromote) from square (3, 2) to square (2, 1) with a promotion to a queen. - - Validate the move `m` using [`validateMove`](#validateMove) to ensure it matches the expected from and to squares and has the correct promotion to a queen. -- **Output**: - - The function does not return any output; it performs validation checks and may halt execution if a test fails. -- **Functions called**: - - [`moveSq`](chesslib/move.c.driver.md#moveSq) - - [`sqI`](chesslib/square.c.driver.md#sqI) - - [`validateMove`](#validateMove) - - [`movePromote`](chesslib/move.c.driver.md#movePromote) - - ---- -### testMoveGetUci -The `testMoveGetUci` function tests the conversion of chess moves to UCI (Universal Chess Interface) format strings. -- **Inputs**: - - None -- **Control Flow**: - - A move `m` is created from square e8 to e7 using [`moveSq`](chesslib/move.c.driver.md#moveSq) and its UCI string is validated against "e8e7" using [`validateString`](#validateString). - - Another move `m` is created from square c2 to b1 with a promotion to a queen using [`movePromote`](chesslib/move.c.driver.md#movePromote), and its UCI string is validated against "c2b1q" using [`validateString`](#validateString). -- **Output**: - - The function does not return any value; it validates the correctness of UCI string conversion for specific moves. -- **Functions called**: - - [`moveSq`](chesslib/move.c.driver.md#moveSq) - - [`sqI`](chesslib/square.c.driver.md#sqI) - - [`validateString`](#validateString) - - [`moveGetUci`](chesslib/move.c.driver.md#moveGetUci) - - [`movePromote`](chesslib/move.c.driver.md#movePromote) - - ---- -### testMoveFromUci -The `testMoveFromUci` function tests the conversion of UCI (Universal Chess Interface) strings into move objects and validates their correctness. -- **Inputs**: - - None -- **Control Flow**: - - The function begins by creating a move object `m` from the UCI string "e8e7" using the [`moveFromUci`](chesslib/move.c.driver.md#moveFromUci) function. - - It then validates this move by checking if it correctly represents a move from square e8 to e7 with no promotion using the [`validateMove`](#validateMove) function. - - Next, it creates another move object `m` from the UCI string "c2b1q", which includes a promotion to a queen. - - It validates this move by checking if it correctly represents a move from square c2 to b1 with a promotion to a queen using the [`validateMove`](#validateMove) function. -- **Output**: - - The function does not return any value; it performs validation checks and may halt execution if a test fails. -- **Functions called**: - - [`moveFromUci`](chesslib/move.c.driver.md#moveFromUci) - - [`validateMove`](#validateMove) - - [`sqI`](chesslib/square.c.driver.md#sqI) - - ---- -### testMoveList -The `testMoveList` function tests the functionality of creating, adding, retrieving, and validating moves in a move list for a chess game. -- **Inputs**: - - None -- **Control Flow**: - - Create three moves using [`moveFromUci`](chesslib/move.c.driver.md#moveFromUci) with UCI strings 'e2e4', 'e7e5', and 'e1e2'. - - Create a new move list using [`moveListCreate`](chesslib/movelist.c.driver.md#moveListCreate). - - Add the three moves to the move list using [`moveListAdd`](chesslib/movelist.c.driver.md#moveListAdd). - - Retrieve the moves from the list using [`moveListGet`](chesslib/movelist.c.driver.md#moveListGet) at indices 0, 1, and 2. - - Convert each retrieved move to its UCI string using [`moveGetUci`](chesslib/move.c.driver.md#moveGetUci) and compare it to the expected UCI string using `strcmp`. - - If the UCI string does not match the expected string, call [`failTest`](#failTest) with a formatted error message. - - Free the UCI string memory after each comparison. - - Free the move list using [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree). -- **Output**: - - The function does not return any value but will terminate the program with an error message if any test fails. -- **Functions called**: - - [`moveFromUci`](chesslib/move.c.driver.md#moveFromUci) - - [`moveListCreate`](chesslib/movelist.c.driver.md#moveListCreate) - - [`moveListAdd`](chesslib/movelist.c.driver.md#moveListAdd) - - [`moveListGet`](chesslib/movelist.c.driver.md#moveListGet) - - [`moveGetUci`](chesslib/move.c.driver.md#moveGetUci) - - [`failTest`](#failTest) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - ---- -### assertPiece -The `assertPiece` function checks if two chess pieces are equal and reports an error if they are not. -- **Inputs**: - - `actual`: The actual piece to be compared. - - `expected`: The expected piece to be compared against. -- **Control Flow**: - - The function compares the `actual` piece with the `expected` piece using the `!=` operator. - - If the pieces are not equal, it retrieves the letter representation of both pieces using [`pieceGetLetter`](chesslib/piece.c.driver.md#pieceGetLetter). - - It formats a message indicating the mismatch using `sprintf`. - - The function then calls [`failTest`](#failTest) with the formatted message to report the error and halt the program. -- **Output**: - - The function does not return a value; it halts the program if the pieces do not match. -- **Functions called**: - - [`pieceGetLetter`](chesslib/piece.c.driver.md#pieceGetLetter) - - [`failTest`](#failTest) - - ---- -### testBoardCreate -The `testBoardCreate` function tests the creation of a chess board and verifies its initial setup and state. -- **Inputs**: - - None -- **Control Flow**: - - Create a new board using `boardCreate()` and store it in `b`. - - Check if the board `b` is `NULL` and fail the test if it is. - - Verify the initial positions of white pieces (rooks, knights, bishops, queen, king, and pawns) on the board using [`assertPiece`](#assertPiece). - - Verify that the squares from index 16 to 47 are empty using [`assertPiece`](#assertPiece). - - Verify the initial positions of black pieces (pawns, rooks, knights, bishops, queen, king) on the board using [`assertPiece`](#assertPiece). - - Check if the current player is set to white (`pcWhite`) and fail the test if not. - - Check if all castling flags are enabled (`0b1111`) and fail the test if not. - - Verify that the en passant target square is `SQ_INVALID` and fail the test if not. - - Check if the half-move clock is set to 0 and fail the test if not. - - Check if the move number is set to 1 and fail the test if not. - - Free the allocated memory for the board `b`. -- **Output**: - - The function does not return any value; it performs assertions to validate the board's initial state and fails the test if any condition is not met. -- **Functions called**: - - [`boardCreate`](chesslib/board.c.driver.md#boardCreate) - - [`failTest`](#failTest) - - [`assertPiece`](#assertPiece) - - [`sqEq`](chesslib/square.c.driver.md#sqEq) - - ---- -### testBoardCreateFromFen -The function `testBoardCreateFromFen` tests the creation of a chess board from a FEN string and verifies the board's state against expected values. -- **Inputs**: - - None -- **Control Flow**: - - Call [`boardCreateFromFen`](chesslib/board.c.driver.md#boardCreateFromFen) with a specific FEN string to create a board. - - Check if the board is NULL and fail the test if it is. - - Iterate over all 64 squares of the board, skipping specific indices where pieces are expected, and assert that the remaining squares are empty. - - Assert that specific squares contain the expected pieces (queens, pawns, kings). - - Verify that the current player is black, failing the test if not. - - Check that all castling flags are disabled, failing the test if not. - - Verify the en passant target square is correct, failing the test if not. - - Check that the half-move clock is zero, failing the test if not. - - Verify the full move number is 46, failing the test if not. - - Free the allocated board memory. -- **Output**: - - The function does not return a value but will terminate the program with an error message if any test condition fails. -- **Functions called**: - - [`boardCreateFromFen`](chesslib/board.c.driver.md#boardCreateFromFen) - - [`failTest`](#failTest) - - [`assertPiece`](#assertPiece) - - [`sqEq`](chesslib/square.c.driver.md#sqEq) - - [`sqI`](chesslib/square.c.driver.md#sqI) - - [`sqGetStr`](chesslib/square.c.driver.md#sqGetStr) - - ---- -### testBoardEq -The `testBoardEq` function is a placeholder for a test that checks if two chess boards are equal, but it is not yet implemented. -- **Inputs**: - - None -- **Control Flow**: - - The function calls [`failTest`](#failTest) with the message 'Not yet implemented', which causes the test to fail and the program to exit. - - There is a commented-out section indicating a future plan to create a board from a FEN string for comparison. -- **Output**: - - The function does not return any value as it is intended to fail the test and exit the program. -- **Functions called**: - - [`failTest`](#failTest) - - ---- -### validateUciIsInMovelist -The `validateUciIsInMovelist` function checks if a given UCI move string is present in a move list and fails the test if it is not found. -- **Inputs**: - - `list`: A pointer to a `moveList` structure representing the list of moves to be searched. - - `expectedUci`: A string representing the expected UCI move that should be present in the move list. -- **Control Flow**: - - Iterate over each node in the move list starting from the head. - - For each node, retrieve the UCI string of the move using [`moveGetUci`](chesslib/move.c.driver.md#moveGetUci). - - Compare the retrieved UCI string with the expected UCI string using `strcmp`. - - If a match is found (comparison result is 0), return from the function, indicating the move is present. - - If the loop completes without finding a match, format an error message indicating the expected UCI was absent. - - Call [`failTest`](#failTest) with the error message to halt the test execution. -- **Output**: - - The function does not return a value; it either returns normally if the UCI is found or calls [`failTest`](#failTest) to halt execution if the UCI is not found. -- **Functions called**: - - [`moveGetUci`](chesslib/move.c.driver.md#moveGetUci) - - [`failTest`](#failTest) - - ---- -### validateListSize -The `validateListSize` function checks if a move list's size matches an expected size and triggers a test failure if they do not match. -- **Inputs**: - - `list`: A pointer to a `moveList` structure, which contains a list of chess moves and its current size. - - `expectedSize`: A `size_t` value representing the expected number of elements in the move list. -- **Control Flow**: - - The function checks if the `size` attribute of the `list` does not equal `expectedSize`. - - If the sizes do not match, it formats an error message indicating the actual and expected sizes. - - The function then calls [`failTest`](#failTest) with the formatted message to indicate a test failure and halt execution. -- **Output**: - - The function does not return a value; it either completes silently if the sizes match or halts the program with an error message if they do not. -- **Functions called**: - - [`failTest`](#failTest) - - ---- -### testPawnMoves -The `testPawnMoves` function tests various scenarios of pawn movements on a chessboard, including normal moves, captures, promotions, and en passant captures, using a series of assertions to validate the correctness of the move generation logic. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a board with a lone white pawn on its starting rank and generate its possible moves, validating that it can move one or two squares forward. - - Set up a board where a pawn can capture enemy pieces diagonally and validate the possible capture moves. - - Test a scenario where a pawn is blocked by another piece and validate that no moves are possible. - - Place a pawn not on its starting rank and validate that it can only move one square forward. - - Set up a board where a white pawn is about to promote and validate all possible promotion moves. - - Test a black pawn on its starting rank and validate its possible moves, including moving two squares forward. - - Set up a scenario where a pawn is blocked with one free spot and validate the single possible move. - - Test a black pawn about to promote with capturing ability and validate all possible promotion and capture moves. - - Set up a board where a white pawn can capture en passant and validate the en passant capture move. - - Test a black pawn with an en passant capture opportunity and validate the en passant capture move. - - Free the allocated memory for the board and move lists after each test case. -- **Output**: - - The function does not return any value; it uses assertions to validate the correctness of pawn move generation logic in various scenarios. -- **Functions called**: - - [`boardCreateFromFen`](chesslib/board.c.driver.md#boardCreateFromFen) - - [`pmGetPawnMoves`](chesslib/piecemoves.c.driver.md#pmGetPawnMoves) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`validateListSize`](#validateListSize) - - [`validateUciIsInMovelist`](#validateUciIsInMovelist) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - ---- -### testKnightMoves -The `testKnightMoves` function tests the generation of legal moves for a knight in various board positions. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board with a lone knight at c3 and generate its moves. - - Validate that the move list contains 8 moves and specific expected moves from c3. - - Free the move list. - - Initialize a chess board with a knight near the edge at h7 and generate its moves. - - Validate that the move list contains 3 moves and specific expected moves from h7. - - Free the move list. - - Initialize a chess board with a knight at f6 surrounded by other pieces and generate its moves. - - Validate that the move list contains 6 moves and specific expected moves from f6. - - Free the move list. -- **Output**: - - The function does not return any value; it validates the correctness of knight move generation through assertions. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`pmGetKnightMoves`](chesslib/piecemoves.c.driver.md#pmGetKnightMoves) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`validateListSize`](#validateListSize) - - [`validateUciIsInMovelist`](#validateUciIsInMovelist) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - ---- -### testBishopMoves -The `testBishopMoves` function tests the move generation for bishops on a chessboard in different scenarios. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board with a lone bishop on e7 using FEN notation. - - Generate all possible moves for the bishop on e7 and store them in a move list. - - Validate that the move list contains exactly 9 moves and includes specific expected moves. - - Free the move list to release memory. - - Reinitialize the chess board with a bishop on c3 and other pieces blocking some paths using FEN notation. - - Generate all possible moves for the bishop on c3 and store them in a move list. - - Validate that the move list contains exactly 5 moves and includes specific expected moves. - - Free the move list to release memory. -- **Output**: - - The function does not return any value; it validates the correctness of bishop move generation through assertions. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`pmGetBishopMoves`](chesslib/piecemoves.c.driver.md#pmGetBishopMoves) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`validateListSize`](#validateListSize) - - [`validateUciIsInMovelist`](#validateUciIsInMovelist) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - ---- -### testRookMoves -The `testRookMoves` function tests the move generation for rooks on a chessboard in different scenarios. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board `b` and a move list pointer `list`. - - Set up a board with a lone rook on d7 using FEN notation and generate its possible moves. - - Validate that the move list contains 14 moves and specific moves like 'd7d8', 'd7e7', etc. - - Free the move list after validation. - - Set up a more complex board with a rook on e5 surrounded by other pieces and generate its possible moves. - - Validate that the move list contains 9 moves and specific moves like 'e5e6', 'e5e7', etc. - - Free the move list after validation. -- **Output**: - - The function does not return any value; it validates the correctness of rook move generation through assertions. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`pmGetRookMoves`](chesslib/piecemoves.c.driver.md#pmGetRookMoves) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`validateListSize`](#validateListSize) - - [`validateUciIsInMovelist`](#validateUciIsInMovelist) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - ---- -### testQueenMoves -The `testQueenMoves` function tests the move generation for a queen piece on a chessboard in different scenarios. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board with a lone queen at position b2 using FEN notation. - - Generate all possible moves for the queen at b2 and store them in a move list. - - Validate that the move list contains 23 moves and specific expected moves like b2b3, b2b4, etc. - - Free the move list to release memory. - - Initialize another chess board with a queen surrounded by other pieces at position d5 using FEN notation. - - Generate all possible moves for the queen at d5 and store them in a move list. - - Validate that the move list contains 11 moves and specific expected moves like d5e6, d5f7, etc. - - Free the move list to release memory. -- **Output**: - - The function does not return any value; it performs assertions to validate the correctness of queen move generation. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`pmGetQueenMoves`](chesslib/piecemoves.c.driver.md#pmGetQueenMoves) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`validateListSize`](#validateListSize) - - [`validateUciIsInMovelist`](#validateUciIsInMovelist) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - ---- -### testKingMoves -The `testKingMoves` function tests the movement generation of a king piece on a chessboard in various scenarios without considering check conditions. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board with a lone king at position c7 and generate possible king moves using [`pmGetKingMoves`](chesslib/piecemoves.c.driver.md#pmGetKingMoves). - - Validate that the generated move list contains 8 moves corresponding to all possible king moves from c7. - - Free the move list memory. - - Initialize a chess board with a king in the corner at position a1 and generate possible king moves. - - Validate that the generated move list contains 3 moves corresponding to all possible king moves from a1. - - Free the move list memory. - - Initialize a chess board with a king surrounded by other pieces at position d5 and generate possible king moves. - - Validate that the generated move list contains 5 moves corresponding to all possible king moves from d5. - - Free the move list memory. -- **Output**: - - The function does not return any value; it validates the correctness of king move generation by asserting expected move lists. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`pmGetKingMoves`](chesslib/piecemoves.c.driver.md#pmGetKingMoves) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`validateListSize`](#validateListSize) - - [`validateUciIsInMovelist`](#validateUciIsInMovelist) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - ---- -### testIsSquareAttacked -The `testIsSquareAttacked` function tests the [`boardIsSquareAttacked`](chesslib/board.c.driver.md#boardIsSquareAttacked) function by setting up various chess board scenarios and verifying if the function correctly identifies attacked squares. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board with a knight and a pawn using FEN notation and iterate over all 64 squares to check if the expected attacked squares match the actual attacked squares as determined by [`boardIsSquareAttacked`](chesslib/board.c.driver.md#boardIsSquareAttacked). - - Reinitialize the board with a lone rook and repeat the process of checking attacked squares for all 64 squares, comparing expected and actual results. - - Set up a board with a rook and potential blocking or capturing pieces, and again verify the attacked status of each square against expected results. -- **Output**: - - The function does not return a value but will call [`failTest`](#failTest) and terminate the program if any test case fails, indicating a discrepancy between expected and actual results. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`sqIndex`](chesslib/square.c.driver.md#sqIndex) - - [`sqEq`](chesslib/square.c.driver.md#sqEq) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`boardIsSquareAttacked`](chesslib/board.c.driver.md#boardIsSquareAttacked) - - [`sqGetStr`](chesslib/square.c.driver.md#sqGetStr) - - [`failTest`](#failTest) - - ---- -### testIsInCheck -The `testIsInCheck` function tests the functionality of checking if a chess board is in check using various board configurations. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board `b` using [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) with a FEN string representing a board where the white king is in check by a black rook. - - Check if the board is in check using [`boardIsInCheck`](chesslib/board.c.driver.md#boardIsInCheck) and fail the test if it is not. - - Check if the black player is in check using [`boardIsPlayerInCheck`](chesslib/board.c.driver.md#boardIsPlayerInCheck) and fail the test if it is. - - Initialize the board `b` with a FEN string representing the Scholar's mate position and repeat the check tests for the white player. - - Initialize the board `b` with a FEN string where checks are blocked by knights and ensure the board is not in check for both players. -- **Output**: - - The function does not return any value but will terminate the program with an error message if any of the checks fail. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`boardIsInCheck`](chesslib/board.c.driver.md#boardIsInCheck) - - [`failTest`](#failTest) - - [`boardIsPlayerInCheck`](chesslib/board.c.driver.md#boardIsPlayerInCheck) - - ---- -### validateBoardEq -The `validateBoardEq` function checks if two chess boards are identical and fails the test with a message if they are not. -- **Inputs**: - - `name`: A string representing the name or description of the test being performed. - - `b1`: A pointer to the first board structure to be compared. - - `b2`: A pointer to the second board structure to be compared. -- **Control Flow**: - - The function calls [`boardEq`](chesslib/board.c.driver.md#boardEq) to compare the two board structures `b1` and `b2` for equality. - - If [`boardEq`](chesslib/board.c.driver.md#boardEq) returns false, indicating the boards are not equal, a message is formatted using `sprintf` to include the provided `name` and a description of the failure. - - The [`failTest`](#failTest) function is then called with the formatted message to indicate the test failure and halt the program. -- **Output**: - - The function does not return a value; it either completes without issue if the boards are equal or calls [`failTest`](#failTest) to terminate the program if they are not. -- **Functions called**: - - [`boardEq`](chesslib/board.c.driver.md#boardEq) - - [`failTest`](#failTest) - - ---- -### testBoardPlayMove -The `testBoardPlayMove` function tests various chess move scenarios on a board to ensure correct move execution and board state validation. -- **Inputs**: - - None -- **Control Flow**: - - Create a new chess board `b` using `boardCreate()`. - - Play the move 1. e4 on board `b` and create a board `bCheck` from a FEN string to represent the expected board state after the move. - - Validate that the board `b` matches `bCheck` using [`validateBoardEq`](#validateBoardEq). - - Check for fuzziness by comparing `b` with `bCheckFuzzy` and ensure they are not exactly equal but contextually the same. - - Play the move 1... Nf6 on board `b` and update `bCheck` to the expected state after the move. - - Validate the board state again using [`validateBoardEq`](#validateBoardEq). - - Test capturing moves by setting up specific board states and playing moves like Rook captures Rook and Bishop captures Pawn. - - Validate each board state after the move using [`validateBoardEq`](#validateBoardEq). - - Test special moves like castling (O-O, O-O-O) and en passant captures by setting up specific board states and playing the moves. - - Validate each board state after the move using [`validateBoardEq`](#validateBoardEq). - - Free the memory allocated for the boards `b` and `bCheck`. -- **Output**: - - The function does not return any value; it performs assertions to validate board states and fails the test if any validation fails. -- **Functions called**: - - [`boardCreate`](chesslib/board.c.driver.md#boardCreate) - - [`boardPlayMoveInPlace`](chesslib/board.c.driver.md#boardPlayMoveInPlace) - - [`moveSq`](chesslib/move.c.driver.md#moveSq) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`boardCreateFromFen`](chesslib/board.c.driver.md#boardCreateFromFen) - - [`validateBoardEq`](#validateBoardEq) - - [`boardEq`](chesslib/board.c.driver.md#boardEq) - - [`failTest`](#failTest) - - [`boardEqContext`](chesslib/board.c.driver.md#boardEqContext) - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`moveFromUci`](chesslib/move.c.driver.md#moveFromUci) - - ---- -### validateUciIsNotInMovelist -The function `validateUciIsNotInMovelist` checks if a given UCI string is absent from a move list and fails the test if it is present. -- **Inputs**: - - `list`: A pointer to a `moveList` structure representing the list of moves to be checked. - - `expectedUci`: A string representing the UCI (Universal Chess Interface) notation of the move expected to be absent from the move list. -- **Control Flow**: - - Iterate through each node in the move list starting from the head. - - For each node, retrieve the UCI string of the move using [`moveGetUci`](chesslib/move.c.driver.md#moveGetUci). - - Compare the retrieved UCI string with the `expectedUci` using `strcmp`. - - If the strings match, construct an error message indicating the presence of the move and call [`failTest`](#failTest) with this message to halt the test. - - If the loop completes without finding a match, the function ends successfully, indicating the move is absent. -- **Output**: - - The function does not return a value; it either completes successfully if the move is absent or calls [`failTest`](#failTest) to halt the program if the move is present. -- **Functions called**: - - [`moveGetUci`](chesslib/move.c.driver.md#moveGetUci) - - [`failTest`](#failTest) - - ---- -### testBoardGenerateMoves -The `testBoardGenerateMoves` function tests the move generation functionality of a chess board implementation by validating the generated moves against expected moves for various board states. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board to the starting position and generate all possible moves. - - Validate that the generated move list contains exactly 20 moves, including all possible pawn and knight moves from the initial position. - - Free the move list to release memory. - - Set up a board with a specific FEN string representing a mid-game position and generate all possible moves. - - Validate the size of the move list and check for the presence of specific pawn, knight, bishop, queen, and king moves. - - Free the move list to release memory. - - Set up a board with fewer pieces and generate all possible moves. - - Validate the size of the move list and check for the presence of specific knight and king moves. - - Free the move list to release memory. - - Set up a board with a pinned knight and generate all possible moves. - - Validate that only king moves are present in the move list and the pinned knight cannot move. - - Free the move list to release memory. - - Set up a board where the king is in check and generate all possible moves. - - Validate that the move list contains only moves that block the check or move the king out of check. - - Free the move list to release memory. -- **Output**: - - The function does not return any output; it performs assertions to validate the correctness of move generation and will halt execution if any test fails. -- **Functions called**: - - [`boardInitInPlace`](chesslib/board.c.driver.md#boardInitInPlace) - - [`boardGenerateMoves`](chesslib/board.c.driver.md#boardGenerateMoves) - - [`validateListSize`](#validateListSize) - - [`validateUciIsInMovelist`](#validateUciIsInMovelist) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`validateUciIsNotInMovelist`](#validateUciIsNotInMovelist) - - ---- -### testBoardGenerateMovesCastling -The function `testBoardGenerateMovesCastling` tests the generation of castling moves in a chess game under various board conditions. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board with a specific FEN string and generate possible moves. - - Validate that the castling move 'e1g1' is in the move list for White's kingside castling. - - Remove the castling flag for White's kingside castling and validate that 'e1g1' is not in the move list. - - Switch to Black's turn and validate that the castling move 'e8g8' is in the move list for Black's kingside castling. - - Initialize the board for White's queenside castling and validate 'e1c1' is in the move list. - - Switch to Black's turn and validate 'e8c8' is in the move list for Black's queenside castling. - - Test scenarios where the king is in check or squares are attacked, ensuring castling is not allowed when it shouldn't be. - - Free the move list after each test case to prevent memory leaks. -- **Output**: - - The function does not return any value; it validates the presence or absence of castling moves in the generated move list and fails the test if the validation does not meet expectations. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`boardGenerateMoves`](chesslib/board.c.driver.md#boardGenerateMoves) - - [`validateUciIsInMovelist`](#validateUciIsInMovelist) - - [`moveListFree`](chesslib/movelist.c.driver.md#moveListFree) - - [`validateUciIsNotInMovelist`](#validateUciIsNotInMovelist) - - ---- -### validateBoardFen -The `validateBoardFen` function checks if a given FEN string correctly represents a chess board state by comparing it to the FEN string generated from the board initialized with the given FEN. -- **Inputs**: - - `fen`: A string representing the Forsyth-Edwards Notation (FEN) of a chess board state. -- **Control Flow**: - - Initialize a `board` structure `b`. - - Call [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) to set up the board `b` using the provided FEN string. - - Generate the FEN string from the board `b` using [`boardGetFen`](chesslib/board.c.driver.md#boardGetFen). - - Call [`validateString`](#validateString) to compare the generated FEN string with the input FEN string. - - Free the memory allocated for the generated FEN string. -- **Output**: - - The function does not return a value; it validates the FEN string and may terminate the program if the validation fails. -- **Functions called**: - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - [`boardGetFen`](chesslib/board.c.driver.md#boardGetFen) - - [`validateString`](#validateString) - - ---- -### testBoardGetFen -The `testBoardGetFen` function validates the correctness of FEN (Forsyth-Edwards Notation) string generation for various chess board states. -- **Inputs**: - - None -- **Control Flow**: - - The function calls [`validateBoardFen`](#validateBoardFen) with the initial FEN string and several other FEN strings representing different chess positions. - - Each call to [`validateBoardFen`](#validateBoardFen) checks if the FEN string generated from a board matches the expected FEN string. -- **Output**: - - The function does not return any value; it performs validation checks and may halt execution if a test fails. -- **Functions called**: - - [`validateBoardFen`](#validateBoardFen) - - ---- -### validateBoardIsInsufficientMaterial -The function `validateBoardIsInsufficientMaterial` checks if a chess board has insufficient material to continue the game and compares the result with an expected value, failing the test if they do not match. -- **Inputs**: - - `b`: A pointer to a `board` structure representing the current state of the chess board. - - `expected`: A `uint8_t` value representing the expected result of whether the board is a draw by insufficient material (1 for true, 0 for false). -- **Control Flow**: - - Call the function [`boardIsInsufficientMaterial`](chesslib/board.c.driver.md#boardIsInsufficientMaterial) with the board `b` to determine if the board is a draw by insufficient material, storing the result in `actual`. - - Compare `actual` with `expected`. - - If `actual` does not equal `expected`, format a message indicating the discrepancy and call [`failTest`](#failTest) with this message to halt the test. -- **Output**: - - The function does not return a value; it either completes successfully or calls [`failTest`](#failTest) to indicate a test failure. -- **Functions called**: - - [`boardIsInsufficientMaterial`](chesslib/board.c.driver.md#boardIsInsufficientMaterial) - - [`failTest`](#failTest) - - ---- -### testBoardIsInsufficientMaterial -The function `testBoardIsInsufficientMaterial` tests various chess board configurations to determine if they result in a draw due to insufficient material. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a chess board `b` using [`boardInitInPlace`](chesslib/board.c.driver.md#boardInitInPlace) and check if it is insufficient material using [`validateBoardIsInsufficientMaterial`](#validateBoardIsInsufficientMaterial) with expected result `0`. - - Set up a board with only kings using [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) and validate it as insufficient material with expected result `1`. - - Set up a board with a king versus a king and knight, validate it as insufficient material with expected result `1`. - - Set up a board with a king versus a king and two knights, validate it as not insufficient material with expected result `0`. - - Set up a board with a king and bishop versus a king and bishop on different colors, validate it as not insufficient material with expected result `0`. - - Set up a board with a king and bishop versus a king and bishop on the same color, validate it as insufficient material with expected result `1`. - - Set up a board with multiple bishops on the same color versus a king and bishops, validate it as insufficient material with expected result `1`. -- **Output**: - - The function does not return a value; it uses assertions to validate the expected outcomes of the tests. -- **Functions called**: - - [`boardInitInPlace`](chesslib/board.c.driver.md#boardInitInPlace) - - [`validateBoardIsInsufficientMaterial`](#validateBoardIsInsufficientMaterial) - - [`boardInitFromFenInPlace`](chesslib/board.c.driver.md#boardInitFromFenInPlace) - - ---- -### testBoardList -The `testBoardList` function tests the functionality of creating, adding to, retrieving from, and freeing a list of chess boards. -- **Inputs**: - - None -- **Control Flow**: - - Create a new board `b1` using `boardCreate()`. - - Create a new board `b2` by playing a move on `b1` using `boardPlayMove(b1, moveFromUci("e2e4"))`. - - Create a new board `b3` by playing a different move on `b1` using `boardPlayMove(b1, moveFromUci("c7c5"))`. - - Create a new board list `l` using `boardListCreate()`. - - Add `b1`, `b2`, and `b3` to the board list `l` using `boardListAdd()`. - - Check if the first board in the list `l` is `b1` using `boardListGet(l, 0)` and call `failTest()` if not. - - Check if the second board in the list `l` is `b2` using `boardListGet(l, 1)` and call `failTest()` if not. - - Check if the third board in the list `l` is `b3` using `boardListGet(l, 2)` and call `failTest()` if not. - - Free the board list `l` using `boardListFree(l)`, which also frees all boards in the list. -- **Output**: - - The function does not return any value, but it will terminate the program with an error message if any of the tests fail. -- **Functions called**: - - [`boardCreate`](chesslib/board.c.driver.md#boardCreate) - - [`boardPlayMove`](chesslib/board.c.driver.md#boardPlayMove) - - [`moveFromUci`](chesslib/move.c.driver.md#moveFromUci) - - [`boardListCreate`](chesslib/boardlist.c.driver.md#boardListCreate) - - [`boardListAdd`](chesslib/boardlist.c.driver.md#boardListAdd) - - [`boardListGet`](chesslib/boardlist.c.driver.md#boardListGet) - - [`failTest`](#failTest) - - [`boardListFree`](chesslib/boardlist.c.driver.md#boardListFree) - - ---- -### testSqSetSet -The `testSqSetSet` function tests the [`sqSetSet`](chesslib/squareset.c.driver.md#sqSetSet) function by setting specific squares on a bitboard and verifying the expected bitboard state. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a 64-bit integer `ss` to 0, representing an empty bitboard. - - Call [`sqSetSet`](chesslib/squareset.c.driver.md#sqSetSet) to set the square 'e4' on the bitboard `ss` to 1. - - Check if `ss` equals `0x0000000010000000` and call [`failTest`](#failTest) if not. - - Call [`sqSetSet`](chesslib/squareset.c.driver.md#sqSetSet) to set the square 'd5' on the bitboard `ss` to 1. - - Check if `ss` equals `0x0000000810000000` and call [`failTest`](#failTest) if not. - - Call [`sqSetSet`](chesslib/squareset.c.driver.md#sqSetSet) to set the square 'a1' on the bitboard `ss` to 1. - - Check if `ss` equals `0x0000000810000001` and call [`failTest`](#failTest) if not. - - Call [`sqSetSet`](chesslib/squareset.c.driver.md#sqSetSet) to set the square 'h8' on the bitboard `ss` to 1. - - Check if `ss` equals `0x8000000810000001` and call [`failTest`](#failTest) if not. -- **Output**: - - The function does not return a value; it uses [`failTest`](#failTest) to indicate test failures. -- **Functions called**: - - [`sqSetSet`](chesslib/squareset.c.driver.md#sqSetSet) - - [`sqS`](chesslib/square.c.driver.md#sqS) - - [`failTest`](#failTest) - - ---- -### testSqSetGet -The `testSqSetGet` function tests the [`sqSetGet`](chesslib/squareset.c.driver.md#sqSetGet) function by verifying the correctness of square set retrieval for specific bit patterns representing chessboard squares. -- **Inputs**: - - None -- **Control Flow**: - - Initialize a 64-bit integer `ss` to represent a diagonal from a1 to h8 with the bit pattern `0x8040201008040201`. - - Iterate over each square index from 0 to 63, converting each index to a square `s` using `sqIndex(i)`. - - For each square, calculate the expected value as 1 if the square's file equals its rank, otherwise 0. - - Retrieve the actual value from the square set using `sqSetGet(&ss, s)`. - - If the expected value does not match the actual value, format an error message and call [`failTest`](#failTest) to indicate a test failure. - - Reinitialize `ss` to represent the entire c file, f file, 3 rank, and 6 rank with the bit pattern `0x2424FF2424FF2424`. - - Repeat the iteration and validation process for the new bit pattern, checking if the square's file or rank matches 3 or 6. -- **Output**: - - The function does not return a value; it uses [`failTest`](#failTest) to halt execution if any test fails, indicating a mismatch between expected and actual values. -- **Functions called**: - - [`sqIndex`](chesslib/square.c.driver.md#sqIndex) - - [`sqSetGet`](chesslib/squareset.c.driver.md#sqSetGet) - - [`sqGetStr`](chesslib/square.c.driver.md#sqGetStr) - - [`failTest`](#failTest) - - diff --git a/driver_docs/src/tests.h.driver.md b/driver_docs/src/tests.h.driver.md deleted file mode 100644 index efac5b2..0000000 --- a/driver_docs/src/tests.h.driver.md +++ /dev/null @@ -1,295 +0,0 @@ -# Purpose -This C header file is designed for testing various components of a chess game implementation. It declares a series of functions that are used to validate different aspects of the chess program, such as board creation, move generation, and piece movement. The file includes functions for testing specific chess functionalities, including square properties, move creation and conversion, board state management, and special conditions like castling and draw by insufficient material. Additionally, it provides a mechanism to fail tests with an optional message, ensuring that any discrepancies in expected behavior can be identified and addressed. This file is essential for maintaining the integrity and correctness of the chess application by systematically verifying its components. -# Function Declarations (Public API) - ---- -### failTest -Fails the current test and terminates the program. -- **Description**: Use this function to immediately fail the currently running test and halt the program execution. It is typically used in a testing environment to indicate that a test has encountered a critical failure. The function outputs a failure message to the standard error stream, which includes the name of the current test and an optional custom message. If the `msg` parameter is `NULL`, only the test name is included in the output. This function will terminate the program using `exit(1)`, so it should be used when no further execution is desired after a test failure. -- **Inputs**: - - `msg`: A pointer to a null-terminated string containing a custom failure message. If `NULL`, no custom message is included in the output. The caller retains ownership of the string, and it must be a valid pointer or `NULL`. -- **Output**: None -- **See also**: [`failTest`](tests.c.driver.md#failTest) (Implementation) - - ---- -### validateString -Compares two strings and fails the test if they are not equal. -- **Description**: This function is used to compare two strings, `actual` and `expected`, during testing. It is typically called within a test case to ensure that the `actual` string matches the `expected` string. If the strings are not equal, the function constructs a detailed error message and calls `failTest` to fail the current test and halt the program. This function should be used when string equality is a critical condition for the test's success. It is important to note that the function will terminate the program if the strings do not match, so it should be used with caution in test environments. -- **Inputs**: - - `actual`: A pointer to a null-terminated string representing the actual value obtained during the test. Must not be null. - - `expected`: A pointer to a null-terminated string representing the expected value to compare against. Must not be null. -- **Output**: None -- **See also**: [`validateString`](tests.c.driver.md#validateString) (Implementation) - - ---- -### testSqI -Tests the square indexing function for correctness. -- **Description**: This function is used to verify the correctness of the square indexing function `sqI` by iterating over all possible chessboard squares and checking if the function returns the expected file and rank. It is intended to be used in a testing environment to ensure that the `sqI` function behaves as expected. If a discrepancy is found between the expected and actual values, the test fails and halts the program, providing a message with the details of the failure. This function should be called in a controlled testing setup where such halts are manageable. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testSqI`](tests.c.driver.md#testSqI) (Implementation) - - ---- -### testSqS -Tests the conversion of chess square strings to square objects. -- **Description**: This function is used to verify that the conversion from chess square notation strings (e.g., "a1", "h8") to square objects is functioning correctly. It iterates over all possible squares on a standard 8x8 chessboard, converting each square's string representation to a square object and checking if the resulting object's file and rank match the expected values. If any conversion does not match the expected result, the test fails and halts execution with an error message. This function is typically used in a testing environment to ensure the correctness of the square conversion logic. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testSqS`](tests.c.driver.md#testSqS) (Implementation) - - ---- -### testSqGetStr -Tests the string representation of chessboard squares. -- **Description**: This function is used to verify that the string representation of each square on a chessboard is correctly generated. It iterates over all possible squares on an 8x8 chessboard, constructs the expected string representation for each square, and validates it against the actual string returned by the `sqGetStr` function. This function is typically used in a testing context to ensure the correctness of the `sqGetStr` function, and it assumes that the `validateString` function will handle any discrepancies by failing the test. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testSqGetStr`](tests.c.driver.md#testSqGetStr) (Implementation) - - ---- -### testSqIsDark -Tests if the function correctly identifies dark squares on a chessboard. -- **Description**: This function is used to verify the correctness of the `sqIsDark` function, which determines whether a given square on a chessboard is dark. It iterates over all squares on a standard 8x8 chessboard, checking if the `sqIsDark` function returns the expected result for each square. The test expects the squares to alternate between dark and light, starting with a dark square at a1. If a discrepancy is found between the actual and expected results, the test fails and halts execution, providing a descriptive error message. This function is typically used during development to ensure the `sqIsDark` function behaves as intended. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testSqIsDark`](tests.c.driver.md#testSqIsDark) (Implementation) - - ---- -### testMoveCreate -Tests the creation and validation of chess moves. -- **Description**: This function is used to test the creation of chess moves and their validation within a chess implementation. It is intended to ensure that moves are correctly created and validated according to expected parameters. This function is typically used during the development and testing phase to verify that move creation and validation logic is functioning as intended. It does not take any parameters and does not return any values, as it is designed to be a self-contained test that will halt the program if a test fails. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testMoveCreate`](tests.c.driver.md#testMoveCreate) (Implementation) - - ---- -### testMoveFromUci -Tests the conversion of UCI strings to move objects. -- **Description**: This function is used to verify that UCI (Universal Chess Interface) strings are correctly converted into move objects within the chess implementation. It is intended for use in a testing environment to ensure that the conversion process produces the expected results. The function does not take any parameters and does not return a value. It is typically called as part of a suite of tests to validate the correctness of move creation from UCI strings. The function assumes that the necessary chess data structures and functions are available and correctly implemented. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testMoveFromUci`](tests.c.driver.md#testMoveFromUci) (Implementation) - - ---- -### testMoveGetUci -Validates the UCI string representation of chess moves. -- **Description**: This function is used to test the correctness of the UCI (Universal Chess Interface) string representation of chess moves. It is intended for use in a testing environment to ensure that the conversion of move objects to their UCI string format is accurate. The function performs validation by comparing the generated UCI string against expected values. It is typically used during the development and testing of a chess engine to verify that move encoding is functioning as expected. This function should be called in a controlled test environment where the test framework can handle any failures. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testMoveGetUci`](tests.c.driver.md#testMoveGetUci) (Implementation) - - ---- -### testMoveList -Tests the functionality of move list operations. -- **Description**: This function is used to verify the correct behavior of move list operations in a chess implementation. It creates a list of moves, adds several moves to the list, retrieves them, and checks their correctness by comparing their UCI (Universal Chess Interface) string representations against expected values. This function is typically used in a testing environment to ensure that move list creation, addition, retrieval, and UCI conversion are functioning as expected. It is important to call this function in a controlled test environment as it will halt the program if any test fails. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testMoveList`](tests.c.driver.md#testMoveList) (Implementation) - - ---- -### testBoardCreate -Tests the creation of a chess board and its initial state. -- **Description**: This function is used to verify that a newly created chess board is initialized correctly with all pieces in their standard starting positions. It checks that the board's initial state matches the expected configuration for a new game, including piece placement, current player, castling rights, en passant target, half-move clock, and move number. This function is typically used in a testing environment to ensure that the board creation logic is functioning as intended. It is important to call this function in a controlled test setup where the program can handle test failures appropriately. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardCreate`](tests.c.driver.md#testBoardCreate) (Implementation) - - ---- -### testBoardCreateFromFen -Tests the creation of a chess board from a FEN string. -- **Description**: This function is used to verify that a chess board can be correctly initialized from a given FEN (Forsyth-Edwards Notation) string. It checks that the board is set up with the correct pieces in their respective positions, the current player to move, castling rights, en passant target square, half-move clock, and full move number. This function is typically used in a testing environment to ensure that the board creation logic is functioning as expected. It is important to call this function in a controlled test environment where the program can be halted if the test fails. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardCreateFromFen`](tests.c.driver.md#testBoardCreateFromFen) (Implementation) - - ---- -### testBoardEq -Fails the test for board equality. -- **Description**: This function is intended to test the equality of two chess boards, but it is currently not implemented. When called, it will immediately fail the test and halt the program with a message indicating that the functionality is not yet implemented. This function is a placeholder and should be completed to perform actual board equality testing in the future. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardEq`](tests.c.driver.md#testBoardEq) (Implementation) - - ---- -### testPawnMoves -Tests the move generation for pawns in various board scenarios. -- **Description**: This function is used to verify the correctness of pawn move generation in a chess game implementation. It sets up different board positions using the Forsyth-Edwards Notation (FEN) and checks the generated moves for pawns in various scenarios, including starting positions, capturing moves, blocked paths, promotion opportunities, and en passant captures. This function is intended for use in a testing environment to ensure that pawn moves are generated accurately according to chess rules. It must be called in a context where the board and move list management functions are available and properly initialized. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testPawnMoves`](tests.c.driver.md#testPawnMoves) (Implementation) - - ---- -### testKnightMoves -Tests the generation of legal knight moves on a chessboard. -- **Description**: This function is used to verify the correctness of knight move generation in a chess implementation. It sets up various board positions with knights and checks if the generated moves match the expected legal moves for those positions. This function is typically used in a testing environment to ensure that the knight move generation logic is functioning correctly. It assumes that the board and move list management functions are working as expected and does not handle any errors or invalid inputs explicitly. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testKnightMoves`](tests.c.driver.md#testKnightMoves) (Implementation) - - ---- -### testBishopMoves -Tests the move generation for bishops on a chessboard. -- **Description**: This function is used to verify the correctness of bishop move generation in a chess implementation. It sets up specific board positions and checks that the generated list of possible moves for a bishop matches the expected moves. This function is typically used during development to ensure that the bishop's movement logic is correctly implemented and handles various board scenarios, including open boards and boards with blocking pieces. It is intended to be part of a suite of tests and should be run in an environment where the chessboard and move generation functions are properly initialized and available. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBishopMoves`](tests.c.driver.md#testBishopMoves) (Implementation) - - ---- -### testRookMoves -Tests the move generation for rooks on a chessboard. -- **Description**: This function is used to verify the correctness of rook move generation in a chess implementation. It sets up specific board positions and checks that the generated moves for a rook match the expected legal moves. This function is typically used in a testing context to ensure that the move generation logic for rooks is functioning correctly. It assumes that the board and move generation functions are correctly implemented and available. The function does not return any value but will halt the program if a test fails, indicating an error in the move generation logic. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testRookMoves`](tests.c.driver.md#testRookMoves) (Implementation) - - ---- -### testQueenMoves -Tests the move generation for a queen on a chessboard. -- **Description**: This function is used to verify the correctness of move generation for a queen piece on a chessboard. It sets up specific board positions and checks that the generated list of possible moves for a queen matches the expected moves. This function is typically used in a testing environment to ensure that the move generation logic for queens is functioning correctly. It assumes that the board and move list structures are properly initialized and that the move generation functions are correctly implemented. The function does not return any value but will halt the program if a test fails. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testQueenMoves`](tests.c.driver.md#testQueenMoves) (Implementation) - - ---- -### testKingMoves -Tests the generation of king moves on a chess board. -- **Description**: This function is used to verify the correctness of king move generation in a chess game implementation. It sets up various board positions and checks if the generated moves for the king are as expected. The function does not consider whether the king moves into check, as it focuses solely on the potential moves a king can make from a given position. This function is useful for ensuring that the move generation logic for the king is functioning correctly, especially in edge cases such as when the king is in a corner or surrounded by other pieces. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testKingMoves`](tests.c.driver.md#testKingMoves) (Implementation) - - ---- -### testIsSquareAttacked -Tests if squares are correctly identified as attacked in various board scenarios. -- **Description**: This function is used to verify the correctness of the square attack detection logic in a chess board implementation. It sets up different board configurations using the Forsyth-Edwards Notation (FEN) and checks if the function responsible for determining if a square is attacked returns the expected results. This function is typically used during the development and testing phase to ensure that the attack detection logic is functioning as intended. It is important to call this function in a controlled test environment as it will halt the program if any test fails. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testIsSquareAttacked`](tests.c.driver.md#testIsSquareAttacked) (Implementation) - - ---- -### testIsInCheck -Tests if a chess board is in check under various scenarios. -- **Description**: This function is used to verify the correctness of check detection logic in a chess board implementation. It sets up different board positions using the FEN notation and checks whether the board is correctly identified as being in check or not. This function is typically used in a testing environment to ensure that the check detection functions, such as `boardIsInCheck` and `boardIsPlayerInCheck`, behave as expected. It is important to call this function in a controlled test environment where the program can be halted if a test fails, as it uses `failTest` to report errors. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testIsInCheck`](tests.c.driver.md#testIsInCheck) (Implementation) - - ---- -### testBoardPlayMove -Tests the functionality of playing moves on a chess board. -- **Description**: This function is used to verify the correctness of move execution on a chess board within a test suite. It performs a series of predefined chess moves, including standard moves, captures, castling, and en passant, and checks the resulting board state against expected outcomes. This function is intended to be used in a testing environment to ensure that the move execution logic is functioning as expected. It assumes that the board and move functions are correctly implemented and available. The function does not return any value but will halt the program if a test fails, indicating an error in the move execution logic. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardPlayMove`](tests.c.driver.md#testBoardPlayMove) (Implementation) - - ---- -### testBoardGenerateMoves -Tests the move generation functionality of a chess board. -- **Description**: This function is used to verify the correctness of move generation on a chess board in various scenarios, including the initial board setup, boards with some moves played, and special cases like pinned pieces and checks. It is intended for use in a testing environment to ensure that the move generation logic produces the expected results. The function does not take any parameters and does not return a value, as it is designed to validate the internal logic of the chess implementation by asserting expected outcomes. It is crucial to run this function in a controlled test environment where failures can be appropriately handled. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardGenerateMoves`](tests.c.driver.md#testBoardGenerateMoves) (Implementation) - - ---- -### testBoardGenerateMovesCastling -Tests castling move generation on a chess board. -- **Description**: This function is used to verify the correct generation of castling moves in various board states during a chess game. It should be called as part of a test suite to ensure that castling is correctly handled under different conditions, such as when the king or rook has moved, when the king is in check, or when squares between the king and rook are attacked. The function does not take any parameters and does not return a value, as it is intended solely for testing purposes. It assumes that the board and move generation functions are correctly implemented and available. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardGenerateMovesCastling`](tests.c.driver.md#testBoardGenerateMovesCastling) (Implementation) - - ---- -### testBoardGetFen -Tests the FEN string generation functionality of the chess board. -- **Description**: This function is used to verify that the chess board's FEN (Forsyth-Edwards Notation) string generation is functioning correctly. It is intended to be used in a testing environment where the correctness of FEN strings is critical for board state representation. The function does not take any parameters and does not return a value. It is expected to be called in a context where the board state can be validated against known FEN strings, ensuring that the board's FEN output matches expected values for various chess positions. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardGetFen`](tests.c.driver.md#testBoardGetFen) (Implementation) - - ---- -### testBoardIsInsufficientMaterial -Tests the board state for insufficient material draw conditions. -- **Description**: This function is used to verify that a chess board correctly identifies draw conditions due to insufficient material. It should be called during testing to ensure that the board's logic for detecting insufficient material is functioning as expected. The function sets up various board states and checks if they are correctly identified as insufficient material scenarios, which are situations where neither player can checkmate the other with the available pieces. This function is part of a suite of tests and should be used in a controlled testing environment. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardIsInsufficientMaterial`](tests.c.driver.md#testBoardIsInsufficientMaterial) (Implementation) - - ---- -### testBoardList -Tests the functionality of board list operations. -- **Description**: This function is used to verify the correct behavior of board list operations in a chess implementation. It creates a series of chess board states, adds them to a board list, and checks if they can be retrieved correctly. This function is typically used in a testing environment to ensure that the board list operations such as creation, addition, retrieval, and freeing of resources are functioning as expected. It is important to call this function in a controlled test environment as it will halt the program if any test fails. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testBoardList`](tests.c.driver.md#testBoardList) (Implementation) - - ---- -### testSqSetSet -Tests the functionality of setting squares in a square set. -- **Description**: This function is used to verify that the `sqSetSet` function correctly sets specific squares in a square set represented by a 64-bit integer. It is intended for use in a testing environment to ensure that the `sqSetSet` function behaves as expected when setting various squares on a chessboard. The function will halt the program and report an error if any of the test cases fail, indicating that the square setting functionality is not working correctly. This function should be used in a controlled testing environment where the program can be safely halted for debugging purposes. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testSqSetSet`](tests.c.driver.md#testSqSetSet) (Implementation) - - ---- -### testSqSetGet -Tests the functionality of square set operations. -- **Description**: This function is used to verify the correctness of square set operations in a chess implementation. It checks whether specific squares on a chessboard are correctly identified as being part of a set, based on predefined patterns. This function is typically used during the development and testing phase to ensure that the square set operations behave as expected. It is important to call this function in a controlled test environment, as it will halt the program if any discrepancies are found between expected and actual results. -- **Inputs**: - - None -- **Output**: None -- **See also**: [`testSqSetGet`](tests.c.driver.md#testSqSetGet) (Implementation) - -