#ifndef POSITION_H_INCLUDED
#define POSITION_H_INCLUDED

#include "ramjet.h"
#include "quadboard.h"
#include "state.h"
#include "move.h"

// the position data type
typedef struct {
    QUADBOARD qb;
    STATE st;
    MOVE lmv;
    HASHKEY key;
} POSITION;

// make the position empty
void pos_clear(POSITION* pos);

// compute a hash digest of the position
HASHKEY pos_hash(const POSITION* pos);

// input/output in FEN format
void pos_scan_fen(char* fen, POSITION* pos);
void pos_print_fen(char* fen, const POSITION* pos);

// execute the move on the given position
void pos_make_mv(POSITION* pos, MOVE mv);
void pos_make_null_mv(POSITION* pos);

// copy the position, execute the move, return legality
int pos_copy_make_mv(const POSITION* curr, POSITION* next, MOVE mv);
void pos_copy_make_null_mv(const POSITION* curr, POSITION* next);

// generate the list of pseudo-legal moves
int pos_gen_mv(const POSITION* pos, MOVE* mv);

// count the leaves at the specified depth of the game tree
NODECOUNT pos_leaf_count(const POSITION* pos, int depth);

// sanity check on the position
int is_pos_bad(const POSITION* pos);

// test the functions above
int pos_test();

// test the tree-generating routines
// the file format is in triplets "fen\ndepth\nnodes\n"
int pos_perft(const char* filename);

#endif // POSITION_H_INCLUDED
