uint8_t PopCnt16[1 << 16];
int8_t SquareDistance[SQUARE_NB][SQUARE_NB];
+Bitboard BoardSizeBB[FILE_NB][RANK_NB];
Bitboard SquareBB[SQUARE_NB];
Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
-Bitboard DistanceRingBB[SQUARE_NB][8];
-Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
-Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
+Bitboard DistanceRingBB[SQUARE_NB][FILE_NB];
- Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
- Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
- Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
+Bitboard PseudoAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+Bitboard PseudoMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+Bitboard LeaperAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+Bitboard LeaperMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
Magic RookMagics[SQUARE_NB];
Magic BishopMagics[SQUARE_NB];
for (unsigned i = 0; i < (1 << 16); ++i)
PopCnt16[i] = (uint8_t) popcount16(i);
- for (Square s = SQ_A1; s <= SQ_H8; ++s)
- SquareBB[s] = (1ULL << s);
+ for (Square s = SQ_A1; s <= SQ_MAX; ++s)
+ SquareBB[s] = make_bitboard(s);
- for (File f = FILE_A; f <= FILE_MAX; ++f)
- FileBB[f] = f > FILE_A ? FileBB[f - 1] << 1 : FileABB;
-
- for (Rank r = RANK_1; r <= RANK_MAX; ++r)
- RankBB[r] = r > RANK_1 ? RankBB[r - 1] << FILE_NB : Rank1BB;
-
- for (Rank r = RANK_1; r < RANK_8; ++r)
+ for (Rank r = RANK_1; r < RANK_MAX; ++r)
- ForwardRanksBB[WHITE][r] = ~(ForwardRanksBB[BLACK][r + 1] = ForwardRanksBB[BLACK][r] | RankBB[r]);
-
- for (Color c = WHITE; c <= BLACK; ++c)
- for (Square s = SQ_A1; s <= SQ_MAX; ++s)
- {
- ForwardFileBB [c][s] = ForwardRanksBB[c][rank_of(s)] & FileBB[file_of(s)];
- PawnAttackSpan[c][s] = ForwardRanksBB[c][rank_of(s)] & adjacent_files_bb(file_of(s));
- PassedPawnMask[c][s] = ForwardFileBB [c][s] | PawnAttackSpan[c][s];
- }
+ ForwardRanksBB[WHITE][r] = ~(ForwardRanksBB[BLACK][r + 1] = ForwardRanksBB[BLACK][r] | rank_bb(r));
- for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
- for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
+ for (File f = FILE_A; f <= FILE_MAX; ++f)
+ for (Rank r = RANK_1; r <= RANK_MAX; ++r)
- BoardSizeBB[f][r] = ForwardFileBB[BLACK][make_square(f, r)] | SquareBB[make_square(f, r)] | (f > FILE_A ? BoardSizeBB[f - 1][r] : 0);
++ BoardSizeBB[f][r] = forward_file_bb(BLACK, make_square(f, r)) | SquareBB[make_square(f, r)] | (f > FILE_A ? BoardSizeBB[f - 1][r] : 0);
+
+ for (Square s1 = SQ_A1; s1 <= SQ_MAX; ++s1)
+ for (Square s2 = SQ_A1; s2 <= SQ_MAX; ++s2)
if (s1 != s2)
{
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
extern int8_t SquareDistance[SQUARE_NB][SQUARE_NB];
+extern Bitboard BoardSizeBB[FILE_NB][RANK_NB];
extern Bitboard SquareBB[SQUARE_NB];
extern Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
-extern Bitboard DistanceRingBB[SQUARE_NB][8];
-extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
-extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
-
+extern Bitboard DistanceRingBB[SQUARE_NB][FILE_NB];
- extern Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
- extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
- extern Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
+extern Bitboard PseudoAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+extern Bitboard PseudoMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+extern Bitboard LeaperAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+extern Bitboard LeaperMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+
+#ifdef LARGEBOARDS
+int popcount(Bitboard b); // required for 128 bit pext
+#endif
/// Magic holds all magic bitboards relevant data for a single square
struct Magic {
unsafeChecks &= mobilityArea[Them];
kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them]
- + 69 * kingAttacksCount[Them] * (1 + 2 * !!pos.max_check_count())
- + 185 * popcount(kingRing[Us] & weak) * (1 + pos.captures_to_hand() + !!pos.max_check_count())
- + 150 * popcount(pos.blockers_for_king(Us) | unsafeChecks)
- + tropism * tropism / 4
- - 873 * !(pos.count<QUEEN>(Them) || pos.captures_to_hand()) / (1 + !!pos.max_check_count())
- - 6 * mg_value(score) / 8
- + mg_value(mobility[Them] - mobility[Us])
- - 30;
- + 69 * kingAttacksCount[Them]
- + 185 * popcount(kingRing[Us] & weak)
++ + 69 * kingAttacksCount[Them] * (1 + 2 * !!pos.max_check_count())
++ + 185 * popcount(kingRing[Us] & weak) * (1 + pos.captures_to_hand() + !!pos.max_check_count())
+ - 100 * bool(attackedBy[Us][KNIGHT] & attackedBy[Us][KING])
+ + 150 * popcount(pos.blockers_for_king(Us) | unsafeChecks)
+ + 5 * tropism * tropism / 16
- - 873 * !pos.count<QUEEN>(Them)
++ - 873 * !(pos.count<QUEEN>(Them) || pos.captures_to_hand()) / (1 + !!pos.max_check_count())
+ - 6 * mg_value(score) / 8
+ + mg_value(mobility[Them] - mobility[Us])
+ - 25;
// Transform the kingDanger units into a Score, and subtract it from the evaluation
if (kingDanger > 0)