summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-10 16:18:23 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-10 16:18:23 +0100
commit6f48becb9186a399e3a4dddb778570e7057752c7 (patch)
tree64d8e53f3c1823ab496de1cfe532429a50842216
parent9e8b8d630cdf7dfafdd0a37bb095b4e4afe10478 (diff)
Improve pawn promotion API
-rw-r--r--src/ChessArbiter.cpp7
-rw-r--r--src/ChessArbiter.hpp3
-rw-r--r--tests/chessarbiter.cpp3
3 files changed, 11 insertions, 2 deletions
diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp
index dece4b9..2830bc1 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(' '), was_enpassant(false) {
+ capture(' '), was_enpassant(false), was_pawn_promotion(false) {
Setup("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
}
@@ -51,6 +51,7 @@ bool ChessArbiter::Play(const std::string &move, char promote) {
SAN = "";
capture = ' ';
was_enpassant=false;
+ was_pawn_promotion=false;
if (IsCapture) {
capture = board.GetPieceAt(dst).piece;
@@ -131,10 +132,12 @@ bool ChessArbiter::Play(const std::string &move, char promote) {
board.RemovePiece(dst);
board.AddPiece(tolower(promote),dst);
SAN+="="+toupper(promote);
+ was_pawn_promotion=true;
} else if(dst[1]=='8'){
board.RemovePiece(dst);
board.AddPiece(toupper(promote),dst);
SAN+="="+toupper(promote);
+ was_pawn_promotion=true;
}
}
// Captures reset half moves
@@ -189,6 +192,8 @@ bool ChessArbiter::Play(const std::string &move, char promote) {
bool ChessArbiter::WasEnPassant() { return (was_enpassant); }
+bool ChessArbiter::WasPawnPromotion() { return (was_pawn_promotion); };
+
bool ChessArbiter::IsAttacked(const 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 c29dd32..aec0342 100644
--- a/src/ChessArbiter.hpp
+++ b/src/ChessArbiter.hpp
@@ -33,7 +33,7 @@ class ChessArbiter {
void SetFEN(const FEN &fen);
std::string SAN, SAN_last;
char capture;
- bool was_enpassant;
+ bool was_enpassant, was_pawn_promotion;
public:
ChessArbiter();
@@ -69,6 +69,7 @@ public:
bool IsDrawByRepetitions();
bool IsDraw();
bool WasEnPassant();
+ bool WasPawnPromotion();
std::string ParseSAN(const std::string &SANMove);
char ParseSANPromotion(const std::string &SANMove);
};
diff --git a/tests/chessarbiter.cpp b/tests/chessarbiter.cpp
index a2b3fc0..3ac95ca 100644
--- a/tests/chessarbiter.cpp
+++ b/tests/chessarbiter.cpp
@@ -478,16 +478,19 @@ TEST_CASE("Specific bugs found on a game", "[BugFixes]") {
a.Setup("1k3r1r/npqbbp2/4p1p1/p2pPnNp/1P3B1P/P1PB4/5PPQ/RN2R1K1 w - - 1 19");
a.Play("e1c1");
CHECK(a.GetFEN() == "1k3r1r/npqbbp2/4p1p1/p2pPnNp/1P3B1P/P1PB4/5PPQ/RNR3K1 b - - 2 19");
+ CHECK(!a.WasPawnPromotion());
// BUG 2 (Promotion)
a.Setup("8/k2P4/2p1ppp1/5qBp/5P1P/8/6PK/8 w - - 0 45");
a.Play("d7d8");
CHECK(a.GetFEN() == "3Q4/k7/2p1ppp1/5qBp/5P1P/8/6PK/8 b - - 0 45");
+ CHECK(a.WasPawnPromotion());
// BUG 3 (Promotion)
a.Setup("8/k2P4/2p1ppp1/5qBp/5P1P/8/6PK/8 w - - 0 45");
a.Play("d7d8",'n');
CHECK(a.GetFEN() == "3N4/k7/2p1ppp1/5qBp/5P1P/8/6PK/8 b - - 0 45");
+ CHECK(a.WasPawnPromotion());
// BUG 4 (Promotion)
char p=a.ParseSANPromotion("d8=Q");