Long-dead code removal: "rv" flag.
[gnushogi.git] / gnushogi / commondsp.c
blobb72d624266aad07a4d16ad0e2fcb7fffe74b110c
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
38 #include "gnushogi.h"
40 #include <stdio.h>
42 #if defined HAVE_GETTIMEOFDAY
43 #include <sys/time.h>
44 #endif
46 #include <ctype.h>
47 #include <signal.h>
49 #include <sys/param.h>
50 #include <sys/types.h>
51 #include <sys/file.h>
53 char mvstr[4][6];
54 int mycnt1, mycnt2;
55 static char *InPtr;
56 struct display *dsp = &raw_display;
58 bool xboard = false;
60 #if defined(BOOKTEST)
62 void
63 movealgbr(short m, char *s)
65 unsigned int f, t;
66 short piece = 0, flag = 0;
68 if (m == 0)
70 strcpy(s, "none");
71 return;
74 f = (m >> 8) & 0x7f;
75 t = m & 0xff;
77 if (f > NO_SQUARES)
79 piece = f - NO_SQUARES;
81 if (piece > NO_PIECES)
82 piece -= NO_PIECES;
84 flag = (dropmask | piece);
87 if (t & 0x80)
89 flag |= promote;
90 t &= 0x7f;
93 if (flag & dropmask)
95 *s = pxx[piece];
96 s++;
97 *s = '*';
98 s++;
99 *s = COL_NAME(column(t));
100 s++;
101 *s = ROW_NAME(row(t));
102 s++;
104 else
106 *s = COL_NAME(column(f));
107 s++;
108 *s = ROW_NAME(row(f));
109 s++;
110 *s = COL_NAME(column(t));
111 s++;
112 *s = ROW_NAME(row(t));
113 s++;
115 if (flag & promote)
117 *s = '+';
118 s++;
122 if (m & 0x8000)
124 *s = '?';
125 s++;
128 *s = '\0';
131 #endif /* BOOKTEST */
135 * Generate move strings in different formats.
137 * INPUT:
138 * - f piece to be moved
139 * - 0 < f < NO_SQUARES source square
140 * - NO_SQUARES <= f NO_SQUARES + 2*NO_PIECES dropped piece modulo NO_PIECES
141 * - t & 0x7f target square
142 * - t & 0x80 promotion flag
143 * - flag
144 * - if flag & dropmask, piece type encoded in flag & pmask
146 * FIXME: that makes 2 ways to specify drops and promotions, why ?
148 * OUTPUT:
149 * - GLOBAL mvstr
152 void
153 algbr(short f, short t, short flags)
155 if (f > NO_SQUARES)
157 short piece;
159 piece = f - NO_SQUARES;
161 if (f > (NO_SQUARES + NO_PIECES))
162 piece -= NO_PIECES;
164 flags = (dropmask | piece);
167 if ((t & 0x80) != 0)
169 flags |= promote;
170 t &= 0x7f;
173 if ((f == t) && ((f != 0) || (t != 0)))
175 if (!XSHOGI) {
176 dsp->Printf("error in algbr: FROM=TO=%d, flags=0x%4x\n", t, flags);
179 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
181 else if ((flags & dropmask) != 0)
183 short piece = flags & pmask;
185 mvstr[0][0] = pxx[piece];
186 mvstr[0][1] = xboard ? '@' : '*';
187 mvstr[0][2] = COL_NAME(column(t));
188 mvstr[0][3] = ROW_NAME(row(t));
189 mvstr[0][4] = '\0';
190 strcpy(mvstr[1], mvstr[0]);
191 strcpy(mvstr[2], mvstr[0]);
192 strcpy(mvstr[3], mvstr[0]);
194 else if ((f != 0) || (t != 0))
196 /* pure coordinates notation */
197 mvstr[0][0] = COL_NAME(column(f));
198 mvstr[0][1] = ROW_NAME(row(f));
199 mvstr[0][2] = COL_NAME(column(t));
200 mvstr[0][3] = ROW_NAME(row(t));
201 mvstr[0][4] = '\0';
203 /* algebraic notation without disambiguation */
204 mvstr[1][0] = pxx[board[f]];
205 mvstr[1][1] = mvstr[0][2]; /* to column */
206 mvstr[1][2] = mvstr[0][3]; /* to row */
207 mvstr[1][3] = '\0';
209 /* algebraic notation with row disambiguation */
210 mvstr[2][0] = mvstr[1][0];
211 mvstr[2][1] = mvstr[0][1];
212 mvstr[2][2] = mvstr[0][2]; /* to column */
213 mvstr[2][3] = mvstr[0][3]; /* to row */
214 mvstr[2][4] = '\0';
216 /* algebraic notation with column disambiguation */
217 strcpy(mvstr[3], mvstr[2]);
218 mvstr[3][1] = mvstr[0][0];
220 if (flags & promote)
222 strcat(mvstr[0], "+");
223 strcat(mvstr[1], "+");
224 strcat(mvstr[2], "+");
225 strcat(mvstr[3], "+");
228 else
230 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
236 * Compare the string 's' to the list of legal moves available for the
237 * opponent. If a match is found, make the move on the board.
240 bool
241 VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
243 static short pnt, tempb, tempc, tempsf, tempst, cnt;
244 static struct leaf xnode;
245 struct leaf *node;
246 short i, l, local_flags;
247 char buffer[60];
249 /* check and remove quality flags */
250 for (i = local_flags = 0, l = strlen(s); i < l; i++)
252 switch(s[i])
254 case '?':
255 local_flags |= badmove;
256 s[i] = '\0';
257 break;
259 case '!':
260 local_flags |= goodmove;
261 s[i] = '\0';
262 break;
264 #ifdef EASY_OPENINGS
265 case '~':
266 local_flags |= difficult;
267 s[i] = '\0';
268 break;
269 #endif
273 *mv = 0;
275 if (iop == UNMAKE_MODE)
277 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
278 return false;
281 cnt = 0;
283 if (iop == VERIFY_AND_MAKE_MODE)
284 generate_move_flags = true;
286 MoveList(opponent, 2, -1, true);
287 generate_move_flags = false;
288 pnt = TrPnt[2];
289 if(s[4] == '=') s[4] = '\0'; /* deferral is implied */
291 while (pnt < TrPnt[3])
293 node = &Tree[pnt++];
294 algbr(node->f, node->t, (short) node->flags);
296 if ((strcmp(s, mvstr[0]) == 0)
297 || (strcmp(s, mvstr[1]) == 0)
298 || (strcmp(s, mvstr[2]) == 0)
299 || (strcmp(s, mvstr[3]) == 0))
301 cnt++;
302 xnode = *node;
306 if ((cnt == 1) && (xnode.score > DONTUSE))
308 bool blocked;
310 MakeMove(opponent, &xnode, &tempb, &tempc,
311 &tempsf, &tempst, &INCscore);
313 if (SqAttacked(PieceList[opponent][0], computer, &blocked))
315 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
316 dsp->AlwaysShowMessage("Illegal move (in check): %s", s);
317 return false;
319 else
321 if (iop == VERIFY_AND_TRY_MODE)
322 return true;
324 dsp->UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
325 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
326 GameList[GameCnt].nodes = 0;
327 ElapsedTime(COMPUTE_AND_INIT_MODE);
328 GameList[GameCnt].time = (short) (et + 50)/100;
329 GameList[GameCnt].flags |= local_flags;
331 if (TCflag)
333 TimeControl.clock[opponent] -= et;
334 timeopp[oppptr] = et;
335 --TimeControl.moves[opponent];
338 *mv = (xnode.f << 8) | xnode.t;
339 algbr(xnode.f, xnode.t, 0);
341 /* in force mode, check for mate conditions */
342 if (flag.force)
344 if (IsCheckmate(opponent ^ 1, -1, -1))
346 char buf[20];
348 sprintf(buf, "%s mates!\n", ColorStr[opponent]);
349 dsp->ShowMessage(buf);
350 flag.mate = true;
354 return true;
358 dsp->AlwaysShowMessage("Illegal move (no match): %s", s);
360 if (!XSHOGI && (cnt > 1))
362 sprintf(buffer, "Ambiguous Move %s!", s);
363 dsp->ShowMessage(buffer);
366 return false;
370 static int
371 parser(char *f, short *fpiece)
373 int c1, r1, c2, r2;
374 short i;
375 bool p = false;
377 if (*f == '+')
378 f++, p = true;
380 for (i = 1, *fpiece = no_piece; i < NO_PIECES; i++)
382 if (f[0] == pxx[i] || f[0] == qxx[i])
384 *fpiece = (p ? promoted[i] : unpromoted[i]);
385 break;
389 if (f[1] == '*' || f[1] == '\'')
391 c2 = COL_NUM(f[2]);
392 r2 = ROW_NUM(f[3]);
394 return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
396 else
398 c1 = COL_NUM(f[1]);
399 r1 = ROW_NUM(f[2]);
400 c2 = COL_NUM(f[3]);
401 r2 = ROW_NUM(f[4]);
402 p = (f[5] == '+') ? 0x80 : 0;
404 return (locn(r1, c1) << 8) | locn(r2, c2) | p;
409 void
410 skip()
412 while (*InPtr != ' ')
413 InPtr++;
415 while (*InPtr == ' ')
416 InPtr++;
420 void
421 skipb()
423 while (*InPtr == ' ')
424 InPtr++;
428 void RequestInputString(char* buffer, unsigned bufsize)
430 static char fmt[10];
431 int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize);
432 if (ret < 0 ) {
433 perror("RequestInputString snprintf");
434 exit(1);
436 if (ret >= sizeof(fmt)) {
437 fprintf(stderr,
438 "Insufficient format-buffer size in %s for bufsize=%u\n",
439 __FUNCTION__, bufsize);
440 exit(1);
442 dsp->doRequestInputString(fmt, buffer);
446 static void
447 GetGame(void)
449 FILE *fd;
450 char fname[256], *p;
451 int c, i, j;
452 short sq;
453 short side, isp;
455 if (savefile[0]) {
456 strcpy(fname, savefile);
457 } else {
458 dsp->ShowMessage("Enter file name: ");
459 RequestInputString(fname, sizeof(fname)-1);
462 if (fname[0] == '\0')
463 strcpy(fname, "shogi.000");
465 if ((fd = fopen(fname, "r")) != NULL)
467 NewGame();
468 fgets(fname, 256, fd);
469 computer = opponent = black;
470 InPtr = fname;
471 skip();
473 if (*InPtr == 'c')
474 computer = white;
475 else
476 opponent = white;
478 /* FIXME: write a skipn() function so that we can get
479 * 3 skips by doing skipn(3) */
480 skip();
481 skip();
482 skip();
483 Game50 = atoi(InPtr);
484 skip();
485 flag.force = (*InPtr == 'f');
486 fgets(fname, 256, fd); /* empty */
487 fgets(fname, 256, fd);
488 InPtr = &fname[11];
489 skipb();
490 TCflag = atoi(InPtr);
491 skip();
492 InPtr += 14;
493 skipb();
494 OperatorTime = atoi(InPtr);
495 fgets(fname, 256, fd);
496 InPtr = &fname[11];
497 skipb();
498 TimeControl.clock[black] = atol(InPtr);
499 skip();
500 skip();
501 TimeControl.moves[black] = atoi(InPtr);
502 fgets(fname, 256, fd);
503 InPtr = &fname[11];
504 skipb();
505 TimeControl.clock[white] = atol(InPtr);
506 skip();
507 skip();
508 TimeControl.moves[white] = atoi(InPtr);
509 fgets(fname, 256, fd); /* empty */
511 for (i = NO_ROWS - 1; i > -1; i--)
513 fgets(fname, 256, fd);
514 p = &fname[2];
515 InPtr = &fname[23];
517 for (j = 0; j < NO_COLS; j++)
519 sq = i * NO_COLS + j;
520 isp = (*p == '+');
521 p++;
523 if (*p == '-')
525 board[sq] = no_piece;
526 color[sq] = neutral;
528 else
530 for (c = 0; c < NO_PIECES; c++)
532 if (*p == pxx[c])
534 if (isp)
535 board[sq] = promoted[c];
536 else
537 board[sq] = unpromoted[c];
539 color[sq] = white;
543 for (c = 0; c < NO_PIECES; c++)
545 if (*p == qxx[c])
547 if (isp)
548 board[sq] = promoted[c];
549 else
550 board[sq] = unpromoted[c];
552 color[sq] = black;
557 p++;
558 Mvboard[sq] = atoi(InPtr);
559 skip();
563 fgets(fname, 256, fd); /* empty */
564 fgets(fname, 256, fd); /* 9 8 7 ... */
565 fgets(fname, 256, fd); /* empty */
566 fgets(fname, 256, fd); /* p l n ... */
567 ClearCaptured();
569 for (side = 0; side <= 1; side++)
571 fgets(fname, 256, fd);
572 InPtr = fname;
573 skip();
574 skipb();
575 Captured[side][pawn] = atoi(InPtr);
576 skip();
577 #ifndef MINISHOGI
578 Captured[side][lance] = atoi(InPtr);
579 skip();
580 Captured[side][knight] = atoi(InPtr);
581 skip();
582 #endif
583 Captured[side][silver] = atoi(InPtr);
584 skip();
585 Captured[side][gold] = atoi(InPtr);
586 skip();
587 Captured[side][bishop] = atoi(InPtr);
588 skip();
589 Captured[side][rook] = atoi(InPtr);
590 skip();
591 Captured[side][king] = atoi(InPtr);
594 GameCnt = 0;
595 flag.regularstart = true;
596 Book = BOOKFAIL;
597 fgets(fname, 256, fd); /* empty */
598 fgets(fname, 256, fd); /* move score ... */
600 while (fgets(fname, 256, fd))
602 struct GameRec *g;
603 int side = computer;
605 side = side ^ 1;
606 ++GameCnt;
607 InPtr = fname;
608 skipb();
609 g = &GameList[GameCnt];
610 g->gmove = parser(InPtr, &g->fpiece);
611 skip();
612 g->score = atoi(InPtr);
613 skip();
614 g->depth = atoi(InPtr);
615 skip();
616 g->nodes = atol(InPtr);
617 skip();
618 g->time = atol(InPtr);
619 skip();
620 g->flags = c = atoi(InPtr);
621 skip();
622 g->hashkey = strtol(InPtr, (char **) NULL, 16);
623 skip();
624 g->hashbd = strtol(InPtr, (char **) NULL, 16);
626 if (c & capture)
628 short i, piece;
630 skip();
632 for (piece = no_piece, i = 0; i < NO_PIECES; i++)
634 if (pxx[i] == *InPtr)
636 piece = i;
637 break;
641 skip();
642 g->color = ((*InPtr == 'W') ? white : black);
643 skip();
644 g->piece = (*InPtr == '+'
645 ? promoted[piece]
646 : unpromoted[piece]);
648 else
650 g->color = neutral;
651 g->piece = no_piece;
655 if (TimeControl.clock[black] > 0)
656 TCflag = true;
658 fclose(fd);
661 ZeroRPT();
662 InitializeStats();
663 dsp->UpdateDisplay(0, 0, 1, 0);
664 Sdepth = 0;
665 hint = 0;
669 static void
670 SaveGame(void)
672 FILE *fd;
673 char fname[256];
674 short sq, i, c, f, t;
675 char p;
676 short side, piece;
677 char empty[2] = "\n";
679 if (savefile[0]) {
680 strcpy(fname, savefile);
681 } else {
682 dsp->ShowMessage("Enter file name: ");
683 RequestInputString(fname, sizeof(fname)-1);
686 if (fname[0] == '\0')
687 strcpy(fname, "shogi.000");
689 if ((fd = fopen(fname, "w")) != NULL)
691 char *b, *w;
692 b = w = "Human ";
694 if (computer == white)
695 w = "computer";
697 if (computer == black)
698 b = "computer";
700 fprintf(fd, "White %s Black %s %d %s\n", w, b, Game50,
701 flag.force ? "force" : "");
702 fputs(empty, fd);
703 fprintf(fd, "TimeControl %d Operator Time %d\n", TCflag, OperatorTime);
704 fprintf(fd, "Black Clock %ld Moves %d\nWhite Clock %ld Moves %d\n",
705 TimeControl.clock[black], TimeControl.moves[black],
706 TimeControl.clock[white], TimeControl.moves[white]);
707 fputs(empty, fd);
709 for (i = NO_ROWS - 1; i > -1; i--)
711 fprintf(fd, "%c ", ROW_NAME(i));
713 for (c = 0; c < NO_COLS; c++)
715 sq = i * NO_COLS + c;
716 piece = board[sq];
717 p = is_promoted[piece] ? '+' : ' ';
718 fprintf(fd, "%c", p);
720 switch(color[sq])
722 case white:
723 p = pxx[piece];
724 break;
726 case black:
727 p = qxx[piece];
728 break;
730 default:
731 p = '-';
734 fprintf(fd, "%c", p);
737 fprintf(fd, " ");
739 for (f = i * NO_COLS; f < i * NO_COLS + NO_ROWS; f++)
740 fprintf(fd, " %d", Mvboard[f]);
742 fprintf(fd, "\n");
745 fputs(empty, fd);
746 #ifndef MINISHOGI
747 fprintf(fd, " 9 8 7 6 5 4 3 2 1\n");
748 fputs(empty, fd);
749 fprintf(fd, " p l n s g b r k\n");
750 #else
751 fprintf(fd, " 5 4 3 2 1\n");
752 fputs(empty, fd);
753 fprintf(fd, " p s g b r k\n");
754 #endif
756 for (side = 0; side <= 1; side++)
758 fprintf(fd, "%c", (side == black) ? 'B' : 'W');
759 fprintf(fd, " %2d", Captured[side][pawn]);
760 #ifndef MINISHOGI
761 fprintf(fd, " %2d", Captured[side][lance]);
762 fprintf(fd, " %2d", Captured[side][knight]);
763 #endif
764 fprintf(fd, " %2d", Captured[side][silver]);
765 fprintf(fd, " %2d", Captured[side][gold]);
766 fprintf(fd, " %2d", Captured[side][bishop]);
767 fprintf(fd, " %2d", Captured[side][rook]);
768 fprintf(fd, " %2d", Captured[side][king]);
769 fprintf(fd, "\n");
772 fputs(empty, fd);
773 fputs(" move score depth nodes time flags capture\n", fd);
775 for (i = 1; i <= GameCnt; i++)
777 struct GameRec *g = &GameList[i];
779 f = g->gmove >> 8;
780 t = (g->gmove & 0xFF);
781 algbr(f, t, g->flags);
783 fprintf(fd, "%c%c%-5s %6d %5d %7ld %6ld %5d 0x%08lx 0x%08lx",
784 ((f > NO_SQUARES)
785 ? ' '
786 : (is_promoted[g->fpiece] ? '+' : ' ')),
787 pxx[g->fpiece],
788 ((f > NO_SQUARES) ? &mvstr[0][1] : mvstr[0]),
789 g->score, g->depth,
790 g->nodes, g->time, g->flags,
791 g->hashkey, g->hashbd);
793 if (g->piece != no_piece)
795 fprintf(fd, " %c %s %c\n",
796 pxx[g->piece], ColorStr[g->color],
797 (is_promoted[g->piece] ? '+' : ' '));
799 else
801 fprintf(fd, "\n");
805 fclose(fd);
807 dsp->ShowMessage("Game saved");
809 else
811 dsp->ShowMessage("Could not open file");
817 * GetXGame, SaveXGame and BookGame used to only be defined if
818 * xshogi wasn't defined -- wonder why?
821 static void
822 GetXGame(void)
824 FILE *fd;
825 char fname[256], *p;
826 int c, i, j;
827 short sq;
828 short side, isp;
830 dsp->ShowMessage("Enter file name: ");
831 RequestInputString(fname, sizeof(fname)-1);
833 if (fname[0] == '\0')
834 strcpy(fname, "xshogi.position.read");
836 if ((fd = fopen(fname, "r")) != NULL)
838 NewGame();
839 flag.regularstart = false;
840 Book = false;
842 /* xshogi position file ... */
843 fgets(fname, 256, fd);
845 #ifdef notdef
846 fname[6] = '\0';
848 if (strcmp(fname, "xshogi"))
849 return;
850 #endif
852 /* -- empty line -- */
853 fgets(fname, 256, fd);
854 /* -- empty line -- */
855 fgets(fname, 256, fd);
857 for (i = NO_ROWS - 1; i > -1; i--)
859 fgets(fname, 256, fd);
860 p = fname;
862 for (j = 0; j < NO_COLS; j++)
864 sq = i * NO_COLS + j;
865 isp = (*p == '+');
866 p++;
868 if (*p == '.')
870 board[sq] = no_piece;
871 color[sq] = neutral;
873 else
875 for (c = 0; c < NO_PIECES; c++)
877 if (*p == qxx[c])
879 if (isp)
880 board[sq] = promoted[c];
881 else
882 board[sq] = unpromoted[c];
884 color[sq] = white;
888 for (c = 0; c < NO_PIECES; c++)
890 if (*p == pxx[c])
892 if (isp)
893 board[sq] = promoted[c];
894 else
895 board[sq] = unpromoted[c];
897 color[sq] = black;
902 p++;
906 ClearCaptured();
908 for (side = 0; side <= 1; side++)
910 fgets(fname, 256, fd);
911 InPtr = fname;
912 Captured[side][pawn] = atoi(InPtr);
913 skip();
914 #ifndef MINISHOGI
915 Captured[side][lance] = atoi(InPtr);
916 skip();
917 Captured[side][knight] = atoi(InPtr);
918 skip();
919 #endif
920 Captured[side][silver] = atoi(InPtr);
921 skip();
922 Captured[side][gold] = atoi(InPtr);
923 skip();
924 Captured[side][bishop] = atoi(InPtr);
925 skip();
926 Captured[side][rook] = atoi(InPtr);
927 skip();
928 Captured[side][king] = atoi(InPtr);
931 if (fgets(fname, 256, fd) != NULL && strncmp(fname, "white", 5) == 0)
933 computer = black;
934 opponent = white;
935 xwndw = BXWNDW;
938 fclose(fd);
941 Game50 = 1;
942 ZeroRPT();
943 InitializeStats();
944 dsp->UpdateDisplay(0, 0, 1, 0);
945 Sdepth = 0;
946 hint = 0;
950 static void
951 SaveXGame(void)
953 FILE *fd;
954 char fname[256], *p;
955 int i, j;
956 short sq, piece;
957 short side, isp;
959 dsp->ShowMessage("Enter file name: ");
960 RequestInputString(fname, sizeof(fname)-1);
962 if (fname[0] == '\0')
963 strcpy(fname, "xshogi.position.read");
965 if ((fd = fopen(fname, "w")) != NULL)
967 fputs("# xshogi position file -- \n", fd);
968 fputs("\n", fd);
969 fputs("\n", fd);
971 for (i = NO_ROWS - 1; i > -1; i--)
973 p = fname;
975 for (j = 0; j < NO_COLS; j++)
977 sq = i * NO_COLS + j;
978 piece = board[sq];
979 isp = is_promoted[piece];
980 *p = (isp ? '+' : ' ');
981 p++;
983 if (piece == no_piece)
984 *p = '.';
985 else if (color[sq] == white)
986 *p = qxx[piece];
987 else
988 *p = pxx[piece];
990 p++;
993 *p++ = '\n';
994 *p++ = '\0';
995 fputs(fname, fd);
998 for (side = 0; side <= 1; side++)
1000 sprintf(fname,
1001 #ifndef MINISHOGI
1002 "%d %d %d %d %d %d %d %d\n",
1003 #else
1004 "%d %d %d %d %d %d\n",
1005 #endif
1006 Captured[side][pawn],
1007 #ifndef MINISHOGI
1008 Captured[side][lance],
1009 Captured[side][knight],
1010 #endif
1011 Captured[side][silver],
1012 Captured[side][gold],
1013 Captured[side][bishop],
1014 Captured[side][rook],
1015 Captured[side][king]);
1017 fputs(fname, fd);
1020 if (computer == black)
1021 fputs("white to play\n", fd);
1022 else
1023 fputs("black to play\n", fd);
1025 fclose(fd);
1030 static void
1031 BookSave(void)
1033 FILE *fd;
1034 char fname[256], sflags[4];
1035 short i, j, f, t;
1037 if (savefile[0]) {
1038 strcpy(fname, savefile);
1039 } else {
1040 /* Enter file name */
1041 dsp->ShowMessage("Enter file name: ");
1042 RequestInputString(fname, sizeof(fname)-1);
1045 if (fname[0] == '\0') {
1046 dsp->AlwaysShowMessage("aborting book save");
1047 return;
1050 if ((fd = fopen(fname, "a")) != NULL)
1052 fprintf(fd, "#\n");
1054 for (i = 1; i <= GameCnt; i++)
1056 struct GameRec *g = &GameList[i];
1057 char mvnr[20], mvs[20];
1059 if (i % 2)
1060 sprintf(mvnr, "%d.", (i + 1)/2);
1061 else
1062 strcpy(mvnr, "");
1064 f = g->gmove >> 8;
1065 t = (g->gmove & 0xFF);
1066 algbr(f, t, g->flags);
1067 j = 0;
1069 /* determine move quality string */
1070 if (g->flags & goodmove)
1071 sflags[j++] = '!';
1073 if (g->flags & badmove)
1074 sflags[j++] = '?';
1076 #ifdef EASY_OPENINGS
1077 if (g->flags & difficult)
1078 sflags[j++] = '~';
1079 #endif
1081 sflags[j] = '\0';
1083 /* determine move string */
1084 if (f > NO_SQUARES)
1086 sprintf(mvs, "%s%s ", &mvstr[0][1], sflags);
1088 else
1090 sprintf(mvs, "%c%c%c%c%c%s%s ",
1091 mvstr[0][0], mvstr[0][1],
1092 (g->flags & capture) ? 'x' : '-',
1093 mvstr[0][2], mvstr[0][3],
1094 (mvstr[0][4] == '+') ? "+" : "",
1095 sflags);
1098 fprintf(fd, "%s%s%c%s",
1099 mvnr,
1100 (f > NO_SQUARES
1101 ? ""
1102 : (is_promoted[g->fpiece] ? "+" : "")),
1103 pxx[g->fpiece],
1104 mvs);
1106 if ((i % 10) == 0)
1107 fprintf(fd, "\n");
1110 if ((i % 10) != 1)
1111 fprintf(fd, "\n");
1113 fclose(fd);
1115 dsp->ShowMessage("Game saved");
1117 else
1119 dsp->ShowMessage("Could not open file");
1124 void
1125 ListGame(void)
1127 FILE *fd;
1128 short i, f, t;
1129 time_t when;
1130 char fname[256], dbuf[256];
1132 if (listfile[0])
1134 strcpy(fname, listfile);
1136 else
1138 time(&when);
1139 strncpy(dbuf, ctime(&when), 20);
1140 dbuf[7] = '\0';
1141 dbuf[10] = '\0';
1142 dbuf[13] = '\0';
1143 dbuf[16] = '\0';
1144 dbuf[19] = '\0';
1146 /* use format "CL.Jan01-020304B" when
1147 date is Jan 1
1148 time is 02:03:04
1149 program played white */
1151 sprintf(fname, "CL.%s%s-%s%s%s%c",
1152 dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14,
1153 dbuf + 17, ColorStr[computer][0]);
1155 /* replace space padding with 0 */
1156 for (i = 0; fname[i] != '\0'; i++)
1158 if (fname[i] == ' ')
1159 fname[i] = '0';
1163 fd = fopen(fname, "w");
1165 if (!fd)
1167 printf("Open failure for file: %s", fname);
1168 exit(1);
1171 fprintf(fd, "gnushogi %s game\n", PACKAGE_VERSION);
1172 fputs(" score depth nodes time ", fd);
1173 fputs(" score depth nodes time\n", fd);
1175 for (i = 1; i <= GameCnt; i++)
1177 f = GameList[i].gmove >> 8;
1178 t = (GameList[i].gmove & 0xFF);
1179 algbr(f, t, GameList[i].flags);
1181 if (GameList[i].flags & book)
1183 fprintf(fd, "%c%c%-5s %5d Book%7ld %5ld",
1184 ((f > NO_SQUARES)
1185 ? ' '
1186 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1187 pxx[GameList[i].fpiece],
1188 ((f > NO_SQUARES)
1189 ? &mvstr[0][1] : mvstr[0]),
1190 GameList[i].score,
1191 GameList[i].nodes,
1192 GameList[i].time);
1194 else
1196 fprintf(fd, "%c%c%-5s %5d %2d %7ld %5ld",
1197 (f > NO_SQUARES
1198 ? ' '
1199 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1200 pxx[GameList[i].fpiece],
1201 (f > NO_SQUARES ? &mvstr[0][1] : mvstr[0]),
1202 GameList[i].score, GameList[i].depth,
1203 GameList[i].nodes, GameList[i].time);
1206 if ((i % 2) == 0)
1208 fprintf(fd, "\n");
1210 else
1212 fprintf(fd, " ");
1216 fprintf(fd, "\n\n");
1218 if (GameList[GameCnt].flags & draw)
1220 fprintf(fd, "Draw %s\n", DRAW);
1222 if (DRAW == DRAW_REPETITION)
1224 short j;
1226 fprintf(fd, "repetition by positions ");
1228 for (j = GameCnt - 1; j >= Game50; j -= 2)
1230 if (GameList[j].hashkey == hashkey &&
1231 GameList[j].hashbd == hashbd)
1232 fprintf(fd, "%d ", j);
1235 fprintf(fd, "\n");
1238 else if (GameList[GameCnt].score == -(SCORE_LIMIT + 999))
1240 fprintf(fd, "%s\n", ColorStr[player ]);
1242 else if (GameList[GameCnt].score == (SCORE_LIMIT + 998))
1244 fprintf(fd, "%s\n", ColorStr[player ^ 1]);
1247 fclose(fd);
1251 static void
1252 FlagMove(char c)
1254 switch(c)
1256 case '?' :
1257 GameList[GameCnt].flags |= badmove;
1258 break;
1260 case '!' :
1261 GameList[GameCnt].flags |= goodmove;
1262 break;
1264 #ifdef EASY_OPENINGS
1265 case '~' :
1266 GameList[GameCnt].flags |= difficult;
1267 break;
1268 #endif
1274 * Undo the most recent half-move.
1277 static void
1278 Undo(void)
1280 short f, t;
1282 f = GameList[GameCnt].gmove >> 8;
1283 t = GameList[GameCnt].gmove & 0x7F;
1285 if (f > NO_SQUARES)
1287 /* the move was a drop */
1288 Captured[color[t]][board[t]]++;
1289 board[t] = no_piece;
1290 color[t] = neutral;
1291 Mvboard[t]--;
1293 else
1295 if (GameList[GameCnt].flags & promote)
1296 board[f] = unpromoted[board[t]];
1297 else
1298 board[f] = board[t];
1300 color[f] = color[t];
1301 board[t] = GameList[GameCnt].piece;
1302 color[t] = GameList[GameCnt].color;
1304 if (board[t] != no_piece)
1305 Captured[color[f]][unpromoted[board[t]]]--;
1307 if (color[t] != neutral)
1308 Mvboard[t]--;
1310 Mvboard[f]--;
1313 InitializeStats();
1315 if (TCflag && (TCmoves > 1))
1316 ++TimeControl.moves[color[f]];
1318 hashkey = GameList[GameCnt].hashkey;
1319 hashbd = GameList[GameCnt].hashbd;
1320 GameCnt--;
1321 computer = computer ^ 1;
1322 opponent = opponent ^ 1;
1323 flag.mate = false;
1324 Sdepth = 0;
1325 player = player ^ 1;
1326 dsp->ShowSidetoMove();
1327 dsp->UpdateDisplay(0, 0, 1, 0);
1329 if (flag.regularstart)
1330 Book = false;
1334 static void
1335 TestSpeed(void(*f)(short side, short ply,
1336 short in_check, bool blockable),
1337 unsigned j)
1339 #ifdef test
1340 unsigned jj;
1341 #endif
1343 unsigned i;
1344 long cnt, t1, t2;
1346 #ifdef HAVE_GETTIMEOFDAY
1347 struct timeval tv;
1348 #endif
1350 #ifdef HAVE_GETTIMEOFDAY
1351 gettimeofday(&tv, NULL);
1352 t1 = (tv.tv_sec*100 + (tv.tv_usec/10000));
1353 #else
1354 t1 = time(0);
1355 #endif
1357 for (i = 0; i < j; i++)
1359 f(opponent, 2, -1, true);
1361 #ifdef test
1362 for (jj = TrPnt[2]; i < TrPnt[3]; jj++)
1364 if (!pick(jj, TrPnt[3] - 1))
1365 break;
1367 #endif
1370 #ifdef HAVE_GETTIMEOFDAY
1371 gettimeofday(&tv, NULL);
1372 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1373 #else
1374 t2 = time(0);
1375 #endif
1377 cnt = j * (TrPnt[3] - TrPnt[2]);
1379 if (t2 - t1)
1380 et = (t2 - t1);
1381 else
1382 et = 1;
1384 dsp->ShowNodeCnt(cnt);
1388 static void
1389 TestPSpeed(short(*f) (short side), unsigned j)
1391 unsigned i;
1392 long cnt, t1, t2;
1393 #ifdef HAVE_GETTIMEOFDAY
1394 struct timeval tv;
1395 #endif
1397 #ifdef HAVE_GETTIMEOFDAY
1398 gettimeofday(&tv, NULL);
1399 t1 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1400 #else
1401 t1 = time(0);
1402 #endif
1404 for (i = 0; i < j; i++)
1405 (void) f(opponent);
1407 #ifdef HAVE_GETTIMEOFDAY
1408 gettimeofday(&tv, NULL);
1409 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1410 #else
1411 t2 = time(0);
1412 #endif
1414 cnt = j;
1416 if (t2 - t1)
1417 et = (t2 - t1);
1418 else
1419 et = 1;
1421 dsp->ShowNodeCnt(cnt);
1425 static void
1426 SetOppTime(char *time)
1428 int m, t;
1430 t = (int)strtol(time, &time, 10);
1432 if (*time == ':')
1434 time++;
1435 /* FIXME: sec is parsed but ignored */
1436 (void)strtol(time, &time, 10);
1439 m = (int)strtol(time, &time, 10);
1441 if (t)
1442 TimeControl.clock[opponent] = t;
1444 if (m)
1445 TimeControl.moves[opponent] = m;
1447 ElapsedTime(COMPUTE_AND_INIT_MODE);
1449 if (XSHOGI)
1451 /* just to inform xshogi about availability of otime command */
1452 printf("otime %d %d\n", t, m);
1457 static void
1458 SetMachineTime(char *time)
1460 int m, t;
1462 t = (int)strtol(time, &time, 10);
1464 if (*time == ':')
1466 time++;
1467 /* FIXME: sec is parsed but ignored */
1468 (void)strtol(time, &time, 10);
1471 m = (int)strtol(time, &time, 10);
1473 if (t)
1474 TimeControl.clock[computer] = t;
1476 if (m)
1477 TimeControl.moves[computer] = m;
1479 ElapsedTime(COMPUTE_AND_INIT_MODE);
1481 if (XSHOGI)
1483 /* just to inform xshogi about availability of time command */
1484 printf("time %d %d\n", t, m);
1489 /* FIXME! This is truly the function from hell! */
1492 * Process the user's command. If easy mode is OFF (the computer is thinking
1493 * on opponents time) and the program is out of book, then make the 'hint'
1494 * move on the board and call SelectMove() to find a response. The user
1495 * terminates the search by entering a command. If the opponent does not make
1496 * the hint move, then set Sdepth to zero.
1499 void
1500 InputCommand(char *command)
1502 #ifdef QUIETBACKGROUND
1503 bool have_shown_prompt = false;
1504 #endif
1505 bool ok, done, is_move = false;
1506 unsigned short mv;
1507 char s[80], sx[80];
1509 ok = flag.quit = done = false;
1510 player = opponent;
1512 #if ttblsz
1513 if (TTadd > ttbllimit)
1514 ZeroTTable();
1515 #endif
1517 if ((hint > 0) && !flag.easy && !flag.force)
1520 * A hint move for the player is available. Compute a move for the
1521 * opponent in background mode assuming that the hint move will be
1522 * selected by the player.
1525 ft = time0; /* Save reference time for the player. */
1526 fflush(stdout);
1527 algbr((short) hint >> 8, (short) hint & 0xff, 0);
1528 strcpy(s, mvstr[0]);
1530 if (flag.post)
1531 dsp->GiveHint();
1533 /* do the hint move */
1534 if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv))
1536 Sdepth = 0;
1538 #ifdef QUIETBACKGROUND
1539 dsp->ShowPrompt();
1540 have_shown_prompt = true;
1541 #endif /* QUIETBACKGROUND */
1543 /* Start computing a move until the search is interrupted. */
1545 #ifdef INTERRUPT_TEST
1546 itime0 = 0;
1547 #endif
1549 /* would love to put null move in here */
1550 /* after we make the hint move make a 2 ply search
1551 * with both plys our moves */
1552 /* think on opponents time */
1553 SelectMove(computer, BACKGROUND_MODE);
1555 #ifdef INTERRUPT_TEST
1556 ElapsedTime(COMPUTE_INTERRUPT_MODE);
1558 if (itime0 == 0)
1560 printf("searching not terminated by interrupt!\n");
1562 else
1564 printf("elapsed time from interrupt to "
1565 "terminating search: %ld\n", it);
1567 #endif
1569 /* undo the hint and carry on */
1570 VerifyMove(s, UNMAKE_MODE, &mv);
1571 Sdepth = 0;
1574 time0 = ft; /* Restore reference time for the player. */
1577 while(!(ok || flag.quit || done))
1579 player = opponent;
1581 #ifdef QUIETBACKGROUND
1582 if (!have_shown_prompt)
1584 #endif /* QUIETBACKGROUND */
1586 dsp->ShowPrompt();
1588 #ifdef QUIETBACKGROUND
1591 have_shown_prompt = false;
1592 #endif /* QUIETBACKGROUND */
1594 if (command == NULL) {
1595 int eof = dsp->GetString(sx);
1596 if (eof)
1597 dsp->ExitShogi();
1598 } else {
1599 strcpy(sx, command);
1600 done = true;
1603 /* extract first word */
1604 if (sscanf(sx, "%s", s) < 1)
1605 continue;
1607 if (strcmp(s, "bd") == 0) /* bd -- display board */
1609 /* FIXME: Hack alert! */
1610 short old_xshogi = XSHOGI;
1612 if (old_xshogi)
1613 display_type = DISPLAY_RAW;
1615 dsp->ClearScreen();
1616 dsp->UpdateDisplay(0, 0, 1, 0);
1618 if (old_xshogi)
1619 display_type = DISPLAY_X;
1621 else if (strcmp(s, "post") == 0)
1623 flag.post = (xboard ? 1 : !flag.post);
1625 else if (strcmp(s, "nopost") == 0)
1627 flag.post = 0;
1629 #ifdef MINISHOGI
1630 else if (strcmp(s, "variant") == 0)
1631 { /* only variant we play is minishogi */
1632 printf("setup (P.BR.S...G.+.++.+Kp.br.s...g.+.++.+k) 5x5+5_shogi rbsgk/4p/5/P4/KGSBR [-] w 0 1\n");
1634 #endif
1635 else if (strcmp(s, "alg") == 0 ||
1636 strcmp(s, "accepted") == 0 || strcmp(s, "rejected") == 0 ||
1637 strcmp(s, "variant") == 0 || strcmp(s, "computer") == 0)
1639 /* noop */ ;
1641 else if ((strcmp(s, "quit") == 0) ||
1642 (strcmp(s, "exit") == 0))
1644 flag.quit = true;
1646 else if (strcmp(s, "xboard") == 0)
1648 if (!xboard) {
1649 /* xboard calls Sente "White" */
1650 const char *tmp = ColorStr[0];
1651 ColorStr[0] = ColorStr[1];
1652 ColorStr[1] = tmp;
1653 xboard = true;
1656 else if (strcmp(s, "protover") == 0)
1658 printf("feature option=\"tsume -check 0\"\n");
1659 printf("feature option=\"Use hash-file -check %d\"\n", flag.hash);
1660 printf("feature option=\"contempt -spin %d -1000 1000\"\n", contempt);
1661 printf("feature option=\"Hash-file search depth -spin %d 0 100\"\n", HashDepth);
1662 printf("feature option=\"Hash-file move number -spin %d 0 100\"\n", HashMoveLimit);
1663 printf("feature myname=\"GNU %s %s\" ",
1664 #ifdef MINISHOGI
1665 "MiniShogi",
1666 #else
1667 "Shogi",
1668 #endif
1669 PACKAGE_VERSION
1671 printf("variants=\"%s\" ",
1672 #ifdef MINISHOGI
1673 "5x5+5_shogi,minishogi"
1674 #else
1675 "shogi"
1676 #endif
1678 printf("debug=1 setboard=0 sigint=0 usermove=1 done=1\n");
1680 else if ((strcmp(s, "set") == 0) ||
1681 (strcmp(s, "edit") == 0))
1683 dsp->EditBoard();
1685 else if (strcmp(s, "setup") == 0)
1687 dsp->SetupBoard();
1689 else if (strcmp(s, "first") == 0)
1691 ok = true;
1693 else if (strcmp(s, "go") == 0)
1695 ok = true;
1696 flag.force = false;
1698 if (computer == black)
1700 computer = white;
1701 opponent = black;
1703 else
1705 computer = black;
1706 opponent = white;
1709 else if (strcmp(s, "help") == 0)
1711 dsp->help();
1713 else if (strcmp(s, "material") == 0)
1715 flag.material = !flag.material;
1717 else if (strcmp(s, "force") == 0)
1719 if (XSHOGI)
1721 flag.force = true;
1722 flag.bothsides = false;
1724 else
1726 flag.force = !flag.force;
1727 flag.bothsides = false;
1730 else if (strcmp(s, "book") == 0)
1732 Book = Book ? 0 : BOOKFAIL;
1734 else if (strcmp(s, "new") == 0)
1736 NewGame();
1737 dsp->UpdateDisplay(0, 0, 1, 0);
1739 else if (strcmp(s, "list") == 0)
1741 ListGame();
1743 else if (strcmp(s, "level") == 0)
1745 dsp->SelectLevel(sx + strlen("level"));
1747 else if (strcmp(s, "clock") == 0)
1749 dsp->SelectLevel(sx + strlen("clock"));
1751 else if (strcmp(s, "hash") == 0)
1753 flag.hash = !flag.hash;
1755 else if (strcmp(s, "gamein") == 0)
1757 flag.gamein = !flag.gamein;
1759 else if (strcmp(s, "beep") == 0)
1761 flag.beep = !flag.beep;
1763 else if (strcmp(s, "time") == 0)
1765 SetMachineTime(sx + strlen("time"));
1767 else if ((strcmp(s, "otime") == 0) ||
1768 (xboard && (strcmp(s, "otim")) == 0))
1770 SetOppTime(sx + strlen("otime"));
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;
1811 dsp->UpdateDisplay(0, 0, 1, 0);
1813 else if (xboard ? strcmp(s, "white") == 0 : strcmp(s, "black") == 0)
1815 computer = white;
1816 opponent = black;
1817 xwndw = WXWNDW;
1818 flag.force = false;
1819 Sdepth = 0;
1822 * ok = true; don't automatically start with black command
1825 else if (xboard ? strcmp(s, "black") == 0 : strcmp(s, "white") == 0)
1827 computer = black;
1828 opponent = white;
1829 xwndw = BXWNDW;
1830 flag.force = false;
1831 Sdepth = 0;
1834 * ok = true; don't automatically start with white command
1837 else if (strcmp(s, "undo") == 0 && GameCnt > 0)
1839 Undo();
1841 else if (strcmp(s, "remove") == 0 && GameCnt > 1)
1843 Undo();
1844 Undo();
1846 /* CHECKME: are these next three correct? */
1847 else if (!XSHOGI && strcmp(s, "xget") == 0)
1849 GetXGame();
1851 else if (!XSHOGI && strcmp(s, "xsave") == 0)
1853 SaveXGame();
1855 else if (!XSHOGI && strcmp(s, "bsave") == 0)
1857 BookSave();
1859 #ifdef EASY_OPENINGS
1860 else if ((strcmp(s, "?") == 0) ||
1861 (strcmp(s, "!") == 0) ||
1862 (strcmp(s, "~") == 0))
1863 #else
1864 else if ((strcmp(s, "?") == 0) ||
1865 (strcmp(s, "!") == 0))
1866 #endif
1868 FlagMove(*s);
1870 else if (strcmp(s, "get") == 0)
1872 GetGame();
1874 else if (strcmp(s, "save") == 0)
1876 SaveGame();
1878 else if (strcmp(s, "depth") == 0)
1880 dsp->ChangeSearchDepth(sx + strlen("depth"));
1882 else if (strcmp(s, "sd") == 0)
1884 dsp->ChangeSearchDepth(sx + strlen("sd"));
1886 else if (strcmp(s, "hashdepth") == 0)
1888 dsp->ChangeHashDepth();
1890 else if (strcmp(s, "random") == 0)
1892 dither = DITHER;
1894 else if (strcmp(s, "hard") == 0)
1896 flag.easy = false;
1898 else if (strcmp(s, "easy") == 0)
1900 flag.easy = !flag.easy;
1902 else if (strcmp(s, "option") == 0)
1904 do {
1905 int value;
1906 if (sscanf(sx, "option tsume=%d", &value) == 1) {
1907 flag.tsume = (value != 0);
1908 break;
1910 if (sscanf(sx, "option Use hash-file=%d", &value) == 1) {
1911 flag.hash = (value != 0);
1912 break;
1914 if (sscanf(sx, "option Hash-file search depth=%hd", &HashDepth) == 1)
1915 break;
1916 if (sscanf(sx, "option Hash-file move number=%hd", &HashMoveLimit) == 1)
1917 break;
1918 if (sscanf(sx, "option contempt=%hd", &contempt) == 1)
1919 break;
1920 dsp->AlwaysShowMessage("Unknown '%s'", sx);
1921 } while(0);
1923 else if (strcmp(s, "tsume") == 0)
1925 flag.tsume = !flag.tsume;
1927 else if (strcmp(s, "contempt") == 0)
1929 dsp->SetContempt();
1931 else if (strcmp(s, "xwndw") == 0)
1933 dsp->ChangeXwindow();
1935 else if (!XSHOGI && strcmp(s, "moves") == 0)
1937 short temp;
1939 #if MAXDEPTH > 3
1940 if (GameCnt > 0)
1942 extern unsigned short PrVar[MAXDEPTH];
1944 SwagHt = (GameList[GameCnt].gmove == PrVar[1])
1945 ? PrVar[2] : 0;
1947 else
1948 #endif
1949 SwagHt = 0;
1951 dsp->ShowMessage("Testing MoveList Speed");
1952 temp = generate_move_flags;
1953 generate_move_flags = true;
1954 TestSpeed(MoveList, 1);
1955 generate_move_flags = temp;
1956 dsp->ShowMessage("Testing CaptureList Speed");
1957 TestSpeed(CaptureList, 1);
1958 dsp->ShowMessage("Testing Eval Speed");
1959 ExaminePosition(opponent);
1960 TestPSpeed(ScorePosition, 1);
1962 else if (!XSHOGI && strcmp(s, "test") == 0)
1964 #ifdef SLOW_CPU
1965 dsp->ShowMessage("Testing MoveList Speed");
1966 TestSpeed(MoveList, 2000);
1967 dsp->ShowMessage("Testing CaptureList Speed");
1968 TestSpeed(CaptureList, 3000);
1969 dsp->ShowMessage("Testing Eval Speed");
1970 ExaminePosition(opponent);
1971 TestPSpeed(ScorePosition, 1500);
1972 #else
1973 dsp->ShowMessage("Testing MoveList Speed");
1974 TestSpeed(MoveList, 20000);
1975 dsp->ShowMessage("Testing CaptureList Speed");
1976 TestSpeed(CaptureList, 30000);
1977 dsp->ShowMessage("Testing Eval Speed");
1978 ExaminePosition(opponent);
1979 TestPSpeed(ScorePosition, 15000);
1980 #endif
1982 else if (!XSHOGI && strcmp(s, "p") == 0)
1984 dsp->ShowPostnValues();
1986 else if (!XSHOGI && strcmp(s, "debug") == 0)
1988 dsp->DoDebug();
1990 else
1992 if (strcmp(s, "usermove") == 0 && sx[8] == ' ')
1993 sscanf(sx + 9, "%s", s);
1995 if (flag.mate)
1997 ok = true;
1999 else if ((ok = VerifyMove(s, VERIFY_AND_MAKE_MODE, &mv)))
2001 /* check for repetition */
2002 short rpt = repetition();
2004 if (rpt >= 3)
2006 DRAW = DRAW_REPETITION;
2007 dsp->ShowMessage(DRAW);
2008 GameList[GameCnt].flags |= draw;
2010 flag.mate = true;
2012 else
2014 is_move = true;
2018 Sdepth = 0;
2022 ElapsedTime(COMPUTE_AND_INIT_MODE);
2024 if (flag.force)
2026 computer = opponent;
2027 opponent = computer ^ 1;
2030 if (XSHOGI)
2032 /* add remaining time in milliseconds for xshogi */
2033 if (is_move)
2035 printf("%d. %s %ld\n",
2036 ++mycnt2, s, TimeControl.clock[player] * 10);