- void init_non_sliding_attacks() {
-
- const int step[][9] = {
- {0},
- {7,9,0}, {17,15,10,6,-6,-10,-15,-17,0}, {0}, {0}, {0},
- {9,7,-7,-9,8,1,-1,-8,0}, {0}, {0},
- {-7,-9,0}, {17,15,10,6,-6,-10,-15,-17,0}, {0}, {0}, {0},
- {9,7,-7,-9,8,1,-1,-8,0}
- };
-
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- for (Piece pc = WP; pc <= BK; pc++)
- for (int k = 0; step[pc][k] != 0; k++)
- {
- Square to = s + Square(step[pc][k]);
-
- if (square_is_ok(to) && square_distance(s, to) < 3)
- set_bit(&NonSlidingAttacksBB[pc][s], to);
- }
+ 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>(b);
+
+ for (int i = 1; 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 * DeBruijnMagic) >> 26] = i;
+ }
+ else
+ BSFTable[((1ULL << i) * DeBruijnMagic) >> 58] = i;
+
+ int steps[][9] = {
+ {0}, {7,9,0}, {17,15,10,6,-6,-10,-15,-17,0}, {0}, {0}, {0}, {9,7,-7,-9,8,1,-1,-8,0}
+ };
+
+ 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);
+ }
+
+ int rookDeltas[4][2] = { {0,1}, {0 ,-1}, {1, 0}, {-1, 0} };
+ int bishopDeltas[4][2] = { {1,1}, {-1, 1}, {1,-1}, {-1,-1} };
+
+ init_sliding_attacks(RAttacks, RMagics, RShift, RMult, rookDeltas);
+ init_sliding_attacks(BAttacks, BMagics, BShift, BMult, bishopDeltas);
+
+ 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);