Skip to content

Commit

Permalink
promote pawn to queen if pawn can promote
Browse files Browse the repository at this point in the history
stay consistant with APL's rbc
  • Loading branch information
acxz committed Apr 21, 2022
1 parent 0c265fb commit 310ae4c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion open_spiel/games/rbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,25 @@ 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;
chess::Move one_forward_move = move;
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().IsPawnPromotionRank(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;
Expand Down

0 comments on commit 310ae4c

Please sign in to comment.