- for (Color c = WHITE; c <= BLACK; c++)
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- {
- SquaresInFrontMask[c][s] = in_front_bb(c, s) & file_bb(s);
- PassedPawnMask[c][s] = in_front_bb(c, s) & this_and_adjacent_files_bb(file_of(s));
- AttackSpanMask[c][s] = in_front_bb(c, s) & adjacent_files_bb(file_of(s));
- }
-
- for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
- for (Square s2 = SQ_A1; s2 <= SQ_H8; s2++)
- SquareDistance[s1][s2] = std::max(file_distance(s1, s2), rank_distance(s1, s2));
-
- for (int i = 0; i < 64; i++)
- if (!Is64Bit) // Matt Taylor's folding trick for 32 bit systems
- {
- Bitboard b = 1ULL << i;
- b ^= b - 1;
- b ^= b >> 32;
- BSFTable[(uint32_t)(b * 0x783A9B23) >> 26] = i;
- }
- else
- BSFTable[((1ULL << i) * 0x218A392CD3D5DBFULL) >> 58] = i;
-
- int steps[][9] = { {}, { 7, 9 }, { 17, 15, 10, 6, -6, -10, -15, -17 },
- {}, {}, {}, { 9, 7, -7, -9, 8, 1, -1, -8 } };
-
- for (Color c = WHITE; c <= BLACK; c++)
- for (PieceType pt = PAWN; pt <= KING; pt++)
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- for (int k = 0; steps[pt][k]; k++)
- {
- Square to = s + Square(c == WHITE ? steps[pt][k] : -steps[pt][k]);
-
- if (is_ok(to) && square_distance(s, to) < 3)
- StepAttacksBB[make_piece(c, pt)][s] |= to;
- }
-
- Square RDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
- Square BDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW };
-
- init_magics(RTable, RAttacks, RMagics, RMasks, RShifts, RDeltas, magic_index<ROOK>);
- init_magics(BTable, BAttacks, BMagics, BMasks, BShifts, BDeltas, magic_index<BISHOP>);
-
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- {
- PseudoAttacks[BISHOP][s] = attacks_bb<BISHOP>(s, 0);
- PseudoAttacks[ROOK][s] = attacks_bb<ROOK>(s, 0);
- PseudoAttacks[QUEEN][s] = PseudoAttacks[BISHOP][s] | PseudoAttacks[ROOK][s];
- }