#ifndef DEFH_INCLUDED
#define DEFH_INCLUDED
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#include<assert.h>
#include<stdlib.h>
#include<math.h>
#ifndef _WIN32
#define min(a, b) (((a)<(b))? (a) : (b))
#define max(a, b) (((a)>(b))? (a) : (b))
//#define min(a, b) MIN((a), (b))
//#define max(a, b) MAX((a), (b))
//#define abs(a) ABS(a)
#endif
#define ASSERT(a) (void)(0)
#define VERSION "091007 JA"
#define MF 34
#define MAXPLY 64
#define MATE 10001
#define MAXPOS 500
#define MAXPOSGAIN 100
#define MAXPOSGAIN2 250
#define MAXPOSNGAIN 500
#define TIMECHECK 4096
#define SEE
#define HASHSIZE 2097152
#define EHASHSIZE 1048576
#define NO_ENTRY 0
#define FAIL_LOW 1
#define EXACT_PV 2
#define FAIL_HIGH 3
/*
 * bit:  4(8)  3(4) 2(2) 1(1)    P=2 N=4 K=6 MT=0 OB=8 sli   lat  dia  col
 * note: 1 & 9 unused
 */
enum Pieces {
	MT, BP = 2, WP, BN, WN, BK, WK, OB, BB = 10, WB, BR, WR, BQ, WQ, nbPieces
};
#define IS_WHITE(p) (((p)&1) && ((p)&6))
#define IS_BLACK(p) (!((p)&1) && ((p)&6))
#define BLACK 0
#define WHITE 1
enum Squares {
	A1 = 64, B1, C1, D1, E1, F1, G1, H1,
	A2 = 80, B2, C2, D2, E2, F2, G2, H2,
	A3 = 96, B3, C3, D3, E3, F3, G3, H3,
	A4 = 112, B4, C4, D4, E4, F4, G4, H4,
	A5 = 128, B5, C5, D5, E5, F5, G5, H5,
	A6 = 144, B6, C6, D6, E6, F6, G6, H6,
	A7 = 160, B7, C7, D7, E7, F7, G7, H7,
	A8 = 176, B8, C8, D8, E8, F8, G8, H8,
	nbSquares
};
#define FILE(sq) ((sq) & 7)
#define RANK(sq) (((sq)-A1) >> 4)
#define SQUARE(r,f) (A1 + ((r << 4) | f))
#define Ox88to64(n) (((n)&7) + ((((n)-A1)&0xf0)>>1))
/*
typedef struct{
    unsigned long long key;
    sMOVES *last;
    int killer1, killer2;
    int pvl;
    int pv[MAXPLY];
    int castle;
    int enpassant;
    int victim;
}sSEARCHDATA;
typedef struct{
    int board[120];
    sMOVES moves[4096];
    int alpha;
    int beta;
    sPLY ply[MAXPLY];
}sTREE;
sTREE tree[1];
(*tree->ply)->killer = 0;
uMOVE * m = (*(tree->ply-1)->last;
only need certain info 'within' search AND not needing all of game history
struct sSearch
struct sGame
*/
enum Movetype {
	CAP, KAP, PRO, ENP, CAK, CAQ, PP2, NOM, KMV
};
enum Threat_t {
IN_CHECK = 1, MATE_THREAT = 2, ONE_REPLY = 4, EMPTY = 8, RECAP = 16, REAL = 32, GOOD_MOVE = 64, NM_TRIED = 128, ALL_THREATS = 255};
#ifdef _MSC_VER
typedef unsigned __int64 UI64;
#else
typedef unsigned long long UI64;
#endif
typedef struct {
	unsigned char   type;
	              
	unsigned char   from;
	unsigned char   dest;
	unsigned char   piece;
	              
}               sMOVE;
typedef union {
	sMOVE           data;
	int             asint;
}               uMOVE;
typedef struct {
	uMOVE           move;
	int             score;
}               sMOVES;
typedef struct {
	UI64            key;
	uMOVE           move;
	unsigned int    victim;
	unsigned int    victii;
	unsigned int    fifty;
	unsigned int    epsquare;
	unsigned int    castle;
	unsigned int    threat;
	unsigned int    nm_refutation;
}               sHISTDATA;
typedef struct {
	unsigned int    best_move;
	unsigned int    lock;
	int             value;
	/*
	 * unused  threat       age  type  draft 0000000000  000000  00000000
	 * 00 000000
	 */
	unsigned int    data;
}               sHASHENTRY;

typedef struct {
	unsigned int    lock;
	int             score;
}               sEHASHENTRY;

/*
typedef struct {
	int             shield;
	int             elevation;
	int             storm;
	int             offenders;
	int             defenders;
	int             total;
}               KINGDANGER;

typedef struct {
	int             raw;
	int             pair;
	int             pawn;
	int             imbalance;
	int             denom;
}               MATERIAL;

typedef struct {
	int             pst;
	int             weak;
	int             doubled;
	int             onopen;
	int             attacked;
}               PAWN;

typedef struct {
	int             trapped;
	int             unmoved;
	int             mobility;
	int             menace;
}               ACTIVE;

typedef struct {
	int             total;
	int             location;
	int             shield;
	int             storm;
	int             offenders;
	int             defenders;
	int             attacks;
	int             coordinated;
}               KINGSAFE;

typedef struct {
	int             count;
	int             won;
	int             outside;
	int             candidate;
	int             base;
	int             bonus;
	int             malis;
}               PASSER;

typedef struct {
	int             phase;
	int             total;
	MATERIAL        material;
	PAWN            pawns;
	ACTIVE          activity;
	KINGSAFE        kingsafe;
	PASSER          passers;
}               EVAL;
*/

enum Feature_t {
	MATERIAL,
	ACTIVITY,
	PIECESQUARE,
	MENACE,
	TROPISM,
	SAFETY,
	SHIELD,
	OFFENSE,
	PASSERS,
	WEAKNESS,
	nbFeatures
	};
	


/*
typedef struct{
    int best_move;
    sMOVES *last;
    int killer0, killer1, killer2;
    int pvl;
    int pv[MAXPLY];
    int bits;
    int null_refutation;
    int pv_score;
    int pv_material; 
}sPLY;
*/
#endif				/* DEFH_INCLUDED */
