Only build pat2inc and declare it as dep for pattern.inc when not cross-compiling.
[gnushogi.git] / gnushogi / commondsp.c
blob90a3ca0d72f42c1dc02a4676630864b42ca97250
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
9 * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
11 * GNU SHOGI is based on GNU CHESS
13 * Copyright (c) 1988, 1989, 1990 John Stanback
14 * Copyright (c) 1992 Free Software Foundation
16 * This file is part of GNU SHOGI.
18 * GNU Shogi is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the
20 * Free Software Foundation; either version 3 of the License,
21 * or (at your option) any later version.
23 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
24 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * for more details.
28 * You should have received a copy of the GNU General Public License along
29 * with GNU Shogi; see the file COPYING. If not, see
30 * <http://www.gnu.org/licenses/>.
31 * ----------------------------------------------------------------------
35 /* request *snprintf prototypes */
36 #define _POSIX_C_SOURCE 200112L
37 #include <stdio.h>
39 #if defined HAVE_GETTIMEOFDAY
40 #include <sys/time.h>
41 #endif
43 #include <ctype.h>
44 #include <signal.h>
46 #include <sys/param.h>
47 #include <sys/types.h>
48 #include <sys/file.h>
50 #include "gnushogi.h"
52 char mvstr[4][6];
53 int mycnt1, mycnt2;
54 static char *InPtr;
55 struct display *dsp = &raw_display;
58 #if defined(BOOKTEST)
60 void
61 movealgbr(short m, char *s)
63 unsigned int f, t;
64 short piece = 0, flag = 0;
66 if (m == 0)
68 strcpy(s, "none");
69 return;
72 f = (m >> 8) & 0x7f;
73 t = m & 0xff;
75 if (f > NO_SQUARES)
77 piece = f - NO_SQUARES;
79 if (piece > NO_PIECES)
80 piece -= NO_PIECES;
82 flag = (dropmask | piece);
85 if (t & 0x80)
87 flag |= promote;
88 t &= 0x7f;
91 if (flag & dropmask)
93 *s = pxx[piece];
94 s++;
95 *s = '*';
96 s++;
97 *s = COL_NAME(column(t));
98 s++;
99 *s = ROW_NAME(row(t));
100 s++;
102 else
104 *s = COL_NAME(column(f));
105 s++;
106 *s = ROW_NAME(row(f));
107 s++;
108 *s = COL_NAME(column(t));
109 s++;
110 *s = ROW_NAME(row(t));
111 s++;
113 if (flag & promote)
115 *s = '+';
116 s++;
120 if (m & 0x8000)
122 *s = '?';
123 s++;
126 *s = '\0';
129 #endif /* BOOKTEST */
133 * Generate move strings in different formats.
135 * INPUT:
136 * - f piece to be moved
137 * - 0 < f < NO_SQUARES source square
138 * - NO_SQUARES <= f NO_SQUARES + 2*NO_PIECES dropped piece modulo NO_PIECES
139 * - t & 0x7f target square
140 * - t & 0x80 promotion flag
141 * - flag
142 * - if flag & dropmask, piece type encoded in flag & pmask
144 * FIXME: that makes 2 ways to specify drops and promotions, why ?
146 * OUTPUT:
147 * - GLOBAL mvstr
150 void
151 algbr(short f, short t, short flag)
153 if (f > NO_SQUARES)
155 short piece;
157 piece = f - NO_SQUARES;
159 if (f > (NO_SQUARES + NO_PIECES))
160 piece -= NO_PIECES;
162 flag = (dropmask | piece);
165 if ((t & 0x80) != 0)
167 flag |= promote;
168 t &= 0x7f;
171 if ((f == t) && ((f != 0) || (t != 0)))
173 if (!XSHOGI) {
174 dsp->Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
177 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
179 else if ((flag & dropmask) != 0)
181 short piece = flag & pmask;
183 mvstr[0][0] = pxx[piece];
184 mvstr[0][1] = '*';
185 mvstr[0][2] = COL_NAME(column(t));
186 mvstr[0][3] = ROW_NAME(row(t));
187 mvstr[0][4] = '\0';
188 strcpy(mvstr[1], mvstr[0]);
189 strcpy(mvstr[2], mvstr[0]);
190 strcpy(mvstr[3], mvstr[0]);
192 else if ((f != 0) || (t != 0))
194 /* pure coordinates notation */
195 mvstr[0][0] = COL_NAME(column(f));
196 mvstr[0][1] = ROW_NAME(row(f));
197 mvstr[0][2] = COL_NAME(column(t));
198 mvstr[0][3] = ROW_NAME(row(t));
199 mvstr[0][4] = '\0';
201 /* algebraic notation without disambiguation */
202 mvstr[1][0] = pxx[board[f]];
203 mvstr[1][1] = mvstr[0][2]; /* to column */
204 mvstr[1][2] = mvstr[0][3]; /* to row */
205 mvstr[1][3] = '\0';
207 /* algebraic notation with row disambiguation */
208 mvstr[2][0] = mvstr[1][0];
209 mvstr[2][1] = mvstr[0][1];
210 mvstr[2][2] = mvstr[0][2]; /* to column */
211 mvstr[2][3] = mvstr[0][3]; /* to row */
212 mvstr[2][4] = '\0';
214 /* algebraic notation with column disambiguation */
215 strcpy(mvstr[3], mvstr[2]);
216 mvstr[3][1] = mvstr[0][0];
218 if (flag & promote)
220 strcat(mvstr[0], "+");
221 strcat(mvstr[1], "+");
222 strcat(mvstr[2], "+");
223 strcat(mvstr[3], "+");
226 else
228 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
234 * Compare the string 's' to the list of legal moves available for the
235 * opponent. If a match is found, make the move on the board.
239 VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
241 static short pnt, tempb, tempc, tempsf, tempst, cnt;
242 static struct leaf xnode;
243 struct leaf *node;
244 short i, l, local_flags;
245 char buffer[60];
247 /* check and remove quality flags */
248 for (i = local_flags = 0, l = strlen(s); i < l; i++)
250 switch(s[i])
252 case '?':
253 local_flags |= badmove;
254 s[i] = '\0';
255 break;
257 case '!':
258 local_flags |= goodmove;
259 s[i] = '\0';
260 break;
262 #ifdef EASY_OPENINGS
263 case '~':
264 local_flags |= difficult;
265 s[i] = '\0';
266 break;
267 #endif
271 *mv = 0;
273 if (iop == UNMAKE_MODE)
275 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
276 return false;
279 cnt = 0;
281 if (iop == VERIFY_AND_MAKE_MODE)
282 generate_move_flags = true;
284 MoveList(opponent, 2, -1, true);
285 generate_move_flags = false;
286 pnt = TrPnt[2];
288 while (pnt < TrPnt[3])
290 node = &Tree[pnt++];
291 algbr(node->f, node->t, (short) node->flags);
293 if ((strcmp(s, mvstr[0]) == 0)
294 || (strcmp(s, mvstr[1]) == 0)
295 || (strcmp(s, mvstr[2]) == 0)
296 || (strcmp(s, mvstr[3]) == 0))
298 cnt++;
299 xnode = *node;
303 if ((cnt == 1) && (xnode.score > DONTUSE))
305 short blocked;
307 MakeMove(opponent, &xnode, &tempb, &tempc,
308 &tempsf, &tempst, &INCscore);
310 if (SqAttacked(PieceList[opponent][0], computer, &blocked))
312 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
313 dsp->AlwaysShowMessage("Illegal move (in check) %s", s);
314 return false;
316 else
318 if (iop == VERIFY_AND_TRY_MODE)
319 return true;
321 dsp->UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
322 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
323 GameList[GameCnt].nodes = 0;
324 ElapsedTime(COMPUTE_AND_INIT_MODE);
325 GameList[GameCnt].time = (short) (et + 50)/100;
326 GameList[GameCnt].flags |= local_flags;
328 if (TCflag)
330 TimeControl.clock[opponent] -= et;
331 timeopp[oppptr] = et;
332 --TimeControl.moves[opponent];
335 *mv = (xnode.f << 8) | xnode.t;
336 algbr(xnode.f, xnode.t, false);
338 /* in force mode, check for mate conditions */
339 if (flag.force)
341 if (IsCheckmate(opponent ^ 1, -1, -1))
343 char buf[20];
345 sprintf(buf, "%s mates!\n", ColorStr[opponent]);
346 dsp->ShowMessage(buf);
347 flag.mate = true;
351 return true;
355 dsp->AlwaysShowMessage("Illegal move (no match) %s", s);
357 if (!XSHOGI && (cnt > 1))
359 sprintf(buffer, "Ambiguous Move %s!", s);
360 dsp->ShowMessage(buffer);
363 return false;
367 static int
368 parser(char *f, short *fpiece)
370 int c1, r1, c2, r2;
371 short i, p = false;
373 if (*f == '+')
374 f++, p = true;
376 for (i = 1, *fpiece = no_piece; i < NO_PIECES; i++)
378 if (f[0] == pxx[i] || f[0] == qxx[i])
380 *fpiece = (p ? promoted[i] : unpromoted[i]);
381 break;
385 if (f[1] == '*' || f[1] == '\'')
387 c2 = COL_NAME(f[2]);
388 r2 = ROW_NAME(f[3]);
390 return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
392 else
394 c1 = COL_NAME(f[1]);
395 r1 = ROW_NAME(f[2]);
396 c2 = COL_NAME(f[3]);
397 r2 = ROW_NAME(f[4]);
398 p = (f[5] == '+') ? 0x80 : 0;
400 return (locn(r1, c1) << 8) | locn(r2, c2) | p;
405 void
406 skip()
408 while (*InPtr != ' ')
409 InPtr++;
411 while (*InPtr == ' ')
412 InPtr++;
416 void
417 skipb()
419 while (*InPtr == ' ')
420 InPtr++;
424 void RequestInputString(char* buffer, unsigned bufsize)
426 static char fmt[10];
427 int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize);
428 if (ret < 0 ) {
429 perror("RequestInputString snprintf");
430 exit(1);
432 if (ret >= sizeof(fmt)) {
433 fprintf(stderr,
434 "Insufficient format-buffer size in %s for bufsize=%u\n",
435 __FUNCTION__, bufsize);
436 exit(1);
438 dsp->doRequestInputString(fmt, buffer);
442 static void
443 GetGame(void)
445 FILE *fd;
446 char fname[256], *p;
447 int c, i, j;
448 short sq;
449 short side, isp;
451 if (savefile[0]) {
452 strcpy(fname, savefile);
453 } else {
454 dsp->ShowMessage("Enter file name: ");
455 RequestInputString(fname, sizeof(fname)-1);
458 if (fname[0] == '\0')
459 strcpy(fname, "shogi.000");
461 if ((fd = fopen(fname, "r")) != NULL)
463 NewGame();
464 fgets(fname, 256, fd);
465 computer = opponent = black;
466 InPtr = fname;
467 skip();
469 if (*InPtr == 'c')
470 computer = white;
471 else
472 opponent = white;
474 /* FIXME: write a skipn() function so that we can get
475 * 3 skips by doing skipn(3) */
476 skip();
477 skip();
478 skip();
479 Game50 = atoi(InPtr);
480 skip();
481 flag.force = (*InPtr == 'f');
482 fgets(fname, 256, fd); /* empty */
483 fgets(fname, 256, fd);
484 InPtr = &fname[11];
485 skipb();
486 TCflag = atoi(InPtr);
487 skip();
488 InPtr += 14;
489 skipb();
490 OperatorTime = atoi(InPtr);
491 fgets(fname, 256, fd);
492 InPtr = &fname[11];
493 skipb();
494 TimeControl.clock[black] = atol(InPtr);
495 skip();
496 skip();
497 TimeControl.moves[black] = atoi(InPtr);
498 fgets(fname, 256, fd);
499 InPtr = &fname[11];
500 skipb();
501 TimeControl.clock[white] = atol(InPtr);
502 skip();
503 skip();
504 TimeControl.moves[white] = atoi(InPtr);
505 fgets(fname, 256, fd); /* empty */
507 for (i = NO_ROWS - 1; i > -1; i--)
509 fgets(fname, 256, fd);
510 p = &fname[2];
511 InPtr = &fname[23];
513 for (j = 0; j < NO_COLS; j++)
515 sq = i * NO_COLS + j;
516 isp = (*p == '+');
517 p++;
519 if (*p == '-')
521 board[sq] = no_piece;
522 color[sq] = neutral;
524 else
526 for (c = 0; c < NO_PIECES; c++)
528 if (*p == pxx[c])
530 if (isp)
531 board[sq] = promoted[c];
532 else
533 board[sq] = unpromoted[c];
535 color[sq] = white;
539 for (c = 0; c < NO_PIECES; c++)
541 if (*p == qxx[c])
543 if (isp)
544 board[sq] = promoted[c];
545 else
546 board[sq] = unpromoted[c];
548 color[sq] = black;
553 p++;
554 Mvboard[sq] = atoi(InPtr);
555 skip();
559 fgets(fname, 256, fd); /* empty */
560 fgets(fname, 256, fd); /* 9 8 7 ... */
561 fgets(fname, 256, fd); /* empty */
562 fgets(fname, 256, fd); /* p l n ... */
563 ClearCaptured();
565 for (side = 0; side <= 1; side++)
567 fgets(fname, 256, fd);
568 InPtr = fname;
569 skip();
570 skipb();
571 Captured[side][pawn] = atoi(InPtr);
572 skip();
573 #ifndef MINISHOGI
574 Captured[side][lance] = atoi(InPtr);
575 skip();
576 Captured[side][knight] = atoi(InPtr);
577 skip();
578 #endif
579 Captured[side][silver] = atoi(InPtr);
580 skip();
581 Captured[side][gold] = atoi(InPtr);
582 skip();
583 Captured[side][bishop] = atoi(InPtr);
584 skip();
585 Captured[side][rook] = atoi(InPtr);
586 skip();
587 Captured[side][king] = atoi(InPtr);
590 GameCnt = 0;
591 flag.regularstart = true;
592 Book = BOOKFAIL;
593 fgets(fname, 256, fd); /* empty */
594 fgets(fname, 256, fd); /* move score ... */
596 while (fgets(fname, 256, fd))
598 struct GameRec *g;
599 int side = computer;
601 side = side ^ 1;
602 ++GameCnt;
603 InPtr = fname;
604 skipb();
605 g = &GameList[GameCnt];
606 g->gmove = parser(InPtr, &g->fpiece);
607 skip();
608 g->score = atoi(InPtr);
609 skip();
610 g->depth = atoi(InPtr);
611 skip();
612 g->nodes = atol(InPtr);
613 skip();
614 g->time = atol(InPtr);
615 skip();
616 g->flags = c = atoi(InPtr);
617 skip();
618 g->hashkey = strtol(InPtr, (char **) NULL, 16);
619 skip();
620 g->hashbd = strtol(InPtr, (char **) NULL, 16);
622 if (c & capture)
624 short i, piece;
626 skip();
628 for (piece = no_piece, i = 0; i < NO_PIECES; i++)
630 if (pxx[i] == *InPtr)
632 piece = i;
633 break;
637 skip();
638 g->color = ((*InPtr == 'W') ? white : black);
639 skip();
640 g->piece = (*InPtr == '+'
641 ? promoted[piece]
642 : unpromoted[piece]);
644 else
646 g->color = neutral;
647 g->piece = no_piece;
651 if (TimeControl.clock[black] > 0)
652 TCflag = true;
654 fclose(fd);
657 ZeroRPT();
658 InitializeStats();
659 dsp->UpdateDisplay(0, 0, 1, 0);
660 Sdepth = 0;
661 hint = 0;
665 static void
666 SaveGame(void)
668 FILE *fd;
669 char fname[256];
670 short sq, i, c, f, t;
671 char p;
672 short side, piece;
673 char empty[2] = "\n";
675 if (savefile[0]) {
676 strcpy(fname, savefile);
677 } else {
678 dsp->ShowMessage("Enter file name: ");
679 RequestInputString(fname, sizeof(fname)-1);
682 if (fname[0] == '\0')
683 strcpy(fname, "shogi.000");
685 if ((fd = fopen(fname, "w")) != NULL)
687 char *b, *w;
688 b = w = "Human ";
690 if (computer == white)
691 w = "computer";
693 if (computer == black)
694 b = "computer";
696 fprintf(fd, "White %s Black %s %d %s\n", w, b, Game50,
697 flag.force ? "force" : "");
698 fputs(empty, fd);
699 fprintf(fd, "TimeControl %d Operator Time %d\n", TCflag, OperatorTime);
700 fprintf(fd, "Black Clock %ld Moves %d\nWhite Clock %ld Moves %d\n",
701 TimeControl.clock[black], TimeControl.moves[black],
702 TimeControl.clock[white], TimeControl.moves[white]);
703 fputs(empty, fd);
705 for (i = NO_ROWS - 1; i > -1; i--)
707 fprintf(fd, "%c ", ROW_NAME(i));
709 for (c = 0; c < NO_COLS; c++)
711 sq = i * NO_COLS + c;
712 piece = board[sq];
713 p = is_promoted[piece] ? '+' : ' ';
714 fprintf(fd, "%c", p);
716 switch(color[sq])
718 case white:
719 p = pxx[piece];
720 break;
722 case black:
723 p = qxx[piece];
724 break;
726 default:
727 p = '-';
730 fprintf(fd, "%c", p);
733 fprintf(fd, " ");
735 for (f = i * NO_COLS; f < i * NO_COLS + NO_ROWS; f++)
736 fprintf(fd, " %d", Mvboard[f]);
738 fprintf(fd, "\n");
741 fputs(empty, fd);
742 #ifndef MINISHOGI
743 fprintf(fd, " 9 8 7 6 5 4 3 2 1\n");
744 fputs(empty, fd);
745 fprintf(fd, " p l n s g b r k\n");
746 #else
747 fprintf(fd, " 5 4 3 2 1\n");
748 fputs(empty, fd);
749 fprintf(fd, " p s g b r k\n");
750 #endif
752 for (side = 0; side <= 1; side++)
754 fprintf(fd, "%c", (side == black) ? 'B' : 'W');
755 fprintf(fd, " %2d", Captured[side][pawn]);
756 #ifndef MINISHOGI
757 fprintf(fd, " %2d", Captured[side][lance]);
758 fprintf(fd, " %2d", Captured[side][knight]);
759 #endif
760 fprintf(fd, " %2d", Captured[side][silver]);
761 fprintf(fd, " %2d", Captured[side][gold]);
762 fprintf(fd, " %2d", Captured[side][bishop]);
763 fprintf(fd, " %2d", Captured[side][rook]);
764 fprintf(fd, " %2d", Captured[side][king]);
765 fprintf(fd, "\n");
768 fputs(empty, fd);
769 fputs(" move score depth nodes time flags capture\n", fd);
771 for (i = 1; i <= GameCnt; i++)
773 struct GameRec *g = &GameList[i];
775 f = g->gmove >> 8;
776 t = (g->gmove & 0xFF);
777 algbr(f, t, g->flags);
779 fprintf(fd, "%c%c%-5s %6d %5d %7ld %6ld %5d 0x%08lx 0x%08lx",
780 ((f > NO_SQUARES)
781 ? ' '
782 : (is_promoted[g->fpiece] ? '+' : ' ')),
783 pxx[g->fpiece],
784 ((f > NO_SQUARES) ? &mvstr[0][1] : mvstr[0]),
785 g->score, g->depth,
786 g->nodes, g->time, g->flags,
787 g->hashkey, g->hashbd);
789 if (g->piece != no_piece)
791 fprintf(fd, " %c %s %c\n",
792 pxx[g->piece], ColorStr[g->color],
793 (is_promoted[g->piece] ? '+' : ' '));
795 else
797 fprintf(fd, "\n");
801 fclose(fd);
803 dsp->ShowMessage("Game saved");
805 else
807 dsp->ShowMessage("Could not open file");
813 * GetXGame, SaveXGame and BookGame used to only be defined if
814 * xshogi wasn't defined -- wonder why?
817 static void
818 GetXGame(void)
820 FILE *fd;
821 char fname[256], *p;
822 int c, i, j;
823 short sq;
824 short side, isp;
826 dsp->ShowMessage("Enter file name: ");
827 RequestInputString(fname, sizeof(fname)-1);
829 if (fname[0] == '\0')
830 strcpy(fname, "xshogi.position.read");
832 if ((fd = fopen(fname, "r")) != NULL)
834 NewGame();
835 flag.regularstart = false;
836 Book = false;
838 /* xshogi position file ... */
839 fgets(fname, 256, fd);
841 #ifdef notdef
842 fname[6] = '\0';
844 if (strcmp(fname, "xshogi"))
845 return;
846 #endif
848 /* -- empty line -- */
849 fgets(fname, 256, fd);
850 /* -- empty line -- */
851 fgets(fname, 256, fd);
853 for (i = NO_ROWS - 1; i > -1; i--)
855 fgets(fname, 256, fd);
856 p = fname;
858 for (j = 0; j < NO_COLS; j++)
860 sq = i * NO_COLS + j;
861 isp = (*p == '+');
862 p++;
864 if (*p == '.')
866 board[sq] = no_piece;
867 color[sq] = neutral;
869 else
871 for (c = 0; c < NO_PIECES; c++)
873 if (*p == qxx[c])
875 if (isp)
876 board[sq] = promoted[c];
877 else
878 board[sq] = unpromoted[c];
880 color[sq] = white;
884 for (c = 0; c < NO_PIECES; c++)
886 if (*p == pxx[c])
888 if (isp)
889 board[sq] = promoted[c];
890 else
891 board[sq] = unpromoted[c];
893 color[sq] = black;
898 p++;
902 ClearCaptured();
904 for (side = 0; side <= 1; side++)
906 fgets(fname, 256, fd);
907 InPtr = fname;
908 Captured[side][pawn] = atoi(InPtr);
909 skip();
910 #ifndef MINISHOGI
911 Captured[side][lance] = atoi(InPtr);
912 skip();
913 Captured[side][knight] = atoi(InPtr);
914 skip();
915 #endif
916 Captured[side][silver] = atoi(InPtr);
917 skip();
918 Captured[side][gold] = atoi(InPtr);
919 skip();
920 Captured[side][bishop] = atoi(InPtr);
921 skip();
922 Captured[side][rook] = atoi(InPtr);
923 skip();
924 Captured[side][king] = atoi(InPtr);
927 if (fgets(fname, 256, fd) != NULL && strncmp(fname, "white", 5) == 0)
929 computer = black;
930 opponent = white;
931 xwndw = BXWNDW;
934 fclose(fd);
937 Game50 = 1;
938 ZeroRPT();
939 InitializeStats();
940 dsp->UpdateDisplay(0, 0, 1, 0);
941 Sdepth = 0;
942 hint = 0;
946 static void
947 SaveXGame(void)
949 FILE *fd;
950 char fname[256], *p;
951 int i, j;
952 short sq, piece;
953 short side, isp;
955 dsp->ShowMessage("Enter file name: ");
956 RequestInputString(fname, sizeof(fname)-1);
958 if (fname[0] == '\0')
959 strcpy(fname, "xshogi.position.read");
961 if ((fd = fopen(fname, "w")) != NULL)
963 fputs("# xshogi position file -- \n", fd);
964 fputs("\n", fd);
965 fputs("\n", fd);
967 for (i = NO_ROWS - 1; i > -1; i--)
969 p = fname;
971 for (j = 0; j < NO_COLS; j++)
973 sq = i * NO_COLS + j;
974 piece = board[sq];
975 isp = is_promoted[piece];
976 *p = (isp ? '+' : ' ');
977 p++;
979 if (piece == no_piece)
980 *p = '.';
981 else if (color[sq] == white)
982 *p = qxx[piece];
983 else
984 *p = pxx[piece];
986 p++;
989 *p++ = '\n';
990 *p++ = '\0';
991 fputs(fname, fd);
994 for (side = 0; side <= 1; side++)
996 sprintf(fname,
997 #ifndef MINISHOGI
998 "%d %d %d %d %d %d %d %d\n",
999 #else
1000 "%d %d %d %d %d %d\n",
1001 #endif
1002 Captured[side][pawn],
1003 #ifndef MINISHOGI
1004 Captured[side][lance],
1005 Captured[side][knight],
1006 #endif
1007 Captured[side][silver],
1008 Captured[side][gold],
1009 Captured[side][bishop],
1010 Captured[side][rook],
1011 Captured[side][king]);
1013 fputs(fname, fd);
1016 if (computer == black)
1017 fputs("white to play\n", fd);
1018 else
1019 fputs("black to play\n", fd);
1021 fclose(fd);
1026 static void
1027 BookSave(void)
1029 FILE *fd;
1030 char fname[256], sflags[4];
1031 short i, j, f, t;
1033 if (savefile[0]) {
1034 strcpy(fname, savefile);
1035 } else {
1036 /* Enter file name */
1037 dsp->ShowMessage("Enter file name: ");
1038 RequestInputString(fname, sizeof(fname)-1);
1041 if (fname[0] == '\0')
1042 return;
1044 if ((fd = fopen(fname, "a")) != NULL)
1046 fprintf(fd, "#\n");
1048 for (i = 1; i <= GameCnt; i++)
1050 struct GameRec *g = &GameList[i];
1051 char mvnr[20], mvs[20];
1053 if (i % 2)
1054 sprintf(mvnr, "%d.", (i + 1)/2);
1055 else
1056 strcpy(mvnr, "");
1058 f = g->gmove >> 8;
1059 t = (g->gmove & 0xFF);
1060 algbr(f, t, g->flags);
1061 j = 0;
1063 /* determine move quality string */
1064 if (g->flags & goodmove)
1065 sflags[j++] = '!';
1067 if (g->flags & badmove)
1068 sflags[j++] = '?';
1070 #ifdef EASY_OPENINGS
1071 if (g->flags & difficult)
1072 sflags[j++] = '~';
1073 #endif
1075 sflags[j] = '\0';
1077 /* determine move string */
1078 if (f > NO_SQUARES)
1080 sprintf(mvs, "%s%s ", &mvstr[0][1], sflags);
1082 else
1084 sprintf(mvs, "%c%c%c%c%c%s%s ",
1085 mvstr[0][0], mvstr[0][1],
1086 (g->flags & capture) ? 'x' : '-',
1087 mvstr[0][2], mvstr[0][3],
1088 (mvstr[0][4] == '+') ? "+" : "",
1089 sflags);
1092 fprintf(fd, "%s%s%c%s",
1093 mvnr,
1094 (f > NO_SQUARES
1095 ? ""
1096 : (is_promoted[g->fpiece] ? "+" : "")),
1097 pxx[g->fpiece],
1098 mvs);
1100 if ((i % 10) == 0)
1101 fprintf(fd, "\n");
1104 if ((i % 10) != 1)
1105 fprintf(fd, "\n");
1107 fclose(fd);
1109 dsp->ShowMessage("Game saved");
1111 else
1113 dsp->ShowMessage("Could not open file");
1118 void
1119 ListGame(void)
1121 FILE *fd;
1122 short i, f, t;
1123 time_t when;
1124 char fname[256], dbuf[256];
1126 if (listfile[0])
1128 strcpy(fname, listfile);
1130 else
1132 time(&when);
1133 strncpy(dbuf, ctime(&when), 20);
1134 dbuf[7] = '\0';
1135 dbuf[10] = '\0';
1136 dbuf[13] = '\0';
1137 dbuf[16] = '\0';
1138 dbuf[19] = '\0';
1140 /* use format "CL.Jan01-020304B" when
1141 date is Jan 1
1142 time is 02:03:04
1143 program played white */
1145 sprintf(fname, "CL.%s%s-%s%s%s%c",
1146 dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14,
1147 dbuf + 17, ColorStr[computer][0]);
1149 /* replace space padding with 0 */
1150 for (i = 0; fname[i] != '\0'; i++)
1152 if (fname[i] == ' ')
1153 fname[i] = '0';
1157 fd = fopen(fname, "w");
1159 if (!fd)
1161 printf("Open failure for file: %s", fname);
1162 exit(1);
1165 fprintf(fd, "gnushogi %s game\n", PACKAGE_VERSION);
1166 fputs(" score depth nodes time ", fd);
1167 fputs(" score depth nodes time\n", fd);
1169 for (i = 1; i <= GameCnt; i++)
1171 f = GameList[i].gmove >> 8;
1172 t = (GameList[i].gmove & 0xFF);
1173 algbr(f, t, GameList[i].flags);
1175 if (GameList[i].flags & book)
1177 fprintf(fd, "%c%c%-5s %5d Book%7ld %5ld",
1178 ((f > NO_SQUARES)
1179 ? ' '
1180 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1181 pxx[GameList[i].fpiece],
1182 ((f > NO_SQUARES)
1183 ? &mvstr[0][1] : mvstr[0]),
1184 GameList[i].score,
1185 GameList[i].nodes,
1186 GameList[i].time);
1188 else
1190 fprintf(fd, "%c%c%-5s %5d %2d %7ld %5ld",
1191 (f > NO_SQUARES
1192 ? ' '
1193 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1194 pxx[GameList[i].fpiece],
1195 (f > NO_SQUARES ? &mvstr[0][1] : mvstr[0]),
1196 GameList[i].score, GameList[i].depth,
1197 GameList[i].nodes, GameList[i].time);
1200 if ((i % 2) == 0)
1202 fprintf(fd, "\n");
1204 else
1206 fprintf(fd, " ");
1210 fprintf(fd, "\n\n");
1212 if (GameList[GameCnt].flags & draw)
1214 fprintf(fd, "Draw %s\n", DRAW);
1216 if (DRAW == DRAW_REPETITION)
1218 short j;
1220 fprintf(fd, "repetition by positions ");
1222 for (j = GameCnt - 1; j >= Game50; j -= 2)
1224 if (GameList[j].hashkey == hashkey &&
1225 GameList[j].hashbd == hashbd)
1226 fprintf(fd, "%d ", j);
1229 fprintf(fd, "\n");
1232 else if (GameList[GameCnt].score == -(SCORE_LIMIT + 999))
1234 fprintf(fd, "%s\n", ColorStr[player ]);
1236 else if (GameList[GameCnt].score == (SCORE_LIMIT + 998))
1238 fprintf(fd, "%s\n", ColorStr[player ^ 1]);
1241 fclose(fd);
1245 static void
1246 FlagMove(char c)
1248 switch(c)
1250 case '?' :
1251 GameList[GameCnt].flags |= badmove;
1252 break;
1254 case '!' :
1255 GameList[GameCnt].flags |= goodmove;
1256 break;
1258 #ifdef EASY_OPENINGS
1259 case '~' :
1260 GameList[GameCnt].flags |= difficult;
1261 break;
1262 #endif
1268 * Undo the most recent half-move.
1271 static void
1272 Undo(void)
1274 short f, t;
1276 f = GameList[GameCnt].gmove >> 8;
1277 t = GameList[GameCnt].gmove & 0x7F;
1279 if (f > NO_SQUARES)
1281 /* the move was a drop */
1282 Captured[color[t]][board[t]]++;
1283 board[t] = no_piece;
1284 color[t] = neutral;
1285 Mvboard[t]--;
1287 else
1289 if (GameList[GameCnt].flags & promote)
1290 board[f] = unpromoted[board[t]];
1291 else
1292 board[f] = board[t];
1294 color[f] = color[t];
1295 board[t] = GameList[GameCnt].piece;
1296 color[t] = GameList[GameCnt].color;
1298 if (board[t] != no_piece)
1299 Captured[color[f]][unpromoted[board[t]]]--;
1301 if (color[t] != neutral)
1302 Mvboard[t]--;
1304 Mvboard[f]--;
1307 InitializeStats();
1309 if (TCflag && (TCmoves > 1))
1310 ++TimeControl.moves[color[f]];
1312 hashkey = GameList[GameCnt].hashkey;
1313 hashbd = GameList[GameCnt].hashbd;
1314 GameCnt--;
1315 computer = computer ^ 1;
1316 opponent = opponent ^ 1;
1317 flag.mate = false;
1318 Sdepth = 0;
1319 player = player ^ 1;
1320 dsp->ShowSidetoMove();
1321 dsp->UpdateDisplay(0, 0, 1, 0);
1323 if (flag.regularstart)
1324 Book = false;
1328 static void
1329 TestSpeed(void(*f)(short side, short ply,
1330 short in_check, short blockable),
1331 unsigned j)
1333 #ifdef test
1334 unsigned jj;
1335 #endif
1337 unsigned i;
1338 long cnt, t1, t2;
1340 #ifdef HAVE_GETTIMEOFDAY
1341 struct timeval tv;
1342 #endif
1344 #ifdef HAVE_GETTIMEOFDAY
1345 gettimeofday(&tv, NULL);
1346 t1 = (tv.tv_sec*100 + (tv.tv_usec/10000));
1347 #else
1348 t1 = time(0);
1349 #endif
1351 for (i = 0; i < j; i++)
1353 f(opponent, 2, -1, true);
1355 #ifdef test
1356 for (jj = TrPnt[2]; i < TrPnt[3]; jj++)
1358 if (!pick(jj, TrPnt[3] - 1))
1359 break;
1361 #endif
1364 #ifdef HAVE_GETTIMEOFDAY
1365 gettimeofday(&tv, NULL);
1366 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1367 #else
1368 t2 = time(0);
1369 #endif
1371 cnt = j * (TrPnt[3] - TrPnt[2]);
1373 if (t2 - t1)
1374 et = (t2 - t1);
1375 else
1376 et = 1;
1378 dsp->ShowNodeCnt(cnt);
1382 static void
1383 TestPSpeed(short(*f) (short side), unsigned j)
1385 unsigned i;
1386 long cnt, t1, t2;
1387 #ifdef HAVE_GETTIMEOFDAY
1388 struct timeval tv;
1389 #endif
1391 #ifdef HAVE_GETTIMEOFDAY
1392 gettimeofday(&tv, NULL);
1393 t1 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1394 #else
1395 t1 = time(0);
1396 #endif
1398 for (i = 0; i < j; i++)
1399 (void) f(opponent);
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;
1410 if (t2 - t1)
1411 et = (t2 - t1);
1412 else
1413 et = 1;
1415 dsp->ShowNodeCnt(cnt);
1419 static void
1420 SetOppTime(char *time)
1422 int m, t, sec;
1424 sec = 0;
1425 t = (int)strtol(time, &time, 10);
1427 if (*time == ':')
1429 time++;
1430 /* FIXME: sec is parsed but ignored */
1431 sec = (int)strtol(time, &time, 10);
1434 m = (int)strtol(time, &time, 10);
1436 if (t)
1437 TimeControl.clock[opponent] = t;
1439 if (m)
1440 TimeControl.moves[opponent] = m;
1442 ElapsedTime(COMPUTE_AND_INIT_MODE);
1444 if (XSHOGI)
1446 /* just to inform xshogi about availability of otime command */
1447 printf("otime %d %d\n", t, m);
1452 static void
1453 SetMachineTime(char *time)
1455 int m, t, sec;
1457 sec = 0;
1458 t = (int)strtol(time, &time, 10);
1460 if (*time == ':')
1462 time++;
1463 /* FIXME: sec is parsed but ignored */
1464 sec = (int)strtol(time, &time, 10);
1467 m = (int)strtol(time, &time, 10);
1469 if (t)
1470 TimeControl.clock[computer] = t;
1472 if (m)
1473 TimeControl.moves[computer] = m;
1475 ElapsedTime(COMPUTE_AND_INIT_MODE);
1477 if (XSHOGI)
1479 /* just to inform xshogi about availability of time command */
1480 printf("time %d %d\n", t, m);
1485 /* FIXME! This is truly the function from hell! */
1488 * Process the user's command. If easy mode is OFF (the computer is thinking
1489 * on opponents time) and the program is out of book, then make the 'hint'
1490 * move on the board and call SelectMove() to find a response. The user
1491 * terminates the search by entering a command. If the opponent does not make
1492 * the hint move, then set Sdepth to zero.
1495 void
1496 InputCommand(char *command)
1498 short have_shown_prompt = false;
1499 short ok, done, is_move = false;
1500 unsigned short mv;
1501 char s[80], sx[80];
1503 ok = flag.quit = done = false;
1504 player = opponent;
1506 #if ttblsz
1507 if (TTadd > ttbllimit)
1508 ZeroTTable();
1509 #endif
1511 if ((hint > 0) && !flag.easy && !flag.force)
1514 * A hint move for the player is available. Compute a move for the
1515 * opponent in background mode assuming that the hint move will be
1516 * selected by the player.
1519 ft = time0; /* Save reference time for the player. */
1520 fflush(stdout);
1521 algbr((short) hint >> 8, (short) hint & 0xff, false);
1522 strcpy(s, mvstr[0]);
1524 if (flag.post)
1525 dsp->GiveHint();
1527 /* do the hint move */
1528 if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv))
1530 Sdepth = 0;
1532 #ifdef QUIETBACKGROUND
1533 dsp->ShowPrompt();
1534 have_shown_prompt = true;
1535 #endif /* QUIETBACKGROUND */
1537 /* Start computing a move until the search is interrupted. */
1539 #ifdef INTERRUPT_TEST
1540 itime0 = 0;
1541 #endif
1543 /* would love to put null move in here */
1544 /* after we make the hint move make a 2 ply search
1545 * with both plys our moves */
1546 /* think on opponents time */
1547 SelectMove(computer, BACKGROUND_MODE);
1549 #ifdef INTERRUPT_TEST
1550 ElapsedTime(COMPUTE_INTERRUPT_MODE);
1552 if (itime0 == 0)
1554 printf("searching not terminated by interrupt!\n");
1556 else
1558 printf("elapsed time from interrupt to "
1559 "terminating search: %ld\n", it);
1561 #endif
1563 /* undo the hint and carry on */
1564 VerifyMove(s, UNMAKE_MODE, &mv);
1565 Sdepth = 0;
1568 time0 = ft; /* Restore reference time for the player. */
1571 while(!(ok || flag.quit || done))
1573 player = opponent;
1575 #ifdef QUIETBACKGROUND
1576 if (!have_shown_prompt)
1578 #endif /* QUIETBACKGROUND */
1580 dsp->ShowPrompt();
1582 #ifdef QUIETBACKGROUND
1585 have_shown_prompt = false;
1586 #endif /* QUIETBACKGROUND */
1588 if (command == NULL) {
1589 int eof = dsp->GetString(sx);
1590 if (eof)
1591 dsp->ExitShogi();
1592 } else {
1593 strcpy(sx, command);
1594 done = true;
1597 /* extract first word */
1598 if (sscanf(sx, "%s", s) < 1)
1599 continue;
1601 if (strcmp(s, "bd") == 0) /* bd -- display board */
1603 /* FIXME: Hack alert! */
1604 short old_xshogi = XSHOGI;
1606 if (old_xshogi)
1607 display_type = DISPLAY_RAW;
1609 dsp->ClearScreen();
1610 dsp->UpdateDisplay(0, 0, 1, 0);
1612 if (old_xshogi)
1613 display_type = DISPLAY_X;
1615 else if (strcmp(s, "post") == 0)
1617 flag.post = !flag.post;
1619 else if (strcmp(s, "alg") == 0)
1621 /* noop */ ;
1623 else if ((strcmp(s, "quit") == 0)
1624 || (strcmp(s, "exit") == 0))
1626 flag.quit = true;
1628 else if ((strcmp(s, "set") == 0)
1629 || (strcmp(s, "edit") == 0))
1631 dsp->EditBoard();
1633 else if (strcmp(s, "setup") == 0)
1635 dsp->SetupBoard();
1637 else if (strcmp(s, "first") == 0)
1639 ok = true;
1641 else if (strcmp(s, "go") == 0)
1643 ok = true;
1644 flag.force = false;
1646 if (computer == black)
1648 computer = white;
1649 opponent = black;
1651 else
1653 computer = black;
1654 opponent = white;
1657 else if (strcmp(s, "help") == 0)
1659 dsp->help();
1661 else if (strcmp(s, "material") == 0)
1663 flag.material = !flag.material;
1665 else if (strcmp(s, "force") == 0)
1667 if (XSHOGI)
1669 flag.force = true;
1670 flag.bothsides = false;
1672 else
1674 flag.force = !flag.force;
1675 flag.bothsides = false;
1678 else if (strcmp(s, "book") == 0)
1680 Book = Book ? 0 : BOOKFAIL;
1682 else if (strcmp(s, "new") == 0)
1684 NewGame();
1685 dsp->UpdateDisplay(0, 0, 1, 0);
1687 else if (strcmp(s, "list") == 0)
1689 ListGame();
1691 else if (strcmp(s, "level") == 0)
1693 dsp->SelectLevel(sx + strlen("level"));
1695 else if (strcmp(s, "clock") == 0)
1697 dsp->SelectLevel(sx + strlen("clock"));
1699 else if (strcmp(s, "hash") == 0)
1701 flag.hash = !flag.hash;
1703 else if (strcmp(s, "gamein") == 0)
1705 flag.gamein = !flag.gamein;
1707 else if (strcmp(s, "beep") == 0)
1709 flag.beep = !flag.beep;
1711 else if (strcmp(s, "time") == 0)
1713 SetMachineTime(sx + strlen("time"));
1715 else if (strcmp(s, "otime") == 0)
1717 SetOppTime(sx + strlen("otime"));
1719 else if (strcmp(s, "Awindow") == 0)
1721 dsp->ChangeAlphaWindow();
1723 else if (strcmp(s, "Bwindow") == 0)
1725 dsp->ChangeBetaWindow();
1727 else if (strcmp(s, "rcptr") == 0)
1729 flag.rcptr = !flag.rcptr;
1731 else if (strcmp(s, "hint") == 0)
1733 dsp->GiveHint();
1735 else if (strcmp(s, "both") == 0)
1737 flag.bothsides = !flag.bothsides;
1738 flag.force = false;
1739 Sdepth = 0;
1740 ElapsedTime(COMPUTE_AND_INIT_MODE);
1741 SelectMove(opponent, FOREGROUND_MODE);
1742 ok = true;
1744 else if (strcmp(s, "reverse") == 0)
1746 flag.reverse = !flag.reverse;
1747 dsp->ClearScreen();
1748 dsp->UpdateDisplay(0, 0, 1, 0);
1750 else if (strcmp(s, "switch") == 0)
1752 computer = computer ^ 1;
1753 opponent = opponent ^ 1;
1754 xwndw = (computer == black) ? WXWNDW : BXWNDW;
1755 flag.force = false;
1756 Sdepth = 0;
1757 ok = true;
1759 else if (strcmp(s, "black") == 0)
1761 computer = white;
1762 opponent = black;
1763 xwndw = WXWNDW;
1764 flag.force = false;
1765 Sdepth = 0;
1768 * ok = true; don't automatically start with black command
1771 else if (strcmp(s, "white") == 0)
1773 computer = black;
1774 opponent = white;
1775 xwndw = BXWNDW;
1776 flag.force = false;
1777 Sdepth = 0;
1780 * ok = true; don't automatically start with white command
1783 else if (strcmp(s, "undo") == 0 && GameCnt > 0)
1785 Undo();
1787 else if (strcmp(s, "remove") == 0 && GameCnt > 1)
1789 Undo();
1790 Undo();
1792 /* CHECKME: are these next three correct? */
1793 else if (!XSHOGI && strcmp(s, "xget") == 0)
1795 GetXGame();
1797 else if (!XSHOGI && strcmp(s, "xsave") == 0)
1799 SaveXGame();
1801 else if (!XSHOGI && strcmp(s, "bsave") == 0)
1803 BookSave();
1805 #ifdef EASY_OPENINGS
1806 else if ((strcmp(s, "?") == 0)
1807 || (strcmp(s, "!") == 0)
1808 || (strcmp(s, "~") == 0))
1809 #else
1810 else if ((strcmp(s, "?") == 0)
1811 || (strcmp(s, "!") == 0))
1812 #endif
1814 FlagMove(*s);
1816 else if (strcmp(s, "get") == 0)
1818 GetGame();
1820 else if (strcmp(s, "save") == 0)
1822 SaveGame();
1824 else if (strcmp(s, "depth") == 0)
1826 dsp->ChangeSearchDepth(sx + strlen("depth"));
1828 else if (strcmp(s, "sd") == 0)
1830 dsp->ChangeSearchDepth(sx + strlen("sd"));
1832 else if (strcmp(s, "hashdepth") == 0)
1834 dsp->ChangeHashDepth();
1836 else if (strcmp(s, "random") == 0)
1838 dither = DITHER;
1840 else if (strcmp(s, "hard") == 0)
1842 flag.easy = false;
1844 else if (strcmp(s, "easy") == 0)
1846 flag.easy = !flag.easy;
1848 else if (strcmp(s, "tsume") == 0)
1850 flag.tsume = !flag.tsume;
1852 else if (strcmp(s, "contempt") == 0)
1854 dsp->SetContempt();
1856 else if (strcmp(s, "xwndw") == 0)
1858 dsp->ChangeXwindow();
1860 else if (strcmp(s, "rv") == 0)
1862 flag.rv = !flag.rv;
1863 dsp->UpdateDisplay(0, 0, 1, 0);
1865 else if (strcmp(s, "coords") == 0)
1867 flag.coords = !flag.coords;
1868 dsp->UpdateDisplay(0, 0, 1, 0);
1870 else if (strcmp(s, "stars") == 0)
1872 flag.stars = !flag.stars;
1873 dsp->UpdateDisplay(0, 0, 1, 0);
1875 else if (!XSHOGI && strcmp(s, "moves") == 0)
1877 short temp;
1879 #if MAXDEPTH > 3
1880 if (GameCnt > 0)
1882 extern unsigned short PrVar[MAXDEPTH];
1884 SwagHt = (GameList[GameCnt].gmove == PrVar[1])
1885 ? PrVar[2] : 0;
1887 else
1888 #endif
1889 SwagHt = 0;
1891 dsp->ShowMessage("Testing MoveList Speed");
1892 temp = generate_move_flags;
1893 generate_move_flags = true;
1894 TestSpeed(MoveList, 1);
1895 generate_move_flags = temp;
1896 dsp->ShowMessage("Testing CaptureList Speed");
1897 TestSpeed(CaptureList, 1);
1898 dsp->ShowMessage("Testing Eval Speed");
1899 ExaminePosition(opponent);
1900 TestPSpeed(ScorePosition, 1);
1902 else if (!XSHOGI && strcmp(s, "test") == 0)
1904 #ifdef SLOW_CPU
1905 dsp->ShowMessage("Testing MoveList Speed");
1906 TestSpeed(MoveList, 2000);
1907 dsp->ShowMessage("Testing CaptureList Speed");
1908 TestSpeed(CaptureList, 3000);
1909 dsp->ShowMessage("Testing Eval Speed");
1910 ExaminePosition(opponent);
1911 TestPSpeed(ScorePosition, 1500);
1912 #else
1913 dsp->ShowMessage("Testing MoveList Speed");
1914 TestSpeed(MoveList, 20000);
1915 dsp->ShowMessage("Testing CaptureList Speed");
1916 TestSpeed(CaptureList, 30000);
1917 dsp->ShowMessage("Testing Eval Speed");
1918 ExaminePosition(opponent);
1919 TestPSpeed(ScorePosition, 15000);
1920 #endif
1922 else if (!XSHOGI && strcmp(s, "p") == 0)
1924 dsp->ShowPostnValues();
1926 else if (!XSHOGI && strcmp(s, "debug") == 0)
1928 dsp->DoDebug();
1930 else
1932 if (flag.mate)
1934 ok = true;
1936 else if ((ok = VerifyMove(s, VERIFY_AND_MAKE_MODE, &mv)))
1938 /* check for repetition */
1939 short rpt = repetition();
1941 if (rpt >= 3)
1943 DRAW = DRAW_REPETITION;
1944 dsp->ShowMessage(DRAW);
1945 GameList[GameCnt].flags |= draw;
1947 flag.mate = true;
1949 else
1951 is_move = true;
1955 Sdepth = 0;
1959 ElapsedTime(COMPUTE_AND_INIT_MODE);
1961 if (flag.force)
1963 computer = opponent;
1964 opponent = computer ^ 1;
1967 if (XSHOGI)
1969 /* add remaining time in milliseconds for xshogi */
1970 if (is_move)
1972 printf("%d. %s %ld\n",
1973 ++mycnt2, s, TimeControl.clock[player] * 10);