From: Marco Costalba Date: Wed, 11 Nov 2009 09:41:46 +0000 (+0100) Subject: Remove update_checkers() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=bf395c6be180528cb3fc90d8b78dd5dd6f27adf6 Remove update_checkers() Now that we have CheckInfo we don't need it anymore. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/position.cpp b/src/position.cpp index ca1c21c3..8954834a 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -343,16 +343,15 @@ void Position::copy(const Position& pos) { template Bitboard Position::hidden_checkers(Color c) const { - Bitboard pinners, result = EmptyBoardBB; + Bitboard result = EmptyBoardBB; + Bitboard pinners = pieces_of_color(FindPinned ? opposite_color(c) : c); // Pinned pieces protect our king, dicovery checks attack // the enemy king. Square ksq = king_square(FindPinned ? c : opposite_color(c)); - // Pinners are sliders, not checkers, that give check when - // candidate pinned is removed. - pinners = (pieces(ROOK, QUEEN, FindPinned ? opposite_color(c) : c) & RookPseudoAttacks[ksq]) - | (pieces(BISHOP, QUEEN, FindPinned ? opposite_color(c) : c) & BishopPseudoAttacks[ksq]); + // Pinners are sliders, not checkers, that give check when candidate pinned is removed + pinners &= (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq]) | (pieces(BISHOP, QUEEN) & BishopPseudoAttacks[ksq]); if (FindPinned && pinners) pinners &= ~st->checkersBB; @@ -647,49 +646,17 @@ bool Position::move_is_check(Move m, const CheckInfo& ci) const { } -/// Position::update_checkers() udpates chekers info given the move. It is called -/// in do_move() and is faster then find_checkers(). - -template -inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, - Square to, Bitboard dcCandidates) { - - const bool Bishop = (Piece == QUEEN || Piece == BISHOP); - const bool Rook = (Piece == QUEEN || Piece == ROOK); - const bool Slider = Bishop || Rook; - - assert(*pCheckersBB == EmptyBoardBB); - - // Direct checks - if ( ( !Slider // try to early skip slide piece attacks - || (Bishop && bit_is_set(BishopPseudoAttacks[ksq], to)) - || (Rook && bit_is_set(RookPseudoAttacks[ksq], to))) - && bit_is_set(Piece == PAWN ? attacks_from(ksq, opposite_color(sideToMove)) : attacks_from(ksq) , to)) - { - *pCheckersBB = SetMaskBB[to]; - } - // Discovery checks - if (Piece != QUEEN && dcCandidates && bit_is_set(dcCandidates, from)) - { - if (Piece != ROOK) - (*pCheckersBB) |= (attacks_from(ksq) & pieces(ROOK, QUEEN, side_to_move())); - - if (Piece != BISHOP) - (*pCheckersBB) |= (attacks_from(ksq) & pieces(BISHOP, QUEEN, side_to_move())); - } -} - - /// Position::do_move() makes a move, and saves all information necessary /// to a StateInfo object. The move is assumed to be legal. /// Pseudo-legal moves should be filtered out before this function is called. void Position::do_move(Move m, StateInfo& newSt) { - do_move(m, newSt, discovered_check_candidates(side_to_move())); + CheckInfo ci(*this); + do_move(m, newSt, ci, move_is_check(m, ci)); } -void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates, bool moveCanBeCheck) { +void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) { assert(is_ok()); assert(move_is_ok(m)); @@ -860,22 +827,24 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates, bool mov // Update checkers bitboard, piece must be already moved st->checkersBB = EmptyBoardBB; - if (moveCanBeCheck) + if (moveIsCheck) { if (ep | pm) st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us); else { - Square ksq = king_square(them); - switch (pt) + // Direct checks + if (bit_is_set(ci.checkSq[pt], to)) + st->checkersBB = SetMaskBB[to]; + + // Discovery checks + if (ci.dcCandidates && bit_is_set(ci.dcCandidates, from)) { - case PAWN: update_checkers(&(st->checkersBB), ksq, from, to, dcCandidates); break; - case KNIGHT: update_checkers(&(st->checkersBB), ksq, from, to, dcCandidates); break; - case BISHOP: update_checkers(&(st->checkersBB), ksq, from, to, dcCandidates); break; - case ROOK: update_checkers(&(st->checkersBB), ksq, from, to, dcCandidates); break; - case QUEEN: update_checkers(&(st->checkersBB), ksq, from, to, dcCandidates); break; - case KING: update_checkers(&(st->checkersBB), ksq, from, to, dcCandidates); break; - default: assert(false); break; + if (pt != ROOK) + st->checkersBB |= (attacks_from(ci.ksq) & pieces(ROOK, QUEEN, us)); + + if (pt != BISHOP) + st->checkersBB |= (attacks_from(ci.ksq) & pieces(BISHOP, QUEEN, us)); } } } diff --git a/src/position.h b/src/position.h index eecf5352..f6e49687 100644 --- a/src/position.h +++ b/src/position.h @@ -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, bool moveCanBeCheck = true); + void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck); void undo_move(Move m); void do_null_move(StateInfo& st); void undo_null_move(); @@ -296,9 +296,6 @@ private: void undo_castle_move(Move m); void find_checkers(); - template - void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates); - template Bitboard hidden_checkers(Color c) const; diff --git a/src/search.cpp b/src/search.cpp index c4e061bd..c217e953 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -349,7 +349,7 @@ int perft(Position& pos, Depth depth) while ((move = mp.get_next_move()) != MOVE_NONE) { StateInfo st; - pos.do_move(move, st, ci.dcCandidates, pos.move_is_check(move, ci)); + pos.do_move(move, st, ci, pos.move_is_check(move, ci)); sum += perft(pos, depth - OnePly); pos.undo_move(move); } @@ -898,13 +898,14 @@ namespace { << " currmovenumber " << i + 1 << std::endl; // Decide search depth for this move + bool moveIsCheck = pos.move_is_check(move); bool captureOrPromotion = pos.move_is_capture_or_promotion(move); bool dangerous; - ext = extension(pos, move, true, captureOrPromotion, pos.move_is_check(move), false, false, &dangerous); + ext = extension(pos, move, true, captureOrPromotion, moveIsCheck, false, false, &dangerous); newDepth = (Iteration - 2) * OnePly + ext + InitialDepth; // Make the move, and search it - pos.do_move(move, st, ci.dcCandidates); + pos.do_move(move, st, ci, moveIsCheck); if (i < MultiPV) { @@ -1135,7 +1136,7 @@ namespace { newDepth = depth - OnePly + ext; // Make and search the move - pos.do_move(move, st, ci.dcCandidates, moveIsCheck); + pos.do_move(move, st, ci, moveIsCheck); if (moveCount == 1) // The first move in list is the PV value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID); @@ -1424,7 +1425,7 @@ namespace { } // Make and search the move - pos.do_move(move, st, ci.dcCandidates, moveIsCheck); + pos.do_move(move, st, ci, 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. @@ -1637,7 +1638,7 @@ namespace { continue; // Make and search the move - pos.do_move(move, st, ci.dcCandidates, moveIsCheck); + pos.do_move(move, st, ci, moveIsCheck); value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID); pos.undo_move(move); @@ -1764,7 +1765,7 @@ namespace { // Make and search the move. StateInfo st; - pos.do_move(move, st, sp->dcCandidates, moveIsCheck); + pos.do_move(move, st, ci, 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. @@ -1870,7 +1871,7 @@ namespace { // Make and search the move. StateInfo st; - pos.do_move(move, st, sp->dcCandidates, moveIsCheck); + pos.do_move(move, st, ci, 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.