From 78749a6af2c3c5e559b042107f0143c6a5be77b3 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Thu, 28 Aug 2025 10:29:19 -0400 Subject: [PATCH] dev: Added QS/KS castle checking; simplified moveList pruning --- Piece.cpp | 7 +++---- Piece.hpp | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Piece.cpp b/Piece.cpp index f15180a..251e5e9 100644 --- a/Piece.cpp +++ b/Piece.cpp @@ -126,10 +126,9 @@ std::vector King::getLegalMoves(const Square &from, const Board &board) co // will this actually work? moveList.erase( std::remove_if(moveList.begin(), moveList.end(), - [&](const Square &x) { - return std::find(x.begin(), x.end(), !x.isValid()) != x.end(); - }), - moveList.end()); + [&](const auto &x) { + return !x.to.isValid(); + })); return moveList; } diff --git a/Piece.hpp b/Piece.hpp index 8d407c8..7f24412 100644 --- a/Piece.hpp +++ b/Piece.hpp @@ -11,6 +11,7 @@ #pragma once #include +#include #include #include #include @@ -34,6 +35,10 @@ enum File { A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, INVALID_FILE = 255 }; +enum CastleSide { + KINGSIDE = 1, QUEENSIDE = 2 +}; + struct Square { Rank rank; File file; @@ -101,11 +106,18 @@ class King : public Piece { return inCheck; } - bool checkForCastle() const { - return canCastle; + bool checkForCastle(enum CastleSide side) const { + if(side == KINGSIDE) { + return canCastleKS; + } else if(side == QUEENSIDE) { + return canCastleQS; + } else { + return false; + } } protected: - bool canCastle = true; + bool canCastleQS = true; + bool canCastleKS = true; bool inCheck = false; };