BSD 4_3_Reno development
[unix-history] / usr / src / games / chess / Xchess / xchess.c
CommitLineData
07013a52
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.2 $ on $Date: 89/04/28 08:44:02 $
24 * $Source: /usr/local/src/source/X.V11R3/contrib/games/xchess/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
67#ifdef notdef
68/*
69 * Serves no purpose.
70 */
71die () {
72fprintf(stderr, "child proc changed status?!\n");
73}
74#endif
75
76void
77main(ac, av)
78 char **av;
79{
80 bool randflag = false;
81 move *m;
82 char *s;
83
84 program = av[0];
85
86#ifdef notdef
87 signal(SIGCHLD, die);
88#endif
89
90 /* Process args. */
91 av++; ac--;
92 while (ac > 0 && **av == '-') {
93 if (eq(*av, "-d")) {
94 debug = true;
95 } else if (eq(*av, "-f")) {
96 av++; ac--;
97 if (*av)
98 record_file = *av;
99 else
100 goto usage;
101 } else if (eq(*av, "-r")) {
102 av++; ac--;
103 if (*av)
104 recfile = *av;
105 else
106 goto usage;
107 } else if (eq(*av, "-i")) {
108 record_english = false;
109 } else if (eq(*av, "-R")) {
110 randflag = true;
111 } else if (eq(*av, "-v")) {
112 win_flashmove = true;
113 } else if (eq(*av, "-q")) {
114 quickflag = true;
115 } else if (eq(*av, "-t")) {
116 av++; ac--;
117 if (*av) {
118 movesperunit = atoi(*av);
119 if (s = index(*av, '/'))
120 timeunit = atoi(s + 1) * 60;
121 else
122 timeunit = 60;
123 } else
124 goto usage;
125 } else if (eq(*av, "-p")) {
126 av++; ac--;
127 if (*av)
128 progname = *av;
129 else
130 goto usage;
131 } else if (eq(*av, "-h")) {
132 av++; ac--;
133 if (*av)
134 proghost = *av;
135 else
136 goto usage;
137 } else if (eq(*av, "-b")) {
138 blackflag = true;
139 } else if (eq(*av, "-c")) {
140 progflag = true;
141 } else if (eq(*av, "-bnw")) {
142 bnwflag = true;
143 } else if (eq(*av, "-s")) {
144 saveflag = true;
145 } else if (eq(*av, "-n")) {
146 noisyflag = true;
147 } else
148 goto usage;
149 av++; ac--;
150 }
151 if (ac > 0)
152 dispname1 = av[0];
153 if (ac > 1)
154 dispname2 = av[1];
155 if (ac > 2)
156 goto usage;
157
158 if (!dispname2)
159 oneboard = true;
160
161 srandom(getpid());
162
163 if (!oneboard && randflag && (random() % 2)) {
164 s = dispname1;
165 dispname1 = dispname2;
166 dispname2 = s;
167 }
168
169 if (!dispname1)
170 dispname1 = getenv("DISPLAY");
171
172 /* Set up the board. */
173 board_setup();
174
175 /* Create the windows. */
176 win_setup(dispname1, dispname2);
177
178 board_drawall();
179
180 /* Start the program if necessary. */
181 if (progflag)
182 if (!program_init(progname))
183 exit(1);
184
185 if (recfile)
186 load_game(recfile);
187
188 /* Go into a loop of prompting players alternately for moves, checking
189 * them, and updating things.
190 */
191 for (;;) {
192 win_process(false);
193 clock_update();
194 if (progflag && ((!blackflag && (nexttomove == BLACK)) ||
195 (blackflag && (nexttomove == WHITE)))) {
196 m = program_get();
197 if (m)
198 prog_move(m);
199 }
200 }
201
202usage: fprintf(stderr, "Usage: %s\n", USAGE);
203 exit(1);
204}
205