- for (int rw = RANK_7, rb = RANK_2; rw >= RANK_1; rw--, rb++)
- {
- InFrontBB[WHITE][rw] = InFrontBB[WHITE][rw + 1] | RankBB[rw + 1];
- InFrontBB[BLACK][rb] = InFrontBB[BLACK][rb - 1] | RankBB[rb - 1];
- }
-
- 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_neighboring_files_bb(s);
- AttackSpanMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
- }
-
- for (Bitboard b = 0; b < 256; b++)
- BitCount8Bit[b] = (uint8_t)count_1s<CNT32_MAX15>(b);
-
- for (int i = 0; i < 64; i++)
- if (!CpuIs64Bit) // 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 (Square s = SQ_A1; s <= SQ_H8; s++)
- for (PieceType pt = PAWN; pt <= KING; pt++)
- for (int k = 0; steps[pt][k]; k++)
- {
- Square to = s + Square(c == WHITE ? steps[pt][k] : -steps[pt][k]);
-
- if (square_is_ok(to) && square_distance(s, to) < 3)
- set_bit(&StepAttacksBB[make_piece(c, pt)][s], to);
- }
-
- Square RDelta[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
- Square BDelta[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW };
-
- init_sliding_attacks(BMult, BAttacks, BAttacksTable, BMask, BShift, BDelta);
- init_sliding_attacks(RMult, RAttacks, RAttacksTable, RMask, RShift, RDelta);
-
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- {
- BishopPseudoAttacks[s] = bishop_attacks_bb(s, EmptyBoardBB);
- RookPseudoAttacks[s] = rook_attacks_bb(s, EmptyBoardBB);
- QueenPseudoAttacks[s] = queen_attacks_bb(s, EmptyBoardBB);
- }
-
- for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
- for (Square s2 = SQ_A1; s2 <= SQ_H8; s2++)
- if (bit_is_set(QueenPseudoAttacks[s1], s2))
- {
- int f = file_distance(s1, s2);
- int r = rank_distance(s1, s2);