Skip to content

Commit

Permalink
Merge pull request #818 from acxz:rbc-pawn-promote
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 446930688
Change-Id: I8e92acc1684e44e4ff7d0d269601bf99fe36145f
  • Loading branch information
lanctot committed May 9, 2022
2 parents eeb3790 + 9fdb46e commit b938000
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 b938000

Please sign in to comment.