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));
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;
+ }
}
}
{
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
}
// 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);
}
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++)
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)
{
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);
}
// 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.
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);
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
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);
// 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.
// 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.