X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fposition.cpp;h=4bc8df597e8e02e1af5cf309b1f2b82d68c1bd7a;hb=d77d555c72df7045901826e95bc012a0d77ca835;hp=e8689ea727316d8f474abcd679999f2326826de6;hpb=9cdca7516c9397f991b2c0194f5de1ade26622e8;p=stockfish diff --git a/src/position.cpp b/src/position.cpp index e8689ea7..4bc8df59 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -102,29 +102,30 @@ void init() { } // namespace Zobrist +namespace { + /// next_attacker() is an helper function used by see() to locate the least /// valuable attacker for the side to move, remove the attacker we just found /// from the 'occupied' bitboard and scan for new X-ray attacks behind it. -template static FORCE_INLINE +template FORCE_INLINE PieceType next_attacker(const Bitboard* bb, const Square& to, const Bitboard& stmAttackers, Bitboard& occupied, Bitboard& attackers) { - const PieceType NextPt = PieceType((int)Pt + 1); - - if (!(stmAttackers & bb[Pt])) - return next_attacker(bb, to, stmAttackers, occupied, attackers); - - Bitboard b = stmAttackers & bb[Pt]; - occupied ^= b & ~(b - 1); + if (stmAttackers & bb[Pt]) + { + Bitboard b = stmAttackers & bb[Pt]; + occupied ^= b & ~(b - 1); - if (Pt == PAWN || Pt == BISHOP || Pt == QUEEN) - attackers |= attacks_bb(to, occupied) & (bb[BISHOP] | bb[QUEEN]); + if (Pt == PAWN || Pt == BISHOP || Pt == QUEEN) + attackers |= attacks_bb(to, occupied) & (bb[BISHOP] | bb[QUEEN]); - if (Pt == ROOK || Pt == QUEEN) - attackers |= attacks_bb(to, occupied) & (bb[ROOK] | bb[QUEEN]); + if (Pt == ROOK || Pt == QUEEN) + attackers |= attacks_bb(to, occupied) & (bb[ROOK] | bb[QUEEN]); - return Pt; + return (PieceType)Pt; + } + return next_attacker(bb, to, stmAttackers, occupied, attackers); } template<> FORCE_INLINE @@ -132,6 +133,8 @@ PieceType next_attacker(const Bitboard*, const Square&, const Bitboard&, B return KING; // No need to update bitboards, it is the last cycle } +} // namespace + /// CheckInfo c'tor @@ -1312,11 +1315,12 @@ int Position::see(Move m) const { stm = ~stm; stmAttackers = attackers & pieces(stm); - // Stop before processing a king capture - if (captured == KING && stmAttackers) + if (captured == KING) { - assert(slIndex < 32); - swapList[slIndex++] = QueenValueMg * 16; + // Stop before processing a king capture + if (stmAttackers) + swapList[slIndex++] = QueenValueMg * 16; + break; }