main.c revision 1.9 1 1.9 jsm /* $NetBSD: main.c,v 1.9 1999/09/13 17:18:58 jsm Exp $ */
2 1.3 cgd
3 1.1 tls /*
4 1.1 tls * Copyright (c) 1994
5 1.1 tls * The Regents of the University of California. All rights reserved.
6 1.1 tls *
7 1.1 tls * This code is derived from software contributed to Berkeley by
8 1.1 tls * Ralph Campbell.
9 1.1 tls *
10 1.1 tls * Redistribution and use in source and binary forms, with or without
11 1.1 tls * modification, are permitted provided that the following conditions
12 1.1 tls * are met:
13 1.1 tls * 1. Redistributions of source code must retain the above copyright
14 1.1 tls * notice, this list of conditions and the following disclaimer.
15 1.1 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 tls * notice, this list of conditions and the following disclaimer in the
17 1.1 tls * documentation and/or other materials provided with the distribution.
18 1.1 tls * 3. All advertising materials mentioning features or use of this software
19 1.1 tls * must display the following acknowledgement:
20 1.1 tls * This product includes software developed by the University of
21 1.1 tls * California, Berkeley and its contributors.
22 1.1 tls * 4. Neither the name of the University nor the names of its contributors
23 1.1 tls * may be used to endorse or promote products derived from this software
24 1.1 tls * without specific prior written permission.
25 1.1 tls *
26 1.1 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 tls * SUCH DAMAGE.
37 1.1 tls */
38 1.1 tls
39 1.4 lukem #include <sys/cdefs.h>
40 1.1 tls #ifndef lint
41 1.4 lukem __COPYRIGHT("@(#) Copyright (c) 1994\n\
42 1.4 lukem The Regents of the University of California. All rights reserved.\n");
43 1.1 tls #endif /* not lint */
44 1.1 tls
45 1.1 tls #ifndef lint
46 1.2 tls #if 0
47 1.1 tls static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95";
48 1.2 tls #else
49 1.9 jsm __RCSID("$NetBSD: main.c,v 1.9 1999/09/13 17:18:58 jsm Exp $");
50 1.2 tls #endif
51 1.1 tls #endif /* not lint */
52 1.1 tls
53 1.1 tls #include <curses.h>
54 1.1 tls #include <err.h>
55 1.1 tls #include <signal.h>
56 1.1 tls #include <stdlib.h>
57 1.1 tls #include <string.h>
58 1.5 perry #include <time.h>
59 1.1 tls #include <unistd.h>
60 1.1 tls
61 1.1 tls #include "gomoku.h"
62 1.1 tls
63 1.1 tls #define USER 0 /* get input from standard input */
64 1.1 tls #define PROGRAM 1 /* get input from program */
65 1.1 tls #define INPUTF 2 /* get input from a file */
66 1.1 tls
67 1.1 tls int interactive = 1; /* true if interactive */
68 1.1 tls int debug; /* true if debugging */
69 1.1 tls int test; /* both moves come from 1: input, 2: computer */
70 1.1 tls char *prog; /* name of program */
71 1.1 tls FILE *debugfp; /* file for debug output */
72 1.1 tls FILE *inputfp; /* file for debug input */
73 1.1 tls
74 1.6 jsm const char pdir[4] = "-\\|/";
75 1.1 tls char fmtbuf[128];
76 1.1 tls
77 1.1 tls struct spotstr board[BAREA]; /* info for board */
78 1.1 tls struct combostr frames[FAREA]; /* storage for all frames */
79 1.1 tls struct combostr *sortframes[2]; /* sorted list of non-empty frames */
80 1.1 tls u_char overlap[FAREA * FAREA]; /* true if frame [a][b] overlap */
81 1.1 tls short intersect[FAREA * FAREA]; /* frame [a][b] intersection */
82 1.1 tls int movelog[BSZ * BSZ]; /* log of all the moves */
83 1.1 tls int movenum; /* current move number */
84 1.6 jsm const char *plyr[2]; /* who's who */
85 1.1 tls
86 1.4 lukem int main __P((int, char *[]));
87 1.1 tls
88 1.4 lukem int
89 1.1 tls main(argc, argv)
90 1.1 tls int argc;
91 1.1 tls char **argv;
92 1.1 tls {
93 1.1 tls char buf[128];
94 1.1 tls int color, curmove, i, ch;
95 1.1 tls int input[2];
96 1.6 jsm static const char *const fmt[2] = {
97 1.1 tls "%3d %-6s",
98 1.1 tls "%3d %-6s"
99 1.1 tls };
100 1.8 jsm
101 1.8 jsm /* Revoke setgid privileges */
102 1.8 jsm setregid(getgid(), getgid());
103 1.1 tls
104 1.4 lukem color = curmove = 0;
105 1.4 lukem
106 1.1 tls prog = strrchr(argv[0], '/');
107 1.1 tls if (prog)
108 1.1 tls prog++;
109 1.1 tls else
110 1.1 tls prog = argv[0];
111 1.1 tls
112 1.4 lukem while ((ch = getopt(argc, argv, "bcdD:u")) != -1) {
113 1.1 tls switch (ch) {
114 1.1 tls case 'b': /* background */
115 1.1 tls interactive = 0;
116 1.1 tls break;
117 1.1 tls case 'd': /* debugging */
118 1.1 tls debug++;
119 1.1 tls break;
120 1.1 tls case 'D': /* log debug output to file */
121 1.1 tls if ((debugfp = fopen(optarg, "w")) == NULL)
122 1.1 tls err(1, "%s", optarg);
123 1.1 tls break;
124 1.1 tls case 'u': /* testing: user verses user */
125 1.1 tls test = 1;
126 1.1 tls break;
127 1.1 tls case 'c': /* testing: computer verses computer */
128 1.1 tls test = 2;
129 1.1 tls break;
130 1.1 tls }
131 1.1 tls }
132 1.1 tls argc -= optind;
133 1.1 tls argv += optind;
134 1.1 tls if (argc) {
135 1.1 tls if ((inputfp = fopen(*argv, "r")) == NULL)
136 1.1 tls err(1, "%s", *argv);
137 1.1 tls }
138 1.1 tls
139 1.1 tls if (!debug)
140 1.1 tls #ifdef SVR4
141 1.1 tls srand(time(0));
142 1.1 tls #else
143 1.1 tls srandom(time(0));
144 1.1 tls #endif
145 1.1 tls if (interactive)
146 1.1 tls cursinit(); /* initialize curses */
147 1.1 tls again:
148 1.1 tls bdinit(board); /* initialize board contents */
149 1.1 tls
150 1.1 tls if (interactive) {
151 1.1 tls plyr[BLACK] = plyr[WHITE] = "???";
152 1.1 tls bdisp_init(); /* initialize display of board */
153 1.1 tls #ifdef DEBUG
154 1.1 tls signal(SIGINT, whatsup);
155 1.1 tls #else
156 1.4 lukem signal(SIGINT, quitsig);
157 1.1 tls #endif
158 1.1 tls
159 1.1 tls if (inputfp == NULL && test == 0) {
160 1.1 tls for (;;) {
161 1.1 tls ask("black or white? ");
162 1.1 tls getline(buf, sizeof(buf));
163 1.1 tls if (buf[0] == 'b' || buf[0] == 'B') {
164 1.1 tls color = BLACK;
165 1.1 tls break;
166 1.1 tls }
167 1.1 tls if (buf[0] == 'w' || buf[0] == 'W') {
168 1.1 tls color = WHITE;
169 1.1 tls break;
170 1.1 tls }
171 1.1 tls move(22, 0);
172 1.1 tls printw("Black moves first. Please enter `black' or `white'\n");
173 1.1 tls }
174 1.1 tls move(22, 0);
175 1.1 tls clrtoeol();
176 1.1 tls }
177 1.1 tls } else {
178 1.1 tls setbuf(stdout, 0);
179 1.1 tls getline(buf, sizeof(buf));
180 1.1 tls if (strcmp(buf, "black") == 0)
181 1.1 tls color = BLACK;
182 1.1 tls else if (strcmp(buf, "white") == 0)
183 1.1 tls color = WHITE;
184 1.1 tls else {
185 1.1 tls sprintf(fmtbuf,
186 1.1 tls "Huh? Expected `black' or `white', got `%s'\n",
187 1.1 tls buf);
188 1.1 tls panic(fmtbuf);
189 1.1 tls }
190 1.1 tls }
191 1.1 tls
192 1.1 tls if (inputfp) {
193 1.1 tls input[BLACK] = INPUTF;
194 1.1 tls input[WHITE] = INPUTF;
195 1.1 tls } else {
196 1.1 tls switch (test) {
197 1.1 tls case 0: /* user verses program */
198 1.1 tls input[color] = USER;
199 1.1 tls input[!color] = PROGRAM;
200 1.1 tls break;
201 1.1 tls
202 1.1 tls case 1: /* user verses user */
203 1.1 tls input[BLACK] = USER;
204 1.1 tls input[WHITE] = USER;
205 1.1 tls break;
206 1.1 tls
207 1.1 tls case 2: /* program verses program */
208 1.1 tls input[BLACK] = PROGRAM;
209 1.1 tls input[WHITE] = PROGRAM;
210 1.1 tls break;
211 1.1 tls }
212 1.1 tls }
213 1.1 tls if (interactive) {
214 1.1 tls plyr[BLACK] = input[BLACK] == USER ? "you" : prog;
215 1.1 tls plyr[WHITE] = input[WHITE] == USER ? "you" : prog;
216 1.1 tls bdwho(1);
217 1.1 tls }
218 1.1 tls
219 1.1 tls for (color = BLACK; ; color = !color) {
220 1.1 tls top:
221 1.1 tls switch (input[color]) {
222 1.1 tls case INPUTF: /* input comes from a file */
223 1.1 tls curmove = readinput(inputfp);
224 1.1 tls if (curmove != ILLEGAL)
225 1.1 tls break;
226 1.1 tls switch (test) {
227 1.1 tls case 0: /* user verses program */
228 1.1 tls input[color] = USER;
229 1.1 tls input[!color] = PROGRAM;
230 1.1 tls break;
231 1.1 tls
232 1.1 tls case 1: /* user verses user */
233 1.1 tls input[BLACK] = USER;
234 1.1 tls input[WHITE] = USER;
235 1.1 tls break;
236 1.1 tls
237 1.1 tls case 2: /* program verses program */
238 1.1 tls input[BLACK] = PROGRAM;
239 1.1 tls input[WHITE] = PROGRAM;
240 1.1 tls break;
241 1.1 tls }
242 1.1 tls plyr[BLACK] = input[BLACK] == USER ? "you" : prog;
243 1.1 tls plyr[WHITE] = input[WHITE] == USER ? "you" : prog;
244 1.1 tls bdwho(1);
245 1.1 tls goto top;
246 1.1 tls
247 1.1 tls case USER: /* input comes from standard input */
248 1.1 tls getinput:
249 1.1 tls if (interactive)
250 1.1 tls ask("move? ");
251 1.1 tls if (!getline(buf, sizeof(buf))) {
252 1.1 tls curmove = RESIGN;
253 1.1 tls break;
254 1.1 tls }
255 1.1 tls if (buf[0] == '\0')
256 1.1 tls goto getinput;
257 1.1 tls curmove = ctos(buf);
258 1.1 tls if (interactive) {
259 1.1 tls if (curmove == SAVE) {
260 1.1 tls FILE *fp;
261 1.1 tls
262 1.1 tls ask("save file name? ");
263 1.1 tls (void)getline(buf, sizeof(buf));
264 1.1 tls if ((fp = fopen(buf, "w")) == NULL) {
265 1.9 jsm glog("cannot create save file");
266 1.1 tls goto getinput;
267 1.1 tls }
268 1.1 tls for (i = 0; i < movenum - 1; i++)
269 1.1 tls fprintf(fp, "%s\n",
270 1.1 tls stoc(movelog[i]));
271 1.1 tls fclose(fp);
272 1.1 tls goto getinput;
273 1.1 tls }
274 1.1 tls if (curmove != RESIGN &&
275 1.1 tls board[curmove].s_occ != EMPTY) {
276 1.9 jsm glog("Illegal move");
277 1.1 tls goto getinput;
278 1.1 tls }
279 1.1 tls }
280 1.1 tls break;
281 1.1 tls
282 1.1 tls case PROGRAM: /* input comes from the program */
283 1.1 tls curmove = pickmove(color);
284 1.1 tls break;
285 1.1 tls }
286 1.1 tls if (interactive) {
287 1.1 tls sprintf(fmtbuf, fmt[color], movenum, stoc(curmove));
288 1.9 jsm glog(fmtbuf);
289 1.1 tls }
290 1.1 tls if ((i = makemove(color, curmove)) != MOVEOK)
291 1.1 tls break;
292 1.1 tls if (interactive)
293 1.1 tls bdisp();
294 1.1 tls }
295 1.1 tls if (interactive) {
296 1.1 tls move(22, 0);
297 1.1 tls switch (i) {
298 1.1 tls case WIN:
299 1.1 tls if (input[color] == PROGRAM)
300 1.1 tls addstr("Ha ha, I won");
301 1.1 tls else
302 1.1 tls addstr("Rats! you won");
303 1.1 tls break;
304 1.1 tls case TIE:
305 1.1 tls addstr("Wow! its a tie");
306 1.1 tls break;
307 1.1 tls case ILLEGAL:
308 1.1 tls addstr("Illegal move");
309 1.1 tls break;
310 1.1 tls }
311 1.1 tls clrtoeol();
312 1.1 tls bdisp();
313 1.1 tls if (i != RESIGN) {
314 1.1 tls replay:
315 1.1 tls ask("replay? ");
316 1.1 tls if (getline(buf, sizeof(buf)) &&
317 1.4 lukem (buf[0] == 'y' || buf[0] == 'Y'))
318 1.1 tls goto again;
319 1.1 tls if (strcmp(buf, "save") == 0) {
320 1.1 tls FILE *fp;
321 1.1 tls
322 1.1 tls ask("save file name? ");
323 1.1 tls (void)getline(buf, sizeof(buf));
324 1.1 tls if ((fp = fopen(buf, "w")) == NULL) {
325 1.9 jsm glog("cannot create save file");
326 1.1 tls goto replay;
327 1.1 tls }
328 1.1 tls for (i = 0; i < movenum - 1; i++)
329 1.1 tls fprintf(fp, "%s\n",
330 1.1 tls stoc(movelog[i]));
331 1.1 tls fclose(fp);
332 1.1 tls goto replay;
333 1.1 tls }
334 1.1 tls }
335 1.1 tls }
336 1.1 tls quit();
337 1.4 lukem /* NOTREACHED */
338 1.4 lukem return(0);
339 1.1 tls }
340 1.1 tls
341 1.4 lukem int
342 1.1 tls readinput(fp)
343 1.1 tls FILE *fp;
344 1.1 tls {
345 1.1 tls char *cp;
346 1.1 tls int c;
347 1.1 tls
348 1.1 tls cp = fmtbuf;
349 1.1 tls while ((c = getc(fp)) != EOF && c != '\n')
350 1.1 tls *cp++ = c;
351 1.1 tls *cp = '\0';
352 1.1 tls return (ctos(fmtbuf));
353 1.1 tls }
354 1.1 tls
355 1.1 tls #ifdef DEBUG
356 1.1 tls /*
357 1.1 tls * Handle strange situations.
358 1.1 tls */
359 1.1 tls void
360 1.1 tls whatsup(signum)
361 1.1 tls int signum;
362 1.1 tls {
363 1.1 tls int i, pnum, n, s1, s2, d1, d2;
364 1.1 tls struct spotstr *sp;
365 1.1 tls FILE *fp;
366 1.1 tls char *str;
367 1.1 tls struct elist *ep;
368 1.1 tls struct combostr *cbp;
369 1.1 tls
370 1.1 tls if (!interactive)
371 1.1 tls quit();
372 1.1 tls top:
373 1.1 tls ask("cmd? ");
374 1.1 tls if (!getline(fmtbuf, sizeof(fmtbuf)))
375 1.1 tls quit();
376 1.1 tls switch (*fmtbuf) {
377 1.1 tls case '\0':
378 1.1 tls goto top;
379 1.1 tls case 'q': /* conservative quit */
380 1.1 tls quit();
381 1.1 tls case 'd': /* set debug level */
382 1.1 tls debug = fmtbuf[1] - '0';
383 1.1 tls sprintf(fmtbuf, "Debug set to %d", debug);
384 1.1 tls dlog(fmtbuf);
385 1.1 tls sleep(1);
386 1.1 tls case 'c':
387 1.1 tls break;
388 1.1 tls case 'b': /* back up a move */
389 1.1 tls if (movenum > 1) {
390 1.1 tls movenum--;
391 1.1 tls board[movelog[movenum - 1]].s_occ = EMPTY;
392 1.1 tls bdisp();
393 1.1 tls }
394 1.1 tls goto top;
395 1.1 tls case 's': /* suggest a move */
396 1.1 tls i = fmtbuf[1] == 'b' ? BLACK : WHITE;
397 1.1 tls sprintf(fmtbuf, "suggest %c %s", i == BLACK ? 'B' : 'W',
398 1.1 tls stoc(pickmove(i)));
399 1.1 tls dlog(fmtbuf);
400 1.1 tls goto top;
401 1.1 tls case 'f': /* go forward a move */
402 1.1 tls board[movelog[movenum - 1]].s_occ = movenum & 1 ? BLACK : WHITE;
403 1.1 tls movenum++;
404 1.1 tls bdisp();
405 1.1 tls goto top;
406 1.1 tls case 'l': /* print move history */
407 1.1 tls if (fmtbuf[1] == '\0') {
408 1.1 tls for (i = 0; i < movenum - 1; i++)
409 1.1 tls dlog(stoc(movelog[i]));
410 1.1 tls goto top;
411 1.1 tls }
412 1.1 tls if ((fp = fopen(fmtbuf + 1, "w")) == NULL)
413 1.1 tls goto top;
414 1.1 tls for (i = 0; i < movenum - 1; i++) {
415 1.1 tls fprintf(fp, "%s", stoc(movelog[i]));
416 1.1 tls if (++i < movenum - 1)
417 1.1 tls fprintf(fp, " %s\n", stoc(movelog[i]));
418 1.1 tls else
419 1.1 tls fputc('\n', fp);
420 1.1 tls }
421 1.1 tls bdump(fp);
422 1.1 tls fclose(fp);
423 1.1 tls goto top;
424 1.1 tls case 'o':
425 1.1 tls n = 0;
426 1.1 tls for (str = fmtbuf + 1; *str; str++)
427 1.1 tls if (*str == ',') {
428 1.1 tls for (d1 = 0; d1 < 4; d1++)
429 1.1 tls if (str[-1] == pdir[d1])
430 1.1 tls break;
431 1.1 tls str[-1] = '\0';
432 1.1 tls sp = &board[s1 = ctos(fmtbuf + 1)];
433 1.1 tls n = (sp->s_frame[d1] - frames) * FAREA;
434 1.1 tls *str++ = '\0';
435 1.1 tls break;
436 1.1 tls }
437 1.1 tls sp = &board[s2 = ctos(str)];
438 1.1 tls while (*str)
439 1.1 tls str++;
440 1.1 tls for (d2 = 0; d2 < 4; d2++)
441 1.1 tls if (str[-1] == pdir[d2])
442 1.1 tls break;
443 1.1 tls n += sp->s_frame[d2] - frames;
444 1.1 tls str = fmtbuf;
445 1.1 tls sprintf(str, "overlap %s%c,", stoc(s1), pdir[d1]);
446 1.1 tls str += strlen(str);
447 1.1 tls sprintf(str, "%s%c = %x", stoc(s2), pdir[d2], overlap[n]);
448 1.1 tls dlog(fmtbuf);
449 1.1 tls goto top;
450 1.1 tls case 'p':
451 1.1 tls sp = &board[i = ctos(fmtbuf + 1)];
452 1.1 tls sprintf(fmtbuf, "V %s %x/%d %d %x/%d %d %d %x", stoc(i),
453 1.1 tls sp->s_combo[BLACK].s, sp->s_level[BLACK],
454 1.1 tls sp->s_nforce[BLACK],
455 1.1 tls sp->s_combo[WHITE].s, sp->s_level[WHITE],
456 1.1 tls sp->s_nforce[WHITE], sp->s_wval, sp->s_flg);
457 1.1 tls dlog(fmtbuf);
458 1.1 tls sprintf(fmtbuf, "FB %s %x %x %x %x", stoc(i),
459 1.1 tls sp->s_fval[BLACK][0].s, sp->s_fval[BLACK][1].s,
460 1.1 tls sp->s_fval[BLACK][2].s, sp->s_fval[BLACK][3].s);
461 1.1 tls dlog(fmtbuf);
462 1.1 tls sprintf(fmtbuf, "FW %s %x %x %x %x", stoc(i),
463 1.1 tls sp->s_fval[WHITE][0].s, sp->s_fval[WHITE][1].s,
464 1.1 tls sp->s_fval[WHITE][2].s, sp->s_fval[WHITE][3].s);
465 1.1 tls dlog(fmtbuf);
466 1.1 tls goto top;
467 1.1 tls case 'e': /* e {b|w} [0-9] spot */
468 1.1 tls str = fmtbuf + 1;
469 1.1 tls if (*str >= '0' && *str <= '9')
470 1.1 tls n = *str++ - '0';
471 1.1 tls else
472 1.1 tls n = 0;
473 1.1 tls sp = &board[i = ctos(str)];
474 1.1 tls for (ep = sp->s_empty; ep; ep = ep->e_next) {
475 1.1 tls cbp = ep->e_combo;
476 1.1 tls if (n) {
477 1.1 tls if (cbp->c_nframes > n)
478 1.1 tls continue;
479 1.1 tls if (cbp->c_nframes != n)
480 1.1 tls break;
481 1.1 tls }
482 1.1 tls printcombo(cbp, fmtbuf);
483 1.1 tls dlog(fmtbuf);
484 1.1 tls }
485 1.1 tls goto top;
486 1.1 tls default:
487 1.1 tls syntax:
488 1.1 tls dlog("Options are:");
489 1.1 tls dlog("q - quit");
490 1.1 tls dlog("c - continue");
491 1.1 tls dlog("d# - set debug level to #");
492 1.1 tls dlog("p# - print values at #");
493 1.1 tls goto top;
494 1.1 tls }
495 1.1 tls }
496 1.1 tls #endif /* DEBUG */
497 1.1 tls
498 1.1 tls /*
499 1.1 tls * Display debug info.
500 1.1 tls */
501 1.4 lukem void
502 1.1 tls dlog(str)
503 1.6 jsm const char *str;
504 1.1 tls {
505 1.1 tls
506 1.1 tls if (debugfp)
507 1.1 tls fprintf(debugfp, "%s\n", str);
508 1.1 tls if (interactive)
509 1.1 tls dislog(str);
510 1.1 tls else
511 1.1 tls fprintf(stderr, "%s\n", str);
512 1.1 tls }
513 1.1 tls
514 1.4 lukem void
515 1.9 jsm glog(str)
516 1.6 jsm const char *str;
517 1.1 tls {
518 1.1 tls
519 1.1 tls if (debugfp)
520 1.1 tls fprintf(debugfp, "%s\n", str);
521 1.1 tls if (interactive)
522 1.1 tls dislog(str);
523 1.1 tls else
524 1.1 tls printf("%s\n", str);
525 1.1 tls }
526 1.1 tls
527 1.1 tls void
528 1.1 tls quit()
529 1.1 tls {
530 1.1 tls if (interactive) {
531 1.1 tls bdisp(); /* show final board */
532 1.1 tls cursfini();
533 1.1 tls }
534 1.1 tls exit(0);
535 1.1 tls }
536 1.1 tls
537 1.4 lukem void
538 1.4 lukem quitsig(dummy)
539 1.7 jsm int dummy __attribute__((__unused__));
540 1.4 lukem {
541 1.4 lukem quit();
542 1.4 lukem }
543 1.4 lukem
544 1.1 tls /*
545 1.1 tls * Die gracefully.
546 1.1 tls */
547 1.4 lukem void
548 1.1 tls panic(str)
549 1.6 jsm const char *str;
550 1.1 tls {
551 1.1 tls fprintf(stderr, "%s: %s\n", prog, str);
552 1.1 tls fputs("resign\n", stdout);
553 1.1 tls quit();
554 1.1 tls }
555