Deal with simple compiler warnings: dead code, unused parameters, etc.
[gnushogi.git] / gnushogi / commondsp.c
blob40bfd22e329e79f415c7086e9b06acd5dd1d700f
1 /*
2 * FILE: commondsp.c
4 * Common display routines for GNU Shogi.
6 * ----------------------------------------------------------------------
7 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
8 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
10 * GNU SHOGI is based on GNU CHESS
12 * Copyright (c) 1988, 1989, 1990 John Stanback
13 * Copyright (c) 1992 Free Software Foundation
15 * This file is part of GNU SHOGI.
17 * GNU Shogi is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 3 of the License,
20 * or (at your option) any later version.
22 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
23 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with GNU Shogi; see the file COPYING. If not, see
29 * <http://www.gnu.org/licenses/>.
30 * ----------------------------------------------------------------------
34 #if defined HAVE_GETTIMEOFDAY
35 #include <sys/time.h>
36 #endif
38 #include <ctype.h>
39 #include <signal.h>
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/file.h>
45 #include "gnushogi.h"
47 char mvstr[4][6];
48 char *InPtr;
49 int InBackground = false;
50 struct display *dsp = &raw_display;
53 #if defined(BOOKTEST)
55 void
56 movealgbr(short m, char *s)
58 unsigned int f, t;
59 short piece = 0, flag = 0;
61 if (m == 0)
63 strcpy(s, "none");
64 return;
67 f = (m >> 8) & 0x7f;
68 t = m & 0xff;
70 if (f > NO_SQUARES)
72 piece = f - NO_SQUARES;
74 if (piece > NO_PIECES)
75 piece -= NO_PIECES;
77 flag = (dropmask | piece);
80 if (t & 0x80)
82 flag |= promote;
83 t &= 0x7f;
86 if (flag & dropmask)
88 *s = pxx[piece];
89 s++;
90 *s = '*';
91 s++;
92 *s = cxx[column(t)];
93 s++;
94 *s = rxx[row(t)];
95 s++;
97 else
99 *s = cxx[column(f)];
100 s++;
101 *s = rxx[row(f)];
102 s++;
103 *s = cxx[column(t)];
104 s++;
105 *s = rxx[row(t)];
106 s++;
108 if (flag & promote)
110 *s = '+';
111 s++;
115 if (m & 0x8000)
117 *s = '?';
118 s++;
121 *s = '\0';
124 #endif /* BOOKTEST */
128 * Generate move strings in different formats.
130 * INPUT:
131 * - f piece to be moved
132 * - 0 < f < NO_SQUARES source square
133 * - NO_SQUARES <= f NO_SQUARES + 2*NO_PIECES dropped piece modulo NO_PIECES
134 * - t & 0x7f target square
135 * - t & 0x80 promotion flag
136 * - flag FIXME: must be zero ?
138 * OUTPUT:
139 * - GLOBAL mvstr
142 void
143 algbr(short f, short t, short flag)
145 if (f > NO_SQUARES)
147 short piece;
149 piece = f - NO_SQUARES;
151 if (f > (NO_SQUARES + NO_PIECES))
152 piece -= NO_PIECES;
154 flag = (dropmask | piece);
157 if ((t & 0x80) != 0)
159 flag |= promote;
160 t &= 0x7f;
163 if ((f == t) && ((f != 0) || (t != 0)))
165 if (!barebones) {
166 dsp->Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
169 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
171 else if ((flag & dropmask) != 0)
173 short piece = flag & pmask;
175 mvstr[0][0] = pxx[piece];
176 mvstr[0][1] = '*';
177 mvstr[0][2] = cxx[column(t)];
178 mvstr[0][3] = rxx[row(t)];
179 mvstr[0][4] = '\0';
180 strcpy(mvstr[1], mvstr[0]);
181 strcpy(mvstr[2], mvstr[0]);
182 strcpy(mvstr[3], mvstr[0]);
184 else if ((f != 0) || (t != 0))
186 /* algebraic notation */
187 mvstr[0][0] = cxx[column(f)];
188 mvstr[0][1] = rxx[row(f)];
189 mvstr[0][2] = cxx[column(t)];
190 mvstr[0][3] = rxx[row(t)];
191 mvstr[0][4] = mvstr[3][0] = '\0';
192 mvstr[1][0] = pxx[board[f]];
194 mvstr[2][0] = mvstr[1][0];
195 mvstr[2][1] = mvstr[0][1];
197 mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */
198 mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */
199 mvstr[2][4] = mvstr[1][3] = '\0';
200 strcpy(mvstr[3], mvstr[2]);
201 mvstr[3][1] = mvstr[0][0];
203 if (flag & promote)
205 strcat(mvstr[0], "+");
206 strcat(mvstr[1], "+");
207 strcat(mvstr[2], "+");
208 strcat(mvstr[3], "+");
211 else
213 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
219 * Compare the string 's' to the list of legal moves available for the
220 * opponent. If a match is found, make the move on the board.
224 VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
226 static short pnt, tempb, tempc, tempsf, tempst, cnt;
227 static struct leaf xnode;
228 struct leaf *node;
229 short i, l, local_flags;
230 char buffer[60];
232 /* check and remove quality flags */
233 for (i = local_flags = 0, l = strlen(s); i < l; i++)
235 switch(s[i])
237 case '?':
238 local_flags |= badmove;
239 s[i] = '\0';
240 break;
242 case '!':
243 local_flags |= goodmove;
244 s[i] = '\0';
245 break;
247 #ifdef EASY_OPENINGS
248 case '~':
249 local_flags |= difficult;
250 s[i] = '\0';
251 break;
252 #endif
256 *mv = 0;
258 if (iop == UNMAKE_MODE)
260 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
261 return false;
264 cnt = 0;
266 if (iop == VERIFY_AND_MAKE_MODE)
267 generate_move_flags = true;
269 MoveList(opponent, 2, -1, true);
270 generate_move_flags = false;
271 pnt = TrPnt[2];
273 while (pnt < TrPnt[3])
275 node = &Tree[pnt++];
276 algbr(node->f, node->t, (short) node->flags);
278 if ((strcmp(s, mvstr[0]) == 0)
279 || (strcmp(s, mvstr[1]) == 0)
280 || (strcmp(s, mvstr[2]) == 0)
281 || (strcmp(s, mvstr[3]) == 0))
283 cnt++;
284 xnode = *node;
288 if ((cnt == 1) && (xnode.score > DONTUSE))
290 short blocked;
292 MakeMove(opponent, &xnode, &tempb, &tempc,
293 &tempsf, &tempst, &INCscore);
295 if (SqAttacked(PieceList[opponent][0], computer, &blocked))
297 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
298 dsp->AlwaysShowMessage("Illegal move (in check) %s", s);
299 return false;
301 else
303 if (iop == VERIFY_AND_TRY_MODE)
304 return true;
306 dsp->UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
307 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
308 GameList[GameCnt].nodes = 0;
309 ElapsedTime(COMPUTE_AND_INIT_MODE);
310 GameList[GameCnt].time = (short) (et + 50)/100;
311 GameList[GameCnt].flags |= local_flags;
313 if (TCflag)
315 TimeControl.clock[opponent] -= et;
316 timeopp[oppptr] = et;
317 --TimeControl.moves[opponent];
320 *mv = (xnode.f << 8) | xnode.t;
321 algbr(xnode.f, xnode.t, false);
323 /* in force mode, check for mate conditions */
324 if (flag.force)
326 if (IsCheckmate(opponent ^ 1, -1, -1))
328 char buf[20];
330 sprintf(buf, "%s mates!\n", ColorStr[opponent]);
331 dsp->ShowMessage(buf);
332 flag.mate = true;
336 return true;
340 dsp->AlwaysShowMessage("Illegal move (no match) %s", s);
342 if (!barebones && (cnt > 1))
344 sprintf(buffer, "Ambiguous Move %s!", s);
345 dsp->ShowMessage(buffer);
348 return false;
352 static int
353 parser(char *f, short *fpiece)
355 int c1, r1, c2, r2;
356 short i, p = false;
358 if (*f == '+')
359 f++, p = true;
361 for (i = 1, *fpiece = no_piece; i < NO_PIECES; i++)
363 if (f[0] == pxx[i] || f[0] == qxx[i])
365 *fpiece = (p ? promoted[i] : unpromoted[i]);
366 break;
370 if (f[1] == '*' || f[1] == '\'')
372 c2 = COL_NAME(f[2]);
373 r2 = ROW_NAME(f[3]);
375 return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
377 else
379 c1 = COL_NAME(f[1]);
380 r1 = ROW_NAME(f[2]);
381 c2 = COL_NAME(f[3]);
382 r2 = ROW_NAME(f[4]);
383 p = (f[5] == '+') ? 0x80 : 0;
385 return (locn(r1, c1) << 8) | locn(r2, c2) | p;
390 void
391 skip()
393 while (*InPtr != ' ')
394 InPtr++;
396 while (*InPtr == ' ')
397 InPtr++;
401 void
402 skipb()
404 while (*InPtr == ' ')
405 InPtr++;
409 void RequestInputString(char* buffer, unsigned bufsize)
411 static char fmt[10];
412 int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize);
413 if (ret < 0 ) {
414 perror("RequestInputString snprintf");
415 exit(1);
417 if (ret >= sizeof(fmt)) {
418 fprintf(stderr,
419 "Insufficient format-buffer size in %s for bufsize=%u\n",
420 __FUNCTION__, bufsize);
421 exit(1);
423 dsp->doRequestInputString(fmt, buffer);
427 void
428 GetGame(void)
430 FILE *fd;
431 char fname[256], *p;
432 int c, i, j;
433 short sq;
434 short side, isp;
436 if (savefile[0]) {
437 strcpy(fname, savefile);
438 } else {
439 dsp->ShowMessage("Enter file name: ");
440 RequestInputString(fname, sizeof(fname)-1);
443 if (fname[0] == '\0')
444 strcpy(fname, "shogi.000");
446 if ((fd = fopen(fname, "r")) != NULL)
448 NewGame();
449 fgets(fname, 256, fd);
450 computer = opponent = black;
451 InPtr = fname;
452 skip();
454 if (*InPtr == 'c')
455 computer = white;
456 else
457 opponent = white;
459 /* FIXME: write a skipn() function so that we can get
460 * 3 skips by doing skipn(3) */
461 skip();
462 skip();
463 skip();
464 Game50 = atoi(InPtr);
465 skip();
466 flag.force = (*InPtr == 'f');
467 fgets(fname, 256, fd); /* empty */
468 fgets(fname, 256, fd);
469 InPtr = &fname[11];
470 skipb();
471 TCflag = atoi(InPtr);
472 skip();
473 InPtr += 14;
474 skipb();
475 OperatorTime = atoi(InPtr);
476 fgets(fname, 256, fd);
477 InPtr = &fname[11];
478 skipb();
479 TimeControl.clock[black] = atol(InPtr);
480 skip();
481 skip();
482 TimeControl.moves[black] = atoi(InPtr);
483 fgets(fname, 256, fd);
484 InPtr = &fname[11];
485 skipb();
486 TimeControl.clock[white] = atol(InPtr);
487 skip();
488 skip();
489 TimeControl.moves[white] = atoi(InPtr);
490 fgets(fname, 256, fd); /* empty */
492 for (i = NO_ROWS - 1; i > -1; i--)
494 fgets(fname, 256, fd);
495 p = &fname[2];
496 InPtr = &fname[23];
498 for (j = 0; j < NO_COLS; j++)
500 sq = i * NO_COLS + j;
501 isp = (*p == '+');
502 p++;
504 if (*p == '-')
506 board[sq] = no_piece;
507 color[sq] = neutral;
509 else
511 for (c = 0; c < NO_PIECES; c++)
513 if (*p == pxx[c])
515 if (isp)
516 board[sq] = promoted[c];
517 else
518 board[sq] = unpromoted[c];
520 color[sq] = white;
524 for (c = 0; c < NO_PIECES; c++)
526 if (*p == qxx[c])
528 if (isp)
529 board[sq] = promoted[c];
530 else
531 board[sq] = unpromoted[c];
533 color[sq] = black;
538 p++;
539 Mvboard[sq] = atoi(InPtr);
540 skip();
544 fgets(fname, 256, fd); /* empty */
545 fgets(fname, 256, fd); /* 9 8 7 ... */
546 fgets(fname, 256, fd); /* empty */
547 fgets(fname, 256, fd); /* p l n ... */
548 ClearCaptured();
550 for (side = 0; side <= 1; side++)
552 fgets(fname, 256, fd);
553 InPtr = fname;
554 skip();
555 skipb();
556 Captured[side][pawn] = atoi(InPtr);
557 skip();
558 #ifndef MINISHOGI
559 Captured[side][lance] = atoi(InPtr);
560 skip();
561 Captured[side][knight] = atoi(InPtr);
562 skip();
563 #endif
564 Captured[side][silver] = atoi(InPtr);
565 skip();
566 Captured[side][gold] = atoi(InPtr);
567 skip();
568 Captured[side][bishop] = atoi(InPtr);
569 skip();
570 Captured[side][rook] = atoi(InPtr);
571 skip();
572 Captured[side][king] = atoi(InPtr);
575 GameCnt = 0;
576 flag.regularstart = true;
577 Book = BOOKFAIL;
578 fgets(fname, 256, fd); /* empty */
579 fgets(fname, 256, fd); /* move score ... */
581 while (fgets(fname, 256, fd))
583 struct GameRec *g;
584 int side = computer;
586 side = side ^ 1;
587 ++GameCnt;
588 InPtr = fname;
589 skipb();
590 g = &GameList[GameCnt];
591 g->gmove = parser(InPtr, &g->fpiece);
592 skip();
593 g->score = atoi(InPtr);
594 skip();
595 g->depth = atoi(InPtr);
596 skip();
597 g->nodes = atol(InPtr);
598 skip();
599 g->time = atol(InPtr);
600 skip();
601 g->flags = c = atoi(InPtr);
602 skip();
603 g->hashkey = strtol(InPtr, (char **) NULL, 16);
604 skip();
605 g->hashbd = strtol(InPtr, (char **) NULL, 16);
607 if (c & capture)
609 short i, piece;
611 skip();
613 for (piece = no_piece, i = 0; i < NO_PIECES; i++)
615 if (pxx[i] == *InPtr)
617 piece = i;
618 break;
622 skip();
623 g->color = ((*InPtr == 'W') ? white : black);
624 skip();
625 g->piece = (*InPtr == '+'
626 ? promoted[piece]
627 : unpromoted[piece]);
629 else
631 g->color = neutral;
632 g->piece = no_piece;
636 if (TimeControl.clock[black] > 0)
637 TCflag = true;
639 fclose(fd);
642 ZeroRPT();
643 InitializeStats();
644 dsp->UpdateDisplay(0, 0, 1, 0);
645 Sdepth = 0;
646 hint = 0;
650 void
651 SaveGame(void)
653 FILE *fd;
654 char fname[256];
655 short sq, i, c, f, t;
656 char p;
657 short side, piece;
658 char empty[2] = "\n";
660 if (savefile[0]) {
661 strcpy(fname, savefile);
662 } else {
663 dsp->ShowMessage("Enter file name: ");
664 RequestInputString(fname, sizeof(fname)-1);
667 if (fname[0] == '\0')
668 strcpy(fname, "shogi.000");
670 if ((fd = fopen(fname, "w")) != NULL)
672 char *b, *w;
673 b = w = "Human ";
675 if (computer == white)
676 w = "computer";
678 if (computer == black)
679 b = "computer";
681 fprintf(fd, "White %s Black %s %d %s\n", w, b, Game50,
682 flag.force ? "force" : "");
683 fputs(empty, fd);
684 fprintf(fd, "TimeControl %d Operator Time %d\n", TCflag, OperatorTime);
685 fprintf(fd, "Black Clock %ld Moves %d\nWhite Clock %ld Moves %d\n",
686 TimeControl.clock[black], TimeControl.moves[black],
687 TimeControl.clock[white], TimeControl.moves[white]);
688 fputs(empty, fd);
690 for (i = NO_ROWS - 1; i > -1; i--)
692 fprintf(fd, "%c ", ROW_NAME(i));
694 for (c = 0; c < NO_COLS; c++)
696 sq = i * NO_COLS + c;
697 piece = board[sq];
698 p = is_promoted[piece] ? '+' : ' ';
699 fprintf(fd, "%c", p);
701 switch(color[sq])
703 case white:
704 p = pxx[piece];
705 break;
707 case black:
708 p = qxx[piece];
709 break;
711 default:
712 p = '-';
715 fprintf(fd, "%c", p);
718 fprintf(fd, " ");
720 for (f = i * NO_COLS; f < i * NO_COLS + NO_ROWS; f++)
721 fprintf(fd, " %d", Mvboard[f]);
723 fprintf(fd, "\n");
726 fputs(empty, fd);
727 #ifndef MINISHOGI
728 fprintf(fd, " 9 8 7 6 5 4 3 2 1\n");
729 fputs(empty, fd);
730 fprintf(fd, " p l n s g b r k\n");
731 #else
732 fprintf(fd, " 5 4 3 2 1\n");
733 fputs(empty, fd);
734 fprintf(fd, " p s g b r k\n");
735 #endif
737 for (side = 0; side <= 1; side++)
739 fprintf(fd, "%c", (side == black) ? 'B' : 'W');
740 fprintf(fd, " %2d", Captured[side][pawn]);
741 #ifndef MINISHOGI
742 fprintf(fd, " %2d", Captured[side][lance]);
743 fprintf(fd, " %2d", Captured[side][knight]);
744 #endif
745 fprintf(fd, " %2d", Captured[side][silver]);
746 fprintf(fd, " %2d", Captured[side][gold]);
747 fprintf(fd, " %2d", Captured[side][bishop]);
748 fprintf(fd, " %2d", Captured[side][rook]);
749 fprintf(fd, " %2d", Captured[side][king]);
750 fprintf(fd, "\n");
753 fputs(empty, fd);
754 fputs(" move score depth nodes time flags capture\n", fd);
756 for (i = 1; i <= GameCnt; i++)
758 struct GameRec *g = &GameList[i];
760 f = g->gmove >> 8;
761 t = (g->gmove & 0xFF);
762 algbr(f, t, g->flags);
764 fprintf(fd, "%c%c%-5s %6d %5d %7ld %6ld %5d 0x%08lx 0x%08lx",
765 ((f > NO_SQUARES)
766 ? ' '
767 : (is_promoted[g->fpiece] ? '+' : ' ')),
768 pxx[g->fpiece],
769 ((f > NO_SQUARES) ? &mvstr[0][1] : mvstr[0]),
770 g->score, g->depth,
771 g->nodes, g->time, g->flags,
772 g->hashkey, g->hashbd);
774 if (g->piece != no_piece)
776 fprintf(fd, " %c %s %c\n",
777 pxx[g->piece], ColorStr[g->color],
778 (is_promoted[g->piece] ? '+' : ' '));
780 else
782 fprintf(fd, "\n");
786 fclose(fd);
788 dsp->ShowMessage("Game saved");
790 else
792 dsp->ShowMessage("Could not open file");
798 * GetXGame, SaveXGame and BookGame used to only be defined if
799 * xshogi wasn't defined -- wonder why?
802 void
803 GetXGame(void)
805 FILE *fd;
806 char fname[256], *p;
807 int c, i, j;
808 short sq;
809 short side, isp;
811 dsp->ShowMessage("Enter file name: ");
812 RequestInputString(fname, sizeof(fname)-1);
814 if (fname[0] == '\0')
815 strcpy(fname, "xshogi.position.read");
817 if ((fd = fopen(fname, "r")) != NULL)
819 NewGame();
820 flag.regularstart = false;
821 Book = false;
823 /* xshogi position file ... */
824 fgets(fname, 256, fd);
826 #ifdef notdef
827 fname[6] = '\0';
829 if (strcmp(fname, "xshogi"))
830 return;
831 #endif
833 /* -- empty line -- */
834 fgets(fname, 256, fd);
835 /* -- empty line -- */
836 fgets(fname, 256, fd);
838 for (i = NO_ROWS - 1; i > -1; i--)
840 fgets(fname, 256, fd);
841 p = fname;
843 for (j = 0; j < NO_COLS; j++)
845 sq = i * NO_COLS + j;
846 isp = (*p == '+');
847 p++;
849 if (*p == '.')
851 board[sq] = no_piece;
852 color[sq] = neutral;
854 else
856 for (c = 0; c < NO_PIECES; c++)
858 if (*p == qxx[c])
860 if (isp)
861 board[sq] = promoted[c];
862 else
863 board[sq] = unpromoted[c];
865 color[sq] = white;
869 for (c = 0; c < NO_PIECES; c++)
871 if (*p == pxx[c])
873 if (isp)
874 board[sq] = promoted[c];
875 else
876 board[sq] = unpromoted[c];
878 color[sq] = black;
883 p++;
887 ClearCaptured();
889 for (side = 0; side <= 1; side++)
891 fgets(fname, 256, fd);
892 InPtr = fname;
893 Captured[side][pawn] = atoi(InPtr);
894 skip();
895 #ifndef MINISHOGI
896 Captured[side][lance] = atoi(InPtr);
897 skip();
898 Captured[side][knight] = atoi(InPtr);
899 skip();
900 #endif
901 Captured[side][silver] = atoi(InPtr);
902 skip();
903 Captured[side][gold] = atoi(InPtr);
904 skip();
905 Captured[side][bishop] = atoi(InPtr);
906 skip();
907 Captured[side][rook] = atoi(InPtr);
908 skip();
909 Captured[side][king] = atoi(InPtr);
912 if (fgets(fname, 256, fd) != NULL && strncmp(fname, "white", 5) == 0)
914 computer = black;
915 opponent = white;
916 xwndw = BXWNDW;
919 fclose(fd);
922 Game50 = 1;
923 ZeroRPT();
924 InitializeStats();
925 dsp->UpdateDisplay(0, 0, 1, 0);
926 Sdepth = 0;
927 hint = 0;
931 void
932 SaveXGame(void)
934 FILE *fd;
935 char fname[256], *p;
936 int i, j;
937 short sq, piece;
938 short side, isp;
940 dsp->ShowMessage("Enter file name: ");
941 RequestInputString(fname, sizeof(fname)-1);
943 if (fname[0] == '\0')
944 strcpy(fname, "xshogi.position.read");
946 if ((fd = fopen(fname, "w")) != NULL)
948 fputs("# xshogi position file -- \n", fd);
949 fputs("\n", fd);
950 fputs("\n", fd);
952 for (i = NO_ROWS - 1; i > -1; i--)
954 p = fname;
956 for (j = 0; j < NO_COLS; j++)
958 sq = i * NO_COLS + j;
959 piece = board[sq];
960 isp = is_promoted[piece];
961 *p = (isp ? '+' : ' ');
962 p++;
964 if (piece == no_piece)
965 *p = '.';
966 else if (color[sq] == white)
967 *p = qxx[piece];
968 else
969 *p = pxx[piece];
971 p++;
974 *p++ = '\n';
975 *p++ = '\0';
976 fputs(fname, fd);
979 for (side = 0; side <= 1; side++)
981 sprintf(fname,
982 #ifndef MINISHOGI
983 "%d %d %d %d %d %d %d %d\n",
984 #else
985 "%d %d %d %d %d %d\n",
986 #endif
987 Captured[side][pawn],
988 #ifndef MINISHOGI
989 Captured[side][lance],
990 Captured[side][knight],
991 #endif
992 Captured[side][silver],
993 Captured[side][gold],
994 Captured[side][bishop],
995 Captured[side][rook],
996 Captured[side][king]);
998 fputs(fname, fd);
1001 if (computer == black)
1002 fputs("white to play\n", fd);
1003 else
1004 fputs("black to play\n", fd);
1006 fclose(fd);
1011 void
1012 BookSave(void)
1014 FILE *fd;
1015 char fname[256], sflags[4];
1016 short i, j, f, t;
1018 if (savefile[0]) {
1019 strcpy(fname, savefile);
1020 } else {
1021 /* Enter file name */
1022 dsp->ShowMessage("Enter file name: ");
1023 RequestInputString(fname, sizeof(fname)-1);
1026 if (fname[0] == '\0')
1027 return;
1029 if ((fd = fopen(fname, "a")) != NULL)
1031 fprintf(fd, "#\n");
1033 for (i = 1; i <= GameCnt; i++)
1035 struct GameRec *g = &GameList[i];
1036 char mvnr[20], mvs[20];
1038 if (i % 2)
1039 sprintf(mvnr, "%d.", (i + 1)/2);
1040 else
1041 strcpy(mvnr, "");
1043 f = g->gmove >> 8;
1044 t = (g->gmove & 0xFF);
1045 algbr(f, t, g->flags);
1046 j = 0;
1048 /* determine move quality string */
1049 if (g->flags & goodmove)
1050 sflags[j++] = '!';
1052 if (g->flags & badmove)
1053 sflags[j++] = '?';
1055 #ifdef EASY_OPENINGS
1056 if (g->flags & difficult)
1057 sflags[j++] = '~';
1058 #endif
1060 sflags[j] = '\0';
1062 /* determine move string */
1063 if (f > NO_SQUARES)
1065 sprintf(mvs, "%s%s ", &mvstr[0][1], sflags);
1067 else
1069 sprintf(mvs, "%c%c%c%c%c%s%s ",
1070 mvstr[0][0], mvstr[0][1],
1071 (g->flags & capture) ? 'x' : '-',
1072 mvstr[0][2], mvstr[0][3],
1073 (mvstr[0][4] == '+') ? "+" : "",
1074 sflags);
1077 fprintf(fd, "%s%s%c%s",
1078 mvnr,
1079 (f > NO_SQUARES
1080 ? ""
1081 : (is_promoted[g->fpiece] ? "+" : "")),
1082 pxx[g->fpiece],
1083 mvs);
1085 if ((i % 10) == 0)
1086 fprintf(fd, "\n");
1089 if ((i % 10) != 1)
1090 fprintf(fd, "\n");
1092 fclose(fd);
1094 dsp->ShowMessage("Game saved");
1096 else
1098 dsp->ShowMessage("Could not open file");
1103 void
1104 ListGame(void)
1106 FILE *fd;
1107 short i, f, t;
1108 time_t when;
1109 char fname[256], dbuf[256];
1111 if (listfile[0])
1113 strcpy(fname, listfile);
1115 else
1117 time(&when);
1118 strncpy(dbuf, ctime(&when), 20);
1119 dbuf[7] = '\0';
1120 dbuf[10] = '\0';
1121 dbuf[13] = '\0';
1122 dbuf[16] = '\0';
1123 dbuf[19] = '\0';
1125 /* use format "CL.Jan01-020304B" when
1126 date is Jan 1
1127 time is 02:03:04
1128 program played white */
1130 sprintf(fname, "CL.%s%s-%s%s%s%c",
1131 dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14,
1132 dbuf + 17, ColorStr[computer][0]);
1134 /* replace space padding with 0 */
1135 for (i = 0; fname[i] != '\0'; i++)
1137 if (fname[i] == ' ')
1138 fname[i] = '0';
1142 fd = fopen(fname, "w");
1144 if (!fd)
1146 printf("Open failure for file: %s", fname);
1147 exit(1);
1150 fprintf(fd, "gnushogi %s game\n", PACKAGE_VERSION);
1151 fputs(" score depth nodes time ", fd);
1152 fputs(" score depth nodes time\n", fd);
1154 for (i = 1; i <= GameCnt; i++)
1156 f = GameList[i].gmove >> 8;
1157 t = (GameList[i].gmove & 0xFF);
1158 algbr(f, t, GameList[i].flags);
1160 if (GameList[i].flags & book)
1162 fprintf(fd, "%c%c%-5s %5d Book%7ld %5ld",
1163 ((f > NO_SQUARES)
1164 ? ' '
1165 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1166 pxx[GameList[i].fpiece],
1167 ((f > NO_SQUARES)
1168 ? &mvstr[0][1] : mvstr[0]),
1169 GameList[i].score,
1170 GameList[i].nodes,
1171 GameList[i].time);
1173 else
1175 fprintf(fd, "%c%c%-5s %5d %2d %7ld %5ld",
1176 (f > NO_SQUARES
1177 ? ' '
1178 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1179 pxx[GameList[i].fpiece],
1180 (f > NO_SQUARES ? &mvstr[0][1] : mvstr[0]),
1181 GameList[i].score, GameList[i].depth,
1182 GameList[i].nodes, GameList[i].time);
1185 if ((i % 2) == 0)
1187 fprintf(fd, "\n");
1189 else
1191 fprintf(fd, " ");
1195 fprintf(fd, "\n\n");
1197 if (GameList[GameCnt].flags & draw)
1199 fprintf(fd, "Draw %s\n", DRAW);
1201 if (DRAW == DRAW_REPETITION)
1203 short j;
1205 fprintf(fd, "repetition by positions ");
1207 for (j = GameCnt - 1; j >= Game50; j -= 2)
1209 if (GameList[j].hashkey == hashkey &&
1210 GameList[j].hashbd == hashbd)
1211 fprintf(fd, "%d ", j);
1214 fprintf(fd, "\n");
1217 else if (GameList[GameCnt].score == -(SCORE_LIMIT + 999))
1219 fprintf(fd, "%s\n", ColorStr[player ]);
1221 else if (GameList[GameCnt].score == (SCORE_LIMIT + 998))
1223 fprintf(fd, "%s\n", ColorStr[player ^ 1]);
1226 fclose(fd);
1230 void
1231 FlagMove(char c)
1233 switch(c)
1235 case '?' :
1236 GameList[GameCnt].flags |= badmove;
1237 break;
1239 case '!' :
1240 GameList[GameCnt].flags |= goodmove;
1241 break;
1243 #ifdef EASY_OPENINGS
1244 case '~' :
1245 GameList[GameCnt].flags |= difficult;
1246 break;
1247 #endif
1253 * Undo the most recent half-move.
1256 void
1257 Undo(void)
1259 short f, t;
1261 f = GameList[GameCnt].gmove >> 8;
1262 t = GameList[GameCnt].gmove & 0x7F;
1264 if (f > NO_SQUARES)
1266 /* the move was a drop */
1267 Captured[color[t]][board[t]]++;
1268 board[t] = no_piece;
1269 color[t] = neutral;
1270 Mvboard[t]--;
1272 else
1274 if (GameList[GameCnt].flags & promote)
1275 board[f] = unpromoted[board[t]];
1276 else
1277 board[f] = board[t];
1279 color[f] = color[t];
1280 board[t] = GameList[GameCnt].piece;
1281 color[t] = GameList[GameCnt].color;
1283 if (board[t] != no_piece)
1284 Captured[color[f]][unpromoted[board[t]]]--;
1286 if (color[t] != neutral)
1287 Mvboard[t]--;
1289 Mvboard[f]--;
1292 InitializeStats();
1294 if (TCflag && (TCmoves > 1))
1295 ++TimeControl.moves[color[f]];
1297 hashkey = GameList[GameCnt].hashkey;
1298 hashbd = GameList[GameCnt].hashbd;
1299 GameCnt--;
1300 computer = computer ^ 1;
1301 opponent = opponent ^ 1;
1302 flag.mate = false;
1303 Sdepth = 0;
1304 player = player ^ 1;
1305 dsp->ShowSidetoMove();
1306 dsp->UpdateDisplay(0, 0, 1, 0);
1308 if (flag.regularstart)
1309 Book = false;
1313 void
1314 FlagString(unsigned short flags, char *s)
1316 short l, piece;
1317 *s = '\0';
1319 if (flags & promote)
1320 strcat(s, " promote");
1322 if (flags & dropmask)
1323 strcat(s, " drop:");
1325 if ((piece = (flags & pmask)))
1327 l = strlen(s);
1329 if (is_promoted[piece])
1330 s[l++] = '+';
1332 s[l++] = pxx[piece];
1333 s[l] = '\0';
1336 if (flags & capture)
1337 strcat(s, " capture");
1339 if (flags & exact)
1340 strcat(s, " exact");
1342 if (flags & tesuji)
1343 strcat(s, " tesuji");
1345 if (flags & check)
1346 strcat(s, " check");
1348 if (flags & draw)
1349 strcat(s, " draw");
1351 if (flags & stupid)
1352 strcat(s, " stupid");
1354 if (flags & questionable)
1355 strcat(s, " questionable");
1357 if (flags & kingattack)
1358 strcat(s, " kingattack");
1360 if (flags & book)
1361 strcat(s, " book");
1365 void
1366 TestSpeed(void(*f)(short side, short ply,
1367 short in_check, short blockable),
1368 unsigned j)
1370 #ifdef test
1371 unsigned jj;
1372 #endif
1374 unsigned i;
1375 long cnt, t1, t2;
1377 #ifdef HAVE_GETTIMEOFDAY
1378 struct timeval tv;
1379 #endif
1381 #ifdef HAVE_GETTIMEOFDAY
1382 gettimeofday(&tv, NULL);
1383 t1 = (tv.tv_sec*100 + (tv.tv_usec/10000));
1384 #else
1385 t1 = time(0);
1386 #endif
1388 for (i = 0; i < j; i++)
1390 f(opponent, 2, -1, true);
1392 #ifdef test
1393 for (jj = TrPnt[2]; i < TrPnt[3]; jj++)
1395 if (!pick(jj, TrPnt[3] - 1))
1396 break;
1398 #endif
1401 #ifdef HAVE_GETTIMEOFDAY
1402 gettimeofday(&tv, NULL);
1403 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1404 #else
1405 t2 = time(0);
1406 #endif
1408 cnt = j * (TrPnt[3] - TrPnt[2]);
1410 if (t2 - t1)
1411 et = (t2 - t1);
1412 else
1413 et = 1;
1415 dsp->ShowNodeCnt(cnt);
1419 void
1420 TestPSpeed(short(*f) (short side), unsigned j)
1422 unsigned i;
1423 long cnt, t1, t2;
1424 #ifdef HAVE_GETTIMEOFDAY
1425 struct timeval tv;
1426 #endif
1428 #ifdef HAVE_GETTIMEOFDAY
1429 gettimeofday(&tv, NULL);
1430 t1 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1431 #else
1432 t1 = time(0);
1433 #endif
1435 for (i = 0; i < j; i++)
1436 (void) f(opponent);
1438 #ifdef HAVE_GETTIMEOFDAY
1439 gettimeofday(&tv, NULL);
1440 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1441 #else
1442 t2 = time(0);
1443 #endif
1445 cnt = j;
1447 if (t2 - t1)
1448 et = (t2 - t1);
1449 else
1450 et = 1;
1452 dsp->ShowNodeCnt(cnt);
1456 void
1457 SetOppTime(char *s)
1459 char *time;
1460 int m, t, sec;
1462 sec = 0;
1463 time = &s[strlen("otime")];
1464 t = (int)strtol(time, &time, 10);
1466 if (*time == ':')
1468 time++;
1469 /* FIXME: sec is parsed but ignored */
1470 sec = (int)strtol(time, &time, 10);
1473 m = (int)strtol(time, &time, 10);
1475 if (t)
1476 TimeControl.clock[opponent] = t;
1478 if (m)
1479 TimeControl.moves[opponent] = m;
1481 ElapsedTime(COMPUTE_AND_INIT_MODE);
1483 if (XSHOGI)
1485 /* just to inform xshogi about availability of otime command */
1486 printf("otime %d %d\n", t, m);
1491 void
1492 SetMachineTime(char *s)
1494 char *time;
1495 int m, t, sec;
1497 time = &s[strlen("time")];
1498 sec = 0;
1499 t = (int)strtol(time, &time, 10);
1501 if (*time == ':')
1503 time++;
1504 /* FIXME: sec is parsed but ignored */
1505 sec = (int)strtol(time, &time, 10);
1508 m = (int)strtol(time, &time, 10);
1510 if (t)
1511 TimeControl.clock[computer] = t;
1513 if (m)
1514 TimeControl.moves[computer] = m;
1516 ElapsedTime(COMPUTE_AND_INIT_MODE);
1518 if (XSHOGI)
1520 /* just to inform xshogi about availability of time command */
1521 printf("time %d %d\n", t, m);
1526 /* FIXME! This is truly the function from hell! */
1529 * Process the user's command. If easy mode is OFF (the computer is thinking
1530 * on opponents time) and the program is out of book, then make the 'hint'
1531 * move on the board and call SelectMove() to find a response. The user
1532 * terminates the search by entering ^C (quit siqnal) before entering a
1533 * command. If the opponent does not make the hint move, then set Sdepth to
1534 * zero.
1537 void
1538 InputCommand(char *command)
1540 int eof = 0;
1541 short have_shown_prompt = false;
1542 short ok, done, is_move = false;
1543 unsigned short mv;
1544 char s[80], sx[80];
1546 ok = flag.quit = done = false;
1547 player = opponent;
1549 #if ttblsz
1550 if (TTadd > ttbllimit)
1551 ZeroTTable();
1552 #endif
1554 if ((hint > 0) && !flag.easy && !flag.force)
1557 * A hint move for the player is available. Compute a move for the
1558 * opponent in background mode assuming that the hint move will be
1559 * selected by the player.
1562 ft = time0; /* Save reference time for the player. */
1563 fflush(stdout);
1564 algbr((short) hint >> 8, (short) hint & 0xff, false);
1565 strcpy(s, mvstr[0]);
1567 #if !defined NOPOST
1568 if (flag.post)
1569 dsp->GiveHint();
1570 #endif
1572 /* do the hint move */
1573 if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv))
1575 Sdepth = 0;
1577 #ifdef QUIETBACKGROUND
1578 dsp->ShowPrompt();
1579 have_shown_prompt = true;
1580 #endif /* QUIETBACKGROUND */
1582 /* Start computing a move until the search is interrupted. */
1584 #ifdef INTERRUPT_TEST
1585 itime0 = 0;
1586 #endif
1588 /* would love to put null move in here */
1589 /* after we make the hint move make a 2 ply search
1590 * with both plys our moves */
1591 /* think on opponents time */
1592 SelectMove(computer, BACKGROUND_MODE);
1594 #ifdef INTERRUPT_TEST
1595 ElapsedTime(COMPUTE_INTERRUPT_MODE);
1597 if (itime0 == 0)
1599 printf("searching not terminated by interrupt!\n");
1601 else
1603 printf("elapsed time from interrupt to "
1604 "terminating search: %ld\n", it);
1606 #endif
1608 /* undo the hint and carry on */
1609 VerifyMove(s, UNMAKE_MODE, &mv);
1610 Sdepth = 0;
1613 time0 = ft; /* Restore reference time for the player. */
1616 while(!(ok || flag.quit || done))
1618 player = opponent;
1620 #ifdef QUIETBACKGROUND
1621 if (!have_shown_prompt)
1623 #endif /* QUIETBACKGROUND */
1625 dsp->ShowPrompt();
1627 #ifdef QUIETBACKGROUND
1630 have_shown_prompt = false;
1631 #endif /* QUIETBACKGROUND */
1633 if (command == NULL) {
1634 if (NOT_CURSES)
1635 s[0] = '\0';
1637 eof = dsp->GetString(sx);
1638 } else {
1639 strcpy(sx, command);
1640 done = true;
1643 sscanf(sx, "%s", s);
1645 if (eof)
1646 dsp->ExitShogi();
1648 if (s[0] == '\0')
1649 continue;
1651 if (strcmp(s, "bd") == 0) /* bd -- display board */
1653 /* FIXME: Hack alert! */
1654 short old_xshogi = XSHOGI;
1656 if (old_xshogi)
1657 display_type = DISPLAY_RAW;
1659 dsp->ClearScreen();
1660 dsp->UpdateDisplay(0, 0, 1, 0);
1662 if (old_xshogi)
1663 display_type = DISPLAY_X;
1665 else if (strcmp(s, "post") == 0)
1667 flag.post = !flag.post;
1669 else if (strcmp(s, "alg") == 0)
1671 /* noop */ ; /* alg */
1673 else if ((strcmp(s, "quit") == 0)
1674 || (strcmp(s, "exit") == 0))
1676 flag.quit = true;
1678 #if !defined NOPOST
1679 else if (strcmp(s, "post") == 0)
1681 flag.post = !flag.post;
1683 #endif
1684 else if ((strcmp(s, "set") == 0)
1685 || (strcmp(s, "edit") == 0))
1687 dsp->EditBoard();
1689 else if ((strcmp(s, "setup") == 0))
1691 dsp->SetupBoard();
1693 else if (strcmp(s, "first") == 0)
1695 ok = true;
1697 else if (strcmp(s, "go") == 0)
1699 ok = true;
1700 flag.force = false;
1702 if (computer == black)
1704 computer = white;
1705 opponent = black;
1707 else
1709 computer = black;
1710 opponent = white;
1713 else if (strcmp(s, "help") == 0)
1715 dsp->help();
1717 else if (strcmp(s, "material") == 0)
1719 flag.material = !flag.material;
1721 else if (strcmp(s, "force") == 0)
1723 if (XSHOGI)
1725 flag.force = true;
1726 flag.bothsides = false;
1728 else
1730 flag.force = !flag.force;
1731 flag.bothsides = false;
1734 else if (strcmp(s, "book") == 0)
1736 Book = Book ? 0 : BOOKFAIL;
1738 else if (strcmp(s, "new") == 0)
1740 NewGame();
1741 dsp->UpdateDisplay(0, 0, 1, 0);
1743 else if (strcmp(s, "list") == 0)
1745 ListGame();
1747 else if ((strcmp(s, "level") == 0)
1748 || (strcmp(s, "clock") == 0))
1750 dsp->SelectLevel(sx);
1752 else if (strcmp(s, "hash") == 0)
1754 flag.hash = !flag.hash;
1756 else if (strcmp(s, "gamein") == 0)
1758 flag.gamein = !flag.gamein;
1760 else if (strcmp(s, "beep") == 0)
1762 flag.beep = !flag.beep;
1764 else if (strcmp(s, "time") == 0)
1766 SetMachineTime(sx);
1768 else if (strcmp(s, "otime") == 0)
1770 SetOppTime(sx);
1772 else if (strcmp(s, "Awindow") == 0)
1774 dsp->ChangeAlphaWindow();
1776 else if (strcmp(s, "Bwindow") == 0)
1778 dsp->ChangeBetaWindow();
1780 else if (strcmp(s, "rcptr") == 0)
1782 flag.rcptr = !flag.rcptr;
1784 else if (strcmp(s, "hint") == 0)
1786 dsp->GiveHint();
1788 else if (strcmp(s, "both") == 0)
1790 flag.bothsides = !flag.bothsides;
1791 flag.force = false;
1792 Sdepth = 0;
1793 ElapsedTime(COMPUTE_AND_INIT_MODE);
1794 SelectMove(opponent, FOREGROUND_MODE);
1795 ok = true;
1797 else if (strcmp(s, "reverse") == 0)
1799 flag.reverse = !flag.reverse;
1800 dsp->ClearScreen();
1801 dsp->UpdateDisplay(0, 0, 1, 0);
1803 else if (strcmp(s, "switch") == 0)
1805 computer = computer ^ 1;
1806 opponent = opponent ^ 1;
1807 xwndw = (computer == black) ? WXWNDW : BXWNDW;
1808 flag.force = false;
1809 Sdepth = 0;
1810 ok = true;
1812 else if (strcmp(s, "black") == 0)
1814 computer = white;
1815 opponent = black;
1816 xwndw = WXWNDW;
1817 flag.force = false;
1818 Sdepth = 0;
1821 * ok = true; don't automatically start with black command
1824 else if (strcmp(s, "white") == 0)
1826 computer = black;
1827 opponent = white;
1828 xwndw = BXWNDW;
1829 flag.force = false;
1830 Sdepth = 0;
1833 * ok = true; don't automatically start with white command
1836 else if (strcmp(s, "undo") == 0 && GameCnt > 0)
1838 Undo();
1840 else if (strcmp(s, "remove") == 0 && GameCnt > 1)
1842 Undo();
1843 Undo();
1845 /* CHECKME: are these next three correct? */
1846 else if (!XSHOGI && strcmp(s, "xget") == 0)
1848 GetXGame();
1850 else if (!XSHOGI && strcmp(s, "xsave") == 0)
1852 SaveXGame();
1854 else if (!XSHOGI && strcmp(s, "bsave") == 0)
1856 BookSave();
1858 #ifdef EASY_OPENINGS
1859 else if ((strcmp(s, "?") == 0)
1860 || (strcmp(s, "!") == 0)
1861 || (strcmp(s, "~") == 0))
1862 #else
1863 else if ((strcmp(s, "?") == 0)
1864 || (strcmp(s, "!") == 0))
1865 #endif
1867 FlagMove(*s);
1869 else if (strcmp(s, "get") == 0)
1871 GetGame();
1873 else if (strcmp(s, "save") == 0)
1875 SaveGame();
1877 else if (strcmp(s, "depth") == 0)
1879 dsp->ChangeSearchDepth();
1881 else if (strcmp(s, "hashdepth") == 0)
1883 dsp->ChangeHashDepth();
1885 else if (strcmp(s, "random") == 0)
1887 dither = DITHER;
1889 else if (strcmp(s, "hard") == 0)
1891 flag.easy = false;
1893 else if (strcmp(s, "easy") == 0)
1895 flag.easy = !flag.easy;
1897 else if (strcmp(s, "tsume") == 0)
1899 flag.tsume = !flag.tsume;
1901 else if (strcmp(s, "contempt") == 0)
1903 dsp->SetContempt();
1905 else if (strcmp(s, "xwndw") == 0)
1907 dsp->ChangeXwindow();
1909 else if (strcmp(s, "rv") == 0)
1911 flag.rv = !flag.rv;
1912 dsp->UpdateDisplay(0, 0, 1, 0);
1914 else if (strcmp(s, "coords") == 0)
1916 flag.coords = !flag.coords;
1917 dsp->UpdateDisplay(0, 0, 1, 0);
1919 else if (strcmp(s, "stars") == 0)
1921 flag.stars = !flag.stars;
1922 dsp->UpdateDisplay(0, 0, 1, 0);
1924 else if (!XSHOGI && strcmp(s, "moves") == 0)
1926 short temp;
1928 #if MAXDEPTH > 3
1929 if (GameCnt > 0)
1931 extern unsigned short PrVar[MAXDEPTH];
1933 SwagHt = (GameList[GameCnt].gmove == PrVar[1])
1934 ? PrVar[2] : 0;
1936 else
1937 #endif
1938 SwagHt = 0;
1940 dsp->ShowMessage("Testing MoveList Speed");
1941 temp = generate_move_flags;
1942 generate_move_flags = true;
1943 TestSpeed(MoveList, 1);
1944 generate_move_flags = temp;
1945 dsp->ShowMessage("Testing CaptureList Speed");
1946 TestSpeed(CaptureList, 1);
1947 dsp->ShowMessage("Testing Eval Speed");
1948 ExaminePosition(opponent);
1949 TestPSpeed(ScorePosition, 1);
1951 else if (!XSHOGI && strcmp(s, "test") == 0)
1953 #ifdef SLOW_CPU
1954 dsp->ShowMessage("Testing MoveList Speed");
1955 TestSpeed(MoveList, 2000);
1956 dsp->ShowMessage("Testing CaptureList Speed");
1957 TestSpeed(CaptureList, 3000);
1958 dsp->ShowMessage("Testing Eval Speed");
1959 ExaminePosition(opponent);
1960 TestPSpeed(ScorePosition, 1500);
1961 #else
1962 dsp->ShowMessage("Testing MoveList Speed");
1963 TestSpeed(MoveList, 20000);
1964 dsp->ShowMessage("Testing CaptureList Speed");
1965 TestSpeed(CaptureList, 30000);
1966 dsp->ShowMessage("Testing Eval Speed");
1967 ExaminePosition(opponent);
1968 TestPSpeed(ScorePosition, 15000);
1969 #endif
1971 else if (!XSHOGI && strcmp(s, "p") == 0)
1973 dsp->ShowPostnValues();
1975 else if (!XSHOGI && strcmp(s, "debug") == 0)
1977 dsp->DoDebug();
1979 else
1981 if (flag.mate)
1983 ok = true;
1985 else if ((ok = VerifyMove(s, VERIFY_AND_MAKE_MODE, &mv)))
1987 /* check for repetition */
1988 short rpt = repetition();
1990 if (rpt >= 3)
1992 DRAW = DRAW_REPETITION;
1993 dsp->ShowMessage(DRAW);
1994 GameList[GameCnt].flags |= draw;
1996 flag.mate = true;
1998 else
2000 is_move = true;
2004 Sdepth = 0;
2008 ElapsedTime(COMPUTE_AND_INIT_MODE);
2010 if (flag.force)
2012 computer = opponent;
2013 opponent = computer ^ 1;
2016 if (XSHOGI)
2018 /* add remaining time in milliseconds for xshogi */
2019 if (is_move)
2021 printf("%d. %s %ld\n",
2022 ++mycnt2, s, TimeControl.clock[player] * 10);
2025 #ifdef notdef /* optional pass best line to frontend with move */
2026 # if !defined NOPOST
2028 if (flag.post && !flag.mate)
2030 int i;
2032 printf(" %6d ", MSCORE);
2034 for (i = 1; MV[i] > 0; i++)
2036 algbr((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
2037 printf("%5s ", mvstr[0]);
2040 # endif
2041 printf("\n");
2042 #endif
2047 void
2048 SetTimeControl(void)
2050 if (TCflag)
2052 TimeControl.moves[black] = TimeControl.moves[white] = TCmoves;
2053 TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100;
2054 TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100;
2056 else
2058 TimeControl.moves[black] = TimeControl.moves[white] = 0;
2059 TimeControl.clock[black] = TimeControl.clock[white] = 0;
2062 flag.onemove = (TCmoves == 1);
2063 et = 0;
2064 ElapsedTime(COMPUTE_AND_INIT_MODE);