docs: Starting to add Doxygen comments

This commit is contained in:
A.M. Rowsell 2025-09-07 17:57:15 -04:00
commit 8e381cf109
Signed by untrusted user who does not match committer: amr
GPG key ID: E0879EDBDB0CA7B1
2 changed files with 75 additions and 5 deletions

View file

@ -88,6 +88,22 @@ void Board::setupInitialPosition() {
}
return;
}
/**
* Sets entire board to nullptr
*/
void Board::clearBoard() {
for(int i = 0; i < 8; i++) {
for(int j = 0; j < 8; j++) {
boardGrid[i][j] = nullptr;
}
}
}
/**
* Takes a FEN string and creates a board to that spec
* @param strFEN A full FEN string
* @return Returns -1 on failure, 0 on success
*/
int Board::setupFromFEN(std::string strFEN) {
std::vector<std::string> splitFEN = split(strFEN, ' ');
@ -269,6 +285,18 @@ int Board::setupFromFEN(std::string strFEN) {
return 0;
}
void Board::nextTurn() {
playerTurn = (playerTurn == PL_WHITE) ? PL_BLACK : PL_WHITE; // switch to other player's turn
// do initial checks -- is their king in check? do they have any legal moves?
// stalemate check - do we really need to call getLegalMoves() on every single Piece?
}
/**
* This function should only be called after you have confirmed the move is legal!
* This will execute the move and assume you've already checked it.
* @param from The Square on which the Piece is departing
* @param to The Square to which the Piece is moving to
*/
void Board::movePiece(Square from, Square to) {
return;
}

View file

@ -9,6 +9,19 @@
#ifndef PIECE_HPP
#define PIECE_HPP
/** @file Piece.hpp
* @brief The header files for the Piece class.
*
* This file contains not only the definition of the Piece class itself, but also all
* of the derived classes (King, Queen, Rook, etc.) I was considering having them be in
* separate files, but each derived class does not contain that much code, so keeping them
* all in one place seemed easier to deal with. This may change in the future!
*
* Also defined here are important enums that help abstract chess terms, for example the
* PieceType, PieceColour, Rank, File, etc. These allow the code to be more readable and
* it helps make it obvious what certain bits of code are doing.
*/
#include <cstdint>
#include <algorithm>
#include <utility>
@ -38,28 +51,44 @@ enum CastleSide {
KINGSIDE = 1, QUEENSIDE = 2
};
/** @struct Square
* A struct that represents a square on the chess board.
*/
struct Square {
Rank rank;
File file;
Rank rank; /**< enum Rank rank represents the rank of the Square */
File file; /**< enum File file represents the file of the Square */
/**
* A function to test if the square is a valid square on the chessboard
* @return True if the square is within the chessboard, False otherwise
*/
bool isValid() const {
return rank >= 0 && rank < 8 && file >= 0 && file < 8;
}
};
/**
* A struct representing the start and end squares of a Move.
*/
struct Move {
Square from;
Square to;
};
/**
* @class Piece Piece.hpp "inc/Piece.hpp"
* @brief A class abstracting chess pieces
*
* This is a polymorphic base class containing the basic properties all chess pieces have.
* It is intended to be extended by a child class for each piece Type, i.e. King, Queen, etc.
*/
class Piece {
private:
friend class Board;
protected:
PieceColour colour;
PieceType pieceType;
std::string pieceName;
char pieceSymbol;
std::string pieceName; /**< std::string pieceName is a string showing the full name of the piece, i.e. "PAWN" */
std::string pieceSymbol; /**< std::string pieceSymbol is a single character, using the standard algebraic chess notation, ie N for Knight */
bool hasMoved = false;
public:
@ -88,6 +117,19 @@ class Piece {
bool checkIfMoved() const {
return hasMoved;
}
/**
* A virtual const function that should get all legal moves for a piece, but it may
* include some moves that need to be pruned, like those exposing the king to check.
* Still working out how to handle this.
*
* @param from the Square the Piece is currently on
* @param board A reference to the Board we are analyzing
* @return std::vector of Move: a list of all potentially legal moves
*/
virtual std::vector<Move> getLegalMoves(const Square &from, Board &board) const;
bool finalMoveChecks(std::vector<Move> *moveList, Board &board);
};
class King : public Piece {