summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-02-19 14:26:58 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-02-19 14:26:58 +0100
commitf60b684790ae7a726763e4c6f9122371c71d17e9 (patch)
tree568ee4b4c7f56ccc33cb82b080e2b99cca1e7efe
parent1e5a34d8d2befa5786adc30e99d85372510f017f (diff)
Debug en passant!
-rw-r--r--src/ChessArbiter.cpp7
-rw-r--r--tests/chessarbiter.cpp16
2 files changed, 23 insertions, 0 deletions
diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp
index 21d0bfa..18e1e1c 100644
--- a/src/ChessArbiter.cpp
+++ b/src/ChessArbiter.cpp
@@ -110,6 +110,13 @@ bool ChessArbiter::Play(std::string move) {
} else if (!fen.player && (dst[1] - src[1] == 2)) {
newFen.en_passant = src[0] + std::string() + (char)(src[1] + 1);
}
+ if (dst == fen.en_passant) {
+ if (fen.player) {
+ board.RemovePiece(dst[0] + std::string() + (char)(dst[1] + 1));
+ } else {
+ board.RemovePiece(dst[0] + std::string() + (char)(dst[1] - 1));
+ }
+ }
newFen.halfmove = 0; // Pawn moves reset half moves
}
// Captures reset half moves
diff --git a/tests/chessarbiter.cpp b/tests/chessarbiter.cpp
index c5206d7..9c1407d 100644
--- a/tests/chessarbiter.cpp
+++ b/tests/chessarbiter.cpp
@@ -397,3 +397,19 @@ TEST_CASE("SimpleCastle", "[SimpleCastle]") {
CHECK(a.GetFEN() ==
"2kr3r/pppnp1pp/1bq1bn2/3p1p2/4P3/1BNB1N2/PPPPQPPP/R3K2R w KQ - 1 3");
}
+
+TEST_CASE("SimpleEnPassant", "[SimpleEnPassant]") {
+ ChessArbiter a;
+
+ // White capture
+ a.Setup("rnbqkbnr/ppppp1pp/8/4Pp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 2");
+ CHECK(a.Play("e5f6"));
+ CHECK(a.GetFEN() ==
+ "rnbqkbnr/ppppp1pp/5P2/8/8/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2");
+
+ // Black capture
+ a.Setup("rnbqkbnr/ppppp1pp/8/8/4Pp2/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1");
+ CHECK(a.Play("f4e3"));
+ CHECK(a.GetFEN() ==
+ "rnbqkbnr/ppppp1pp/8/8/8/4p3/PPPP1PPP/RNBQKBNR w KQkq - 0 2");
+}