Skip to content

Commit

Permalink
musketeer xboard castling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cross-of-north committed Apr 13, 2024
1 parent a7a51b0 commit f484cfd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
21 changes: 16 additions & 5 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 15 additions & 6 deletions src/uci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,24 @@ Move UCI::to_move(const Position& pos, string& str) {
for (const auto& m : MoveList<LEGAL>(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;
}
Expand Down

0 comments on commit f484cfd

Please sign in to comment.