XBoard: split printing of the features line for clarity.
[gnushogi.git] / gnushogi / commondsp.c
blob4718fd9c5547298036266da4fcb3c6a16f21e35f
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;
57 short xboard = false;
59 #if defined(BOOKTEST)
61 void
62 movealgbr(short m, char *s)
64 unsigned int f, t;
65 short piece = 0, flag = 0;
67 if (m == 0)
69 strcpy(s, "none");
70 return;
73 f = (m >> 8) & 0x7f;
74 t = m & 0xff;
76 if (f > NO_SQUARES)
78 piece = f - NO_SQUARES;
80 if (piece > NO_PIECES)
81 piece -= NO_PIECES;
83 flag = (dropmask | piece);
86 if (t & 0x80)
88 flag |= promote;
89 t &= 0x7f;
92 if (flag & dropmask)
94 *s = pxx[piece];
95 s++;
96 *s = '*';
97 s++;
98 *s = COL_NAME(column(t));
99 s++;
100 *s = ROW_NAME(row(t));
101 s++;
103 else
105 *s = COL_NAME(column(f));
106 s++;
107 *s = ROW_NAME(row(f));
108 s++;
109 *s = COL_NAME(column(t));
110 s++;
111 *s = ROW_NAME(row(t));
112 s++;
114 if (flag & promote)
116 *s = '+';
117 s++;
121 if (m & 0x8000)
123 *s = '?';
124 s++;
127 *s = '\0';
130 #endif /* BOOKTEST */
134 * Generate move strings in different formats.
136 * INPUT:
137 * - f piece to be moved
138 * - 0 < f < NO_SQUARES source square
139 * - NO_SQUARES <= f NO_SQUARES + 2*NO_PIECES dropped piece modulo NO_PIECES
140 * - t & 0x7f target square
141 * - t & 0x80 promotion flag
142 * - flag
143 * - if flag & dropmask, piece type encoded in flag & pmask
145 * FIXME: that makes 2 ways to specify drops and promotions, why ?
147 * OUTPUT:
148 * - GLOBAL mvstr
151 void
152 algbr(short f, short t, short flag)
154 if (f > NO_SQUARES)
156 short piece;
158 piece = f - NO_SQUARES;
160 if (f > (NO_SQUARES + NO_PIECES))
161 piece -= NO_PIECES;
163 flag = (dropmask | piece);
166 if ((t & 0x80) != 0)
168 flag |= promote;
169 t &= 0x7f;
172 if ((f == t) && ((f != 0) || (t != 0)))
174 if (!XSHOGI) {
175 dsp->Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
178 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
180 else if ((flag & dropmask) != 0)
182 short piece = flag & pmask;
184 mvstr[0][0] = pxx[piece];
185 mvstr[0][1] = xboard ? '@' : '*';
186 mvstr[0][2] = COL_NAME(column(t));
187 mvstr[0][3] = ROW_NAME(row(t));
188 mvstr[0][4] = '\0';
189 strcpy(mvstr[1], mvstr[0]);
190 strcpy(mvstr[2], mvstr[0]);
191 strcpy(mvstr[3], mvstr[0]);
193 else if ((f != 0) || (t != 0))
195 /* pure coordinates notation */
196 mvstr[0][0] = COL_NAME(column(f));
197 mvstr[0][1] = ROW_NAME(row(f));
198 mvstr[0][2] = COL_NAME(column(t));
199 mvstr[0][3] = ROW_NAME(row(t));
200 mvstr[0][4] = '\0';
202 /* algebraic notation without disambiguation */
203 mvstr[1][0] = pxx[board[f]];
204 mvstr[1][1] = mvstr[0][2]; /* to column */
205 mvstr[1][2] = mvstr[0][3]; /* to row */
206 mvstr[1][3] = '\0';
208 /* algebraic notation with row disambiguation */
209 mvstr[2][0] = mvstr[1][0];
210 mvstr[2][1] = mvstr[0][1];
211 mvstr[2][2] = mvstr[0][2]; /* to column */
212 mvstr[2][3] = mvstr[0][3]; /* to row */
213 mvstr[2][4] = '\0';
215 /* algebraic notation with column disambiguation */
216 strcpy(mvstr[3], mvstr[2]);
217 mvstr[3][1] = mvstr[0][0];
219 if (flag & promote)
221 strcat(mvstr[0], "+");
222 strcat(mvstr[1], "+");
223 strcat(mvstr[2], "+");
224 strcat(mvstr[3], "+");
227 else
229 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
235 * Compare the string 's' to the list of legal moves available for the
236 * opponent. If a match is found, make the move on the board.
240 VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
242 static short pnt, tempb, tempc, tempsf, tempst, cnt;
243 static struct leaf xnode;
244 struct leaf *node;
245 short i, l, local_flags;
246 char buffer[60];
248 /* check and remove quality flags */
249 for (i = local_flags = 0, l = strlen(s); i < l; i++)
251 switch(s[i])
253 case '?':
254 local_flags |= badmove;
255 s[i] = '\0';
256 break;
258 case '!':
259 local_flags |= goodmove;
260 s[i] = '\0';
261 break;
263 #ifdef EASY_OPENINGS
264 case '~':
265 local_flags |= difficult;
266 s[i] = '\0';
267 break;
268 #endif
272 *mv = 0;
274 if (iop == UNMAKE_MODE)
276 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
277 return false;
280 cnt = 0;
282 if (iop == VERIFY_AND_MAKE_MODE)
283 generate_move_flags = true;
285 MoveList(opponent, 2, -1, true);
286 generate_move_flags = false;
287 pnt = TrPnt[2];
289 while (pnt < TrPnt[3])
291 node = &Tree[pnt++];
292 algbr(node->f, node->t, (short) node->flags);
294 if ((strcmp(s, mvstr[0]) == 0)
295 || (strcmp(s, mvstr[1]) == 0)
296 || (strcmp(s, mvstr[2]) == 0)
297 || (strcmp(s, mvstr[3]) == 0))
299 cnt++;
300 xnode = *node;
304 if ((cnt == 1) && (xnode.score > DONTUSE))
306 short blocked;
308 MakeMove(opponent, &xnode, &tempb, &tempc,
309 &tempsf, &tempst, &INCscore);
311 if (SqAttacked(PieceList[opponent][0], computer, &blocked))
313 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
314 dsp->AlwaysShowMessage("Illegal move (in check): %s", s);
315 return false;
317 else
319 if (iop == VERIFY_AND_TRY_MODE)
320 return true;
322 dsp->UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
323 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
324 GameList[GameCnt].nodes = 0;
325 ElapsedTime(COMPUTE_AND_INIT_MODE);
326 GameList[GameCnt].time = (short) (et + 50)/100;
327 GameList[GameCnt].flags |= local_flags;
329 if (TCflag)
331 TimeControl.clock[opponent] -= et;
332 timeopp[oppptr] = et;
333 --TimeControl.moves[opponent];
336 *mv = (xnode.f << 8) | xnode.t;
337 algbr(xnode.f, xnode.t, false);
339 /* in force mode, check for mate conditions */
340 if (flag.force)
342 if (IsCheckmate(opponent ^ 1, -1, -1))
344 char buf[20];
346 sprintf(buf, "%s mates!\n", ColorStr[opponent]);
347 dsp->ShowMessage(buf);
348 flag.mate = true;
352 return true;
356 dsp->AlwaysShowMessage("Illegal move (no match): %s", s);
358 if (!XSHOGI && (cnt > 1))
360 sprintf(buffer, "Ambiguous Move %s!", s);
361 dsp->ShowMessage(buffer);
364 return false;
368 static int
369 parser(char *f, short *fpiece)
371 int c1, r1, c2, r2;
372 short i, p = false;
374 if (*f == '+')
375 f++, p = true;
377 for (i = 1, *fpiece = no_piece; i < NO_PIECES; i++)
379 if (f[0] == pxx[i] || f[0] == qxx[i])
381 *fpiece = (p ? promoted[i] : unpromoted[i]);
382 break;
386 if (f[1] == '*' || f[1] == '\'')
388 c2 = COL_NUM(f[2]);
389 r2 = ROW_NUM(f[3]);
391 return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
393 else
395 c1 = COL_NUM(f[1]);
396 r1 = ROW_NUM(f[2]);
397 c2 = COL_NUM(f[3]);
398 r2 = ROW_NUM(f[4]);
399 p = (f[5] == '+') ? 0x80 : 0;
401 return (locn(r1, c1) << 8) | locn(r2, c2) | p;
406 void
407 skip()
409 while (*InPtr != ' ')
410 InPtr++;
412 while (*InPtr == ' ')
413 InPtr++;
417 void
418 skipb()
420 while (*InPtr == ' ')
421 InPtr++;
425 void RequestInputString(char* buffer, unsigned bufsize)
427 static char fmt[10];
428 int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize);
429 if (ret < 0 ) {
430 perror("RequestInputString snprintf");
431 exit(1);
433 if (ret >= sizeof(fmt)) {
434 fprintf(stderr,
435 "Insufficient format-buffer size in %s for bufsize=%u\n",
436 __FUNCTION__, bufsize);
437 exit(1);
439 dsp->doRequestInputString(fmt, buffer);
443 static void
444 GetGame(void)
446 FILE *fd;
447 char fname[256], *p;
448 int c, i, j;
449 short sq;
450 short side, isp;
452 if (savefile[0]) {
453 strcpy(fname, savefile);
454 } else {
455 dsp->ShowMessage("Enter file name: ");
456 RequestInputString(fname, sizeof(fname)-1);
459 if (fname[0] == '\0')
460 strcpy(fname, "shogi.000");
462 if ((fd = fopen(fname, "r")) != NULL)
464 NewGame();
465 fgets(fname, 256, fd);
466 computer = opponent = black;
467 InPtr = fname;
468 skip();
470 if (*InPtr == 'c')
471 computer = white;
472 else
473 opponent = white;
475 /* FIXME: write a skipn() function so that we can get
476 * 3 skips by doing skipn(3) */
477 skip();
478 skip();
479 skip();
480 Game50 = atoi(InPtr);
481 skip();
482 flag.force = (*InPtr == 'f');
483 fgets(fname, 256, fd); /* empty */
484 fgets(fname, 256, fd);
485 InPtr = &fname[11];
486 skipb();
487 TCflag = atoi(InPtr);
488 skip();
489 InPtr += 14;
490 skipb();
491 OperatorTime = atoi(InPtr);
492 fgets(fname, 256, fd);
493 InPtr = &fname[11];
494 skipb();
495 TimeControl.clock[black] = atol(InPtr);
496 skip();
497 skip();
498 TimeControl.moves[black] = atoi(InPtr);
499 fgets(fname, 256, fd);
500 InPtr = &fname[11];
501 skipb();
502 TimeControl.clock[white] = atol(InPtr);
503 skip();
504 skip();
505 TimeControl.moves[white] = atoi(InPtr);
506 fgets(fname, 256, fd); /* empty */
508 for (i = NO_ROWS - 1; i > -1; i--)
510 fgets(fname, 256, fd);
511 p = &fname[2];
512 InPtr = &fname[23];
514 for (j = 0; j < NO_COLS; j++)
516 sq = i * NO_COLS + j;
517 isp = (*p == '+');
518 p++;
520 if (*p == '-')
522 board[sq] = no_piece;
523 color[sq] = neutral;
525 else
527 for (c = 0; c < NO_PIECES; c++)
529 if (*p == pxx[c])
531 if (isp)
532 board[sq] = promoted[c];
533 else
534 board[sq] = unpromoted[c];
536 color[sq] = white;
540 for (c = 0; c < NO_PIECES; c++)
542 if (*p == qxx[c])
544 if (isp)
545 board[sq] = promoted[c];
546 else
547 board[sq] = unpromoted[c];
549 color[sq] = black;
554 p++;
555 Mvboard[sq] = atoi(InPtr);
556 skip();
560 fgets(fname, 256, fd); /* empty */
561 fgets(fname, 256, fd); /* 9 8 7 ... */
562 fgets(fname, 256, fd); /* empty */
563 fgets(fname, 256, fd); /* p l n ... */
564 ClearCaptured();
566 for (side = 0; side <= 1; side++)
568 fgets(fname, 256, fd);
569 InPtr = fname;
570 skip();
571 skipb();
572 Captured[side][pawn] = atoi(InPtr);
573 skip();
574 #ifndef MINISHOGI
575 Captured[side][lance] = atoi(InPtr);
576 skip();
577 Captured[side][knight] = atoi(InPtr);
578 skip();
579 #endif
580 Captured[side][silver] = atoi(InPtr);
581 skip();
582 Captured[side][gold] = atoi(InPtr);
583 skip();
584 Captured[side][bishop] = atoi(InPtr);
585 skip();
586 Captured[side][rook] = atoi(InPtr);
587 skip();
588 Captured[side][king] = atoi(InPtr);
591 GameCnt = 0;
592 flag.regularstart = true;
593 Book = BOOKFAIL;
594 fgets(fname, 256, fd); /* empty */
595 fgets(fname, 256, fd); /* move score ... */
597 while (fgets(fname, 256, fd))
599 struct GameRec *g;
600 int side = computer;
602 side = side ^ 1;
603 ++GameCnt;
604 InPtr = fname;
605 skipb();
606 g = &GameList[GameCnt];
607 g->gmove = parser(InPtr, &g->fpiece);
608 skip();
609 g->score = atoi(InPtr);
610 skip();
611 g->depth = atoi(InPtr);
612 skip();
613 g->nodes = atol(InPtr);
614 skip();
615 g->time = atol(InPtr);
616 skip();
617 g->flags = c = atoi(InPtr);
618 skip();
619 g->hashkey = strtol(InPtr, (char **) NULL, 16);
620 skip();
621 g->hashbd = strtol(InPtr, (char **) NULL, 16);
623 if (c & capture)
625 short i, piece;
627 skip();
629 for (piece = no_piece, i = 0; i < NO_PIECES; i++)
631 if (pxx[i] == *InPtr)
633 piece = i;
634 break;
638 skip();
639 g->color = ((*InPtr == 'W') ? white : black);
640 skip();
641 g->piece = (*InPtr == '+'
642 ? promoted[piece]
643 : unpromoted[piece]);
645 else
647 g->color = neutral;
648 g->piece = no_piece;
652 if (TimeControl.clock[black] > 0)
653 TCflag = true;
655 fclose(fd);
658 ZeroRPT();
659 InitializeStats();
660 dsp->UpdateDisplay(0, 0, 1, 0);
661 Sdepth = 0;
662 hint = 0;
666 static void
667 SaveGame(void)
669 FILE *fd;
670 char fname[256];
671 short sq, i, c, f, t;
672 char p;
673 short side, piece;
674 char empty[2] = "\n";
676 if (savefile[0]) {
677 strcpy(fname, savefile);
678 } else {
679 dsp->ShowMessage("Enter file name: ");
680 RequestInputString(fname, sizeof(fname)-1);
683 if (fname[0] == '\0')
684 strcpy(fname, "shogi.000");
686 if ((fd = fopen(fname, "w")) != NULL)
688 char *b, *w;
689 b = w = "Human ";
691 if (computer == white)
692 w = "computer";
694 if (computer == black)
695 b = "computer";
697 fprintf(fd, "White %s Black %s %d %s\n", w, b, Game50,
698 flag.force ? "force" : "");
699 fputs(empty, fd);
700 fprintf(fd, "TimeControl %d Operator Time %d\n", TCflag, OperatorTime);
701 fprintf(fd, "Black Clock %ld Moves %d\nWhite Clock %ld Moves %d\n",
702 TimeControl.clock[black], TimeControl.moves[black],
703 TimeControl.clock[white], TimeControl.moves[white]);
704 fputs(empty, fd);
706 for (i = NO_ROWS - 1; i > -1; i--)
708 fprintf(fd, "%c ", ROW_NAME(i));
710 for (c = 0; c < NO_COLS; c++)
712 sq = i * NO_COLS + c;
713 piece = board[sq];
714 p = is_promoted[piece] ? '+' : ' ';
715 fprintf(fd, "%c", p);
717 switch(color[sq])
719 case white:
720 p = pxx[piece];
721 break;
723 case black:
724 p = qxx[piece];
725 break;
727 default:
728 p = '-';
731 fprintf(fd, "%c", p);
734 fprintf(fd, " ");
736 for (f = i * NO_COLS; f < i * NO_COLS + NO_ROWS; f++)
737 fprintf(fd, " %d", Mvboard[f]);
739 fprintf(fd, "\n");
742 fputs(empty, fd);
743 #ifndef MINISHOGI
744 fprintf(fd, " 9 8 7 6 5 4 3 2 1\n");
745 fputs(empty, fd);
746 fprintf(fd, " p l n s g b r k\n");
747 #else
748 fprintf(fd, " 5 4 3 2 1\n");
749 fputs(empty, fd);
750 fprintf(fd, " p s g b r k\n");
751 #endif
753 for (side = 0; side <= 1; side++)
755 fprintf(fd, "%c", (side == black) ? 'B' : 'W');
756 fprintf(fd, " %2d", Captured[side][pawn]);
757 #ifndef MINISHOGI
758 fprintf(fd, " %2d", Captured[side][lance]);
759 fprintf(fd, " %2d", Captured[side][knight]);
760 #endif
761 fprintf(fd, " %2d", Captured[side][silver]);
762 fprintf(fd, " %2d", Captured[side][gold]);
763 fprintf(fd, " %2d", Captured[side][bishop]);
764 fprintf(fd, " %2d", Captured[side][rook]);
765 fprintf(fd, " %2d", Captured[side][king]);
766 fprintf(fd, "\n");
769 fputs(empty, fd);
770 fputs(" move score depth nodes time flags capture\n", fd);
772 for (i = 1; i <= GameCnt; i++)
774 struct GameRec *g = &GameList[i];
776 f = g->gmove >> 8;
777 t = (g->gmove & 0xFF);
778 algbr(f, t, g->flags);
780 fprintf(fd, "%c%c%-5s %6d %5d %7ld %6ld %5d 0x%08lx 0x%08lx",
781 ((f > NO_SQUARES)
782 ? ' '
783 : (is_promoted[g->fpiece] ? '+' : ' ')),
784 pxx[g->fpiece],
785 ((f > NO_SQUARES) ? &mvstr[0][1] : mvstr[0]),
786 g->score, g->depth,
787 g->nodes, g->time, g->flags,
788 g->hashkey, g->hashbd);
790 if (g->piece != no_piece)
792 fprintf(fd, " %c %s %c\n",
793 pxx[g->piece], ColorStr[g->color],
794 (is_promoted[g->piece] ? '+' : ' '));
796 else
798 fprintf(fd, "\n");
802 fclose(fd);
804 dsp->ShowMessage("Game saved");
806 else
808 dsp->ShowMessage("Could not open file");
814 * GetXGame, SaveXGame and BookGame used to only be defined if
815 * xshogi wasn't defined -- wonder why?
818 static void
819 GetXGame(void)
821 FILE *fd;
822 char fname[256], *p;
823 int c, i, j;
824 short sq;
825 short side, isp;
827 dsp->ShowMessage("Enter file name: ");
828 RequestInputString(fname, sizeof(fname)-1);
830 if (fname[0] == '\0')
831 strcpy(fname, "xshogi.position.read");
833 if ((fd = fopen(fname, "r")) != NULL)
835 NewGame();
836 flag.regularstart = false;
837 Book = false;
839 /* xshogi position file ... */
840 fgets(fname, 256, fd);
842 #ifdef notdef
843 fname[6] = '\0';
845 if (strcmp(fname, "xshogi"))
846 return;
847 #endif
849 /* -- empty line -- */
850 fgets(fname, 256, fd);
851 /* -- empty line -- */
852 fgets(fname, 256, fd);
854 for (i = NO_ROWS - 1; i > -1; i--)
856 fgets(fname, 256, fd);
857 p = fname;
859 for (j = 0; j < NO_COLS; j++)
861 sq = i * NO_COLS + j;
862 isp = (*p == '+');
863 p++;
865 if (*p == '.')
867 board[sq] = no_piece;
868 color[sq] = neutral;
870 else
872 for (c = 0; c < NO_PIECES; c++)
874 if (*p == qxx[c])
876 if (isp)
877 board[sq] = promoted[c];
878 else
879 board[sq] = unpromoted[c];
881 color[sq] = white;
885 for (c = 0; c < NO_PIECES; c++)
887 if (*p == pxx[c])
889 if (isp)
890 board[sq] = promoted[c];
891 else
892 board[sq] = unpromoted[c];
894 color[sq] = black;
899 p++;
903 ClearCaptured();
905 for (side = 0; side <= 1; side++)
907 fgets(fname, 256, fd);
908 InPtr = fname;
909 Captured[side][pawn] = atoi(InPtr);
910 skip();
911 #ifndef MINISHOGI
912 Captured[side][lance] = atoi(InPtr);
913 skip();
914 Captured[side][knight] = atoi(InPtr);
915 skip();
916 #endif
917 Captured[side][silver] = atoi(InPtr);
918 skip();
919 Captured[side][gold] = atoi(InPtr);
920 skip();
921 Captured[side][bishop] = atoi(InPtr);
922 skip();
923 Captured[side][rook] = atoi(InPtr);
924 skip();
925 Captured[side][king] = atoi(InPtr);
928 if (fgets(fname, 256, fd) != NULL && strncmp(fname, "white", 5) == 0)
930 computer = black;
931 opponent = white;
932 xwndw = BXWNDW;
935 fclose(fd);
938 Game50 = 1;
939 ZeroRPT();
940 InitializeStats();
941 dsp->UpdateDisplay(0, 0, 1, 0);
942 Sdepth = 0;
943 hint = 0;
947 static void
948 SaveXGame(void)
950 FILE *fd;
951 char fname[256], *p;
952 int i, j;
953 short sq, piece;
954 short side, isp;
956 dsp->ShowMessage("Enter file name: ");
957 RequestInputString(fname, sizeof(fname)-1);
959 if (fname[0] == '\0')
960 strcpy(fname, "xshogi.position.read");
962 if ((fd = fopen(fname, "w")) != NULL)
964 fputs("# xshogi position file -- \n", fd);
965 fputs("\n", fd);
966 fputs("\n", fd);
968 for (i = NO_ROWS - 1; i > -1; i--)
970 p = fname;
972 for (j = 0; j < NO_COLS; j++)
974 sq = i * NO_COLS + j;
975 piece = board[sq];
976 isp = is_promoted[piece];
977 *p = (isp ? '+' : ' ');
978 p++;
980 if (piece == no_piece)
981 *p = '.';
982 else if (color[sq] == white)
983 *p = qxx[piece];
984 else
985 *p = pxx[piece];
987 p++;
990 *p++ = '\n';
991 *p++ = '\0';
992 fputs(fname, fd);
995 for (side = 0; side <= 1; side++)
997 sprintf(fname,
998 #ifndef MINISHOGI
999 "%d %d %d %d %d %d %d %d\n",
1000 #else
1001 "%d %d %d %d %d %d\n",
1002 #endif
1003 Captured[side][pawn],
1004 #ifndef MINISHOGI
1005 Captured[side][lance],
1006 Captured[side][knight],
1007 #endif
1008 Captured[side][silver],
1009 Captured[side][gold],
1010 Captured[side][bishop],
1011 Captured[side][rook],
1012 Captured[side][king]);
1014 fputs(fname, fd);
1017 if (computer == black)
1018 fputs("white to play\n", fd);
1019 else
1020 fputs("black to play\n", fd);
1022 fclose(fd);
1027 static void
1028 BookSave(void)
1030 FILE *fd;
1031 char fname[256], sflags[4];
1032 short i, j, f, t;
1034 if (savefile[0]) {
1035 strcpy(fname, savefile);
1036 } else {
1037 /* Enter file name */
1038 dsp->ShowMessage("Enter file name: ");
1039 RequestInputString(fname, sizeof(fname)-1);
1042 if (fname[0] == '\0') {
1043 dsp->AlwaysShowMessage("aborting book save");
1044 return;
1047 if ((fd = fopen(fname, "a")) != NULL)
1049 fprintf(fd, "#\n");
1051 for (i = 1; i <= GameCnt; i++)
1053 struct GameRec *g = &GameList[i];
1054 char mvnr[20], mvs[20];
1056 if (i % 2)
1057 sprintf(mvnr, "%d.", (i + 1)/2);
1058 else
1059 strcpy(mvnr, "");
1061 f = g->gmove >> 8;
1062 t = (g->gmove & 0xFF);
1063 algbr(f, t, g->flags);
1064 j = 0;
1066 /* determine move quality string */
1067 if (g->flags & goodmove)
1068 sflags[j++] = '!';
1070 if (g->flags & badmove)
1071 sflags[j++] = '?';
1073 #ifdef EASY_OPENINGS
1074 if (g->flags & difficult)
1075 sflags[j++] = '~';
1076 #endif
1078 sflags[j] = '\0';
1080 /* determine move string */
1081 if (f > NO_SQUARES)
1083 sprintf(mvs, "%s%s ", &mvstr[0][1], sflags);
1085 else
1087 sprintf(mvs, "%c%c%c%c%c%s%s ",
1088 mvstr[0][0], mvstr[0][1],
1089 (g->flags & capture) ? 'x' : '-',
1090 mvstr[0][2], mvstr[0][3],
1091 (mvstr[0][4] == '+') ? "+" : "",
1092 sflags);
1095 fprintf(fd, "%s%s%c%s",
1096 mvnr,
1097 (f > NO_SQUARES
1098 ? ""
1099 : (is_promoted[g->fpiece] ? "+" : "")),
1100 pxx[g->fpiece],
1101 mvs);
1103 if ((i % 10) == 0)
1104 fprintf(fd, "\n");
1107 if ((i % 10) != 1)
1108 fprintf(fd, "\n");
1110 fclose(fd);
1112 dsp->ShowMessage("Game saved");
1114 else
1116 dsp->ShowMessage("Could not open file");
1121 void
1122 ListGame(void)
1124 FILE *fd;
1125 short i, f, t;
1126 time_t when;
1127 char fname[256], dbuf[256];
1129 if (listfile[0])
1131 strcpy(fname, listfile);
1133 else
1135 time(&when);
1136 strncpy(dbuf, ctime(&when), 20);
1137 dbuf[7] = '\0';
1138 dbuf[10] = '\0';
1139 dbuf[13] = '\0';
1140 dbuf[16] = '\0';
1141 dbuf[19] = '\0';
1143 /* use format "CL.Jan01-020304B" when
1144 date is Jan 1
1145 time is 02:03:04
1146 program played white */
1148 sprintf(fname, "CL.%s%s-%s%s%s%c",
1149 dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14,
1150 dbuf + 17, ColorStr[computer][0]);
1152 /* replace space padding with 0 */
1153 for (i = 0; fname[i] != '\0'; i++)
1155 if (fname[i] == ' ')
1156 fname[i] = '0';
1160 fd = fopen(fname, "w");
1162 if (!fd)
1164 printf("Open failure for file: %s", fname);
1165 exit(1);
1168 fprintf(fd, "gnushogi %s game\n", PACKAGE_VERSION);
1169 fputs(" score depth nodes time ", fd);
1170 fputs(" score depth nodes time\n", fd);
1172 for (i = 1; i <= GameCnt; i++)
1174 f = GameList[i].gmove >> 8;
1175 t = (GameList[i].gmove & 0xFF);
1176 algbr(f, t, GameList[i].flags);
1178 if (GameList[i].flags & book)
1180 fprintf(fd, "%c%c%-5s %5d Book%7ld %5ld",
1181 ((f > NO_SQUARES)
1182 ? ' '
1183 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1184 pxx[GameList[i].fpiece],
1185 ((f > NO_SQUARES)
1186 ? &mvstr[0][1] : mvstr[0]),
1187 GameList[i].score,
1188 GameList[i].nodes,
1189 GameList[i].time);
1191 else
1193 fprintf(fd, "%c%c%-5s %5d %2d %7ld %5ld",
1194 (f > NO_SQUARES
1195 ? ' '
1196 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1197 pxx[GameList[i].fpiece],
1198 (f > NO_SQUARES ? &mvstr[0][1] : mvstr[0]),
1199 GameList[i].score, GameList[i].depth,
1200 GameList[i].nodes, GameList[i].time);
1203 if ((i % 2) == 0)
1205 fprintf(fd, "\n");
1207 else
1209 fprintf(fd, " ");
1213 fprintf(fd, "\n\n");
1215 if (GameList[GameCnt].flags & draw)
1217 fprintf(fd, "Draw %s\n", DRAW);
1219 if (DRAW == DRAW_REPETITION)
1221 short j;
1223 fprintf(fd, "repetition by positions ");
1225 for (j = GameCnt - 1; j >= Game50; j -= 2)
1227 if (GameList[j].hashkey == hashkey &&
1228 GameList[j].hashbd == hashbd)
1229 fprintf(fd, "%d ", j);
1232 fprintf(fd, "\n");
1235 else if (GameList[GameCnt].score == -(SCORE_LIMIT + 999))
1237 fprintf(fd, "%s\n", ColorStr[player ]);
1239 else if (GameList[GameCnt].score == (SCORE_LIMIT + 998))
1241 fprintf(fd, "%s\n", ColorStr[player ^ 1]);
1244 fclose(fd);
1248 static void
1249 FlagMove(char c)
1251 switch(c)
1253 case '?' :
1254 GameList[GameCnt].flags |= badmove;
1255 break;
1257 case '!' :
1258 GameList[GameCnt].flags |= goodmove;
1259 break;
1261 #ifdef EASY_OPENINGS
1262 case '~' :
1263 GameList[GameCnt].flags |= difficult;
1264 break;
1265 #endif
1271 * Undo the most recent half-move.
1274 static void
1275 Undo(void)
1277 short f, t;
1279 f = GameList[GameCnt].gmove >> 8;
1280 t = GameList[GameCnt].gmove & 0x7F;
1282 if (f > NO_SQUARES)
1284 /* the move was a drop */
1285 Captured[color[t]][board[t]]++;
1286 board[t] = no_piece;
1287 color[t] = neutral;
1288 Mvboard[t]--;
1290 else
1292 if (GameList[GameCnt].flags & promote)
1293 board[f] = unpromoted[board[t]];
1294 else
1295 board[f] = board[t];
1297 color[f] = color[t];
1298 board[t] = GameList[GameCnt].piece;
1299 color[t] = GameList[GameCnt].color;
1301 if (board[t] != no_piece)
1302 Captured[color[f]][unpromoted[board[t]]]--;
1304 if (color[t] != neutral)
1305 Mvboard[t]--;
1307 Mvboard[f]--;
1310 InitializeStats();
1312 if (TCflag && (TCmoves > 1))
1313 ++TimeControl.moves[color[f]];
1315 hashkey = GameList[GameCnt].hashkey;
1316 hashbd = GameList[GameCnt].hashbd;
1317 GameCnt--;
1318 computer = computer ^ 1;
1319 opponent = opponent ^ 1;
1320 flag.mate = false;
1321 Sdepth = 0;
1322 player = player ^ 1;
1323 dsp->ShowSidetoMove();
1324 dsp->UpdateDisplay(0, 0, 1, 0);
1326 if (flag.regularstart)
1327 Book = false;
1331 static void
1332 TestSpeed(void(*f)(short side, short ply,
1333 short in_check, short blockable),
1334 unsigned j)
1336 #ifdef test
1337 unsigned jj;
1338 #endif
1340 unsigned i;
1341 long cnt, t1, t2;
1343 #ifdef HAVE_GETTIMEOFDAY
1344 struct timeval tv;
1345 #endif
1347 #ifdef HAVE_GETTIMEOFDAY
1348 gettimeofday(&tv, NULL);
1349 t1 = (tv.tv_sec*100 + (tv.tv_usec/10000));
1350 #else
1351 t1 = time(0);
1352 #endif
1354 for (i = 0; i < j; i++)
1356 f(opponent, 2, -1, true);
1358 #ifdef test
1359 for (jj = TrPnt[2]; i < TrPnt[3]; jj++)
1361 if (!pick(jj, TrPnt[3] - 1))
1362 break;
1364 #endif
1367 #ifdef HAVE_GETTIMEOFDAY
1368 gettimeofday(&tv, NULL);
1369 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1370 #else
1371 t2 = time(0);
1372 #endif
1374 cnt = j * (TrPnt[3] - TrPnt[2]);
1376 if (t2 - t1)
1377 et = (t2 - t1);
1378 else
1379 et = 1;
1381 dsp->ShowNodeCnt(cnt);
1385 static void
1386 TestPSpeed(short(*f) (short side), unsigned j)
1388 unsigned i;
1389 long cnt, t1, t2;
1390 #ifdef HAVE_GETTIMEOFDAY
1391 struct timeval tv;
1392 #endif
1394 #ifdef HAVE_GETTIMEOFDAY
1395 gettimeofday(&tv, NULL);
1396 t1 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1397 #else
1398 t1 = time(0);
1399 #endif
1401 for (i = 0; i < j; i++)
1402 (void) f(opponent);
1404 #ifdef HAVE_GETTIMEOFDAY
1405 gettimeofday(&tv, NULL);
1406 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1407 #else
1408 t2 = time(0);
1409 #endif
1411 cnt = j;
1413 if (t2 - t1)
1414 et = (t2 - t1);
1415 else
1416 et = 1;
1418 dsp->ShowNodeCnt(cnt);
1422 static void
1423 SetOppTime(char *time)
1425 int m, t;
1427 t = (int)strtol(time, &time, 10);
1429 if (*time == ':')
1431 time++;
1432 /* FIXME: sec is parsed but ignored */
1433 (void)strtol(time, &time, 10);
1436 m = (int)strtol(time, &time, 10);
1438 if (t)
1439 TimeControl.clock[opponent] = t;
1441 if (m)
1442 TimeControl.moves[opponent] = m;
1444 ElapsedTime(COMPUTE_AND_INIT_MODE);
1446 if (XSHOGI)
1448 /* just to inform xshogi about availability of otime command */
1449 printf("otime %d %d\n", t, m);
1454 static void
1455 SetMachineTime(char *time)
1457 int m, t;
1459 t = (int)strtol(time, &time, 10);
1461 if (*time == ':')
1463 time++;
1464 /* FIXME: sec is parsed but ignored */
1465 (void)strtol(time, &time, 10);
1468 m = (int)strtol(time, &time, 10);
1470 if (t)
1471 TimeControl.clock[computer] = t;
1473 if (m)
1474 TimeControl.moves[computer] = m;
1476 ElapsedTime(COMPUTE_AND_INIT_MODE);
1478 if (XSHOGI)
1480 /* just to inform xshogi about availability of time command */
1481 printf("time %d %d\n", t, m);
1486 /* FIXME! This is truly the function from hell! */
1489 * Process the user's command. If easy mode is OFF (the computer is thinking
1490 * on opponents time) and the program is out of book, then make the 'hint'
1491 * move on the board and call SelectMove() to find a response. The user
1492 * terminates the search by entering a command. If the opponent does not make
1493 * the hint move, then set Sdepth to zero.
1496 void
1497 InputCommand(char *command)
1499 #ifdef QUIETBACKGROUND
1500 short have_shown_prompt = false;
1501 #endif
1502 short ok, done, is_move = false;
1503 unsigned short mv;
1504 char s[80], sx[80];
1506 ok = flag.quit = done = false;
1507 player = opponent;
1509 #if ttblsz
1510 if (TTadd > ttbllimit)
1511 ZeroTTable();
1512 #endif
1514 if ((hint > 0) && !flag.easy && !flag.force)
1517 * A hint move for the player is available. Compute a move for the
1518 * opponent in background mode assuming that the hint move will be
1519 * selected by the player.
1522 ft = time0; /* Save reference time for the player. */
1523 fflush(stdout);
1524 algbr((short) hint >> 8, (short) hint & 0xff, false);
1525 strcpy(s, mvstr[0]);
1527 if (flag.post)
1528 dsp->GiveHint();
1530 /* do the hint move */
1531 if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv))
1533 Sdepth = 0;
1535 #ifdef QUIETBACKGROUND
1536 dsp->ShowPrompt();
1537 have_shown_prompt = true;
1538 #endif /* QUIETBACKGROUND */
1540 /* Start computing a move until the search is interrupted. */
1542 #ifdef INTERRUPT_TEST
1543 itime0 = 0;
1544 #endif
1546 /* would love to put null move in here */
1547 /* after we make the hint move make a 2 ply search
1548 * with both plys our moves */
1549 /* think on opponents time */
1550 SelectMove(computer, BACKGROUND_MODE);
1552 #ifdef INTERRUPT_TEST
1553 ElapsedTime(COMPUTE_INTERRUPT_MODE);
1555 if (itime0 == 0)
1557 printf("searching not terminated by interrupt!\n");
1559 else
1561 printf("elapsed time from interrupt to "
1562 "terminating search: %ld\n", it);
1564 #endif
1566 /* undo the hint and carry on */
1567 VerifyMove(s, UNMAKE_MODE, &mv);
1568 Sdepth = 0;
1571 time0 = ft; /* Restore reference time for the player. */
1574 while(!(ok || flag.quit || done))
1576 player = opponent;
1578 #ifdef QUIETBACKGROUND
1579 if (!have_shown_prompt)
1581 #endif /* QUIETBACKGROUND */
1583 dsp->ShowPrompt();
1585 #ifdef QUIETBACKGROUND
1588 have_shown_prompt = false;
1589 #endif /* QUIETBACKGROUND */
1591 if (command == NULL) {
1592 int eof = dsp->GetString(sx);
1593 if (eof)
1594 dsp->ExitShogi();
1595 } else {
1596 strcpy(sx, command);
1597 done = true;
1600 /* extract first word */
1601 if (sscanf(sx, "%s", s) < 1)
1602 continue;
1604 if (strcmp(s, "bd") == 0) /* bd -- display board */
1606 /* FIXME: Hack alert! */
1607 short old_xshogi = XSHOGI;
1609 if (old_xshogi)
1610 display_type = DISPLAY_RAW;
1612 dsp->ClearScreen();
1613 dsp->UpdateDisplay(0, 0, 1, 0);
1615 if (old_xshogi)
1616 display_type = DISPLAY_X;
1618 else if (strcmp(s, "post") == 0)
1620 flag.post = (xboard ? 1 : !flag.post);
1622 else if (strcmp(s, "nopost") == 0)
1624 flag.post = 0;
1626 #ifdef MINISHOGI
1627 else if (strcmp(s, "variant") == 0)
1628 { /* only variant we play is minishogi */
1629 printf("setup (P.BR.S...G.+.++.+Kp.br.s...g.+.++.+k) 5x5+5_shogi rbsgk/4p/5/P4/KGSBR [-] w 0 1\n");
1631 #endif
1632 else if (strcmp(s, "alg") == 0 ||
1633 strcmp(s, "accepted") == 0 || strcmp(s, "rejected") == 0 ||
1634 strcmp(s, "variant") == 0 || strcmp(s, "computer") == 0)
1636 /* noop */ ;
1638 else if ((strcmp(s, "quit") == 0) ||
1639 (strcmp(s, "exit") == 0))
1641 flag.quit = true;
1643 else if (strcmp(s, "xboard") == 0)
1645 xboard = true;
1646 strcpy(ColorStr[0], "White");
1647 strcpy(ColorStr[1], "Black");
1649 else if (strcmp(s, "protover") == 0)
1651 printf("feature myname=\"GNU %s %s\" ",
1652 #ifdef MINISHOGI
1653 "MiniShogi",
1654 #else
1655 "Shogi",
1656 #endif
1657 PACKAGE_VERSION
1659 printf("variants=\"%s\" ",
1660 #ifdef MINISHOGI
1661 "5x5+5_shogi,minishogi"
1662 #else
1663 "shogi"
1664 #endif
1666 printf("debug=1 setboard=0 sigint=0 done=1\n");
1668 else if ((strcmp(s, "set") == 0) ||
1669 (strcmp(s, "edit") == 0))
1671 dsp->EditBoard();
1673 else if (strcmp(s, "setup") == 0)
1675 dsp->SetupBoard();
1677 else if (strcmp(s, "first") == 0)
1679 ok = true;
1681 else if (strcmp(s, "go") == 0)
1683 ok = true;
1684 flag.force = false;
1686 if (computer == black)
1688 computer = white;
1689 opponent = black;
1691 else
1693 computer = black;
1694 opponent = white;
1697 else if (strcmp(s, "help") == 0)
1699 dsp->help();
1701 else if (strcmp(s, "material") == 0)
1703 flag.material = !flag.material;
1705 else if (strcmp(s, "force") == 0)
1707 if (XSHOGI)
1709 flag.force = true;
1710 flag.bothsides = false;
1712 else
1714 flag.force = !flag.force;
1715 flag.bothsides = false;
1718 else if (strcmp(s, "book") == 0)
1720 Book = Book ? 0 : BOOKFAIL;
1722 else if (strcmp(s, "new") == 0)
1724 NewGame();
1725 dsp->UpdateDisplay(0, 0, 1, 0);
1727 else if (strcmp(s, "list") == 0)
1729 ListGame();
1731 else if (strcmp(s, "level") == 0)
1733 dsp->SelectLevel(sx + strlen("level"));
1735 else if (strcmp(s, "clock") == 0)
1737 dsp->SelectLevel(sx + strlen("clock"));
1739 else if (strcmp(s, "hash") == 0)
1741 flag.hash = !flag.hash;
1743 else if (strcmp(s, "gamein") == 0)
1745 flag.gamein = !flag.gamein;
1747 else if (strcmp(s, "beep") == 0)
1749 flag.beep = !flag.beep;
1751 else if (strcmp(s, "time") == 0)
1753 SetMachineTime(sx + strlen("time"));
1755 else if ((strcmp(s, "otime") == 0) ||
1756 (xboard && (strcmp(s, "otim")) == 0))
1758 SetOppTime(sx + strlen("otime"));
1760 else if (strcmp(s, "Awindow") == 0)
1762 dsp->ChangeAlphaWindow();
1764 else if (strcmp(s, "Bwindow") == 0)
1766 dsp->ChangeBetaWindow();
1768 else if (strcmp(s, "rcptr") == 0)
1770 flag.rcptr = !flag.rcptr;
1772 else if (strcmp(s, "hint") == 0)
1774 dsp->GiveHint();
1776 else if (strcmp(s, "both") == 0)
1778 flag.bothsides = !flag.bothsides;
1779 flag.force = false;
1780 Sdepth = 0;
1781 ElapsedTime(COMPUTE_AND_INIT_MODE);
1782 SelectMove(opponent, FOREGROUND_MODE);
1783 ok = true;
1785 else if (strcmp(s, "reverse") == 0)
1787 flag.reverse = !flag.reverse;
1788 dsp->ClearScreen();
1789 dsp->UpdateDisplay(0, 0, 1, 0);
1791 else if (strcmp(s, "switch") == 0)
1793 computer = computer ^ 1;
1794 opponent = opponent ^ 1;
1795 xwndw = (computer == black) ? WXWNDW : BXWNDW;
1796 flag.force = false;
1797 Sdepth = 0;
1798 ok = true;
1799 dsp->UpdateDisplay(0, 0, 1, 0);
1801 else if (xboard ? strcmp(s, "white") == 0 : strcmp(s, "black") == 0)
1803 computer = white;
1804 opponent = black;
1805 xwndw = WXWNDW;
1806 flag.force = false;
1807 Sdepth = 0;
1810 * ok = true; don't automatically start with black command
1813 else if (xboard ? strcmp(s, "black") == 0 : strcmp(s, "white") == 0)
1815 computer = black;
1816 opponent = white;
1817 xwndw = BXWNDW;
1818 flag.force = false;
1819 Sdepth = 0;
1822 * ok = true; don't automatically start with white command
1825 else if (strcmp(s, "undo") == 0 && GameCnt > 0)
1827 Undo();
1829 else if (strcmp(s, "remove") == 0 && GameCnt > 1)
1831 Undo();
1832 Undo();
1834 /* CHECKME: are these next three correct? */
1835 else if (!XSHOGI && strcmp(s, "xget") == 0)
1837 GetXGame();
1839 else if (!XSHOGI && strcmp(s, "xsave") == 0)
1841 SaveXGame();
1843 else if (!XSHOGI && strcmp(s, "bsave") == 0)
1845 BookSave();
1847 #ifdef EASY_OPENINGS
1848 else if ((strcmp(s, "?") == 0) ||
1849 (strcmp(s, "!") == 0) ||
1850 (strcmp(s, "~") == 0))
1851 #else
1852 else if ((strcmp(s, "?") == 0) ||
1853 (strcmp(s, "!") == 0))
1854 #endif
1856 FlagMove(*s);
1858 else if (strcmp(s, "get") == 0)
1860 GetGame();
1862 else if (strcmp(s, "save") == 0)
1864 SaveGame();
1866 else if (strcmp(s, "depth") == 0)
1868 dsp->ChangeSearchDepth(sx + strlen("depth"));
1870 else if (strcmp(s, "sd") == 0)
1872 dsp->ChangeSearchDepth(sx + strlen("sd"));
1874 else if (strcmp(s, "hashdepth") == 0)
1876 dsp->ChangeHashDepth();
1878 else if (strcmp(s, "random") == 0)
1880 dither = DITHER;
1882 else if (strcmp(s, "hard") == 0)
1884 flag.easy = false;
1886 else if (strcmp(s, "easy") == 0)
1888 flag.easy = !flag.easy;
1890 else if (strcmp(s, "tsume") == 0)
1892 flag.tsume = !flag.tsume;
1894 else if (strcmp(s, "contempt") == 0)
1896 dsp->SetContempt();
1898 else if (strcmp(s, "xwndw") == 0)
1900 dsp->ChangeXwindow();
1902 else if (strcmp(s, "rv") == 0)
1904 flag.rv = !flag.rv;
1905 dsp->UpdateDisplay(0, 0, 1, 0);
1907 else if (strcmp(s, "coords") == 0)
1909 flag.coords = !flag.coords;
1910 dsp->UpdateDisplay(0, 0, 1, 0);
1912 else if (strcmp(s, "stars") == 0)
1914 flag.stars = !flag.stars;
1915 dsp->UpdateDisplay(0, 0, 1, 0);
1917 else if (!XSHOGI && strcmp(s, "moves") == 0)
1919 short temp;
1921 #if MAXDEPTH > 3
1922 if (GameCnt > 0)
1924 extern unsigned short PrVar[MAXDEPTH];
1926 SwagHt = (GameList[GameCnt].gmove == PrVar[1])
1927 ? PrVar[2] : 0;
1929 else
1930 #endif
1931 SwagHt = 0;
1933 dsp->ShowMessage("Testing MoveList Speed");
1934 temp = generate_move_flags;
1935 generate_move_flags = true;
1936 TestSpeed(MoveList, 1);
1937 generate_move_flags = temp;
1938 dsp->ShowMessage("Testing CaptureList Speed");
1939 TestSpeed(CaptureList, 1);
1940 dsp->ShowMessage("Testing Eval Speed");
1941 ExaminePosition(opponent);
1942 TestPSpeed(ScorePosition, 1);
1944 else if (!XSHOGI && strcmp(s, "test") == 0)
1946 #ifdef SLOW_CPU
1947 dsp->ShowMessage("Testing MoveList Speed");
1948 TestSpeed(MoveList, 2000);
1949 dsp->ShowMessage("Testing CaptureList Speed");
1950 TestSpeed(CaptureList, 3000);
1951 dsp->ShowMessage("Testing Eval Speed");
1952 ExaminePosition(opponent);
1953 TestPSpeed(ScorePosition, 1500);
1954 #else
1955 dsp->ShowMessage("Testing MoveList Speed");
1956 TestSpeed(MoveList, 20000);
1957 dsp->ShowMessage("Testing CaptureList Speed");
1958 TestSpeed(CaptureList, 30000);
1959 dsp->ShowMessage("Testing Eval Speed");
1960 ExaminePosition(opponent);
1961 TestPSpeed(ScorePosition, 15000);
1962 #endif
1964 else if (!XSHOGI && strcmp(s, "p") == 0)
1966 dsp->ShowPostnValues();
1968 else if (!XSHOGI && strcmp(s, "debug") == 0)
1970 dsp->DoDebug();
1972 else
1974 if (flag.mate)
1976 ok = true;
1978 else if ((ok = VerifyMove(s, VERIFY_AND_MAKE_MODE, &mv)))
1980 /* check for repetition */
1981 short rpt = repetition();
1983 if (rpt >= 3)
1985 DRAW = DRAW_REPETITION;
1986 dsp->ShowMessage(DRAW);
1987 GameList[GameCnt].flags |= draw;
1989 flag.mate = true;
1991 else
1993 is_move = true;
1997 Sdepth = 0;
2001 ElapsedTime(COMPUTE_AND_INIT_MODE);
2003 if (flag.force)
2005 computer = opponent;
2006 opponent = computer ^ 1;
2009 if (XSHOGI)
2011 /* add remaining time in milliseconds for xshogi */
2012 if (is_move)
2014 printf("%d. %s %ld\n",
2015 ++mycnt2, s, TimeControl.clock[player] * 10);