4 * ----------------------------------------------------------------------
5 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
8 * GNU SHOGI is based on GNU CHESS
10 * Copyright (c) 1988, 1989, 1990 John Stanback
11 * Copyright (c) 1992 Free Software Foundation
13 * This file is part of GNU SHOGI.
15 * GNU Shogi is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 3 of the License,
18 * or (at your option) any later version.
20 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
21 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * You should have received a copy of the GNU General Public License along
26 * with GNU Shogi; see the file COPYING. If not, see
27 * <http://www.gnu.org/licenses/>.
28 * ----------------------------------------------------------------------
37 void print_arglist(int argc, char **argv)
41 for (i = 0; i < argc; i++)
42 printf("argv[%d] = %s\n", i, argv[i]);
49 main (int argc, char **argv)
52 * Process command-line arguments.
55 /* Get rid of the program name. */
60 /* CHECKME: get rid of the '+' syntax? */
62 while ((argc > 0) && ((argv[0][0] == '-') || (argv[0][0] == '+')))
67 /* Need the "+" syntax here... */
68 ahead = ((argv[0][0] == '-') ? false : true);
90 binbookfile = argv[0];
96 /* Curses interface. */
97 display_type = DISPLAY_CURSES;
98 dsp = &curses_display;
103 /* Need the "+" syntax here... */
104 hash = ((argv[0][0] == '-') ? false : true);
120 strcpy(listfile, argv[0]);
128 strcpy(savefile, argv[0]);
136 bookmaxply = atoi(argv[0]);
140 /* Raw text interface. */
141 display_type = DISPLAY_RAW;
150 booksize = atoi(argv[0]);
159 rehash = atoi(argv[0]);
160 if (rehash > MAXrehash)
169 ttblsize = atoi(argv[0]);
170 if (ttblsize <= MINTTABLE)
171 ttblsize = (MINTTABLE) + 1;
175 case 'c': /* Create or test persistent transposition table. */
180 filesz = atoi(argv[0]);
184 if ((filesz > 0) && (filesz < 24))
185 filesz = (1 << filesz) - 1 + MAXrehash;
187 filesz = filesz + MAXrehash;
189 if ((hashfile = fopen(HASHFILE, RWA_ACC)) == NULL)
190 hashfile = fopen(HASHFILE, WA_ACC);
192 if (hashfile != NULL)
197 fputs("Filling transposition file, wait!\n", stdout);
203 for (j = 0; j < filesz + 1; j++)
204 fwrite(&n, sizeof(struct fileentry), 1, hashfile);
210 printf("Create failed for %s\n", HASHFILE);
215 case 't': /* Create or test persistent transposition table. */
216 hashfile = fopen(HASHFILE, RWA_ACC);
220 fseek(hashfile, 0L, SEEK_END);
221 filesz = (ftell(hashfile) / (sizeof(struct fileentry))) - 1;
224 if (hashfile != NULL)
230 fputs("Counting transposition file entries, wait!\n", stdout);
232 for (i = 0; i < MAXDEPTH; i++)
235 fseek(hashfile, 0L, SEEK_END);
236 i = ftell(hashfile) / (sizeof(struct fileentry));
237 fseek(hashfile, 0L, SEEK_SET);
239 for (j = 0; j < i + 1; j++)
241 fread(&n, sizeof(struct fileentry), 1, hashfile);
243 if (n.depth > MAXDEPTH)
256 printf("The file contains %d entries out of max %ld\n", nr[0], i);
258 for (j = 1; j < MAXDEPTH; j++)
259 printf("%d ", nr[j]);
266 #endif /* HASHFILE */
270 fprintf(stderr, "gnushogi version %s\n", PACKAGE_VERSION);
276 display_type = DISPLAY_X;
289 fputs("Usage: gnushogi [-a] [-t] [-c size] [-s savefile][-l listfile] [-x xwndw]\n", stderr);
301 MaxResponseTime = 100L * strtol(argv[1], &p, 10);
305 MaxResponseTime = 60L * MaxResponseTime +
306 100L * strtol(++p, (char **) NULL, 10);
321 printf("Time Control Error\n");
325 TCmoves = atoi(argv[1]);
326 TCminutes = (short)strtol(argv[2], &p, 10);
329 TCseconds = (short)strtol(p + 1, (char **) NULL, 10);
339 XCmoves[XC] = atoi(argv[0]);
340 XCminutes[XC] = (short)strtol(argv[1], &p, 10);
343 XCseconds[XC] = (short)strtol(p + 1, (char **) NULL, 10);
347 if (XCmoves[XC] && (XCminutes[XC] || XCseconds[XC]))
351 printf("Time Control Error\n");
362 * If we got here, there are unknown arguments, so issue
363 * an error message and quit.
366 printf("Invalid command-line arguments:\n");
367 print_arglist(argc, argv);
377 oppptr = (oppptr + 1) % MINGAMEIN;
379 if (flag.bothsides && !flag.mate)
380 SelectMove(opponent, FOREGROUND_MODE);
384 if (opponent == white)
386 if (flag.gamein || TCadd)
390 else if (TimeControl.moves[opponent] == 0)
396 TCmoves = XCmoves[XCmore];
397 TCminutes = XCminutes[XCmore];
398 TCseconds = XCseconds[XCmore];
407 compptr = (compptr + 1) % MINGAMEIN;
409 if (!(flag.quit || flag.mate || flag.force))
411 #ifdef INTERRUPT_TEST
412 printf("starting search...\n");
414 SelectMove(computer, FOREGROUND_MODE);
416 if (computer == white)
422 else if (TimeControl.moves[computer] == 0)
428 TCmoves = XCmoves[XCmore];
429 TCminutes = XCminutes[XCmore];
430 TCseconds = XCseconds[XCmore];