home *** CD-ROM | disk | FTP | other *** search
/ Ragnaroek / Ragnaroek.img / OpponentApp / GameState.h < prev    next >
Text File  |  1991-12-08  |  2KB  |  85 lines

  1. #import <objc/Object.h>
  2.  
  3. struct move {unsigned char from, to;};
  4. struct spot {unsigned char who, idnum;};
  5. struct capture {short when; unsigned char where, idnum;};
  6.  
  7. extern const unsigned char board[256];
  8. extern BOOL pawn_legal[256];
  9. extern BOOL loki_legal[256];
  10.  
  11. #define OFFBOARD  0
  12. #define PLAIN     1
  13. #define CENTER    2
  14. #define CORNER    3
  15. #define CAPTURE_HELPER(where) (board[where] > PLAIN)
  16.  
  17. typedef void (*IMPMakeMove)(id, SEL, struct move);
  18. extern IMPMakeMove makeMove, makeWhiteMove, makeBlackMove;
  19.  
  20. typedef void (*IMPUndoMove)(id, SEL);
  21. extern IMPUndoMove undoMove, undoWhiteMove, undoBlackMove;
  22.  
  23. typedef BOOL (*IMPAnyLegalMoves)(id, SEL);
  24. extern IMPAnyLegalMoves anyLegalMoves;
  25.  
  26. @interface GameState:Object
  27. {
  28. @public
  29.  
  30. unsigned char pieceLocs[37];
  31. #define XYTONUM(x,y) ( ((x)+2) + ((y)+2)*16 )
  32. #define NUMTOX(num)  (((num) % 16) - 2)
  33. #define NUMTOY(num)  (((num) / 16) - 2)
  34. #define EAST    1
  35. #define WEST   -1
  36. #define NORTH  16
  37. #define SOUTH -16
  38.  
  39. struct spot pieces[256];
  40. #define NOBODY 0
  41. #define W_PAWN 1
  42. #define B_PAWN 2
  43. #define LOKI   3
  44. #define UNOCCUPIED(where) (pieces[(where)].who == NOBODY)
  45. #define WHITEPIECE(where) (pieces[(where)].who == W_PAWN)
  46. #define BLACKPIECE(where) (pieces[(where)].who >= B_PAWN)
  47.  
  48. unsigned char whoseTurn; 
  49. #define BLACK     0
  50. #define WHITE     1
  51. #define BLACK_WON 2
  52. #define WHITE_WON 3
  53. #define DRAW      4
  54. #define GAMEOVER(whoseTurn)  ((whoseTurn) >= 2)
  55.  
  56. unsigned char numPawns[2];
  57.  
  58. struct move moves[1024];
  59. short numMoves;
  60.  
  61. struct capture captures[36];
  62. short numCaptures;
  63. }
  64.  
  65. + initialize;
  66.  
  67. - init;
  68. - (void)resetState;
  69.  
  70. - (void)makeMove:(struct move)request;
  71. - (void)makeWhiteMove:(struct move)request;
  72. - (void)makeBlackMove:(struct move)request;
  73.  
  74. - (void)undoMove;
  75. - (void)undoWhiteMove;
  76. - (void)undoBlackMove;
  77.  
  78. - (BOOL)anyLegalMoves;
  79. - (BOOL)checkMove:(struct move)request;
  80.  
  81. - read:(NXTypedStream *)stream;
  82. - write:(NXTypedStream *)stream;
  83.  
  84. @end
  85.