- // Each uint32_t stores results of 32 positions, one per bit
- uint32_t KPKBitbase[IndexMax / 32];
-
- int compute_index(Square wksq, Square bksq, Square wpsq, Color stm);
-}
-
-
-uint32_t probe_kpk_bitbase(Square wksq, Square wpsq, Square bksq, Color stm) {
-
- int index = compute_index(wksq, bksq, wpsq, stm);
-
- return KPKBitbase[index / 32] & (1 << (index & 31));
-}
-
-
-void kpk_bitbase_init() {
-
- Result db[IndexMax];
- KPKPosition pos;
- int index, bit, repeat = 1;
-
- // Initialize table
- for (index = 0; index < IndexMax; index++)
- db[index] = pos.classify_knowns(index);
-
- // Iterate until all positions are classified (30 cycles needed)
- while (repeat)
- for (repeat = index = 0; index < IndexMax; index++)
- if ( db[index] == RESULT_UNKNOWN
- && pos.classify(index, db) != RESULT_UNKNOWN)
- repeat = 1;
-
- // Map 32 position results into one KPKBitbase[] entry
- for (index = 0; index < IndexMax / 32; index++)
- for (bit = 0; bit < 32; bit++)
- if (db[32 * index + bit] == RESULT_WIN)
- KPKBitbase[index] |= (1 << bit);
-}