#define PC_PAWN_UNMOVED 1
#define PC_PAWN_MOVED 2
#define PC_ROOK 3
#define PC_KNIGHT 4
#define PC_BISHOP 5
#define PC_QUEEN 6
#define PC_KING 7

#define PC_WHITE 0x00
#define PC_BLACK 0x08
#define PC_MOVED 0x80 // for kings and rooks to know when castling is possible
#define PC_PAWN_ENPASS 0x40 // to indicate that this pawn can be killed via en passant
                            // set this bit at the end of double move
                            // unset this bit at the end of any other turn


struct board
{
  unsigned char tiles[8][8];
};

struct coord
{
  unsigned char row; // for memcmp() this struct must not contain bitfields
  unsigned char col;
};

struct screen_coord
{
  unsigned x;
  unsigned y;
};

#define TURN_WHITE 0
#define TURN_BLACK 1

struct movecoords
{
  struct coord src;
  struct coord dst;
};

struct move
{
  struct movecoords coords;
  unsigned resign:1;
  unsigned staledraw:1;
  int32_t score;
  unsigned char ascend;
  unsigned char checkmate_found;
};

struct pmove
{
  struct movecoords coords;
  unsigned resign:1;
};

struct piece_all_moves
{
  unsigned char move_count;
  struct move moves[MAX_MOVES];
  struct coord legal_moves[MAX_MOVES];
};

struct game_position
{
  struct board board;
//  unsigned turn:1;
};

#define LAST_MOVES_COUNT 0x100
#define LAST_MOVES_MASK 0xFF

struct lastmove
{
  struct movecoords coords;
  unsigned chk:3;
};

struct last_moves
{
  struct game_position position[LAST_MOVES_COUNT];
  struct lastmove lastmoves[LAST_MOVES_COUNT];
  unsigned char index;
};


struct game_status
{
  struct last_moves last_moves;
  unsigned moves_pawn_capture;
  unsigned long move_start_time;
  unsigned long white_time;
  unsigned long black_time;
  unsigned turn:1;
  unsigned resign_asked:1;
};

struct piece_count
{
  unsigned char queen_count;
  unsigned char rook_count;
  unsigned char bishop_count;
  unsigned char knight_count;
  unsigned char pawn_count;
};

struct menuitem
{
  char *str;
  int (*fnptr)(void*);
  struct menu *submenu;
  unsigned char *value;
  unsigned *time;
  char **choices;
  unsigned char *minvalue;
  unsigned char *maxvalue;
  unsigned passive:1;
};

struct menu
{
  struct menuitem *menuitems;
  signed char menuitem_count;
  unsigned prev:1;
};

struct opening
{
  unsigned char moves_left;
  unsigned char move_count;
  char name[64];
//  char (*moves)[7];
  struct movecoords *moves;
  struct board pos;
};



struct bitmap
{
  unsigned char height;
  unsigned char width;
  unsigned char *bitmap;
};

struct movekeys
{
  int up:1;
  int down:1;
  int left:1;
  int right:1;
};

struct entitybitmap
{
  unsigned char height;
  unsigned char width;
  unsigned char depth;
  unsigned char *front;
  unsigned char *right;
  unsigned char *left;
  unsigned char *back;
  unsigned char *bottom;
  unsigned char *top;
};

