Start development on 386BSD 0.0
[unix-history] / .ref-BSD-4_3_Net_2 / usr / src / games / chess / Xchess / xchess.c.150
CommitLineData
cb290b32
C
1
2/* This file contains code for X-CHESS.
3 Copyright (C) 1986 Free Software Foundation, Inc.
4
5This file is part of X-CHESS.
6
7X-CHESS is distributed in the hope that it will be useful,
8but WITHOUT ANY WARRANTY. No author or distributor
9accepts responsibility to anyone for the consequences of using it
10or for whether it serves any particular purpose or works at all,
11unless he says so in writing. Refer to the X-CHESS General Public
12License for full details.
13
14Everyone is granted permission to copy, modify and redistribute
15X-CHESS, but only under the conditions described in the
16X-CHESS General Public License. A copy of this license is
17supposed to have been given to you along with X-CHESS so you
18can know your rights and responsibilities. It should be in a
19file named COPYING. Among other things, the copyright notice
20and 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
37bool debug = false;
38bool oneboard = false;
39bool bnwflag = false;
40bool progflag = false;
41bool blackflag = false;
42bool quickflag = false;
43
44char *progname = DEF_PROGRAM;
45char *proghost = NULL;
46char *piecenames[] = { "pawn", "rook", "knight", "bishop", "queen", "king" } ;
47char *colornames[] = { "white", "black", "none" } ;
48char *movetypenames[] = { "move", "qcastle", "kcastle", "capture" } ;
49char *dispname1 = NULL, *dispname2 = NULL;
50
51char *black_piece_color = BLACK_PIECE_COLOR;
52char *white_piece_color = WHITE_PIECE_COLOR;
53char *black_square_color = BLACK_SQUARE_COLOR;
54char *white_square_color = WHITE_SQUARE_COLOR;
55char *border_color = BORDER_COLOR;
56char *text_color = TEXT_COLOR;
57char *text_back = TEXT_BACK;
58char *error_text = ERROR_TEXT;
59char *player_text = PLAYER_TEXT;
60char *cursor_color = CURSOR_COLOR;
61
62int num_flashes = NUM_FLASHES;
63int flash_size = FLASH_SIZE;
64char *program;
65char *recfile = NULL;
66
67die () {
68fprintf(stderr, "child proc changed status?!\n");
69}
70
71void
72main(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
194usage: fprintf(stderr, "Usage: %s\n", USAGE);
195 exit(1);
196}
197