diff --git a/src/position.cpp b/src/position.cpp index d9d57c0b3..fa732836c 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -966,13 +966,22 @@ void Position::do_move(Move m, // Move the piece. The tricky Chess960 castling is handled earlier if (m.type_of() != CASTLING) { + Piece toPc = pc; + if (m.type_of() == PROMOTION) + toPc = make_piece(us, m.promotion_type()); + if (captured && m.type_of() != EN_PASSANT) { remove_piece(from, &dts); - swap_piece(to, pc, &dts); + swap_piece(to, toPc, &dts); } - else + else if (pc == toPc) move_piece(from, to, &dts); + else + { + remove_piece(from, &dts); + put_piece(toPc, to, &dts); + } } // If the moving piece is a pawn do some special extra work @@ -1011,8 +1020,6 @@ void Position::do_move(Move m, assert(relative_rank(us, to) == RANK_8); assert(type_of(promotion) >= KNIGHT && type_of(promotion) <= QUEEN); - swap_piece(to, promotion, &dts); - dp.add_pc = promotion; dp.add_sq = to; dp.to = SQ_NONE;