Commit | Line | Data |
---|---|---|
cb290b32 C |
1 | |
2 | /* This file contains code for X-CHESS. | |
3 | Copyright (C) 1986 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of X-CHESS. | |
6 | ||
7 | X-CHESS is distributed in the hope that it will be useful, | |
8 | but WITHOUT ANY WARRANTY. No author or distributor | |
9 | accepts responsibility to anyone for the consequences of using it | |
10 | or for whether it serves any particular purpose or works at all, | |
11 | unless he says so in writing. Refer to the X-CHESS General Public | |
12 | License for full details. | |
13 | ||
14 | Everyone is granted permission to copy, modify and redistribute | |
15 | X-CHESS, but only under the conditions described in the | |
16 | X-CHESS General Public License. A copy of this license is | |
17 | supposed to have been given to you along with X-CHESS so you | |
18 | can know your rights and responsibilities. It should be in a | |
19 | file named COPYING. Among other things, the copyright notice | |
20 | and this notice must be preserved on all copies. */ | |
21 | ||
22 | ||
23 | /* RCS Info: $Revision: 1.5 $ on $Date: 86/11/26 12:11:32 $ | |
24 | * $Source: /users/faustus/xchess/RCS/xchess.c,v $ | |
25 | * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group | |
26 | * Permission is granted to do anything with this code except sell it | |
27 | * or remove this message. | |
28 | */ | |
29 | ||
30 | #define USAGE "xchess [ -d ] [ -f recordfile ] [ -r savedfile ] [ -i ]\n\ | |
31 | \t[ -t moves/timeunit ] [ -c ] [ -p program ] [ -b ] [ -bnw ] [ -s ]\n\ | |
32 | \t[ -n ] [ -h host ] [ -v ] [ -R ] [ whitedisplay ] [ blackdisplay ]" | |
33 | ||
34 | #include <signal.h> | |
35 | #include "xchess.h" | |
36 | ||
37 | bool debug = false; | |
38 | bool oneboard = false; | |
39 | bool bnwflag = false; | |
40 | bool progflag = false; | |
41 | bool blackflag = false; | |
42 | bool quickflag = false; | |
43 | ||
44 | char *progname = DEF_PROGRAM; | |
45 | char *proghost = NULL; | |
46 | char *piecenames[] = { "pawn", "rook", "knight", "bishop", "queen", "king" } ; | |
47 | char *colornames[] = { "white", "black", "none" } ; | |
48 | char *movetypenames[] = { "move", "qcastle", "kcastle", "capture" } ; | |
49 | char *dispname1 = NULL, *dispname2 = NULL; | |
50 | ||
51 | char *black_piece_color = BLACK_PIECE_COLOR; | |
52 | char *white_piece_color = WHITE_PIECE_COLOR; | |
53 | char *black_square_color = BLACK_SQUARE_COLOR; | |
54 | char *white_square_color = WHITE_SQUARE_COLOR; | |
55 | char *border_color = BORDER_COLOR; | |
56 | char *text_color = TEXT_COLOR; | |
57 | char *text_back = TEXT_BACK; | |
58 | char *error_text = ERROR_TEXT; | |
59 | char *player_text = PLAYER_TEXT; | |
60 | char *cursor_color = CURSOR_COLOR; | |
61 | ||
62 | int num_flashes = NUM_FLASHES; | |
63 | int flash_size = FLASH_SIZE; | |
64 | char *program; | |
65 | char *recfile = NULL; | |
66 | ||
67 | die () { | |
68 | fprintf(stderr, "child proc changed status?!\n"); | |
69 | } | |
70 | ||
71 | void | |
72 | main(ac, av) | |
73 | char **av; | |
74 | { | |
75 | bool randflag = false; | |
76 | move *m; | |
77 | char *s; | |
78 | ||
79 | program = av[0]; | |
80 | ||
81 | signal(SIGCHLD, die); | |
82 | /* Process args. */ | |
83 | av++; ac--; | |
84 | while (ac > 0 && **av == '-') { | |
85 | if (eq(*av, "-d")) { | |
86 | debug = true; | |
87 | } else if (eq(*av, "-f")) { | |
88 | av++; ac--; | |
89 | if (*av) | |
90 | record_file = *av; | |
91 | else | |
92 | goto usage; | |
93 | } else if (eq(*av, "-r")) { | |
94 | av++; ac--; | |
95 | if (*av) | |
96 | recfile = *av; | |
97 | else | |
98 | goto usage; | |
99 | } else if (eq(*av, "-i")) { | |
100 | record_english = false; | |
101 | } else if (eq(*av, "-R")) { | |
102 | randflag = true; | |
103 | } else if (eq(*av, "-v")) { | |
104 | win_flashmove = true; | |
105 | } else if (eq(*av, "-q")) { | |
106 | quickflag = true; | |
107 | } else if (eq(*av, "-t")) { | |
108 | av++; ac--; | |
109 | if (*av) { | |
110 | movesperunit = atoi(*av); | |
111 | if (s = index(*av, '/')) | |
112 | timeunit = atoi(s + 1) * 60; | |
113 | else | |
114 | timeunit = 60; | |
115 | } else | |
116 | goto usage; | |
117 | } else if (eq(*av, "-p")) { | |
118 | av++; ac--; | |
119 | if (*av) | |
120 | progname = *av; | |
121 | else | |
122 | goto usage; | |
123 | } else if (eq(*av, "-h")) { | |
124 | av++; ac--; | |
125 | if (*av) | |
126 | proghost = *av; | |
127 | else | |
128 | goto usage; | |
129 | } else if (eq(*av, "-b")) { | |
130 | blackflag = true; | |
131 | } else if (eq(*av, "-c")) { | |
132 | progflag = true; | |
133 | } else if (eq(*av, "-bnw")) { | |
134 | bnwflag = true; | |
135 | } else if (eq(*av, "-s")) { | |
136 | saveflag = true; | |
137 | } else if (eq(*av, "-n")) { | |
138 | noisyflag = true; | |
139 | } else | |
140 | goto usage; | |
141 | av++; ac--; | |
142 | } | |
143 | if (ac > 0) | |
144 | dispname1 = av[0]; | |
145 | if (ac > 1) | |
146 | dispname2 = av[1]; | |
147 | if (ac > 2) | |
148 | goto usage; | |
149 | ||
150 | if (!dispname2) | |
151 | oneboard = true; | |
152 | ||
153 | srandom(getpid()); | |
154 | ||
155 | if (!oneboard && randflag && (random() % 2)) { | |
156 | s = dispname1; | |
157 | dispname1 = dispname2; | |
158 | dispname2 = s; | |
159 | } | |
160 | ||
161 | if (!dispname1) | |
162 | dispname1 = getenv("DISPLAY"); | |
163 | ||
164 | /* Set up the board. */ | |
165 | board_setup(); | |
166 | ||
167 | /* Create the windows. */ | |
168 | win_setup(dispname1, dispname2); | |
169 | ||
170 | board_drawall(); | |
171 | ||
172 | /* Start the program if necessary. */ | |
173 | if (progflag) | |
174 | if (!program_init(progname)) | |
175 | exit(1); | |
176 | ||
177 | if (recfile) | |
178 | load_game(recfile); | |
179 | ||
180 | /* Go into a loop of prompting players alternately for moves, checking | |
181 | * them, and updating things. | |
182 | */ | |
183 | for (;;) { | |
184 | win_process(false); | |
185 | clock_update(); | |
186 | if (progflag && ((!blackflag && (nexttomove == BLACK)) || | |
187 | (blackflag && (nexttomove == WHITE)))) { | |
188 | m = program_get(); | |
189 | if (m) | |
190 | prog_move(m); | |
191 | } | |
192 | } | |
193 | ||
194 | usage: fprintf(stderr, "Usage: %s\n", USAGE); | |
195 | exit(1); | |
196 | } | |
197 |