4 * ----------------------------------------------------------------------
6 * Copyright (c) 2012 Free Software Foundation
8 * GNU SHOGI is based on GNU CHESS
10 * This file is part of GNU SHOGI.
12 * GNU Shogi is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 3 of the License,
15 * or (at your option) any later version.
17 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with GNU Shogi; see the file COPYING. If not, see
24 * <http://www.gnu.org/licenses/>.
25 * ----------------------------------------------------------------------
35 void print_arglist(int argc, char **argv)
39 for (i = 0; i < argc; i++)
40 printf("argv[%d] = %s\n", i, argv[i]);
47 main (int argc, char **argv)
50 * Process command-line arguments.
53 /* Get rid of the program name. */
58 /* CHECKME: get rid of the '+' syntax? */
60 while ((argc > 0) && ((argv[0][0] == '-') || (argv[0][0] == '+')))
65 /* Need the "+" syntax here... */
66 ahead = ((argv[0][0] == '-') ? false : true);
90 binbookfile = argv[0];
96 /* Curses interface. */
97 display_type = DISPLAY_CURSES;
103 /* Need the "+" syntax here... */
104 hash = ((argv[0][0] == '-') ? false : true);
123 strcpy(listfile, argv[0]);
132 strcpy(savefile, argv[0]);
142 bookmaxply = atoi(argv[0]);
148 /* Raw text interface. */
149 display_type = DISPLAY_RAW;
159 booksize = atoi(argv[0]);
168 rehash = atoi(argv[0]);
170 if (rehash > MAXrehash)
181 ttblsize = atoi(argv[0]);
183 if ((ttblsize <= MINTTABLE))
184 ttblsize = (MINTTABLE) + 1;
189 case 'c': /* Create or test persistent transposition table. */
194 filesz = atoi(argv[0]);
198 if ((filesz > 0) && (filesz < 24))
199 filesz = (1 << filesz) - 1 + MAXrehash;
201 filesz = filesz + MAXrehash;
203 if ((hashfile = fopen(HASHFILE, RWA_ACC)) == NULL)
204 hashfile = fopen(HASHFILE, WA_ACC);
206 if (hashfile != NULL)
211 fputs(CP[66], stdout);
217 for (j = 0; j < filesz + 1; j++)
218 fwrite(&n, sizeof(struct fileentry), 1, hashfile);
224 printf(CP[50], HASHFILE);
230 case 't': /* Create or test persistent transposition table. */
231 hashfile = fopen(HASHFILE, RWA_ACC);
235 fseek(hashfile, 0L, SEEK_END);
236 filesz = (ftell(hashfile) / (sizeof(struct fileentry))) - 1;
239 if (hashfile != NULL)
245 fputs(CP[49], stdout);
247 for (i = 0; i < MAXDEPTH; i++)
250 fseek(hashfile, 0L, SEEK_END);
251 i = ftell(hashfile) / (sizeof(struct fileentry));
252 fseek(hashfile, 0L, SEEK_SET);
254 for (j = 0; j < i + 1; j++)
256 fread(&n, sizeof(struct fileentry), 1, hashfile);
258 if (n.depth > MAXDEPTH)
271 printf(CP[109], nr[0], i);
273 for (j = 1; j < MAXDEPTH; j++)
274 printf("%d ", nr[j]);
282 #endif /* HASHFILE */
286 fprintf(stderr, CP[102], version, patchlevel);
292 display_type = DISPLAY_X;
308 fputs(CP[113], stderr);
320 MaxResponseTime = 100L * strtol(argv[1], &p, 10);
324 MaxResponseTime = 60L * MaxResponseTime +
325 100L * strtol(++p, (char **) NULL, 10);
340 printf("%s\n", CP[220]);
344 TCmoves = atoi(argv[1]);
345 TCminutes = (short)strtol(argv[2], &p, 10);
348 TCseconds = (short)strtol(p + 1, (char **) NULL, 10);
358 XCmoves[XC] = atoi(argv[0]);
359 XCminutes[XC] = (short)strtol(argv[1], &p, 10);
362 XCseconds[XC] = (short)strtol(p + 1, (char **) NULL, 10);
366 if (XCmoves[XC] && (XCminutes[XC] || XCseconds[XC]))
370 printf("%s\n", CP[220]);
381 * If we got here, there are unknown arguments, so issue
382 * an error message and quit.
385 printf("%s\n", CP[233]);
386 print_arglist(argc, argv);
396 oppptr = (oppptr + 1) % MINGAMEIN;
398 if (flag.bothsides && !flag.mate)
399 SelectMove(opponent, FOREGROUND_MODE);
403 if (opponent == white)
405 if (flag.gamein || TCadd)
409 else if (TimeControl.moves[opponent] == 0)
415 TCmoves = XCmoves[XCmore];
416 TCminutes = XCminutes[XCmore];
417 TCseconds = XCseconds[XCmore];
426 compptr = (compptr + 1) % MINGAMEIN;
428 if (!(flag.quit || flag.mate || flag.force))
430 #ifdef INTERRUPT_TEST
431 printf("starting search...\n");
433 SelectMove(computer, FOREGROUND_MODE);
435 if (computer == white)
441 else if (TimeControl.moves[computer] == 0)
447 TCmoves = XCmoves[XCmore];
448 TCminutes = XCminutes[XCmore];
449 TCseconds = XCseconds[XCmore];