#include "position.h"
#include "psqtab.h"
#include "san.h"
+#include "tt.h"
#include "ucioption.h"
using std::string;
// case of non-reversible moves is taken care of later.
st->rule50++;
+ // Update side to move
+ st->key ^= zobSideToMove;
+
if (move_is_castle(m))
do_castle_move(m);
else if (move_is_promotion(m))
st->capture = type_of_piece_on(to);
if (st->capture)
- do_capture_move(st->capture, them, to);
-
- // Move the piece
- Bitboard move_bb = make_move_bb(from, to);
- do_move_bb(&(byColorBB[us]), move_bb);
- do_move_bb(&(byTypeBB[pt]), move_bb);
- do_move_bb(&(byTypeBB[0]), move_bb); // HACK: byTypeBB[0] == occupied squares
-
- board[to] = board[from];
- board[from] = EMPTY;
+ do_capture_move(st->capture, them, to);
// Update hash key
st->key ^= zobrist[us][pt][from] ^ zobrist[us][pt][to];
- // Update incremental scores
- st->mgValue += pst_delta<MidGame>(piece, from, to);
- st->egValue += pst_delta<EndGame>(piece, from, to);
-
- // If the moving piece was a king, update the king square
- if (pt == KING)
- kingSquare[us] = to;
-
// Reset en passant square
if (st->epSquare != SQ_NONE)
{
st->epSquare = SQ_NONE;
}
+ // Update castle rights, try to shortcut a common case
+ if ((castleRightsMask[from] & castleRightsMask[to]) != ALL_CASTLES)
+ {
+ st->key ^= zobCastle[st->castleRights];
+ st->castleRights &= castleRightsMask[from];
+ st->castleRights &= castleRightsMask[to];
+ st->key ^= zobCastle[st->castleRights];
+ }
+
+ // Prefetch TT access as soon as we know key is updated
+ TT.prefetch(st->key);
+
+ // Move the piece
+ Bitboard move_bb = make_move_bb(from, to);
+ do_move_bb(&(byColorBB[us]), move_bb);
+ do_move_bb(&(byTypeBB[pt]), move_bb);
+ do_move_bb(&(byTypeBB[0]), move_bb); // HACK: byTypeBB[0] == occupied squares
+
+ board[to] = board[from];
+ board[from] = EMPTY;
+
// If the moving piece was a pawn do some special extra work
if (pt == PAWN)
{
}
}
+ // Update incremental scores
+ st->mgValue += pst_delta<MidGame>(piece, from, to);
+ st->egValue += pst_delta<EndGame>(piece, from, to);
+
+ // If the moving piece was a king, update the king square
+ if (pt == KING)
+ kingSquare[us] = to;
+
// Update piece lists
pieceList[us][pt][index[from]] = to;
index[to] = index[from];
- // Update castle rights, try to shortcut a common case
- if ((castleRightsMask[from] & castleRightsMask[to]) != ALL_CASTLES)
- {
- st->key ^= zobCastle[st->castleRights];
- st->castleRights &= castleRightsMask[from];
- st->castleRights &= castleRightsMask[to];
- st->key ^= zobCastle[st->castleRights];
- }
-
// Update checkers bitboard, piece must be already moved
st->checkersBB = EmptyBoardBB;
Square ksq = king_square(them);
}
// Finish
- st->key ^= zobSideToMove;
sideToMove = opposite_color(sideToMove);
gamePly++;
history[gamePly] = st->key;
// Update the necessary information
- sideToMove = opposite_color(sideToMove);
if (st->epSquare != SQ_NONE)
st->key ^= zobEp[st->epSquare];
+ st->key ^= zobSideToMove;
+ TT.prefetch(st->key);
+ sideToMove = opposite_color(sideToMove);
st->epSquare = SQ_NONE;
st->rule50++;
gamePly++;
- st->key ^= zobSideToMove;
st->mgValue += (sideToMove == WHITE)? TempoValueMidgame : -TempoValueMidgame;
st->egValue += (sideToMove == WHITE)? TempoValueEndgame : -TempoValueEndgame;