Rewrite initialization of PseudoMoves

This is a non-functional code style change. I believe master is a bit convoluted
here and propose this version for clarity.

No functional change
This commit is contained in:
protonspring
2020-01-03 11:33:18 -07:00
committed by Stéphane Nicolet
parent 384bff4264
commit 7f623206f4

View File

@@ -76,25 +76,29 @@ void Bitboards::init() {
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1) for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2) for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2)); SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
int steps[][5] = { {}, { 7, 9 }, { 6, 10, 15, 17 }, {}, {}, {}, { 1, 7, 8, 9 } }; 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));
}
for (Color c : { WHITE, BLACK }) // Helper returning the target bitboard of a step from a square
for (PieceType pt : { PAWN, KNIGHT, KING }) auto landing_square_bb = [&](Square s, int step)
for (Square s = SQ_A1; s <= SQ_H8; ++s) {
for (int i = 0; steps[pt][i]; ++i) Square to = Square(s + step);
{ return is_ok(to) && distance(s, to) <= 2 ? square_bb(to) : Bitboard(0);
Square to = s + Direction(c == WHITE ? steps[pt][i] : -steps[pt][i]); };
if (is_ok(to) && distance(s, to) < 3) for (Square s = SQ_A1; s <= SQ_H8; ++s)
{ {
if (pt == PAWN) for (int step : {-9, -8, -7, -1, 1, 7, 8, 9} )
PawnAttacks[c][s] |= to; PseudoAttacks[KING][s] |= landing_square_bb(s, step);
else
PseudoAttacks[pt][s] |= to; for (int step : {-17, -15, -10, -6, 6, 10, 15, 17} )
} PseudoAttacks[KNIGHT][s] |= landing_square_bb(s, step);
} }
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST }; Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST }; Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };