- // Init king safety tables only if we are going to use them
- if (pos.non_pawn_material(Us) >= QueenValueMg)
+ // Find our pawns on the first two ranks, and those which are blocked
+ Bitboard b = pos.pieces(Us, PAWN) & (shift<Down>(pos.pieces()) | LowRanks);
+
+ // Squares occupied by those pawns, by our king, or controlled by enemy pawns
+ // are excluded from the mobility area.
+ ei.mobilityArea[Us] = ~(b | pos.square<KING>(Us) | ei.pe->pawn_attacks(Them));
+
+ // Initialise the attack bitboards with the king and pawn information
+ b = ei.attackedBy[Us][KING] = pos.attacks_from<KING>(pos.square<KING>(Us));
+ ei.attackedBy[Us][PAWN] = ei.pe->pawn_attacks(Us);
+
+ ei.attackedBy2[Us] = b & ei.attackedBy[Us][PAWN];
+ ei.attackedBy[Us][ALL_PIECES] = b | ei.attackedBy[Us][PAWN];
+
+ // Init our king safety tables only if we are going to use them
+ if (pos.non_pawn_material(Them) >= QueenValueMg)