-#include "move.h"
-#include "square.h"
-
-
-////
-//// Local definitions
-////
-
-namespace {
-
- enum Result {
- RESULT_UNKNOWN,
- RESULT_INVALID,
- RESULT_WIN,
- RESULT_LOSS,
- RESULT_DRAW
- };
-
- struct KPKPosition {
- void from_index(int index);
- int to_index() const;
- bool is_legal() const;
- bool is_immediate_draw() const;
- bool is_immediate_win() const;
- Bitboard wk_attacks() const;
- Bitboard bk_attacks() const;
- Bitboard pawn_attacks() const;
-
- Square whiteKingSquare, blackKingSquare, pawnSquare;
- Color sideToMove;
- };
-
-
- Result *Bitbase;
- const int IndexMax = 2*24*64*64;
- int UnknownCount = 0;
-
- void initialize();
- bool next_iteration();
- Result classify_wtm(const KPKPosition &p);
- Result classify_btm(const KPKPosition &p);
- int compute_index(Square wksq, Square bksq, Square psq, Color stm);
- int compress_result(Result r);
-
-}
-
-
-////
-//// Functions
-////
-
-void generate_kpk_bitbase(uint8_t bitbase[]) {
- // Allocate array and initialize:
- Bitbase = new Result[IndexMax];
- initialize();
-
- // Iterate until all positions are classified:
- while(next_iteration());
-
- // Compress bitbase into the supplied parameter:
- int i, j, b;
- for(i = 0; i < 24576; i++) {
- for(b = 0, j = 0; j < 8; b |= (compress_result(Bitbase[8*i+j]) << j), j++);
- bitbase[i] = b;
- }
-
- // Release allocated memory:
- delete [] Bitbase;
-}
-