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 * ----------------------------------------------------------------------
38 void print_arglist(int argc, char **argv)
42 for (i = 0; i < argc; i++)
43 printf("argv[%d] = %s\n", i, argv[i]);
50 main (int argc, char **argv)
53 * Process command-line arguments.
56 /* Get rid of the program name. */
61 /* CHECKME: get rid of the '+' syntax? */
63 while ((argc > 0) && ((argv[0][0] == '-') || (argv[0][0] == '+')))
68 /* Need the "+" syntax here... */
69 ahead = ((argv[0][0] == '-') ? false : true);
93 binbookfile = argv[0];
100 /* Curses interface. */
101 display_type = DISPLAY_CURSES;
107 /* Need the "+" syntax here... */
108 hash = ((argv[0][0] == '-') ? false : true);
127 strcpy(listfile, argv[0]);
136 strcpy(savefile, argv[0]);
146 bookmaxply = atoi(argv[0]);
152 /* Raw text interface. */
153 display_type = DISPLAY_RAW;
163 booksize = atoi(argv[0]);
172 rehash = atoi(argv[0]);
174 if (rehash > MAXrehash)
185 ttblsize = atoi(argv[0]);
187 if ((ttblsize <= MINTTABLE))
188 ttblsize = (MINTTABLE) + 1;
193 case 'c': /* Create or test persistent transposition table. */
198 filesz = atoi(argv[0]);
202 if ((filesz > 0) && (filesz < 24))
203 filesz = (1 << filesz) - 1 + MAXrehash;
205 filesz = filesz + MAXrehash;
207 if ((hashfile = fopen(HASHFILE, RWA_ACC)) == NULL)
208 hashfile = fopen(HASHFILE, WA_ACC);
210 if (hashfile != NULL)
215 fputs(CP[66], stdout);
221 for (j = 0; j < filesz + 1; j++)
222 fwrite(&n, sizeof(struct fileentry), 1, hashfile);
228 printf(CP[50], HASHFILE);
234 case 't': /* Create or test persistent transposition table. */
235 hashfile = fopen(HASHFILE, RWA_ACC);
239 fseek(hashfile, 0L, SEEK_END);
240 filesz = (ftell(hashfile) / (sizeof(struct fileentry))) - 1;
243 if (hashfile != NULL)
249 fputs(CP[49], stdout);
251 for (i = 0; i < MAXDEPTH; i++)
254 fseek(hashfile, 0L, SEEK_END);
255 i = ftell(hashfile) / (sizeof(struct fileentry));
256 fseek(hashfile, 0L, SEEK_SET);
258 for (j = 0; j < i + 1; j++)
260 fread(&n, sizeof(struct fileentry), 1, hashfile);
262 if (n.depth > MAXDEPTH)
275 printf(CP[109], nr[0], i);
277 for (j = 1; j < MAXDEPTH; j++)
278 printf("%d ", nr[j]);
286 #endif /* HASHFILE */
290 fprintf(stderr, CP[102], version, patchlevel);
296 display_type = DISPLAY_X;
312 fputs(CP[113], stderr);
324 MaxResponseTime = 100L * strtol(argv[1], &p, 10);
328 MaxResponseTime = 60L * MaxResponseTime +
329 100L * strtol(++p, (char **) NULL, 10);
344 printf("%s\n", CP[220]);
348 TCmoves = atoi(argv[1]);
349 TCminutes = (short)strtol(argv[2], &p, 10);
352 TCseconds = (short)strtol(p + 1, (char **) NULL, 10);
362 XCmoves[XC] = atoi(argv[0]);
363 XCminutes[XC] = (short)strtol(argv[1], &p, 10);
366 XCseconds[XC] = (short)strtol(p + 1, (char **) NULL, 10);
370 if (XCmoves[XC] && (XCminutes[XC] || XCseconds[XC]))
374 printf("%s\n", CP[220]);
385 * If we got here, there are unknown arguments, so issue
386 * an error message and quit.
389 printf("%s\n", CP[233]);
390 print_arglist(argc, argv);
400 oppptr = (oppptr + 1) % MINGAMEIN;
402 if (flag.bothsides && !flag.mate)
403 SelectMove(opponent, FOREGROUND_MODE);
407 if (opponent == white)
409 if (flag.gamein || TCadd)
413 else if (TimeControl.moves[opponent] == 0)
419 TCmoves = XCmoves[XCmore];
420 TCminutes = XCminutes[XCmore];
421 TCseconds = XCseconds[XCmore];
430 compptr = (compptr + 1) % MINGAMEIN;
432 if (!(flag.quit || flag.mate || flag.force))
434 #ifdef INTERRUPT_TEST
435 printf("starting search...\n");
437 SelectMove(computer, FOREGROUND_MODE);
439 if (computer == white)
445 else if (TimeControl.moves[computer] == 0)
451 TCmoves = XCmoves[XCmore];
452 TCminutes = XCminutes[XCmore];
453 TCseconds = XCseconds[XCmore];