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);
91 binbookfile = argv[0];
97 /* Curses interface. */
98 display_type = DISPLAY_CURSES;
99 dsp = &curses_display;
104 /* Need the "+" syntax here... */
105 hash = ((argv[0][0] == '-') ? false : true);
121 strcpy(listfile, argv[0]);
129 strcpy(savefile, argv[0]);
137 bookmaxply = atoi(argv[0]);
141 /* Raw text interface. */
142 display_type = DISPLAY_RAW;
151 booksize = atoi(argv[0]);
160 rehash = atoi(argv[0]);
161 if (rehash > MAXrehash)
170 ttblsize = atoi(argv[0]);
171 if (ttblsize <= MINTTABLE)
172 ttblsize = (MINTTABLE) + 1;
176 case 'c': /* Create or test persistent transposition table. */
181 filesz = atoi(argv[0]);
185 if ((filesz > 0) && (filesz < 24))
186 filesz = (1 << filesz) - 1 + MAXrehash;
188 filesz = filesz + MAXrehash;
190 if ((hashfile = fopen(HASHFILE, RWA_ACC)) == NULL)
191 hashfile = fopen(HASHFILE, WA_ACC);
193 if (hashfile != NULL)
198 fputs("Filling transposition file, wait!\n", stdout);
204 for (j = 0; j < filesz + 1; j++)
205 fwrite(&n, sizeof(struct fileentry), 1, hashfile);
211 printf("Create failed for %s\n", HASHFILE);
216 case 't': /* Create or test persistent transposition table. */
217 hashfile = fopen(HASHFILE, RWA_ACC);
221 fseek(hashfile, 0L, SEEK_END);
222 filesz = (ftell(hashfile) / (sizeof(struct fileentry))) - 1;
225 if (hashfile != NULL)
231 fputs("Counting transposition file entries, wait!\n", stdout);
233 for (i = 0; i < MAXDEPTH; i++)
236 fseek(hashfile, 0L, SEEK_END);
237 i = ftell(hashfile) / (sizeof(struct fileentry));
238 fseek(hashfile, 0L, SEEK_SET);
240 for (j = 0; j < i + 1; j++)
242 fread(&n, sizeof(struct fileentry), 1, hashfile);
244 if (n.depth > MAXDEPTH)
257 printf("The file contains %d entries out of max %ld\n", nr[0], i);
259 for (j = 1; j < MAXDEPTH; j++)
260 printf("%d ", nr[j]);
267 #endif /* HASHFILE */
271 fprintf(stderr, "gnushogi version %s\n", PACKAGE_VERSION);
277 display_type = DISPLAY_X;
290 fputs("Usage: gnushogi [-a] [-t] [-c size] [-s savefile][-l listfile] [-x xwndw]\n", stderr);
302 MaxResponseTime = 100L * strtol(argv[1], &p, 10);
306 MaxResponseTime = 60L * MaxResponseTime +
307 100L * strtol(++p, (char **) NULL, 10);
322 printf("Time Control Error\n");
326 TCmoves = atoi(argv[1]);
327 TCminutes = (short)strtol(argv[2], &p, 10);
330 TCseconds = (short)strtol(p + 1, (char **) NULL, 10);
340 XCmoves[XC] = atoi(argv[0]);
341 XCminutes[XC] = (short)strtol(argv[1], &p, 10);
344 XCseconds[XC] = (short)strtol(p + 1, (char **) NULL, 10);
348 if (XCmoves[XC] && (XCminutes[XC] || XCseconds[XC]))
352 printf("Time Control Error\n");
363 * If we got here, there are unknown arguments, so issue
364 * an error message and quit.
367 printf("Invalid command-line arguments:\n");
368 print_arglist(argc, argv);
378 oppptr = (oppptr + 1) % MINGAMEIN;
380 if (flag.bothsides && !flag.mate)
381 SelectMove(opponent, FOREGROUND_MODE);
385 if (opponent == white)
387 if (flag.gamein || TCadd)
391 else if (TimeControl.moves[opponent] == 0)
397 TCmoves = XCmoves[XCmore];
398 TCminutes = XCminutes[XCmore];
399 TCseconds = XCseconds[XCmore];
408 compptr = (compptr + 1) % MINGAMEIN;
410 if (!(flag.quit || flag.mate || flag.force))
412 #ifdef INTERRUPT_TEST
413 printf("starting search...\n");
415 SelectMove(computer, FOREGROUND_MODE);
417 if (computer == white)
423 else if (TimeControl.moves[computer] == 0)
429 TCmoves = XCmoves[XCmore];
430 TCminutes = XCminutes[XCmore];
431 TCseconds = XCseconds[XCmore];