Skip to content

Commit

Permalink
Small refactor and docs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jsilll committed Jul 6, 2023
1 parent e120282 commit 67403da
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ ehthumbs.db
Thumbs.db

# Documentation Files
docs/html/
*/docs/html/
2 changes: 1 addition & 1 deletion codbrain/docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB_RECURSE HEADERS ../include/codbrain/*.hpp)

# -- Building Documentation --
doxygen_add_docs(docs_codchess ${HEADERS} COMMENT "Generating Documentation for CodBrain")
doxygen_add_docs(docs_codbrain ${HEADERS} COMMENT "Generating Documentation for CodBrain")
2 changes: 1 addition & 1 deletion codchess/docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB_RECURSE HEADERS ../include/codchess/*.hpp)

# -- Building Documentation --
doxygen_add_docs(docs_codbrain ${HEADERS} COMMENT "Generating Documentation for CodChess")
doxygen_add_docs(docs_codchess ${HEADERS} COMMENT "Generating Documentation for CodChess")
2 changes: 1 addition & 1 deletion codchess/include/codchess/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ enum Color : std::uint8_t {
/// @brief The types of pieces
/// @note This enum is used both for iterating over the piece types and for
/// @note indexing into arrays
enum PieceType : std::uint8_t {
enum Piece : std::uint8_t {
PAWN [[maybe_unused]],
KNIGHT [[maybe_unused]],
BISHOP [[maybe_unused]],
Expand Down
26 changes: 13 additions & 13 deletions codchess/include/codchess/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ namespace cod::chess {
class Board final {
public:
/// @brief A piece on the board
struct Piece {
struct ColoredPiece {
/// @brief The color of the piece
Color color;
/// @brief The type of the piece
PieceType type;
Piece type;

/// @brief Equality operator
/// @param p1 Piece 1
/// @param p2 Piece 2
/// @param p1 ColoredPiece 1
/// @param p2 ColoredPiece 2
/// @return True if the pieces are equal, false otherwise
friend constexpr bool operator==(const Piece &p1,
const Piece &p2) noexcept {
friend constexpr bool operator==(const ColoredPiece &p1,
const ColoredPiece &p2) noexcept {
return p1.color == p2.color and p1.type == p2.type;
}

/// @brief Inequality operator
/// @param p1 Piece 1
/// @param p2 Piece 2
/// @param p1 ColoredPiece 1
/// @param p2 ColoredPiece 2
/// @return True if the pieces are not equal, false otherwise
friend constexpr bool operator!=(const Piece &p1,
const Piece &p2) noexcept {
friend constexpr bool operator!=(const ColoredPiece &p1,
const ColoredPiece &p2) noexcept {
return p1.color != p2.color or p1.type != p2.type;
}
};
Expand Down Expand Up @@ -132,7 +132,7 @@ class Board final {
/// @param color The color
/// @param type The type
[[nodiscard]] constexpr auto pieces(const Color color,
const PieceType type) const noexcept {
const Piece type) const noexcept {
return _pieces[color][type];
}

Expand Down Expand Up @@ -175,7 +175,7 @@ class Board final {
/// @return Whether the current side to move is in check
[[nodiscard]] bool IsCheck() const noexcept {
const auto king_sq =
bitboard::BitScanForward(_pieces[_active][PieceType::KING]);
bitboard::BitScanForward(_pieces[_active][Piece::KING]);
return IsSquareAttacked(king_sq, utils::GetOpponent(_active));
}

Expand Down Expand Up @@ -279,7 +279,7 @@ class Board final {

/// @brief The squares representation of the board
/// @note This should be synced with the bitboards
Piece _piece[N_SQUARES]{};
ColoredPiece _piece[N_SQUARES]{};
/// @brief The occupancy bitboards
/// @note This should be synced with the bitboards
std::uint64_t _occupancies[N_COLORS + 1]{};
Expand Down
6 changes: 3 additions & 3 deletions codchess/include/codchess/move.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ class Move final {
/// @brief Returns the piece
/// @return The piece
[[maybe_unused]] [[nodiscard]] constexpr auto MovedPiece() const noexcept {
return static_cast<PieceType>((_encoded & 0x7000) >> 12);
return static_cast<Piece>((_encoded & 0x7000) >> 12);
}

/// @brief Returns the captured piece
/// @return The captured piece
[[maybe_unused]] [[nodiscard]] constexpr auto
CapturedPiece() const noexcept {
return static_cast<PieceType>((_encoded & 0x38000) >> 15);
return static_cast<Piece>((_encoded & 0x38000) >> 15);
}

/// @brief Returns the promoted piece
/// @return The promoted piece
[[maybe_unused]] [[nodiscard]] constexpr auto
PromotedPiece() const noexcept {
return static_cast<PieceType>((_encoded & 0x1C0000) >> 18);
return static_cast<Piece>((_encoded & 0x1C0000) >> 18);
}

/// @brief Returns if it is a double push
Expand Down
2 changes: 1 addition & 1 deletion codchess/include/codchess/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ GetOpponent(const Color to_move) noexcept {
/// @param color The color
/// @param ascii Whether to use ascii or unicode characters
/// @return The string representation
[[nodiscard]] std::string PieceToString(PieceType piece, Color color,
[[nodiscard]] std::string PieceToString(Piece piece, Color color,
bool ascii = true) noexcept;

/// @brief Returns whether the FEN is valid
Expand Down
4 changes: 2 additions & 2 deletions codchess/src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ PawnDoublePushes(MoveList &move_list, const Board &board) noexcept {
/// leaper moves to.
/// @param board The board to generate leaper moves
/// on.
template <Color ToMove, PieceType PType, GenType GType>
template <Color ToMove, Piece PType, GenType GType>
static void
LeaperMoves(MoveList &move_list, const Board &board) noexcept {
static_assert(ToMove == WHITE or ToMove == BLACK, "Invalid color");
Expand Down Expand Up @@ -350,7 +350,7 @@ LeaperMoves(MoveList &move_list, const Board &board) noexcept {
/// @tparam GType The type of move generation to perform.
/// @param move_list The list of moves to add the slider moves to.
/// @param board The board to generate slider moves on.
template <Color ToMove, PieceType PType, GenType GType>
template <Color ToMove, Piece PType, GenType GType>
static void
SliderMoves(MoveList &move_list, const Board &board) {
static_assert(ToMove == WHITE or ToMove == BLACK, "Invalid color");
Expand Down
4 changes: 2 additions & 2 deletions codchess/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ SquareToString(const Square sq) noexcept {
}

std::string
PieceToString(const PieceType piece, const Color color,
PieceToString(const Piece piece, const Color color,
const bool ascii) noexcept {
/// @brief The representation of the pieces aligned with the PieceType enum
/// @brief The representation of the pieces aligned with the Piece enum
/// @note The first 13 elements are the ascii representation of the pieces
/// and
/// @note the last 13 are the unicode representation
Expand Down
2 changes: 1 addition & 1 deletion codchess/src/zobrist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Hash(const Board &board) noexcept {
for (int piece = PAWN; piece < N_PIECES; ++piece) {
for (int side = WHITE; side < BOTH; ++side) {
auto bitboard = board.pieces(static_cast<Color>(side),
static_cast<PieceType>(piece));
static_cast<Piece>(piece));
while (bitboard) {
const auto sq = bitboard::BitScanForward(bitboard);
final_key ^= PIECE_KEY[side][piece][sq];
Expand Down
Loading

0 comments on commit 67403da

Please sign in to comment.