mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-22 01:56:58 +08:00
Consolidate all attacks bitboards
This is a non-functional simplification that simplifies getting attacks bitboards.
* consolidates all attacks to attacks_bb (remove Position::attacks_from(..)).
* attacks_bb<PieceType>(square) gets pseudo attacks
* attacks_bb<PieceType>(square, bitboard) gets attacks considering occupied squares in the bitboard).
* pawn_attacks_bb(Color, Square) gets pawn attacks like other pawn attack bitboards.
* Wraps all access to PawnAttacks arrays and PseudoAttacks arrays and adds asserts as appropriate.
Passed STC
LLR: 2.95 (-2.94,2.94) {-1.50,0.50}
Total: 90208 W: 17533 L: 17482 D: 55193
Ptnml(0-2): 1412, 10232, 21798, 10217, 1445
https://tests.stockfishchess.org/tests/view/5ece996275787cc0c05d9790
closes https://github.com/official-stockfish/Stockfish/pull/2703
No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
fb8095718b
commit
a5e3b4edde
@@ -235,7 +235,7 @@ namespace {
|
||||
mobilityArea[Us] = ~(b | pos.pieces(Us, KING, QUEEN) | pos.blockers_for_king(Us) | pe->pawn_attacks(Them));
|
||||
|
||||
// Initialize attackedBy[] for king and pawns
|
||||
attackedBy[Us][KING] = pos.attacks_from<KING>(ksq);
|
||||
attackedBy[Us][KING] = attacks_bb<KING>(ksq);
|
||||
attackedBy[Us][PAWN] = pe->pawn_attacks(Us);
|
||||
attackedBy[Us][ALL_PIECES] = attackedBy[Us][KING] | attackedBy[Us][PAWN];
|
||||
attackedBy2[Us] = dblAttackByPawn | (attackedBy[Us][KING] & attackedBy[Us][PAWN]);
|
||||
@@ -243,7 +243,7 @@ namespace {
|
||||
// Init our king safety tables
|
||||
Square s = make_square(Utility::clamp(file_of(ksq), FILE_B, FILE_G),
|
||||
Utility::clamp(rank_of(ksq), RANK_2, RANK_7));
|
||||
kingRing[Us] = PseudoAttacks[KING][s] | s;
|
||||
kingRing[Us] = attacks_bb<KING>(s) | s;
|
||||
|
||||
kingAttackersCount[Them] = popcount(kingRing[Us] & pe->pawn_attacks(Them));
|
||||
kingAttacksCount[Them] = kingAttackersWeight[Them] = 0;
|
||||
@@ -273,7 +273,7 @@ namespace {
|
||||
// Find attacked squares, including x-ray attacks for bishops and rooks
|
||||
b = Pt == BISHOP ? attacks_bb<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN))
|
||||
: Pt == ROOK ? attacks_bb< ROOK>(s, pos.pieces() ^ pos.pieces(QUEEN) ^ pos.pieces(Us, ROOK))
|
||||
: pos.attacks_from<Pt>(s);
|
||||
: attacks_bb<Pt>(s, pos.pieces());
|
||||
|
||||
if (pos.blockers_for_king(Us) & s)
|
||||
b &= LineBB[pos.square<KING>(Us)][s];
|
||||
@@ -323,7 +323,7 @@ namespace {
|
||||
* (!(attackedBy[Us][PAWN] & s) + popcount(blocked & CenterFiles));
|
||||
|
||||
// Penalty for all enemy pawns x-rayed
|
||||
score -= BishopXRayPawns * popcount(PseudoAttacks[BISHOP][s] & pos.pieces(Them, PAWN));
|
||||
score -= BishopXRayPawns * popcount(attacks_bb<BISHOP>(s) & pos.pieces(Them, PAWN));
|
||||
|
||||
// Bonus for bishop on a long diagonal which can "see" both center squares
|
||||
if (more_than_one(attacks_bb<BISHOP>(s, pos.pieces(PAWN)) & Center))
|
||||
@@ -438,7 +438,7 @@ namespace {
|
||||
unsafeChecks |= b2 & attackedBy[Them][BISHOP];
|
||||
|
||||
// Enemy knights checks
|
||||
knightChecks = pos.attacks_from<KNIGHT>(ksq) & attackedBy[Them][KNIGHT];
|
||||
knightChecks = attacks_bb<KNIGHT>(ksq) & attackedBy[Them][KNIGHT];
|
||||
if (knightChecks & safe)
|
||||
kingDanger += more_than_one(knightChecks & safe) ? KnightSafeCheck * 162/100
|
||||
: KnightSafeCheck;
|
||||
@@ -564,12 +564,12 @@ namespace {
|
||||
Square s = pos.square<QUEEN>(Them);
|
||||
safe = mobilityArea[Us] & ~stronglyProtected;
|
||||
|
||||
b = attackedBy[Us][KNIGHT] & pos.attacks_from<KNIGHT>(s);
|
||||
b = attackedBy[Us][KNIGHT] & attacks_bb<KNIGHT>(s);
|
||||
|
||||
score += KnightOnQueen * popcount(b & safe);
|
||||
|
||||
b = (attackedBy[Us][BISHOP] & pos.attacks_from<BISHOP>(s))
|
||||
| (attackedBy[Us][ROOK ] & pos.attacks_from<ROOK >(s));
|
||||
b = (attackedBy[Us][BISHOP] & attacks_bb<BISHOP>(s, pos.pieces()))
|
||||
| (attackedBy[Us][ROOK ] & attacks_bb<ROOK >(s, pos.pieces()));
|
||||
|
||||
score += SliderOnQueen * popcount(b & safe & attackedBy2[Us]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user