- {
- SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
- DistanceRingBB[s1][SquareDistance[s1][s2]] |= s2;
- }
-
- int steps[][5] = { {}, { 7, 9 }, { 6, 10, 15, 17 }, {}, {}, {}, { 1, 7, 8, 9 } };
-
- for (Color c = WHITE; c <= BLACK; ++c)
- for (PieceType pt : { PAWN, KNIGHT, KING })
- for (Square s = SQ_A1; s <= SQ_H8; ++s)
- for (int i = 0; steps[pt][i]; ++i)
- {
- Square to = s + Direction(c == WHITE ? steps[pt][i] : -steps[pt][i]);
-
- if (is_ok(to) && distance(s, to) < 3)
- {
- if (pt == PAWN)
- PawnAttacks[c][s] |= to;
- else
- PseudoAttacks[pt][s] |= to;
- }
- }
+ SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
+
+ for (Square s = SQ_A1; s <= SQ_H8; ++s)
+ {
+ PawnAttacks[WHITE][s] = pawn_attacks_bb<WHITE>(square_bb(s));
+ PawnAttacks[BLACK][s] = pawn_attacks_bb<BLACK>(square_bb(s));
+ }
+
+ // Helper returning the target bitboard of a step from a square
+ auto landing_square_bb = [&](Square s, int step)
+ {
+ Square to = Square(s + step);
+ return is_ok(to) && distance(s, to) <= 2 ? square_bb(to) : Bitboard(0);
+ };
+
+ for (Square s = SQ_A1; s <= SQ_H8; ++s)
+ {
+ for (int step : {-9, -8, -7, -1, 1, 7, 8, 9} )
+ PseudoAttacks[KING][s] |= landing_square_bb(s, step);
+
+ for (int step : {-17, -15, -10, -6, 6, 10, 15, 17} )
+ PseudoAttacks[KNIGHT][s] |= landing_square_bb(s, step);
+ }