// captured piece, which is taken care of later.
u = undoInfoUnion;
u.capture = NO_PIECE_TYPE;
+ previous = &u;
// Save the current key to the history[] array, in order to be able to
// detect repetition draws.
if (move_is_castle(m))
do_castle_move(m);
else if (move_promotion(m))
- do_promotion_move(m, u);
+ do_promotion_move(m);
else if (move_is_ep(m))
do_ep_move(m);
else
/// UndoInfo object, which has been initialized in Position::do_move, is
/// used to store the captured piece (if any).
-void Position::do_promotion_move(Move m, UndoInfo &u) {
+void Position::do_promotion_move(Move m) {
Color us, them;
Square from, to;
if (capture)
{
- u.capture = capture;
+ previous->capture = capture;
do_capture_move(m, capture, them, to);
}
/// important that Position::undo_move is called with the same move and UndoInfo
/// object as the earlier call to Position::do_move.
-void Position::undo_move(Move m, const UndoInfo &u) {
+void Position::undo_move(Move m) {
assert(is_ok());
assert(move_is_ok(m));
// Restore information from our UndoInfo object (except the captured piece,
// which is taken care of later)
- undoInfoUnion = u;
+ undoInfoUnion = *previous;
if (move_is_castle(m))
undo_castle_move(m);
else if (move_promotion(m))
- undo_promotion_move(m, u);
+ undo_promotion_move(m);
else if (move_is_ep(m))
undo_ep_move(m);
else
{
Color us, them;
Square from, to;
- PieceType piece, capture;
+ PieceType piece;
us = side_to_move();
them = opposite_color(us);
pieceList[us][piece][index[to]] = from;
index[from] = index[to];
- capture = u.capture;
-
if (capture)
{
assert(capture != KING);
/// function. The UndoInfo object, which has been initialized in
/// Position::do_move, is used to put back the captured piece (if any).
-void Position::undo_promotion_move(Move m, const UndoInfo &u) {
+void Position::undo_promotion_move(Move m) {
Color us, them;
Square from, to;
- PieceType capture, promotion;
+ PieceType promotion;
assert(move_is_ok(m));
assert(move_promotion(m));
pieceCount[us][promotion]--;
pieceCount[us][PAWN]++;
- capture = u.capture;
-
if (capture)
{
assert(capture != KING);
assert(!is_check());
// Back up the information necessary to undo the null move to the supplied
- // UndoInfo object. In the case of a null move, the only thing we need to
+ // UndoInfo object. In the case of a null move, the only thing we need to
// remember is the last move made and the en passant square.
u.lastMove = lastMove;
u.epSquare = epSquare;
+ u.previous = previous;
+ previous = &u;
// Save the current key to the history[] array, in order to be able to
// detect repetition draws.
/// Position::undo_null_move() unmakes a "null move".
-void Position::undo_null_move(const UndoInfo &u) {
+void Position::undo_null_move() {
assert(is_ok());
assert(!is_check());
- // Restore information from the supplied UndoInfo object:
- lastMove = u.lastMove;
- epSquare = u.epSquare;
+ // Restore information from the our UndoInfo object
+ lastMove = previous->lastMove;
+ epSquare = previous->epSquare;
+ previous = previous->previous;
+
if (epSquare != SQ_NONE)
key ^= zobEp[epSquare];
- // Update the necessary information.
+ // Update the necessary information
sideToMove = opposite_color(sideToMove);
rule50--;
gamePly--;
epSquare = SQ_NONE;
rule50 = 0;
gamePly = 0;
+ previous = NULL;
}
if (is_mate())
result = true;
- undo_move(mlist[i].move, u2);
+ undo_move(mlist[i].move);
}
// Undo null move, if necessary
if (c != stm)
- undo_null_move(u1);
+ undo_null_move();
return result;
}