/// Position::set_state() computes the hash keys of the position, and other
/// data that once computed is updated incrementally as moves are made.
-/// The function is only used when a new position is set up, and to verify
-/// the correctness of the StateInfo data when running in debug mode.
+/// The function is only used when a new position is set up
void Position::set_state() const {
return true;
assert(color_of(piece_on(from)) == sideToMove);
- Bitboard occupied = pieces() ^ from ^ to;
+ Bitboard occupied = pieces() ^ from ^ to; // xoring to is important for pinned piece logic
Color stm = sideToMove;
Bitboard attackers = attackers_to(to, occupied);
Bitboard stmAttackers, bb;
{
if ((swap = PawnValueMg - swap) < res)
break;
-
occupied ^= least_significant_square_bb(bb);
+
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
}
{
if ((swap = KnightValueMg - swap) < res)
break;
-
occupied ^= least_significant_square_bb(bb);
}
{
if ((swap = BishopValueMg - swap) < res)
break;
-
occupied ^= least_significant_square_bb(bb);
+
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
}
{
if ((swap = RookValueMg - swap) < res)
break;
-
occupied ^= least_significant_square_bb(bb);
+
attackers |= attacks_bb<ROOK>(to, occupied) & pieces(ROOK, QUEEN);
}
{
if ((swap = QueenValueMg - swap) < res)
break;
-
occupied ^= least_significant_square_bb(bb);
+
attackers |= (attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN))
| (attacks_bb<ROOK >(to, occupied) & pieces(ROOK , QUEEN));
}