#define MYPIECE -1
#define EMPTY 1
#define OPPIECE 0
#define ILLEGAL 2

#define LocAltX(l) (l).x2
#define LocAltY(l) (l).y2
#define LocationX(l)  (l).x
#define LocationY(l)  (l).y
#define LocationWhere(l)  (l).where

#define OFFBOARD 0
#define ONBOARD 1
#define INMYTRAY 2
#define INOPTRAY 3
#define INYOURHAND 4
#define ALTERNATE 5
#define COVERED 6

typedef struct Location_struct {
  int x, y;
  int where;
  int x2, y2;
  struct Table_struct *table;
} Location;


#define PieceLocation(p) ((p)->location)
#define PieceBaseX(p) LocationX((p)->location)
#define PieceBaseY(p) LocationY((p)->location)
#define PieceAltX(p) LocAltX((p)->location)
#define PieceAltY(p) LocAltY((p)->location)
#define PieceWhere(p) LocationWhere((p)->location)
#define PieceTable(p) ((p)->table)
#define PieceSetColor(p, c) ((p)->color = c)
#define PieceColor(p) ((p)->color)
#define PieceSetType(p, t) ((p)->type = t)
#define PieceType(p) ((p)->type)
#define PieceMoveStatus(p) ((p)->moved)

typedef struct Piece_struct {
  Location location;
  int type; 
  int color;
  struct Table_struct *table;
  int moved;
} Piece;

#define BoardTable(b) ((b)->table)
#define BoardXYPiece(b,x,y) ((b)->grid[x][y])
typedef struct Board_struct { 
  Piece *grid[8][8];
  struct Table_struct *table;
} Board;


#define TrayXYPiece(b,x,y) ((b)->grid[x][y])
typedef struct Tray_struct {
  Piece *grid[8][2];
  struct Table_struct *table;
} Tray;

#define TablePiece(t,i) ((t)->pieces[i])
#define TableBoard(t) ((t)->board)
#define TableTray(t,who) ((t)->tray[who])
#define TableMyTray(t) ((t)->tray[(t)->mycolor])
#define TableOpTray(t) ((t)->tray[!((t)->mycolor)])
#define TableWindow(t) ((t)->window)
#define TableClock(t) ((t)->clock)
#define TablePieceMoveStatus(t,i ) ((t)->pieces[i].moved)

#define DONTSET -1

#define SetTableBoardPiece(t,x,y,p) (BoardXYPiece(&(TableBoard(t)),x,y) = p)
#define SetTableMyTrayPiece(t,x,y,p) (BoardXYPiece(&(TableMyTray(t)),x,y) = p)
#define SetTableOpTrayPiece(t,x,y,p) (BoardXYPiece(&(TableOpTray(t)),x,y) = p)

typedef struct Table_struct {
  struct clock_data *clock; 
  Piece pieces[64];
  Board board;
  Tray tray[2];
  Window window;
  char mycolor;
} Table;

 
#define CoordX(c) c.x
#define CoordY(c) c.y

typedef struct Coord_struct {
  int x,y;
} Coord;

#define DULL 0
#define CASTLE 1
#define SOMEFRENCHWORD 2
#define PROMOTION 3

#define SpecialType(s) ((s)->type)
#define SpecialNewPiece(s) ((s)->new)
#define SpecialOldPiece(s) ((s)->old)
#define SpecialOldPiecePtr(s) ((s)->oldptr)

typedef struct Special_struct {
  int type; 
  Piece old, *oldptr, new;
} Special;


#define NOTGRABBED 0
#define GRABBED 1
#define FIXED 2
#define MoveFromLoc(m) ((m)->from)
#define MoveToLoc(m) ((m)->to)
#define MoveStatus(m) ((m)->status)
#define MovePieceTaken(m) ((m)->piecetaken)
#define MovePieceTakenPtr(m) ((m)->takenptr)
#define MovePiece(m) ((m)->piecegrabbed)
#define MovePiecePtr(m) ((m)->grabbedptr)
#define MoveMouseCoord(m) ((m)->mouseloc)
#define MoveMouseCoordX(m) (CoordX(((m)->mouseloc)))
#define MoveMouseCoordY(m) (CoordY(((m)->mouseloc)))
#define MovePixel(m) ((m)->pixel)
#define MovePixelX(m) (CoordX(((m)->pixel)))
#define MovePixelY(m) (CoordY(((m)->pixel)))
#define MoveSpecial(m) ((m)->cases)

typedef struct Move_struct {
  Location from,to;
  Coord pixel, mouseloc ;
  Piece piecegrabbed, *grabbedptr;
  Piece piecetaken, *takenptr;
  int status;
  Special cases;
  struct Move_struct *prev_move, *next_move;
} Move;



Piece *XY2Piece();
Move *InitMove();
Move *NewMove();
Piece *FindDeadPiece();
Piece **Search4Piece();
