1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Propagate "move is check" info to do_move()

When false (common case) we avoid to update checkers
bitboard that although not so costly slows down a bit
this very hot and critical path.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-11-10 11:05:20 +01:00
parent f7f09b91ea
commit dd5a3ae4a6
3 changed files with 32 additions and 26 deletions

View file

@ -689,7 +689,7 @@ void Position::do_move(Move m, StateInfo& newSt) {
do_move(m, newSt, discovered_check_candidates(side_to_move()));
}
void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates, bool moveCanBeCheck) {
assert(is_ok());
assert(move_is_ok(m));
@ -858,21 +858,25 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
st->key = key;
// Update checkers bitboard, piece must be already moved
if (ep | pm)
st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us);
else
st->checkersBB = EmptyBoardBB;
if (moveCanBeCheck)
{
st->checkersBB = EmptyBoardBB;
Square ksq = king_square(them);
switch (pt)
if (ep | pm)
st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us);
else
{
case PAWN: update_checkers<PAWN>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case KNIGHT: update_checkers<KNIGHT>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case BISHOP: update_checkers<BISHOP>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case ROOK: update_checkers<ROOK>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case QUEEN: update_checkers<QUEEN>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case KING: update_checkers<KING>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
default: assert(false); break;
Square ksq = king_square(them);
switch (pt)
{
case PAWN: update_checkers<PAWN>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case KNIGHT: update_checkers<KNIGHT>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case BISHOP: update_checkers<BISHOP>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case ROOK: update_checkers<ROOK>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case QUEEN: update_checkers<QUEEN>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
case KING: update_checkers<KING>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
default: assert(false); break;
}
}
}

View file

@ -236,7 +236,7 @@ public:
// Doing and undoing moves
void saveState();
void do_move(Move m, StateInfo& st);
void do_move(Move m, StateInfo& st, Bitboard dcCandidates);
void do_move(Move m, StateInfo& st, Bitboard dcCandidates, bool moveCanBeCheck = true);
void undo_move(Move m);
void do_null_move(StateInfo& st);
void undo_null_move();

View file

@ -334,7 +334,6 @@ int perft(Position& pos, Depth depth)
{
Move move;
MovePicker mp = MovePicker(pos, MOVE_NONE, depth, H);
Bitboard dcCandidates = pos.discovered_check_candidates(pos.side_to_move());
int sum = 0;
// If we are at the last ply we don't need to do and undo
@ -346,10 +345,11 @@ int perft(Position& pos, Depth depth)
}
// Loop through all legal moves
CheckInfo ci(pos);
while ((move = mp.get_next_move()) != MOVE_NONE)
{
StateInfo st;
pos.do_move(move, st, dcCandidates);
pos.do_move(move, st, ci.dcCandidates, pos.move_is_check(move, ci));
sum += perft(pos, depth - OnePly);
pos.undo_move(move);
}
@ -862,7 +862,7 @@ namespace {
Value oldAlpha = alpha;
Value value;
Bitboard dcCandidates = pos.discovered_check_candidates(pos.side_to_move());
CheckInfo ci(pos);
// Loop through all the moves in the root move list
for (int i = 0; i < rml.move_count() && !AbortSearch; i++)
@ -904,7 +904,7 @@ namespace {
newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
// Make the move, and search it
pos.do_move(move, st, dcCandidates);
pos.do_move(move, st, ci.dcCandidates);
if (i < MultiPV)
{
@ -1135,7 +1135,7 @@ namespace {
newDepth = depth - OnePly + ext;
// Make and search the move
pos.do_move(move, st, ci.dcCandidates);
pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
if (moveCount == 1) // The first move in list is the PV
value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID);
@ -1423,7 +1423,7 @@ namespace {
}
// Make and search the move
pos.do_move(move, st, ci.dcCandidates);
pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
@ -1520,7 +1520,7 @@ namespace {
StateInfo st;
Move ttMove, move;
Value staticValue, bestValue, value, futilityValue;
bool isCheck, enoughMaterial;
bool isCheck, enoughMaterial, moveIsCheck;
const TTEntry* tte = NULL;
int moveCount = 0;
bool pvNode = (beta - alpha != 1);
@ -1602,12 +1602,14 @@ namespace {
moveCount++;
ss[ply].currentMove = move;
moveIsCheck = pos.move_is_check(move, ci);
// Futility pruning
if ( enoughMaterial
&& !isCheck
&& !pvNode
&& !moveIsCheck
&& !move_is_promotion(move)
&& !pos.move_is_check(move, ci)
&& !pos.move_is_passed_pawn_push(move))
{
futilityValue = staticValue
@ -1633,7 +1635,7 @@ namespace {
continue;
// Make and search the move
pos.do_move(move, st, ci.dcCandidates);
pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID);
pos.undo_move(move);
@ -1760,7 +1762,7 @@ namespace {
// Make and search the move.
StateInfo st;
pos.do_move(move, st, sp->dcCandidates);
pos.do_move(move, st, sp->dcCandidates, moveIsCheck);
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
@ -1866,7 +1868,7 @@ namespace {
// Make and search the move.
StateInfo st;
pos.do_move(move, st, sp->dcCandidates);
pos.do_move(move, st, sp->dcCandidates, moveIsCheck);
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.