summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-03-07 11:30:55 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-03-07 11:30:55 +0100
commit9025383477acf5f9a6360877c502232eaec24e02 (patch)
tree4fbfff916cf43a63d6a3743d373dc802c9e4de3f
parent934b00f7291f4c7c44fc5c713819b04862974603 (diff)
Add WasEnPassant() method for convenience
-rw-r--r--src/ChessArbiter.cpp6
-rw-r--r--src/ChessArbiter.hpp8
-rw-r--r--tests/chessarbiter.cpp4
3 files changed, 15 insertions, 3 deletions
diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp
index 537c1a7..db1830c 100644
--- a/src/ChessArbiter.cpp
+++ b/src/ChessArbiter.cpp
@@ -3,7 +3,7 @@
namespace chessarbiter {
ChessArbiter::ChessArbiter()
: wPawn(1), wRook(5), wKnight(3), wBishop(3), wQueen(9), wKing(0), SAN(""),
- capture(' ') {
+ capture(' '), was_enpassant(false) {
Setup("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
}
@@ -50,6 +50,7 @@ bool ChessArbiter::Play(std::string move) {
INIT_BACKUP();
SAN = "";
capture = ' ';
+ was_enpassant=false;
if (IsCapture) {
capture = board.GetPieceAt(dst).piece;
@@ -120,6 +121,7 @@ bool ChessArbiter::Play(std::string move) {
board.RemovePiece(dst[0] + std::string() + (char)(dst[1] - 1));
capture = 'p';
}
+ was_enpassant=true;
}
newFen.halfmove = 0; // Pawn moves reset half moves
}
@@ -173,6 +175,8 @@ bool ChessArbiter::Play(std::string move) {
return (false);
}
+bool ChessArbiter::WasEnPassant() { return (was_enpassant); }
+
bool ChessArbiter::IsAttacked(std::string square, bool by) {
std::vector<std::string> moves = board.ListPossibleMoves(by);
for (std::string &m : moves) {
diff --git a/src/ChessArbiter.hpp b/src/ChessArbiter.hpp
index e012b4a..19a4ba1 100644
--- a/src/ChessArbiter.hpp
+++ b/src/ChessArbiter.hpp
@@ -10,14 +10,16 @@
if (positions.find(fen.board) != positions.end()) \
positions_backup = positions[fen.board]; \
std::string SAN_backup = SAN; \
- char capture_backup = capture;
+ char capture_backup = capture; \
+ bool was_enpassant_backup = was_enpassant;
#define RESTORE_BACKUP() \
SetFEN(fen_backup); \
if (positions_backup != 0) \
positions[fen.board] = positions_backup; \
SAN = SAN_backup; \
- capture = capture_backup;
+ capture = capture_backup; \
+ was_enpassant = was_enpassant_backup;
namespace chessarbiter {
class ChessArbiter {
@@ -31,6 +33,7 @@ class ChessArbiter {
void SetFEN(FEN);
std::string SAN, SAN_last;
char capture;
+ bool was_enpassant;
public:
ChessArbiter();
@@ -65,6 +68,7 @@ public:
bool IsDrawByNoMoves();
bool IsDrawByRepetitions();
bool IsDraw();
+ bool WasEnPassant();
std::string ParseSAN(std::string SANMove);
};
} // namespace chessarbiter
diff --git a/tests/chessarbiter.cpp b/tests/chessarbiter.cpp
index 0682979..c5f34ea 100644
--- a/tests/chessarbiter.cpp
+++ b/tests/chessarbiter.cpp
@@ -368,6 +368,7 @@ TEST_CASE("SimpleCapture", "[SimplePieceCapture]") {
CHECK(a.GetFEN() ==
"rnbqkbnr/ppp1pppp/8/3P4/8/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2");
CHECK(a.GetCapture() == 'p');
+ CHECK_FALSE(a.WasEnPassant());
}
TEST_CASE("SimpleCastle", "[SimpleCastle]") {
@@ -407,6 +408,7 @@ TEST_CASE("SimpleEnPassant", "[SimpleEnPassant]") {
CHECK(a.GetFEN() ==
"rnbqkbnr/ppppp1pp/5P2/8/8/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2");
CHECK(a.GetCapture() == 'p');
+ CHECK(a.WasEnPassant());
// Black capture
a.Setup("rnbqkbnr/ppppp1pp/8/8/4Pp2/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1");
@@ -414,6 +416,7 @@ TEST_CASE("SimpleEnPassant", "[SimpleEnPassant]") {
CHECK(a.GetFEN() ==
"rnbqkbnr/ppppp1pp/8/8/8/4p3/PPPP1PPP/RNBQKBNR w KQkq - 0 2");
CHECK(a.GetCapture() == 'P');
+ CHECK(a.WasEnPassant());
// Check en_passant is set
a.Setup(
@@ -421,6 +424,7 @@ TEST_CASE("SimpleEnPassant", "[SimpleEnPassant]") {
CHECK(a.Play("f7f5"));
CHECK(a.GetFEN() == "r3k2r/1pqbb2p/1nn1p1p1/p2pPp2/3P1PP1/PP1B4/1B1NN2P/"
"R2Q1RK1 w kq f6 0 15");
+ CHECK_FALSE(a.WasEnPassant());
}
TEST_CASE("ParseSAN", "[ParseSAN]") {