X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=3526a3d023a5ef38a9e214193bb15820cd30f780;hp=ad7ed3d915b7913e76a0f7a7e51ecce342f59356;hb=a6c5b4c6fbd1db45377f9dfecd361cebffe27a8d;hpb=1a8f63a8963fa9c3afd043f4c611df8a5afcf038 diff --git a/src/position.cpp b/src/position.cpp index ad7ed3d9..3526a3d0 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -59,17 +59,18 @@ Key Position::exclusion_key() const { return st->key ^ Zobrist::exclusion;} namespace { -// next_attacker() is an helper function used by see() to locate the least +// min_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. +// from the bitboards and scan for new X-ray attacks behind it. template FORCE_INLINE -PieceType next_attacker(const Bitboard* bb, const Square& to, const Bitboard& stmAttackers, - Bitboard& occupied, Bitboard& attackers) { +PieceType min_attacker(const Bitboard* bb, const Square& to, const Bitboard& stmAttackers, + Bitboard& occupied, Bitboard& attackers) { - if (stmAttackers & bb[Pt]) + Bitboard b = stmAttackers & bb[Pt]; + + if (b) { - Bitboard b = stmAttackers & bb[Pt]; occupied ^= b & ~(b - 1); if (Pt == PAWN || Pt == BISHOP || Pt == QUEEN) @@ -78,13 +79,15 @@ PieceType next_attacker(const Bitboard* bb, const Square& to, const Bitboard& st if (Pt == ROOK || Pt == QUEEN) attackers |= attacks_bb(to, occupied) & (bb[ROOK] | bb[QUEEN]); + attackers &= occupied; // Remove the just found attacker + return (PieceType)Pt; } - return next_attacker(bb, to, stmAttackers, occupied, attackers); + return min_attacker(bb, to, stmAttackers, occupied, attackers); } template<> FORCE_INLINE -PieceType next_attacker(const Bitboard*, const Square&, const Bitboard&, Bitboard&, Bitboard&) { +PieceType min_attacker(const Bitboard*, const Square&, const Bitboard&, Bitboard&, Bitboard&) { return KING; // No need to update bitboards, it is the last cycle } @@ -1133,7 +1136,7 @@ int Position::see_sign(Move m) const { // Early return if SEE cannot be negative because captured piece value // is not less then capturing one. Note that king moves always return // here because king midgame value is set to 0. - if (PieceValue[MG][piece_on(to_sq(m))] >= PieceValue[MG][piece_moved(m)]) + if (PieceValue[MG][piece_moved(m)] <= PieceValue[MG][piece_on(to_sq(m))]) return 1; return see(m); @@ -1194,26 +1197,21 @@ int Position::see(Move m, int asymmThreshold) const { do { assert(slIndex < 32); + if (captured == KING) // Stop before processing a king capture + { + swapList[slIndex++] = QueenValueMg * 16; + break; + } + // Add the new entry to the swap list swapList[slIndex] = -swapList[slIndex - 1] + PieceValue[MG][captured]; slIndex++; - // Locate and remove from 'occupied' the next least valuable attacker - captured = next_attacker(byTypeBB, to, stmAttackers, occupied, attackers); - - attackers &= occupied; // Remove the just found attacker + // Locate and remove the next least valuable attacker + captured = min_attacker(byTypeBB, to, stmAttackers, occupied, attackers); stm = ~stm; stmAttackers = attackers & pieces(stm); - if (captured == KING) - { - // Stop before processing a king capture - if (stmAttackers) - swapList[slIndex++] = QueenValueMg * 16; - - break; - } - } while (stmAttackers); // If we are doing asymmetric SEE evaluation and the same side does the first