#ifndef SEARCHH_INCLUDED
#define SEARCHH_INCLUDED

#include "defs.h"

#include <stdio.h>
#include <stdlib.h> 
#include <string.h>

/*
	TRACE
*/


/*
	LOGGING
*/

//#define LOG

#define BLUNDERS


#define ASPIRATION  
#define RADIUS 40
#define RADIUS2 120
#define PVSt
#define PVSs

#define HASH

#define IID  


#define ETC           


#define RETURNBOUNDS  


#define NULLMOVE 
#define REDUCE 2        

#define MATEDISTPRUNE

#define LMR
#define LMR_DEPTH 3 
#define LMR_PHASE 9 
#define LMR_RED 1


#define DELTAPRUNE    
#define FUTILITY 
#define XFUTILITY 

//#define QMATE

/*
    extend iff:
        - stm NOT already ahead by LEMARGIN in material
        - depth+depth+ply < idepth+idepth+idepth
        
        ** BETTER against GES_136 without limits
*/


#define LEMARGIN 500   



/*
    depth, ply, and idepth
    
    When sum of remaining depth + ply deep < 2 x iteration depth, is ok to extend
*/


//#define MATETHREAT 
#define CHECK
//#define ONEREPLY  
//#define PAWN27TH 
//#define RTD
//#define RECAPTURE

extern const int pval[16];
extern const int mval[16];
extern const int cval[16];
extern const int fval[16];
extern const int rank7[192];
extern const int rank67[2][192];
extern const int border[192];
extern const int btrap[192];
extern const int f_curve[128];
extern FILE * debuglog;
extern FILE * trace;
extern FILE * blunders;

extern int board[256];
extern int epsquare;
extern int ext_pawn, ext_check, ext_1rep, ext_threat, ext_etd, ext_end, ext_recap, ext_real;
extern int fails;
extern int fhn, fh1;
extern int fifty;
extern int followpv;
extern int force[2];
extern int idepth;


extern int killer0[MAXPLY];
extern int killer1[MAXPLY];
extern int killer2[MAXPLY];
extern int kingsq[2];
extern int misses;
extern int nodes;
extern int marker;
extern int ply;
extern int probes;
extern int used;
extern int pseudoev[256];
extern int pvl[MAXPLY];
extern int qnodes;
extern int evals;
extern int red_nohist;
extern int red_razor;
extern int red_delta;
extern int red_futile;
extern int red_xfutile;
extern int red_null_fh;
extern int researches;
extern int sdepth;
extern int qdepth;
extern int shallow;
extern int stm;
extern int stop_search;
extern sHISTDATA * mhs;
extern sHISTDATA move_history[512];
extern sMOVES * last_move[MAXPLY];
extern sMOVES move_list[4096];
extern UI64 key;
extern UI64 st;
extern UI64 zobrist[nbPieces][192];
extern uMOVE pv[MAXPLY][MAXPLY];
extern unsigned int history[2][64*64];
extern unsigned int histcnt[2][64*64];
extern int types[16];
extern /*const*/ char pst[16][192];

extern int rootalpha;
extern int rootbeta;
extern int rootphase;

extern char ms[128];

extern int distance[256];

extern int mb_best;

extern float bf; 

int material(int * drawn);
void eclear(void);
int evaluate(void);


int inCheck(int c);
int attacked(int side, int sq);
int raytrace(int vs);
int next(sMOVES *m, int targ);


int squies(int alpha, int beta);
int rep(void);
int rep2(void);
int rep3(void);
int danger_move(const uMOVE * m);
int passer_move(uMOVE *m);
int passer_on_7th(int c);
int val_move(uMOVE *m);
int big_potential_move(uMOVE *m);
int big_potential_caps(uMOVE *m);
int opti_cap(int c);
int full_search(int depth, int alpha, int beta, int ntype, int flags);




int tagpv(sMOVES *m, int targ, int score);
int tally_exchanges(void);
int think(int maxtime, int reserve, int maxdeep);
sHASHENTRY * probe(void);
sMOVES * find_move(int l, int sm);
UI64 _tick(void);
int Bioskey(void);
void agehash(void);
void bubblemvs(void);
void clearhash(void);
void display(void);
void domove(const uMOVE *);
void freshen(sHASHENTRY * h);
void gen(void);
int genc(void);
void hbump(const uMOVE *, int);
void htry(const uMOVE *, int);
void hflat(int c, const uMOVE * m, int d);
int damp_history(int d);
int hget(const uMOVE * m);
void move2str(uMOVE * m, char * s);
void npop(void);
void npush(void);
void printmv(const uMOVE *m);
void setup(char *);
void sortmvs(sMOVES * fm);
void sorthmvs(sMOVES * fm);
void stuffpv(int m, int draft);
void store(int type, int draft, int score, int best_move, int threat);
void unmove(void);
void buildepd(char *);


int checkboard(void);
int checkmove(uMOVE *);
int move_is_legal(uMOVE * mv);
int isdrawn(void);

int return_ks(int s);




#endif /* SEARCHH_INCLUDED */
