#pragma once

#include "bitboard.h"

class BitKPK
{
protected:
    i8 *temp;				// temporary data used when generating bitbases

    i32 invalid;			// invalid positions
    i32 wins;				// won positions
    i32 draws;				// drawn positions
    i32 remaining;			// remaining positions

    // for debugging only
    void boardFromIndex( BitBoard &b, i32 index ) const;

    i32 indexFromPos( u8 turn, u8 wk, u8 bk, u8 wp ) const;
    void posFromIndex( i32 index, u8 &turn, u8 &wk, u8 &bk, u8 &wp ) const;

    // generate next iteration
    void iterate();

    u8 *bitmap;				// drawn position bitmap

public:
    BitKPK();
    ~BitKPK();
    void generate();

    // result: 0 = draw, -1 = loss, +1 = win, -2 = invalid/unknown
    i32 probe( const BitBoard &b ) const;

    // save bitmap
    // returns 1 on success
    bool saveBin( const char *fnm ) const;
    // load bitmap
    // returns 1 on success
    bool loadBin( const char *fnm );
};
