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;
}
void generate_kpk_bitbase(uint8_t bitbase[]) {

  // Try to load bitbase from disk
  std::ifstream inFile(kpk_bitbase_filename().c_str(),
                       std::ios::in | std::ios::binary);
  if(inFile.is_open()) {
    if(inFile.read((char *)bitbase, 24576)) {
      // Successfully read 24576 bytes
      std::cout << "Successfully read bitbase file from disk!" << std::endl;
      inFile.close();
      return;
    }
    inFile.close();
  }

  // Reading the bitbase from disk failed, generate it and dump it to disk
  // instead.
  std::cout << "Generating KP vs K bitbase..." << std::endl;

  // 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++);
    assert(b == int(uint8_t(b)));
    bitbase[i] = (uint8_t)b;
  }

  // Release allocated memory:
  delete [] Bitbase;

  // Save bitbase to disk
  std::ofstream outFile(kpk_bitbase_filename().c_str(),
                        std::ios::out|std::ios::binary);
  if(outFile.is_open())
    outFile.write((char *)bitbase, 24576);
}