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..18746ad --- /dev/null +++ b/driver_docs/c_cpp_export_test/README.md @@ -0,0 +1,14 @@ + + + + + +C and C++ chess game implementation with build instructions and MIT licensing. + + +## 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/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/boardlist.c.driver.md b/driver_docs/src/chesslib/boardlist.c.driver.md deleted file mode 100644 index 5649425..0000000 --- a/driver_docs/src/chesslib/boardlist.c.driver.md +++ /dev/null @@ -1,106 +0,0 @@ -# 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. - -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. -# Imports and Dependencies - ---- -- `stdlib.h` -- `chesslib/boardlist.h` - - -# Functions - ---- -### boardListCreate -The `boardListCreate` function initializes and returns a new, empty `boardList` structure. -- **Inputs**: - - None -- **Control Flow**: - - Allocate memory for a new `boardList` structure. - - 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. - - Return the pointer to the newly created `boardList`. -- **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`. -- **Inputs**: - - `b`: A pointer to a `board` structure that the new `boardListNode` 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. - - ---- -### 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. -- **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. -- **Functions called**: - - [`boardListNodeCreate`](#boardListNodeCreate) - - ---- -### 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. - - `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. - - ---- -### boardListUndo -The `boardListUndo` function removes the last node from a singly linked list of boards, freeing its memory and updating the list's tail and size. -- **Inputs**: - - `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 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. - - ---- -### boardListFree -The `boardListFree` function deallocates all memory associated with a `boardList` and its nodes. -- **Inputs**: - - `list`: A pointer to a `boardList` structure that needs 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 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. - - diff --git a/driver_docs/src/chesslib/chess.c.driver.md b/driver_docs/src/chesslib/chess.c.driver.md deleted file mode 100644 index 13e6810..0000000 --- a/driver_docs/src/chesslib/chess.c.driver.md +++ /dev/null @@ -1,449 +0,0 @@ -# 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. - -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. -# Imports and Dependencies - ---- -- `stdlib.h` -- `chesslib/chess.h` -- `chesslib/move.h` - - -# Functions - ---- -### chessCreate -The `chessCreate` function initializes a new chess game using the standard initial position in FEN notation. -- **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. -- **Functions called**: - - [`chessCreateFen`](#chessCreateFen) - - ---- -### 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). -- **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. -- **Functions called**: - - [`chessInitFenInPlace`](#chessInitFenInPlace) - - ---- -### chessInitInPlace -The `chessInitInPlace` function initializes a given chess game structure to the starting position using the standard initial FEN string. -- **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. -- **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. -- **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. - - Return 0 to indicate successful initialization. -- **Output**: - - Returns 0 on successful initialization, or 1 if the board creation from the FEN string fails. -- **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) - - [`chessCalculateFields`](#chessCalculateFields) - - ---- -### 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. -- **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 `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. -- **Functions called**: - - [`boardListFree`](boardlist.c.driver.md#boardListFree) - - [`moveListFree`](movelist.c.driver.md#moveListFree) - - ---- -### chessGetBoard -The function `chessGetBoard` 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. - - ---- -### chessGetLegalMoves -The function `chessGetLegalMoves` retrieves the list of currently legal moves for a given chess game state. -- **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. - - ---- -### chessGetTerminalState -The function `chessGetTerminalState` retrieves the current terminal state of a chess game. -- **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. - - ---- -### chessGetBoardHistory -The function `chessGetBoardHistory` retrieves the history of board states from a chess game instance. -- **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`. - - 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. - - ---- -### 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. -- **Control Flow**: - - The function directly 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. - - ---- -### chessGetRepetitions -The function `chessGetRepetitions` retrieves the number of times the current board position has been repeated in the game. -- **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`. - - 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. - - ---- -### 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. -- **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. - - 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. - - 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. - - 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. -- **Functions called**: - - [`moveEq`](move.c.driver.md#moveEq) - - [`boardPlayMove`](board.c.driver.md#boardPlayMove) - - [`chessGetBoard`](#chessGetBoard) - - [`boardListAdd`](boardlist.c.driver.md#boardListAdd) - - [`moveListAdd`](movelist.c.driver.md#moveListAdd) - - [`chessCalculateFields`](#chessCalculateFields) - - ---- -### chessUndo -The `chessUndo` function reverts the last move in a chess game, updating the game state accordingly. -- **Inputs**: - - `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. - - 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). -- **Functions called**: - - [`boardListUndo`](boardlist.c.driver.md#boardListUndo) - - [`moveListUndo`](movelist.c.driver.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. -- **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. - - 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. -- **Functions called**: - - [`boardGetPiece`](board.c.driver.md#boardGetPiece) - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessGetPlayer -The function `chessGetPlayer` retrieves the current player's color from a chess game state. -- **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 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). -- **Functions called**: - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessGetCastleState -The function `chessGetCastleState` retrieves the current castling rights state from a chess game structure. -- **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 structure `c` to obtain the current board state. - - 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. -- **Functions called**: - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessGetEpTarget -The function `chessGetEpTarget` retrieves the en passant target square from the current board state of a chess game. -- **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. -- **Functions called**: - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessGetHalfMoveClock -The function `chessGetHalfMoveClock` retrieves the half-move clock value from the current board state of a chess game. -- **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 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. -- **Functions called**: - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessGetMoveNumber -The function `chessGetMoveNumber` retrieves the current move number from a chess game state. -- **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. -- **Functions called**: - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessGetMoveHistoryUci -The function `chessGetMoveHistoryUci` retrieves the move history of a chess game in UCI (Universal Chess Interface) format. -- **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. -- **Functions called**: - - [`moveListGetUciString`](movelist.c.driver.md#moveListGetUciString) - - [`chessGetMoveHistory`](#chessGetMoveHistory) - - ---- -### chessIsInCheck -The `chessIsInCheck` function checks if the current player's king is in check on the chess board. -- **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). -- **Functions called**: - - [`boardIsInCheck`](board.c.driver.md#boardIsInCheck) - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessIsSquareAttacked -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. -- **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). -- **Functions called**: - - [`chessGetBoard`](#chessGetBoard) - - [`boardIsSquareAttacked`](board.c.driver.md#boardIsSquareAttacked) - - ---- -### chessGetFen -The `chessGetFen` function 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. -- **Functions called**: - - [`boardGetFen`](board.c.driver.md#boardGetFen) - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessCanClaimDraw50 -The function `chessCanClaimDraw50` checks if a chess game can claim a draw based on the 50-move rule. -- **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. -- **Functions called**: - - [`chessGetBoard`](#chessGetBoard) - - ---- -### chessCanClaimDrawThreefold -The function `chessCanClaimDrawThreefold` checks if a chess game can claim a draw due to the threefold repetition rule. -- **Inputs**: - - `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). - - ---- -### chessClaimDraw50 -The function `chessClaimDraw50` sets the terminal state of a chess game to a draw due to the 50-move rule if the conditions for claiming such a draw are met. -- **Inputs**: - - `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 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. -- **Functions called**: - - [`chessCanClaimDraw50`](#chessCanClaimDraw50) - - ---- -### chessClaimDrawThreefold -The function `chessClaimDrawThreefold` sets the terminal state of a chess game to a draw due to threefold repetition if the conditions are met. -- **Inputs**: - - `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. -- **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. -- **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`. - - Initialize the repetition count to zero. - - Iterate over the board history to count how many times the current board state has occurred. - - 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`. - - 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`. -- **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) - - 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/movelist.c.driver.md b/driver_docs/src/chesslib/movelist.c.driver.md deleted file mode 100644 index f428e79..0000000 --- a/driver_docs/src/chesslib/movelist.c.driver.md +++ /dev/null @@ -1,125 +0,0 @@ -# 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. - -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. -# Imports and Dependencies - ---- -- `stdlib.h` -- `string.h` -- `chesslib/movelist.h` - - -# Functions - ---- -### moveListCreate -The `moveListCreate` function allocates and initializes a new `moveList` structure with default values. -- **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. - - Return the pointer to the newly created `moveList` structure. -- **Output**: - - A pointer to a newly allocated and initialized `moveList` structure. - - ---- -### moveListNodeCreate -The function `moveListNodeCreate` allocates memory for a new `moveListNode`, initializes it with a given move, and sets its next pointer to NULL. -- **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`. - - 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. - - 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. - - ---- -### moveListAdd -The `moveListAdd` function appends a new move to the end of a move list, updating the list's head, tail, and size accordingly. -- **Inputs**: - - `list`: A pointer to a `moveList` structure where the new move will be added. - - `move`: A `move` structure representing the move to be added to the list. -- **Control Flow**: - - 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. - - 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. -- **Functions called**: - - [`moveListNodeCreate`](#moveListNodeCreate) - - ---- -### moveListGet -The `moveListGet` function retrieves a move from a linked list of moves at a specified index. -- **Inputs**: - - `list`: A pointer to a `moveList` structure, which is a linked list of moves. - - `index`: An unsigned integer representing the position in the list from which to retrieve the move. -- **Control Flow**: - - 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`. - - ---- -### moveListUndo -The `moveListUndo` function removes the last move from a singly linked list of moves, updating the list's head, tail, and size accordingly. -- **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. - - ---- -### moveListGetUciString -The function `moveListGetUciString` generates a UCI (Universal Chess Interface) formatted string from a list of chess moves. -- **Inputs**: - - `list`: A pointer to a `moveList` structure, which contains a linked list of chess moves. -- **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. - - 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. -- **Functions called**: - - [`moveGetUci`](move.c.driver.md#moveGetUci) - - ---- -### moveListFree -The `moveListFree` function deallocates all memory associated with a `moveList` and its nodes. -- **Inputs**: - - `list`: A pointer to a `moveList` structure that needs 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 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. - - diff --git a/driver_docs/src/chesslib/piece.c.driver.md b/driver_docs/src/chesslib/piece.c.driver.md deleted file mode 100644 index 9bcb709..0000000 --- a/driver_docs/src/chesslib/piece.c.driver.md +++ /dev/null @@ -1,92 +0,0 @@ -# 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. -# Imports and Dependencies - ---- -- `ctype.h` -- `chesslib/piece.h` - - -# Functions - ---- -### pieceGetType -The function `pieceGetType` determines the type of a chess piece from its encoded value. -- **Inputs**: - - `p`: An encoded value representing a chess piece, which includes both type and color information. -- **Control Flow**: - - 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.). - - ---- -### 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. -- **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`. - - ---- -### 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. -- **Control Flow**: - - The function uses a switch statement to determine the character representation based on the `pieceType` value `pe`. - - If `pe` is `ptPawn`, it returns 'P'. - - If `pe` is `ptKnight`, it returns 'N'. - - If `pe` is `ptBishop`, it returns 'B'. - - If `pe` is `ptRook`, it returns 'R'. - - 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. - - ---- -### 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. -- **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. - - 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. -- **Functions called**: - - [`pieceTypeGetLetter`](#pieceTypeGetLetter) - - [`pieceGetType`](#pieceGetType) - - [`pieceGetColor`](#pieceGetColor) - - ---- -### 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. -- **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. -- **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. - - 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) - -