#ifndef GLOBAL_H
#define GLOBAL_H

#if defined(WIN32) || defined(WIN64)
#include <windows.h>
typedef unsigned __int64 uint64_t;
typedef __int64 int64_t;
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned short uint16_t;
typedef short int16_t;
typedef unsigned char uint8_t;
typedef signed char int8_t;
#define CONST64U(x) (x##UI64)
#define CONST64(x)  (x##I64)
#define SUFF64     "%I64u"
#define SUFF64_8   "%8I64u"
#else
#include <stdint.h>
#define CONST64U(x) (x##ull)
#define CONST64(x)  (x##ll)
#define SUFF64     "%ull"
#define SUFF64_8   "%8ull"
#endif

#if (_MSC_VER >= 1400) /* VC8+ Disable all deprecation warnings */
    #pragma warning(disable : 4996) 
#endif /* VC8+ */
#ifndef max
#define max(x, y) ((x) > (y) ? (x) : (y))
#endif
#ifndef min
#define min(x, y) ((x) < (y) ? (x) : (y))
#endif

#define DIE  (*(int *)(NULL) = 0)

#define WHITE 0
#define BLACK 1

#define TOMOVE        (!white_to_move)
#define NOTTOMOVE     (white_to_move)

/* define names for piece constants: */
#define frame   0
#define wpawn   1
#define bpawn   2
#define wknight 3
#define bknight 4
#define wbishop 5
#define bbishop 6
#define wking   7
#define bking   8
#define wrook   9
#define brook   10
#define wqueen  11
#define bqueen  12
#define npiece  13

#define PIECET(s,x)     ((((s)->board[(x)])+1)>>1)
#define PIECESIDE(s,x)  (((s)->board[(x)]+1)&1)

#define PIECETYPE(x)    (((x)+1)>>1)
#define PIECECOLOR(x)   (((x)+1)&1)

#define File(x)         ((x) & 7)
#define Rank(x)         ((x) >> 3)

#define pawn    1
#define knight  2
#define bishop  3
#define king    4
#define rook    5
#define queen   6


typedef struct {
    int from;
    int target;
    int captured;
    int promoted;	        
    int ep; 
    int cap_num;
    int epsq;      
} move_s;

typedef struct {
    int board[144];
    int pieces[33];
    int squares[144];    
    int wking_loc;
    int bking_loc;  
    int white_to_move;
    int ep_square;          
    int piece_count;             
} state_s;

typedef struct {
    int npieces[14];
    int pawnrank[2][8];
} matsig_s;

typedef uint64_t INDEX;

#define MOVE_BUFF     240
#define INF        100000
#define MATE           50
#define BROKEN         60

#endif
