#pragma once

#include "board.h"
#include <vector>
#include <map>

enum {
	maxBook = 256					// max book line length
};

class BookMove
{
public:
	Move m;							// move
	i16 w;							// win percentage*10
	u16 c;							// played_count
	inline BookMove()
	{
		m.clear();
		w = 0;
		c = 0;
	}
	inline bool operator <( const BookMove &o ) const
	{
		if ( w != o.w )
			return w > o.w;
		return c > o.c;
	}
};

class Book
{
public:
	std::map< u64, std::vector< BookMove > > book;
	// clear this book
	void clear();
	// purge this book
	void purge();
	// compile book from pgn
	void compile( const char *pgn );
	// parse book
	void parse( const char *fnm );
	// parse binary book
	void parseBin( const char *fnm );
	// export binary book
	void exportBin( const char *fnm );
	// try book move. returns -1 if not found, otherwise move index!
	i32 check( i32 turn, const Board &b, u64 h, i32 nm, Move *m ) const;
};
