2 * main.c - C source for GNU SHOGI based on GNU CHESS
4 * Copyright (c) 1988,1989,1990 John Stanback (GNU Chess)
5 * Copyright (c) 1992 Free Software Foundation
6 * Copyright (c) 1993,1994,1995 Matthias Mutz (GNU Shogi)
8 * This file is part of GNU SHOGI.
10 * GNU Shogi is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 1, or (at your option)
15 * GNU Shogi is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with GNU Shogi; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
42 /* print all possible moves for all pieces from all squares */
47 register unsigned char *ppos
, *pdir
;
51 for ( piece
= 0; piece
< NO_PIECES
; piece
++ ) {
52 printf("move list for piece %i\n",piece
);
53 for ( sq
= 0; sq
< NO_SQUARES
; sq
++ ) {
54 printf(" from square %i to ",sq
);
55 ptyp
= ptype
[black
][piece
];
56 ppos
= (*nextpos
)[ptyp
][sq
];
61 if (u
!= sq
) printf(", ");
65 /* pdir = (*nextdir)[ptyp][sq]; */
68 if ( strcmp(s
,"exit") == 0 )
78 main (int argc
, char **argv
)
82 console_options
.ncols
= 100;
91 if (argv
[1][0] == '-' && argv
[1][1] == 'L')
99 while (argc
> 1 && ((argv
[1][0] == '-') || (argv
[1][0] == '+')))
104 ahead
= ((argv
[1][0] == '-') ? false : true);
122 binbookfile
= argv
[1];
126 hash
= ((argv
[1][0] == '-') ? false : true);
132 strcpy (savefile
, argv
[1]);
138 strcpy (listfile
, argv
[1]);
143 if(argc
> 1)booksize
= atoi(argv
[1]);
148 if(argc
> 1)bookmaxply
= atoi(argv
[1]);
154 rehash
= atoi (argv
[2]);
157 if (rehash
> MAXrehash
)
162 ttblsize
= atoi (argv
[2]);
165 if ((ttblsize
<= MINTTABLE
)) ttblsize
= (MINTTABLE
)+1;
168 case 't': /* create or test persistent transposition
170 hashfile
= fopen (HASHFILE
, RWA_ACC
);
173 fseek (hashfile
, 0L, SEEK_END
);
174 filesz
= (ftell (hashfile
) / sizeof (struct fileentry
)) - 1;
176 if (hashfile
!= NULL
)
183 for (i
= 0; i
< MAXDEPTH
; i
++)
185 fseek (hashfile
, 0L, SEEK_END
);
186 i
= ftell (hashfile
) / sizeof (struct fileentry
);
187 fseek (hashfile
, 0L, SEEK_SET
);
188 for (j
= 0; j
< i
+ 1; j
++)
190 fread (&n
, sizeof (struct fileentry
), 1, hashfile
);
191 if(n
.depth
>MAXDEPTH
) {printf("ERROR\n");exit(1);}
200 for (j
= 1; j
< MAXDEPTH
; j
++)
201 printf ("%d ", nr
[j
]);
205 case 'c': /* create or test persistent transposition
208 filesz
= atoi (argv
[2]);
211 if (filesz
> 0 && filesz
< 24)
212 filesz
= (1 << filesz
) - 1 + MAXrehash
;
214 filesz
= filesz
+ MAXrehash
;
216 if ((hashfile
= fopen (HASHFILE
, RWA_ACC
)) == NULL
)
217 hashfile
= fopen (HASHFILE
, WA_ACC
);
218 if (hashfile
!= NULL
)
228 for (j
= 0; j
< filesz
+ 1; j
++)
229 fwrite (&n
, sizeof (struct fileentry
), 1, hashfile
);
233 printf (CP
[50], HASHFILE
);
236 #endif /* HASHFILE */
242 fprintf (stderr
, CP
[102], version
, patchlevel
);
245 fprintf (stderr
, CP
[113]);
256 MaxResponseTime
= 100L * strtol (argv
[1], &p
, 10);
258 MaxResponseTime
= 60L * MaxResponseTime
+
259 100L * strtol (++p
, (char **) NULL
, 10);
271 printf ("%s\n", CP
[220]);
274 TCmoves
= atoi (argv
[1]);
275 TCminutes
= (short)strtol (argv
[2], &p
, 10);
277 TCseconds
= (short)strtol (p
+ 1, (char **) NULL
, 10);
285 XCmoves
[XC
] = atoi (argv
[0]);
286 XCminutes
[XC
] = (short)strtol (argv
[1], &p
, 10);
288 XCseconds
[XC
] = (short)strtol (p
+ 1, (char **) NULL
, 10);
291 if (XCmoves
[XC
] && (XCminutes
[XC
] || XCseconds
[XC
]))
303 printf ("%s\n", CP
[220]);
308 if ( InitMain() != 0 )
317 oppptr
= (oppptr
+ 1) % MINGAMEIN
;
318 if (flag
.bothsides
&& !flag
.mate
) {
319 SelectMove (opponent
, FOREGROUND_MODE
);
322 if (opponent
== white
)
323 if (flag
.gamein
|| TCadd
)
327 else if (TimeControl
.moves
[opponent
] == 0)
332 TCmoves
= XCmoves
[XCmore
];
333 TCminutes
= XCminutes
[XCmore
];
334 TCseconds
= XCseconds
[XCmore
];
340 compptr
= (compptr
+ 1) % MINGAMEIN
;
341 if (!(flag
.quit
|| flag
.mate
|| flag
.force
))
343 #ifdef INTTERRUPT_TEST
344 printf("starting search...\n");
346 SelectMove (computer
, FOREGROUND_MODE
);
347 if (computer
== white
)
352 else if (TimeControl
.moves
[computer
] == 0)
357 TCmoves
= XCmoves
[XCmore
];
358 TCminutes
= XCminutes
[XCmore
];
359 TCseconds
= XCseconds
[XCmore
];