From b5f647e72a080a9ee7a8a13b0ff11d844aba9e18 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 24 Feb 2022 21:08:21 +0100 Subject: [PATCH] Debug en passant --- src/ChessArbiter.cpp | 2 +- tests/chessarbiter.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp index 400b011..59afaf7 100644 --- a/src/ChessArbiter.cpp +++ b/src/ChessArbiter.cpp @@ -105,7 +105,7 @@ bool ChessArbiter::Play(std::string move) { // Check enpassant newFen.en_passant = "-"; if (moved.piece == 'p' || moved.piece == 'P') { - if (fen.player && (dst[1] - src[1] == 2)) { + if (fen.player && (src[1] - dst[1] == 2)) { newFen.en_passant = src[0] + std::string() + (char)(src[1] - 1); } else if (!fen.player && (dst[1] - src[1] == 2)) { newFen.en_passant = src[0] + std::string() + (char)(src[1] + 1); diff --git a/tests/chessarbiter.cpp b/tests/chessarbiter.cpp index a6a3241..94d4dae 100644 --- a/tests/chessarbiter.cpp +++ b/tests/chessarbiter.cpp @@ -255,10 +255,10 @@ TEST_CASE("Play Basic", "[chessarbiter/Play]") { // Black turn CHECK(a.Play("e7e5")); CHECK(a.GetFEN() == - "rnbqkbnr/pppp1ppp/8/4p3/8/4P3/PPPP1PPP/RNBQKBNR w KQkq - 0 2"); + "rnbqkbnr/pppp1ppp/8/4p3/8/4P3/PPPP1PPP/RNBQKBNR w KQkq e6 0 2"); CHECK_FALSE(a.Play("d7d6")); // White turn CHECK(a.GetFEN() == - "rnbqkbnr/pppp1ppp/8/4p3/8/4P3/PPPP1PPP/RNBQKBNR w KQkq - 0 2"); + "rnbqkbnr/pppp1ppp/8/4p3/8/4P3/PPPP1PPP/RNBQKBNR w KQkq e6 0 2"); // White turn CHECK(a.Play("b1c3")); @@ -412,6 +412,13 @@ TEST_CASE("SimpleEnPassant", "[SimpleEnPassant]") { CHECK(a.Play("f4e3")); CHECK(a.GetFEN() == "rnbqkbnr/ppppp1pp/8/8/8/4p3/PPPP1PPP/RNBQKBNR w KQkq - 0 2"); + + // Check en_passant is set + a.Setup( + "r3k2r/1pqbbp1p/1nn1p1p1/p2pP3/3P1PP1/PP1B4/1B1NN2P/R2Q1RK1 b kq - 2 14"); + CHECK(a.Play("f7f5")); + CHECK(a.GetFEN() == "r3k2r/1pqbb2p/1nn1p1p1/p2pPp2/3P1PP1/PP1B4/1B1NN2P/" + "R2Q1RK1 w kq f6 0 15"); } TEST_CASE("ParseSAN", "[ParseSAN]") {