summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-26 22:01:22 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-26 22:01:22 +0100
commit3ba7bd82d255c555aec3882f897be471fdb69a8d (patch)
treea76cae0e8b8c1c40c4f66a8a5bbb580a98ee7fcc /src
parentdd4574691a862548a7b7341a529bded347718068 (diff)
Support for promotiongit add -A
Diffstat (limited to 'src')
-rw-r--r--src/ChessArbiter.cpp28
-rw-r--r--src/ChessArbiter.hpp3
2 files changed, 29 insertions, 2 deletions
diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp
index d64ac83..96c7d49 100644
--- a/src/ChessArbiter.cpp
+++ b/src/ChessArbiter.cpp
@@ -39,7 +39,7 @@ bool ChessArbiter::IsCheck(bool isBlack) {
return (IsAttacked(kingloc, !isBlack));
}
-bool ChessArbiter::Play(std::string move) {
+bool ChessArbiter::Play(std::string move, char promote) {
std::vector<std::string> moves = ListLegalMoves(fen.player);
if (find(moves.begin(), moves.end(), move) != moves.end()) {
Piece moved = board.GetPieceAt(move.substr(0, 2)); // This call never fail
@@ -125,6 +125,18 @@ bool ChessArbiter::Play(std::string move) {
}
newFen.halfmove = 0; // Pawn moves reset half moves
}
+ // Check pawn promotion
+ if(moved.piece == 'p' || moved.piece == 'P'){
+ if(moved.piece == 'p' && dst[1]=='1'){
+ board.RemovePiece(dst);
+ board.AddPiece(tolower(promote),dst);
+ SAN+="="+promote;
+ } else if(dst[1]=='8'){
+ board.RemovePiece(dst);
+ board.AddPiece(toupper(promote),dst);
+ SAN+="="+toupper(promote);
+ }
+ }
// Captures reset half moves
if (IsCapture) {
newFen.halfmove = 0;
@@ -518,4 +530,18 @@ std::string ChessArbiter::ParseSAN(std::string SANMove) {
return (src + dst);
}
+char ChessArbiter::ParseSANPromotion(std::string SANMove){
+ for(short i=0;i<SANMove.length();i++){
+ if(SANMove[i]=='='){
+ if((i+1)<SANMove.length()){
+ char p=SANMove[i+1]; // Must be upper
+ if(p=='Q' || p=='R' || p=='B' || p=='N'){
+ return SANMove[i+1];
+ }
+ }
+ }
+ }
+ return 'Q';
+}
+
} // namespace chessarbiter \ No newline at end of file
diff --git a/src/ChessArbiter.hpp b/src/ChessArbiter.hpp
index 19a4ba1..d63ab06 100644
--- a/src/ChessArbiter.hpp
+++ b/src/ChessArbiter.hpp
@@ -44,7 +44,7 @@ public:
/// @brief Check if a side is in check
bool IsCheck(bool);
/// @brief Play a move (return false if it's illegal)
- bool Play(std::string);
+ bool Play(std::string, char promote='Q');
/// @brief Check if a square is attacked by a particular player
bool IsAttacked(std::string, bool);
/// @brief Get the serialized board
@@ -70,5 +70,6 @@ public:
bool IsDraw();
bool WasEnPassant();
std::string ParseSAN(std::string SANMove);
+ char ParseSANPromotion(std::string SANMove);
};
} // namespace chessarbiter