xchess.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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:32 $
  18. * $Source: /users/faustus/xchess/RCS/xchess.c,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. #define USAGE "xchess [ -d ] [ -f recordfile ] [ -r savedfile ] [ -i ]\n\
  24. \t[ -t moves/timeunit ] [ -c ] [ -p program ] [ -b ] [ -bnw ] [ -s ]\n\
  25. \t[ -n ] [ -h host ] [ -v ] [ -R ] [ whitedisplay ] [ blackdisplay ]"
  26. #include "xchess.h"
  27. bool debug = false;
  28. bool oneboard = false;
  29. bool bnwflag = false;
  30. bool progflag = false;
  31. bool blackflag = false;
  32. bool quickflag = false;
  33. char *progname = DEF_PROGRAM;
  34. char *proghost = NULL;
  35. char *piecenames[] = { "pawn", "rook", "knight", "bishop", "queen", "king" } ;
  36. char *colornames[] = { "white", "black", "none" } ;
  37. char *movetypenames[] = { "move", "qcastle", "kcastle", "capture" } ;
  38. char *dispname1 = NULL, *dispname2 = NULL;
  39. char *black_piece_color = BLACK_PIECE_COLOR;
  40. char *white_piece_color = WHITE_PIECE_COLOR;
  41. char *black_square_color = BLACK_SQUARE_COLOR;
  42. char *white_square_color = WHITE_SQUARE_COLOR;
  43. char *border_color = BORDER_COLOR;
  44. char *text_color = TEXT_COLOR;
  45. char *text_back = TEXT_BACK;
  46. char *error_text = ERROR_TEXT;
  47. char *player_text = PLAYER_TEXT;
  48. char *cursor_color = CURSOR_COLOR;
  49. int num_flashes = NUM_FLASHES;
  50. int flash_size = FLASH_SIZE;
  51. void
  52. main(ac, av)
  53. char **av;
  54. {
  55. char *program = av[0];
  56. char *recfile = NULL, *s;
  57. bool randflag = false;
  58. move *m;
  59. /* Process args. */
  60. av++; ac--;
  61. while (**av == '-') {
  62. if (eq(*av, "-d")) {
  63. debug = true;
  64. } else if (eq(*av, "-f")) {
  65. av++; ac--;
  66. if (*av)
  67. record_file = *av;
  68. else
  69. goto usage;
  70. } else if (eq(*av, "-r")) {
  71. av++; ac--;
  72. if (*av)
  73. recfile = *av;
  74. else
  75. goto usage;
  76. } else if (eq(*av, "-i")) {
  77. record_english = false;
  78. } else if (eq(*av, "-R")) {
  79. randflag = true;
  80. } else if (eq(*av, "-v")) {
  81. win_flashmove = true;
  82. } else if (eq(*av, "-q")) {
  83. quickflag = true;
  84. } else if (eq(*av, "-t")) {
  85. av++; ac--;
  86. if (*av) {
  87. movesperunit = atoi(*av);
  88. if (s = index(*av, '/'))
  89. timeunit = atoi(s + 1);
  90. else
  91. timeunit = 60;
  92. } else
  93. goto usage;
  94. } else if (eq(*av, "-p")) {
  95. av++; ac--;
  96. if (*av)
  97. progname = *av;
  98. else
  99. goto usage;
  100. } else if (eq(*av, "-h")) {
  101. av++; ac--;
  102. if (*av)
  103. proghost = *av;
  104. else
  105. goto usage;
  106. } else if (eq(*av, "-b")) {
  107. blackflag = true;
  108. } else if (eq(*av, "-c")) {
  109. progflag = true;
  110. } else if (eq(*av, "-bnw")) {
  111. bnwflag = true;
  112. } else if (eq(*av, "-s")) {
  113. saveflag = true;
  114. } else if (eq(*av, "-n")) {
  115. noisyflag = true;
  116. } else
  117. goto usage;
  118. av++; ac--;
  119. }
  120. if (ac > 0)
  121. dispname1 = av[0];
  122. if (ac > 1)
  123. dispname2 = av[1];
  124. if (ac > 2)
  125. goto usage;
  126. if (!dispname2)
  127. oneboard = true;
  128. srandom(getpid());
  129. if (!oneboard && randflag && (random() % 2)) {
  130. s = dispname1;
  131. dispname1 = dispname2;
  132. dispname2 = s;
  133. }
  134. if (!dispname1)
  135. dispname1 = getenv("DISPLAY");
  136. /* Now get boolean defaults... */
  137. if ((s = XGetDefault(program, "noisy")) && eq(s, "on"))
  138. noisyflag = true;
  139. if ((s = XGetDefault(program, "savemoves")) && eq(s, "on"))
  140. saveflag = true;
  141. if ((s = XGetDefault(program, "algebraic")) && eq(s, "on"))
  142. record_english = false;
  143. if ((s = XGetDefault(program, "blackandwhite")) && eq(s, "on"))
  144. bnwflag = true;
  145. if ((s = XGetDefault(program, "quickrestore")) && eq(s, "on"))
  146. quickflag = true;
  147. if ((s = XGetDefault(program, "flash")) && eq(s, "on"))
  148. win_flashmove = true;
  149. /* ... numeric variables ... */
  150. if (s = XGetDefault(program, "numflashes"))
  151. num_flashes = atoi(s);
  152. if (s = XGetDefault(program, "flashsize"))
  153. flash_size = atoi(s);
  154. /* ... and strings. */
  155. if (s = XGetDefault(program, "progname"))
  156. progname = s;
  157. if (s = XGetDefault(program, "proghost"))
  158. proghost = s;
  159. if (s = XGetDefault(program, "recordfile"))
  160. recfile = s;
  161. if (s = XGetDefault(program, "blackpiece"))
  162. black_piece_color = s;
  163. if (s = XGetDefault(program, "whitepiece"))
  164. white_piece_color = s;
  165. if (s = XGetDefault(program, "blacksquare"))
  166. black_square_color = s;
  167. if (s = XGetDefault(program, "whitesquare"))
  168. white_square_color = s;
  169. if (s = XGetDefault(program, "bordercolor"))
  170. border_color = s;
  171. if (s = XGetDefault(program, "textcolor"))
  172. text_color = s;
  173. if (s = XGetDefault(program, "textback"))
  174. text_back = s;
  175. if (s = XGetDefault(program, "errortext"))
  176. error_text = s;
  177. if (s = XGetDefault(program, "playertext"))
  178. player_text = s;
  179. if (s = XGetDefault(program, "cursorcolor"))
  180. cursor_color = s;
  181. /* Set up the board. */
  182. board_setup();
  183. /* Create the windows. */
  184. win_setup(dispname1, dispname2);
  185. board_drawall();
  186. /* Start the program if necessary. */
  187. if (progflag)
  188. if (!program_init(progname))
  189. exit(1);
  190. XSync(0);
  191. if (recfile)
  192. load_game(recfile);
  193. /* Go into a loop of prompting players alternately for moves, checking
  194. * them, and updating things.
  195. */
  196. for (;;) {
  197. win_process(false);
  198. clock_update();
  199. if (progflag && ((!blackflag && (nexttomove == BLACK)) ||
  200. (blackflag && (nexttomove == WHITE)))) {
  201. m = program_get();
  202. if (m)
  203. prog_move(m);
  204. }
  205. }
  206. usage: fprintf(stderr, "Usage: %s\n", USAGE);
  207. exit(1);
  208. }