home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume9 / othello2 / part03 / othello.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-27  |  6.7 KB  |  174 lines

  1.  
  2. /* @(#)othello.h 1.6 90/04/10
  3.  *
  4.  *  Definitions used by the othello program.
  5.  *
  6.  *  Original SunView version by Ed Falk - Sun Microsystems Inc.
  7.  *
  8.  *  Rewritten for independent use by
  9.  *          Rich Burridge, Sun Microsystems, Australia
  10.  *
  11.  *  Copyright (c) Ed Falk & Rich Burridge - Sun Microsystems.
  12.  *                                          All rights reserved.
  13.  *
  14.  *  Permission is given to distribute these sources, as long as the
  15.  *  introductory messages are not removed, and no monies are exchanged.
  16.  *
  17.  *  No responsibility is taken for any errors on inaccuracies inherent
  18.  *  either to the comments or the code of this program, but if reported
  19.  *  to me, then an attempt will be made to fix them.
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <sys/ioctl.h>
  25. #include <sys/types.h>
  26. #include <sys/time.h>
  27. #include <signal.h>
  28.  
  29. #define  FCLOSE        (void) fclose      /* To make lint happy. */
  30. #define  FFLUSH        (void) fflush
  31. #define  FSEEK         (void) fseek
  32. #define  FPRINTF       (void) fprintf
  33. #define  GETTIMEOFDAY  (void) gettimeofday
  34. #define  IOCTL         (void) ioctl
  35. #define  PUTC          (void) putc
  36. #define  READ          (void) read
  37. #define  SELECT        (void) select
  38. #define  SIGNAL        (void) signal
  39. #define  SPRINTF       (void) sprintf
  40. #define  STRCAT        (void) strcat
  41. #define  STRCPY        (void) strcpy
  42. #define  WRITE         (void) write
  43.  
  44. #define  BBORDER       15       /* Width of the othello border. */
  45. #define  BOARD_SIZE    8        /* 8x8 playing board */
  46. #define  BGAP          10       /* Width of the gap between buttons. */
  47. #define  BHEIGHT       32       /* Height of an othello button item. */
  48. #define  BWIDTH        64       /* Width of an othello button item. */
  49. #define  CELL_SIZE     (int) ((TOTAL_WIDTH-(2*BBORDER)) / BOARD_SIZE)
  50. #define  CHEIGHT       20       /* Height of an othello cycle item. */
  51. #define  CWIDTH        32       /* Width of an othello cycle item. */
  52. #define  CY            ((NOROWS*BHEIGHT) + ((NOROWS-1)*BGAP) + (2*BBORDER))
  53. #define  NOBUTS        6        /* Number of othello buttons. */
  54. #define  NOROWS        6        /* Number of rows of othello items. */
  55. #define  PIECE_MARGIN  8
  56. #define  PIECE_RAD     (CELL_SIZE / 2 - PIECE_MARGIN)
  57. #define  TOTAL_HEIGHT  CY + (8 * CELL_SIZE) + (2 * BBORDER)
  58. #define  TOTAL_WIDTH   ((NOBUTS*BWIDTH) + ((NOBUTS-1)*BGAP) + (2*BBORDER))
  59.  
  60. #define  BLACK         1       /* Piece definitions. */
  61. #define  FREE          0
  62. #define  WHITE         -1
  63.  
  64. #define  FALSE         0       /* Boolean definitions. */
  65. #define  TRUE          1
  66.  
  67. #define  ESCAPE        27      /* ASCII escape character. */
  68. #define  EQUAL(a, b)   !strncmp(a, b, strlen(b))
  69. #define  FOR_BOARD(i)  for (i = 0; i < 64; i++)
  70. #define  ICONHEIGHT    64      /* Height in pixels for Othello icon. */
  71. #define  ICONWIDTH     64      /* Width in pixels of Othello icon. */
  72. #define  INC           argc-- ; argv++ ;
  73. #define  INFINITY      10000
  74. #define  INIT_ASPIRE   3
  75. #define  INIT_DEPTH    2
  76. #define  ISMOVE(pos, player) \
  77.          (nextmove(pos, NOMOVE, (BOARD *) NULL, player) != NOMOVE)
  78. #define  MAXASPIRE     6
  79. #define  MAXCHOICES    7       /* Limit on number of choices for cyclic. */
  80. #define  MAXCURSORS    3       /* Maximum number of cursor types. */
  81. #define  MAXDEPTH      6
  82. #define  MAXFONTS      2       /* Maximum number of font types. */
  83. #define  MAXIMAGES     9       /* Maximum number of image types. */
  84. #define  MAXITEMS      13      /* Number of buttons, cyclics and messages. */
  85.  
  86. #ifndef  MAXLINE
  87. #define  MAXLINE       80      /* Length of character strings. */
  88. #endif /*MAXLINE*/
  89.  
  90. #define  MAXMENUS      4       /* Maximum number of popup menus. */
  91. #define  NOMOVE        -1
  92. #define  OPPONENT(p)   p * -1
  93. #define  PAUSE         usleep(500000)
  94. #define  PSIZE         40      /* Diameter of playing piece. */
  95.  
  96. #ifndef  REMNAME
  97. #define  REMNAME       "othello.remarks"
  98. #endif /*REMNAME*/
  99.  
  100. #ifndef  NO_4_3SIGNAL
  101. #define  SIGRET        void
  102. #else
  103. #define  SIGRET        int
  104. #endif /*NO_4_3SIGNAL*/
  105.  
  106. #define  VINVUL        50
  107.  
  108. #define  MAX_REMARKS   50
  109. #define  FIRST_REMARK  (INFINITY+1)
  110.  
  111. /* Various pseudo events used by the othello program. */
  112. #define  FRAME_REPAINT    100    /* Othello window needs repainting. */
  113. #define  ENTER_WINDOW     101    /* Mouse has entered the Othello window. */
  114. #define  EXIT_WINDOW      102    /* Mouse has exited Othello window. */
  115. #define  LEFT_DOWN        103    /* Left mouse button was depressed. */
  116. #define  LEFT_UP          104    /* Left mouse button was debounced. */
  117. #define  MIDDLE_DOWN      105    /* Middle mouse button was depressed. */
  118. #define  MIDDLE_UP        106    /* Middle mouse button was debounced. */
  119. #define  RIGHT_DOWN       107    /* Right mouse button was depressed. */
  120. #define  RIGHT_UP         108    /* Right mouse button was debounced. */
  121. #define  KEYBOARD         109    /* Keyboard character has been pressed. */
  122. #define  MOUSE_MOVING     110    /* Mouse is moving. */
  123. #define  IGNORE_EVENT     111    /* No interest in this event. */
  124.  
  125. /* Batch or locking direction (ON or OFF). */
  126. enum bltype   { IS_OFF, IS_ON } ;
  127.  
  128. /* Othello move status. */
  129. enum cantype  { WHITE_START, WHITE_MOVING,
  130.                 BLACK_START, BLACK_MOVING, GAME_OVER } ;
  131.  
  132. /* Current cursor type. */
  133. enum curtype  { CANVASCUR, HOURGLASS, NOCURSOR } ;
  134.  
  135. enum font_type { NFONT, BFONT } ;        /* Text font definitions. */
  136.  
  137. /* Different types of graphic images. */
  138. enum image_type { BUT_NORMAL, BUT_INVERT, BUT_STENCIL,
  139.                   CY_NORMAL, CY_LINVERT, CY_RINVERT, CY_STENCIL,
  140.                   P_WHITE, P_BLACK } ;
  141.  
  142. /* Different types of panel items. */
  143. enum item_type { P_BUTTON, P_CYCLE, P_MESSAGE } ;
  144.  
  145. /* Different panel items. */
  146. enum panel_type { DONE_BUT, LAST_BUT, NEW_GAME_BUT, SUGGEST_BUT, UNDO_BUT,
  147.                   QUIT_BUT, COMPUTER_PLAYS, REMARK, ASPIRATION, DIFFICULTY,
  148.                   PANEL_MES, REMARK_MES, SCORE_MES } ;
  149.  
  150. enum set_type { INCREMENT, DECREMENT, NONE } ;   /* Cycle directions. */
  151.  
  152. enum optype   { RCLR, RINV, RSRC } ;       /* Rasterop codes. */
  153.  
  154. enum playtype { PLAY_BLACK, PLAY_WHITE } ; /* What the computer is playing. */
  155.  
  156. char *getenv(), *sprintf() ;
  157.  
  158. typedef struct {
  159.           int square[64] ;
  160.           int moves_left ;
  161. } BOARD ;
  162.  
  163. struct iteminfo               /* Item information record. */
  164.   {
  165.     enum item_type type ;     /* Item type. */
  166.     int x ;                   /* X position of this panel item. */
  167.     int y ;                   /* Y position of this panel item. */
  168.     int width ;               /* Width of this panel item. */
  169.     int height ;              /* Height of this panel item. */
  170.     char text[60] ;           /* Text string associated with this item. */
  171.     int value ;               /* Current value of item. */
  172.     int (*func)() ;           /* Function to obey for this panel item. */
  173.   } ;
  174.