+ // The possible pawns squares are 24, the first 4 files and ranks from 2 to 7
+ const unsigned IndexMax = 24*64*64*2; // wp_sq * wk_sq * bk_sq * stm = 196608
+
+ // Each uint32_t stores results of 32 positions, one per bit
+ uint32_t KPKBitbase[IndexMax / 32];
+
+ // A KPK bitbase index is an integer in [0, IndexMax] range
+ //
+ // Information is mapped in this way
+ //
+ // bit 0: side to move (WHITE or BLACK)
+ // bit 1- 6: black king square (from SQ_A1 to SQ_H8)
+ // bit 7-12: white king square (from SQ_A1 to SQ_H8)
+ // bit 13-14: white pawn file (from FILE_A to FILE_D)
+ // bit 15-17: white pawn 6 - rank (from 6 - RANK_7 to 6 - RANK_2)
+ unsigned index(Color stm, Square bksq, Square wksq, Square psq) {
+ return stm + (bksq << 1) + (wksq << 7) + (file_of(psq) << 13) + ((6 - rank_of(psq)) << 15);
+ }
+