From f484cfd4fbe1dccf172cd18e9e195a80726e20e1 Mon Sep 17 00:00:00 2001 From: cross-of-north Date: Sat, 13 Apr 2024 13:56:59 +0700 Subject: [PATCH] musketeer xboard castling fixes --- src/position.cpp | 21 ++++++++++++++++----- src/position.h | 2 +- src/uci.cpp | 21 +++++++++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index b285a44fe..fe0ba7b51 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -3379,15 +3379,26 @@ bool Position::pos_is_ok() const { return true; } -PieceType Position::committed_piece_type(Move m) const { +PieceType Position::committed_piece_type(Move m, bool castlingRook) const { PieceType result = NO_PIECE_TYPE; if (commit_gates()) { Square from = from_sq(m); Rank r = rank_of(from); - if(r == RANK_1){ - result = committed_piece_type(WHITE, file_of( from )); - } else if(r == max_rank()){ - result = committed_piece_type(BLACK, file_of(from)); + if (castlingRook){ + if (type_of(m) == CASTLING){ + from = to_sq(m); + } else { + from = SQ_NONE; + } + } + if (from != SQ_NONE){ + if (r == RANK_1){ + result = committed_piece_type(WHITE, file_of(from)); + } else if (r == max_rank()){ + result = committed_piece_type(BLACK, file_of(from)); + } else{ + assert(false); + } } } return result; diff --git a/src/position.h b/src/position.h index be12a6fcb..40bd05cec 100644 --- a/src/position.h +++ b/src/position.h @@ -283,7 +283,7 @@ class Position { bool gives_check(Move m) const; Piece moved_piece(Move m) const; Piece captured_piece() const; - PieceType committed_piece_type(Move m) const; + PieceType committed_piece_type(Move m, bool castlingRook) const; // Piece specific bool pawn_passed(Color c, Square s) const; diff --git a/src/uci.cpp b/src/uci.cpp index ebb6e0e05..e62cc9439 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -577,15 +577,24 @@ Move UCI::to_move(const Position& pos, string& str) { for (const auto& m : MoveList(pos)) { auto move_str = UCI::move(pos, m); - // special processing of optional gating suffix + // special processing of optional gating suffix from xboard // like "b1c3o" => "b1c3" if (CurrentProtocol == XBOARD && str.length() == 5 && move_str.length() == 4) { - if (str[1] == move_str[1] && str[2] == move_str[2] && str[3] == move_str[3]) { - PieceType pt = pos.committed_piece_type(m); + if (memcmp(str.c_str(), move_str.c_str(), 4) == 0){ + PieceType pt = pos.committed_piece_type(m, false); + PieceType ptCastling = pos.committed_piece_type(m, true); if ( - pt != NO_PIECE_TYPE - && - pos.piece_to_char()[make_piece(BLACK, pos.committed_piece_type(m))] == str[4] + ( + pt != NO_PIECE_TYPE + && + pos.piece_to_char()[make_piece(BLACK, pt)] == str[4] + ) + || + ( + ptCastling != NO_PIECE_TYPE + && + pos.piece_to_char()[make_piece(BLACK, ptCastling)] == str[4] + ) ) { return m; }