xchess.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* This file contains code for X-CHESS.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. This file is part of X-CHESS.
  4. X-CHESS is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the X-CHESS General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. X-CHESS, but only under the conditions described in the
  12. X-CHESS General Public License. A copy of this license is
  13. supposed to have been given to you along with X-CHESS so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. /* RCS Info: $Revision: 1.5 $ on $Date: 86/11/26 12:11:39 $
  18. * $Source: /users/faustus/xchess/RCS/xchess.h,v $
  19. * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
  20. * Permission is granted to do anything with this code except sell it
  21. * or remove this message.
  22. *
  23. * Definitions for the X chess program.
  24. */
  25. #include "std.h"
  26. #include <X/Xlib.h>
  27. #include "scrollText/scrollText.h"
  28. #define SIZE 8
  29. typedef enum piecetype { PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING } piecetype;
  30. typedef enum movetype { MOVE, QCASTLE, KCASTLE, CAPTURE } movetype;
  31. typedef enum color { WHITE, BLACK, NONE } color;
  32. typedef struct piece {
  33. enum piecetype type;
  34. enum color color;
  35. } piece;
  36. /* The board has y=0 and black at the top... This probably isn't the best
  37. * place to keep track of who can castle, but it's part of the game state...
  38. */
  39. typedef struct board {
  40. piece square[SIZE][SIZE];
  41. bool white_cant_castle_k;
  42. bool white_cant_castle_q;
  43. bool black_cant_castle_k;
  44. bool black_cant_castle_q;
  45. } board;
  46. typedef struct move {
  47. movetype type;
  48. piece piece;
  49. piece taken;
  50. int fromx, fromy;
  51. int tox, toy;
  52. struct move *next;
  53. bool enpassant;
  54. bool check;
  55. } move;
  56. #define iswhite(win, i, j) (!(((i) + (j)) % 2))
  57. /* Stuff for the display. */
  58. typedef struct windata {
  59. Display *display;
  60. Window basewin;
  61. Window boardwin;
  62. Window recwin;
  63. Window wclockwin;
  64. Window bclockwin;
  65. Window messagewin;
  66. Window buttonwin;
  67. Window jailwin;
  68. Window icon;
  69. Pixmap iconpixmap;
  70. Color blackpiece;
  71. Color whitepiece;
  72. Color blacksquare;
  73. Color whitesquare;
  74. Color border;
  75. Color textcolor;
  76. Color textback;
  77. Color errortext;
  78. Color playertext;
  79. Color cursorcolor;
  80. FontInfo *small;
  81. FontInfo *medium;
  82. FontInfo *large;
  83. bool bnw;
  84. color color;
  85. bool flipped;
  86. double whitehands[3];
  87. double blackhands[3];
  88. char *txtassoc;
  89. } windata;
  90. #define SMALL_FONT "6x10"
  91. #define MEDIUM_FONT "vtsingle"
  92. #define LARGE_FONT "corfx"
  93. #define JAIL_FONT "ctl25fx"
  94. #define SQUARE_WIDTH 80
  95. #define SQUARE_HEIGHT 80
  96. #define BORDER_WIDTH 3
  97. #define BOARD_WIDTH 8 * SQUARE_WIDTH + 7 * BORDER_WIDTH
  98. #define BOARD_HEIGHT 8 * SQUARE_HEIGHT + 7 * BORDER_WIDTH
  99. #define BOARD_XPOS 0
  100. #define BOARD_YPOS 0
  101. #define RECORD_WIDTH 265 /* 40 chars * 6 pixels / character. */
  102. #define RECORD_HEIGHT 433
  103. #define RECORD_XPOS BOARD_WIDTH + BORDER_WIDTH
  104. #define RECORD_YPOS 0
  105. #define JAIL_WIDTH RECORD_WIDTH
  106. #define JAIL_HEIGHT 163
  107. #define JAIL_XPOS RECORD_XPOS
  108. #define JAIL_YPOS RECORD_YPOS + RECORD_HEIGHT + BORDER_WIDTH
  109. #define CLOCK_WIDTH 131
  110. #define CLOCK_HEIGHT 131 + BORDER_WIDTH + 20
  111. #define WCLOCK_XPOS RECORD_XPOS
  112. #define WCLOCK_YPOS RECORD_HEIGHT + JAIL_HEIGHT + BORDER_WIDTH * 2
  113. #define BCLOCK_XPOS WCLOCK_XPOS + CLOCK_WIDTH + BORDER_WIDTH
  114. #define BCLOCK_YPOS WCLOCK_YPOS
  115. #define MESS_WIDTH 329
  116. #define MESS_HEIGHT 92
  117. #define MESS_XPOS 0
  118. #define MESS_YPOS BOARD_HEIGHT + BORDER_WIDTH
  119. #define BUTTON_WIDTH MESS_WIDTH
  120. #define BUTTON_HEIGHT MESS_HEIGHT
  121. #define BUTTON_XPOS MESS_WIDTH + BORDER_WIDTH
  122. #define BUTTON_YPOS MESS_YPOS
  123. #define BASE_WIDTH BOARD_WIDTH + RECORD_WIDTH + BORDER_WIDTH * 3
  124. #define BASE_HEIGHT BOARD_HEIGHT + MESS_HEIGHT + BORDER_WIDTH * 3
  125. #define BASE_XPOS 50
  126. #define BASE_YPOS 50
  127. #define BLACK_PIECE_COLOR "#202020"
  128. #define WHITE_PIECE_COLOR "#FFFFCC"
  129. #define BLACK_SQUARE_COLOR "#67925D"
  130. #define WHITE_SQUARE_COLOR "#C8C365"
  131. #define BORDER_COLOR "#902E39"
  132. #define TEXT_COLOR "#006D6D"
  133. #define TEXT_BACK "#FFFFDD"
  134. #define ERROR_TEXT "Red"
  135. #define PLAYER_TEXT "Blue"
  136. #define CURSOR_COLOR "#FF606F"
  137. #define DEF_RECORD_FILE "xchess.game"
  138. #define NUM_FLASHES 5
  139. #define FLASH_SIZE 10
  140. /* xchess.c */
  141. extern void main();
  142. extern bool debug;
  143. extern char *progname;
  144. extern char *proghost;
  145. extern char *piecenames[];
  146. extern char *colornames[];
  147. extern char *movetypenames[];
  148. extern char *dispname1, *dispname2;
  149. extern bool oneboard;
  150. extern bool bnwflag;
  151. extern bool progflag;
  152. extern bool blackflag;
  153. extern bool quickflag;
  154. extern int num_flashes;
  155. extern int flash_size;
  156. extern char *black_piece_color;
  157. extern char *white_piece_color;
  158. extern char *black_square_color;
  159. extern char *white_square_color;
  160. extern char *border_color;
  161. extern char *text_color;
  162. extern char *text_back;
  163. extern char *error_text;
  164. extern char *player_text;
  165. extern char *cursor_color;
  166. /* board.c */
  167. extern void board_setup();
  168. extern void board_drawall();
  169. extern void board_move();
  170. extern board *chessboard;
  171. extern void board_init();
  172. /* window.c */
  173. extern bool win_setup();
  174. extern void win_redraw();
  175. extern void win_restart();
  176. extern void win_drawboard();
  177. extern void win_drawpiece();
  178. extern void win_erasepiece();
  179. extern void win_process();
  180. extern void win_flash();
  181. extern windata *win1, *win2;
  182. extern bool win_flashmove;
  183. /* control.c */
  184. extern void button_pressed();
  185. extern void button_released();
  186. extern void move_piece();
  187. extern void prog_move();
  188. extern move *moves;
  189. extern move *foremoves;
  190. extern color nexttomove;
  191. extern void replay();
  192. extern void forward();
  193. extern void cleanup();
  194. extern void restart();
  195. extern bool noisyflag;
  196. /* valid.c */
  197. extern bool valid_move();
  198. /* record.c */
  199. extern void record_move();
  200. extern void record_reset();
  201. extern void record_save();
  202. extern void record_back();
  203. extern void record_init();
  204. extern void record_end();
  205. extern bool record_english;
  206. extern char *record_file;
  207. extern int movenum;
  208. extern bool saveflag;
  209. /* message.c */
  210. extern void message_init();
  211. extern void message_add();
  212. extern void message_send();
  213. /* clock.c */
  214. extern void clock_init();
  215. extern void clock_draw();
  216. extern void clock_update();
  217. extern void clock_switch();
  218. extern bool clock_started;
  219. extern int movesperunit;
  220. extern int timeunit;
  221. extern int whiteseconds;
  222. extern int blackseconds;
  223. /* button.c */
  224. extern void button_draw();
  225. extern void button_service();
  226. /* jail.c */
  227. extern void jail_init();
  228. extern void jail_draw();
  229. extern void jail_add();
  230. extern void jail_remove();
  231. /* program.c */
  232. extern bool program_init();
  233. extern void program_end();
  234. extern void program_send();
  235. extern void program_undo();
  236. extern move *program_get();
  237. /* parse.c */
  238. extern void load_game();
  239. extern move *parse_file();
  240. extern move *parse_move();
  241. extern move *parse_imove();
  242. extern bool loading_flag;
  243. extern bool loading_paused;
  244. /* popup.c */
  245. extern bool pop_question();