- // Update piece counts
- pieceCount[us][promotion]--;
- pieceCount[us][PAWN]++;
-
- if (st->capture)
- {
- assert(st->capture != KING);
-
- // Insert captured piece:
- set_bit(&(byColorBB[them]), to);
- set_bit(&(byTypeBB[st->capture]), to);
- set_bit(&(byTypeBB[0]), to); // HACK: byTypeBB[0] == occupied squares
- board[to] = piece_of_color_and_type(them, st->capture);
-
- // Update piece list
- pieceList[them][st->capture][pieceCount[them][st->capture]] = to;
- index[to] = pieceCount[them][st->capture];
-
- // Update piece count
- pieceCount[them][st->capture]++;
- } else
- board[to] = EMPTY;
-}
-
-
-/// Position::undo_ep_move() is a private method used to unmake an en passant
-/// capture. It is called from the main Position::undo_move function.
-
-void Position::undo_ep_move(Move m) {
-
- assert(move_is_ok(m));
- assert(move_is_ep(m));
-
- // When we have arrived here, some work has already been done by
- // Position::undo_move. In particular, the side to move has been switched,
- // so the code below is correct.
- Color us = side_to_move();
- Color them = opposite_color(us);
- Square from = move_from(m);
- Square to = move_to(m);
- Square capsq = (us == WHITE)? (to - DELTA_N) : (to - DELTA_S);
-
- assert(to == st->previous->epSquare);
- assert(relative_rank(us, to) == RANK_6);
- assert(piece_on(to) == piece_of_color_and_type(us, PAWN));
- assert(piece_on(from) == EMPTY);
- assert(piece_on(capsq) == EMPTY);
-
- // Restore captured pawn
- set_bit(&(byColorBB[them]), capsq);
- set_bit(&(byTypeBB[PAWN]), capsq);
- set_bit(&(byTypeBB[0]), capsq);
- board[capsq] = piece_of_color_and_type(them, PAWN);
-
- // Move capturing pawn back to source square
- Bitboard move_bb = make_move_bb(to, from);
- do_move_bb(&(byColorBB[us]), move_bb);
- do_move_bb(&(byTypeBB[PAWN]), move_bb);
- do_move_bb(&(byTypeBB[0]), move_bb);
- board[to] = EMPTY;
- board[from] = piece_of_color_and_type(us, PAWN);
-
- // Update piece list
- pieceList[us][PAWN][index[to]] = from;
- index[from] = index[to];
- pieceList[them][PAWN][pieceCount[them][PAWN]] = capsq;
- index[capsq] = pieceCount[them][PAWN];