From 5469576d17ec12e4b739ebacdfa2f89870412707 Mon Sep 17 00:00:00 2001 From: acxz <17132214+acxz@users.noreply.github.com> Date: Thu, 21 Apr 2022 14:03:28 -0400 Subject: [PATCH] promote pawn to queen if pawn can promote stay consistant with APL's rbc --- open_spiel/games/rbc.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/open_spiel/games/rbc.cc b/open_spiel/games/rbc.cc index e670043a54..cee4ba1640 100644 --- a/open_spiel/games/rbc.cc +++ b/open_spiel/games/rbc.cc @@ -382,9 +382,12 @@ void RbcState::DoApplyAction(Action action) { // Illegal move was chosen. illegal_move_attempted_ = true; - // Check why the move was illegal: if it is pawn two-squares-forward move, + // Check why the move was illegal: + // if it is pawn two-squares-forward move, // and there is an enemy piece blocking it, the attempt to move only one // square forward (if that would be a legal move). + // if it is pawn move to last rank, change to pawn move & queen promotion + // (if that would be a legal move) if (move.piece.type == chess::PieceType::kPawn && abs(move.from.y - move.to.y) == 2) { const int dy = move.to.y - move.from.y > 0 ? 1 : -1; @@ -392,6 +395,12 @@ void RbcState::DoApplyAction(Action action) { one_forward_move.to.y -= dy; move = Board().IsMoveLegal(one_forward_move) ? one_forward_move : chess::kPassMove; + } else if (move.piece.type == chess::PieceType::kPawn && + Board().IsPawnPromotion(move.to)) { + chess::Move promote_move = move; + promote_move.promotion_type = chess::PieceType::kQueen; + move = Board().IsMoveLegal(promote_move) ? promote_move + : chess::kPassMove; } else { // Treat the illegal move as a pass. move = chess::kPassMove;