4 * ----------------------------------------------------------------------
5 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
7 * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
9 * GNU SHOGI is based on GNU CHESS
11 * Copyright (c) 1988, 1989, 1990 John Stanback
12 * Copyright (c) 1992 Free Software Foundation
14 * This file is part of GNU SHOGI.
16 * GNU Shogi is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 3 of the License,
19 * or (at your option) any later version.
21 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
22 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * You should have received a copy of the GNU General Public License along
27 * with GNU Shogi; see the file COPYING. If not, see
28 * <http://www.gnu.org/licenses/>.
29 * ----------------------------------------------------------------------
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("Filling transposition file, wait!\n", stdout);
221 for (j = 0; j < filesz + 1; j++)
222 fwrite(&n, sizeof(struct fileentry), 1, hashfile);
228 printf("Create failed for %s\n", 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("Counting transposition file entries, wait!\n", 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("The file contains %d entries out of max %d\n", nr[0], i);
277 for (j = 1; j < MAXDEPTH; j++)
278 printf("%d ", nr[j]);
286 #endif /* HASHFILE */
290 fprintf(stderr, "gnushogi version %s\n", PACKAGE_VERSION);
296 display_type = DISPLAY_X;
312 fputs("Usage: gnushogi [-a] [-t] [-c size] [-s savefile][-l listfile] [-x xwndw]\n", stderr);
324 MaxResponseTime = 100L * strtol(argv[1], &p, 10);
328 MaxResponseTime = 60L * MaxResponseTime +
329 100L * strtol(++p, (char **) NULL, 10);
344 printf("Time Control Error\n");
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("Time Control Error\n");
385 * If we got here, there are unknown arguments, so issue
386 * an error message and quit.
389 printf("Invalid command-line arguments:\n");
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];