Restore previous copyright information that got removed by error.
[gnushogi.git] / gnushogi / commondsp.c
blobdb90fd31ef1a866204a8b4f018cd57264ccdc1fd
1 /*
2 * FILE: commondsp.c
4 * Common display routines for GNU Shogi.
6 * ----------------------------------------------------------------------
7 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
8 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
10 * GNU SHOGI is based on GNU CHESS
12 * Copyright (c) 1988, 1989, 1990 John Stanback
13 * Copyright (c) 1992 Free Software Foundation
15 * This file is part of GNU SHOGI.
17 * GNU Shogi is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 3 of the License,
20 * or (at your option) any later version.
22 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
23 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with GNU Shogi; see the file COPYING. If not, see
29 * <http://www.gnu.org/licenses/>.
30 * ----------------------------------------------------------------------
34 #if defined HAVE_GETTIMEOFDAY
35 #include <sys/time.h>
36 #endif
38 #include <ctype.h>
39 #include <signal.h>
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/file.h>
45 #include <curses.h>
46 #include "gnushogi.h"
48 char mvstr[4][6];
49 char *InPtr;
50 int InBackground = false;
53 #if defined(BOOKTEST)
55 void
56 movealgbr(short m, char *s)
58 unsigned int f, t;
59 short piece = 0, flag = 0;
61 if (m == 0)
63 strcpy(s, "none");
64 return;
67 f = (m >> 8) & 0x7f;
68 t = m & 0xff;
70 if (f > NO_SQUARES)
72 piece = f - NO_SQUARES;
74 if (piece > NO_PIECES)
75 piece -= NO_PIECES;
77 flag = (dropmask | piece);
80 if (t & 0x80)
82 flag |= promote;
83 t &= 0x7f;
86 if (flag & dropmask)
88 *s = pxx[piece];
89 s++;
90 *s = '*';
91 s++;
92 *s = cxx[column(t)];
93 s++;
94 *s = rxx[row(t)];
95 s++;
97 else
99 *s = cxx[column(f)];
100 s++;
101 *s = rxx[row(f)];
102 s++;
103 *s = cxx[column(t)];
104 s++;
105 *s = rxx[row(t)];
106 s++;
108 if (flag & promote)
110 *s = '+';
111 s++;
115 if (m & 0x8000)
117 *s = '?';
118 s++;
121 *s = '\0';
124 #endif /* BOOKTEST */
130 * Generate move strings in different formats.
132 * INPUT:
133 * - f piece to be moved
134 * - 0 < f < NO_SQUARES source square
135 * - NO_SQUARES <= f NO_SQUARES + 2*NO_PIECES dropped piece modulo NO_PIECES
136 * - t & 0x7f target square
137 * - t & 0x80 promotion flag
138 * - flag FIXME: must be zero ?
140 * OUTPUT:
141 * - GLOBAL mvstr
144 void
145 algbr(short f, short t, short flag)
147 if (f > NO_SQUARES)
149 short piece;
151 piece = f - NO_SQUARES;
153 if (f > (NO_SQUARES + NO_PIECES))
154 piece -= NO_PIECES;
156 flag = (dropmask | piece);
159 if ((t & 0x80) != 0)
161 flag |= promote;
162 t &= 0x7f;
165 if ((f == t) && ((f != 0) || (t != 0)))
167 if (!barebones)
169 if (NOT_CURSES)
170 printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
171 else
172 printw("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
175 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
177 else if ((flag & dropmask) != 0)
179 short piece = flag & pmask;
181 mvstr[0][0] = pxx[piece];
182 mvstr[0][1] = '*';
183 mvstr[0][2] = cxx[column(t)];
184 mvstr[0][3] = rxx[row(t)];
185 mvstr[0][4] = '\0';
186 strcpy(mvstr[1], mvstr[0]);
187 strcpy(mvstr[2], mvstr[0]);
188 strcpy(mvstr[3], mvstr[0]);
190 else if ((f != 0) || (t != 0))
192 /* algebraic notation */
193 mvstr[0][0] = cxx[column(f)];
194 mvstr[0][1] = rxx[row(f)];
195 mvstr[0][2] = cxx[column(t)];
196 mvstr[0][3] = rxx[row(t)];
197 mvstr[0][4] = mvstr[3][0] = '\0';
198 mvstr[1][0] = pxx[board[f]];
200 mvstr[2][0] = mvstr[1][0];
201 mvstr[2][1] = mvstr[0][1];
203 mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */
204 mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */
205 mvstr[2][4] = mvstr[1][3] = '\0';
206 strcpy(mvstr[3], mvstr[2]);
207 mvstr[3][1] = mvstr[0][0];
209 if (flag & promote)
211 strcat(mvstr[0], "+");
212 strcat(mvstr[1], "+");
213 strcat(mvstr[2], "+");
214 strcat(mvstr[3], "+");
217 else
219 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
226 * Compare the string 's' to the list of legal moves available for the
227 * opponent. If a match is found, make the move on the board.
231 VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
233 static short pnt, tempb, tempc, tempsf, tempst, cnt;
234 static struct leaf xnode;
235 struct leaf *node;
236 short i, l, local_flags;
237 char buffer[60];
239 /* check and remove quality flags */
240 for (i = local_flags = 0, l = strlen(s); i < l; i++)
242 switch(s[i])
244 case '?':
245 local_flags |= badmove;
246 s[i] = '\0';
247 break;
249 case '!':
250 local_flags |= goodmove;
251 s[i] = '\0';
252 break;
254 #ifdef EASY_OPENINGS
255 case '~':
256 local_flags |= difficult;
257 s[i] = '\0';
258 break;
259 #endif
263 *mv = 0;
265 if (iop == UNMAKE_MODE)
267 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
268 return false;
271 cnt = 0;
273 if (iop == VERIFY_AND_MAKE_MODE)
274 generate_move_flags = true;
276 MoveList(opponent, 2, -1, true);
277 generate_move_flags = false;
278 pnt = TrPnt[2];
280 while (pnt < TrPnt[3])
282 node = &Tree[pnt++];
283 algbr(node->f, node->t, (short) node->flags);
285 if ((strcmp(s, mvstr[0]) == 0)
286 || (strcmp(s, mvstr[1]) == 0)
287 || (strcmp(s, mvstr[2]) == 0)
288 || (strcmp(s, mvstr[3]) == 0))
290 cnt++;
291 xnode = *node;
295 if ((cnt == 1) && (xnode.score > DONTUSE))
297 short blocked;
299 MakeMove(opponent, &xnode, &tempb, &tempc,
300 &tempsf, &tempst, &INCscore);
302 if (SqAttacked(PieceList[opponent][0], computer, &blocked))
304 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
306 if (NOT_CURSES)
308 /* Illegal move in check */
309 printf(CP[77], mvstr[0]);
310 printf("\n");
312 else
314 /* Illegal move in check */
315 sprintf(buffer, CP[77], s);
316 ShowMessage(buffer);
319 return false;
321 else
323 if (iop == VERIFY_AND_TRY_MODE)
324 return true;
326 UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
327 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
328 GameList[GameCnt].nodes = 0;
329 ElapsedTime(COMPUTE_AND_INIT_MODE);
330 GameList[GameCnt].time = (short) (et + 50)/100;
331 GameList[GameCnt].flags |= local_flags;
333 if (TCflag)
335 TimeControl.clock[opponent] -= et;
336 timeopp[oppptr] = et;
337 --TimeControl.moves[opponent];
340 *mv = (xnode.f << 8) | xnode.t;
341 algbr(xnode.f, xnode.t, false);
343 /* in force mode, check for mate conditions */
344 if (flag.force)
346 if (IsCheckmate(opponent ^ 1, -1, -1))
348 char buf[20];
350 sprintf(buf, "%s mates!\n", ColorStr[opponent]);
351 ShowMessage(buf);
352 flag.mate = true;
356 return true;
360 if (NOT_CURSES)
362 /* Illegal move */
363 printf (CP[75], s);
365 else /* Curses. */
367 /* Illegal move */
368 sprintf(buffer, CP[76], s);
369 ShowMessage(buffer);
372 if (!barebones && (cnt > 1))
374 sprintf(buffer, CP[32], s);
375 ShowMessage(buffer);
378 return false;
383 static int
384 parser(char *f, int side, short *fpiece)
386 int c1, r1, c2, r2;
387 short i, p = false;
389 if (*f == '+')
390 f++, p = true;
392 for (i = 1, *fpiece = no_piece; i < NO_PIECES; i++)
394 if (f[0] == pxx[i] || f[0] == qxx[i])
396 *fpiece = (p ? promoted[i] : unpromoted[i]);
397 break;
401 if (f[1] == '*' || f[1] == '\'')
403 c2 = COL_NAME(f[2]);
404 r2 = ROW_NAME(f[3]);
406 return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
408 else
410 c1 = COL_NAME(f[1]);
411 r1 = ROW_NAME(f[2]);
412 c2 = COL_NAME(f[3]);
413 r2 = ROW_NAME(f[4]);
414 p = (f[5] == '+') ? 0x80 : 0;
416 return (locn(r1, c1) << 8) | locn(r2, c2) | p;
421 void
422 skip()
424 while (*InPtr != ' ')
425 InPtr++;
427 while (*InPtr == ' ')
428 InPtr++;
433 void
434 skipb()
436 while (*InPtr == ' ')
437 InPtr++;
442 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])
453 strcpy(fname, savefile);
455 else
457 /* Enter file name */
458 ShowMessage(CP[63]);
460 if (NOT_CURSES)
462 scanf("%s", fname);
464 else
466 fflush(stdout);
467 scanw("%s", fname);
471 /* shogi.000 */
472 if (fname[0] == '\0')
473 strcpy(fname, CP[137]);
475 if ((fd = fopen(fname, "r")) != NULL)
477 NewGame();
478 fgets(fname, 256, fd);
479 computer = opponent = black;
480 InPtr = fname;
481 skip();
483 if (*InPtr == 'c')
484 computer = white;
485 else
486 opponent = white;
488 /* FIXME: write a skipn() function so that we can get
489 * 3 skips by doing skipn(3) */
490 skip();
491 skip();
492 skip();
493 Game50 = atoi(InPtr);
494 skip();
495 flag.force = (*InPtr == 'f');
496 fgets(fname, 256, fd); /* empty */
497 fgets(fname, 256, fd);
498 InPtr = &fname[11];
499 skipb();
500 TCflag = atoi(InPtr);
501 skip();
502 InPtr += 14;
503 skipb();
504 OperatorTime = atoi(InPtr);
505 fgets(fname, 256, fd);
506 InPtr = &fname[11];
507 skipb();
508 TimeControl.clock[black] = atol(InPtr);
509 skip();
510 skip();
511 TimeControl.moves[black] = atoi(InPtr);
512 fgets(fname, 256, fd);
513 InPtr = &fname[11];
514 skipb();
515 TimeControl.clock[white] = atol(InPtr);
516 skip();
517 skip();
518 TimeControl.moves[white] = atoi(InPtr);
519 fgets(fname, 256, fd); /* empty */
521 for (i = NO_ROWS - 1; i > -1; i--)
523 fgets(fname, 256, fd);
524 p = &fname[2];
525 InPtr = &fname[23];
527 for (j = 0; j < NO_COLS; j++)
529 sq = i * NO_COLS + j;
530 isp = (*p == '+');
531 p++;
533 if (*p == '-')
535 board[sq] = no_piece;
536 color[sq] = neutral;
538 else
540 for (c = 0; c < NO_PIECES; c++)
542 if (*p == pxx[c])
544 if (isp)
545 board[sq] = promoted[c];
546 else
547 board[sq] = unpromoted[c];
549 color[sq] = white;
553 for (c = 0; c < NO_PIECES; c++)
555 if (*p == qxx[c])
557 if (isp)
558 board[sq] = promoted[c];
559 else
560 board[sq] = unpromoted[c];
562 color[sq] = black;
567 p++;
568 Mvboard[sq] = atoi(InPtr);
569 skip();
573 fgets(fname, 256, fd); /* empty */
574 fgets(fname, 256, fd); /* 9 8 7 ... */
575 fgets(fname, 256, fd); /* empty */
576 fgets(fname, 256, fd); /* p l n ... */
577 ClearCaptured();
579 for (side = 0; side <= 1; side++)
581 fgets(fname, 256, fd);
582 InPtr = fname;
583 skip();
584 skipb();
585 Captured[side][pawn] = atoi(InPtr);
586 skip();
587 Captured[side][lance] = atoi(InPtr);
588 skip();
589 Captured[side][knight] = atoi(InPtr);
590 skip();
591 Captured[side][silver] = atoi(InPtr);
592 skip();
593 Captured[side][gold] = atoi(InPtr);
594 skip();
595 Captured[side][bishop] = atoi(InPtr);
596 skip();
597 Captured[side][rook] = atoi(InPtr);
598 skip();
599 Captured[side][king] = atoi(InPtr);
602 GameCnt = 0;
603 flag.regularstart = true;
604 Book = BOOKFAIL;
605 fgets(fname, 256, fd); /* empty */
606 fgets(fname, 256, fd); /* move score ... */
608 while (fgets(fname, 256, fd))
610 struct GameRec *g;
611 int side = computer;
613 side = side ^ 1;
614 ++GameCnt;
615 InPtr = fname;
616 skipb();
617 g = &GameList[GameCnt];
618 g->gmove = parser(InPtr, side, &g->fpiece);
619 skip();
620 g->score = atoi(InPtr);
621 skip();
622 g->depth = atoi(InPtr);
623 skip();
624 g->nodes = atol(InPtr);
625 skip();
626 g->time = atol(InPtr);
627 skip();
628 g->flags = c = atoi(InPtr);
629 skip();
630 g->hashkey = strtol(InPtr, (char **) NULL, 16);
631 skip();
632 g->hashbd = strtol(InPtr, (char **) NULL, 16);
634 if (c & capture)
636 short i, piece;
638 skip();
640 for (piece = no_piece, i = 0; i < NO_PIECES; i++)
642 if (pxx[i] == *InPtr)
644 piece = i;
645 break;
649 skip();
650 g->color = ((*InPtr == CP[119][0]) ? white : black);
651 skip();
652 g->piece = (*InPtr == '+'
653 ? promoted[piece]
654 : unpromoted[piece]);
656 else
658 g->color = neutral;
659 g->piece = no_piece;
663 if (TimeControl.clock[black] > 0)
664 TCflag = true;
666 fclose(fd);
669 ZeroRPT();
670 InitializeStats();
671 UpdateDisplay(0, 0, 1, 0);
672 Sdepth = 0;
673 hint = 0;
678 void
679 SaveGame(void)
681 FILE *fd;
682 char fname[256];
683 short sq, i, c, f, t;
684 char p;
685 short side, piece;
686 char empty[2] = "\n";
688 if (savefile[0])
690 strcpy(fname, savefile);
692 else
694 /* Enter file name */
695 ShowMessage(CP[63]);
697 if (NOT_CURSES)
699 scanf("%s", fname);
701 else
703 fflush(stdout);
704 scanw("%s", fname);
708 if (fname[0] == '\0') /* shogi.000 */
709 strcpy(fname, CP[137]);
711 if ((fd = fopen(fname, "w")) != NULL)
713 char *b, *w;
714 b = w = CP[74];
716 if (computer == white)
717 w = CP[141];
719 if (computer == black)
720 b = CP[141];
722 fprintf(fd, CP[37], w, b, Game50,
723 flag.force ? "force" : "");
724 fputs(empty, fd);
725 fprintf(fd, CP[111], TCflag, OperatorTime);
726 fprintf(fd, CP[117],
727 TimeControl.clock[black], TimeControl.moves[black],
728 TimeControl.clock[white], TimeControl.moves[white]);
729 fputs(empty, fd);
731 for (i = NO_ROWS - 1; i > -1; i--)
733 fprintf(fd, "%c ", ROW_NAME(i));
735 for (c = 0; c < NO_COLS; c++)
737 sq = i * NO_COLS + c;
738 piece = board[sq];
739 p = is_promoted[piece] ? '+' : ' ';
740 fprintf(fd, "%c", p);
742 switch(color[sq])
744 case white:
745 p = pxx[piece];
746 break;
748 case black:
749 p = qxx[piece];
750 break;
752 default:
753 p = '-';
756 fprintf(fd, "%c", p);
759 fprintf(fd, " ");
761 for (f = i * NO_COLS; f < i * NO_COLS + NO_ROWS; f++)
762 fprintf(fd, " %d", Mvboard[f]);
764 fprintf(fd, "\n");
767 fputs(empty, fd);
768 fprintf(fd, " 9 8 7 6 5 4 3 2 1\n"); /* FIXME */
769 fputs(empty, fd);
770 fprintf(fd, " p l n s g b r k\n");
772 for (side = 0; side <= 1; side++)
774 fprintf(fd, "%c", (side == black) ? 'B' : 'W');
775 fprintf(fd, " %2d", Captured[side][pawn]);
776 fprintf(fd, " %2d", Captured[side][lance]);
777 fprintf(fd, " %2d", Captured[side][knight]);
778 fprintf(fd, " %2d", Captured[side][silver]);
779 fprintf(fd, " %2d", Captured[side][gold]);
780 fprintf(fd, " %2d", Captured[side][bishop]);
781 fprintf(fd, " %2d", Captured[side][rook]);
782 fprintf(fd, " %2d", Captured[side][king]);
783 fprintf(fd, "\n");
786 fputs(empty, fd);
787 fputs(CP[126], fd);
789 for (i = 1; i <= GameCnt; i++)
791 struct GameRec *g = &GameList[i];
793 f = g->gmove >> 8;
794 t = (g->gmove & 0xFF);
795 algbr(f, t, g->flags);
797 fprintf(fd, "%c%c%-5s %6d %5d %7ld %6ld %5d 0x%08lx 0x%08lx",
798 ((f > NO_SQUARES)
799 ? ' '
800 : (is_promoted[g->fpiece] ? '+' : ' ')),
801 pxx[g->fpiece],
802 ((f > NO_SQUARES) ? &mvstr[0][1] : mvstr[0]),
803 g->score, g->depth,
804 g->nodes, g->time, g->flags,
805 g->hashkey, g->hashbd);
807 if (g->piece != no_piece)
809 fprintf(fd, " %c %s %c\n",
810 pxx[g->piece], ColorStr[g->color],
811 (is_promoted[g->piece] ? '+' : ' '));
813 else
815 fprintf(fd, "\n");
819 fclose(fd);
821 /* Game saved */
822 ShowMessage(CP[70]);
824 else
826 /* ShowMessage("Could not open file"); */
827 ShowMessage(CP[48]);
834 * GetXGame, SaveXGame and BookGame used to only be defined if
835 * xshogi wasn't defined -- wonder why?
838 void
839 GetXGame(void)
841 FILE *fd;
842 char fname[256], *p;
843 int c, i, j;
844 short sq;
845 short side, isp;
847 /* Enter file name */
848 ShowMessage(CP[63]);
850 if (NOT_CURSES)
852 scanf("%s", fname);
854 else
856 fflush(stdout);
857 scanw("%s", fname);
860 if (fname[0] == '\0') /* XSHOGI.position.read */
861 strcpy(fname, CP[205]);
863 if ((fd = fopen(fname, "r")) != NULL)
865 NewGame();
866 flag.regularstart = false;
867 Book = false;
869 /* xshogi position file ... */
870 fgets(fname, 256, fd);
872 #ifdef notdef
873 fname[6] = '\0';
875 if (strcmp(fname, CP[206]))
876 return;
877 #endif
879 /* -- empty line -- */
880 fgets(fname, 256, fd);
881 /* -- empty line -- */
882 fgets(fname, 256, fd);
884 for (i = NO_ROWS - 1; i > -1; i--)
886 fgets(fname, 256, fd);
887 p = fname;
889 for (j = 0; j < NO_COLS; j++)
891 sq = i * NO_COLS + j;
892 isp = (*p == '+');
893 p++;
895 if (*p == '.')
897 board[sq] = no_piece;
898 color[sq] = neutral;
900 else
902 for (c = 0; c < NO_PIECES; c++)
904 if (*p == qxx[c])
906 if (isp)
907 board[sq] = promoted[c];
908 else
909 board[sq] = unpromoted[c];
911 color[sq] = white;
915 for (c = 0; c < NO_PIECES; c++)
917 if (*p == pxx[c])
919 if (isp)
920 board[sq] = promoted[c];
921 else
922 board[sq] = unpromoted[c];
924 color[sq] = black;
929 p++;
933 ClearCaptured();
935 for (side = 0; side <= 1; side++)
937 fgets(fname, 256, fd);
938 InPtr = fname;
939 Captured[side][pawn] = atoi(InPtr);
940 skip();
941 Captured[side][lance] = atoi(InPtr);
942 skip();
943 Captured[side][knight] = atoi(InPtr);
944 skip();
945 Captured[side][silver] = atoi(InPtr);
946 skip();
947 Captured[side][gold] = atoi(InPtr);
948 skip();
949 Captured[side][bishop] = atoi(InPtr);
950 skip();
951 Captured[side][rook] = atoi(InPtr);
952 skip();
953 Captured[side][king] = atoi(InPtr);
956 if (fgets(fname, 256, fd) != NULL && strncmp(fname, "white", 5) == 0)
958 computer = black;
959 opponent = white;
960 xwndw = BXWNDW;
963 fclose(fd);
966 Game50 = 1;
967 ZeroRPT();
968 InitializeStats();
969 UpdateDisplay(0, 0, 1, 0);
970 Sdepth = 0;
971 hint = 0;
975 void
976 SaveXGame(void)
978 FILE *fd;
979 char fname[256], *p;
980 int i, j;
981 short sq, piece;
982 short side, isp;
984 /* Enter file name */
985 ShowMessage(CP[63]);
987 if (NOT_CURSES)
989 scanf("%s", fname);
991 else
993 fflush(stdout);
994 scanw("%s", fname);
997 if (fname[0] == '\0') /* XSHOGI.position.read */
998 strcpy(fname, CP[205]);
1000 if ((fd = fopen(fname, "w")) != NULL)
1002 /* xshogi position file ... */
1003 fputs("# xshogi position file -- \n", fd);
1004 /* -- empty line -- */
1005 fputs("\n", fd);
1006 /* -- empty line -- */
1007 fputs("\n", fd);
1009 for (i = NO_ROWS - 1; i > -1; i--)
1011 p = fname;
1013 for (j = 0; j < NO_COLS; j++)
1015 sq = i * NO_COLS + j;
1016 piece = board[sq];
1017 isp = is_promoted[piece];
1018 *p = (isp ? '+' : ' ');
1019 p++;
1021 if (piece == no_piece)
1022 *p = '.';
1023 else if (color[sq] == white)
1024 *p = qxx[piece];
1025 else
1026 *p = pxx[piece];
1028 p++;
1031 *p++ = '\n';
1032 *p++ = '\0';
1033 fputs(fname, fd);
1036 for (side = 0; side <= 1; side++)
1038 sprintf(fname, "%d %d %d %d %d %d %d %d\n",
1039 Captured[side][pawn],
1040 Captured[side][lance],
1041 Captured[side][knight],
1042 Captured[side][silver],
1043 Captured[side][gold],
1044 Captured[side][bishop],
1045 Captured[side][rook],
1046 Captured[side][king]);
1048 fputs(fname, fd);
1051 if (computer == black)
1052 fputs("white to play\n", fd);
1053 else
1054 fputs("black to play\n", fd);
1056 fclose(fd);
1061 void
1062 BookSave(void)
1064 FILE *fd;
1065 char fname[256], sflags[4];
1066 short i, j, f, t;
1068 if (savefile[0])
1070 strcpy(fname, savefile);
1072 else
1074 /* Enter file name */
1075 ShowMessage(CP[63]);
1077 if (NOT_CURSES)
1079 scanf("%s", fname);
1081 else
1083 fflush(stdout);
1084 scanw("%s", fname);
1088 if (fname[0] == '\0')
1089 return;
1091 if ((fd = fopen(fname, "a")) != NULL)
1093 fprintf(fd, "#\n");
1095 for (i = 1; i <= GameCnt; i++)
1097 struct GameRec *g = &GameList[i];
1098 char mvnr[20], mvs[20];
1100 if (i % 2)
1101 sprintf(mvnr, "%d.", (i + 1)/2);
1102 else
1103 strcpy(mvnr, "");
1105 f = g->gmove >> 8;
1106 t = (g->gmove & 0xFF);
1107 algbr(f, t, g->flags);
1108 j = 0;
1110 /* determine move quality string */
1111 if (g->flags & goodmove)
1112 sflags[j++] = '!';
1114 if (g->flags & badmove)
1115 sflags[j++] = '?';
1117 #ifdef EASY_OPENINGS
1118 if (g->flags & difficult)
1119 sflags[j++] = '~';
1120 #endif
1122 sflags[j] = '\0';
1124 /* determine move string */
1125 if (f > NO_SQUARES)
1127 sprintf(mvs, "%s%s ", &mvstr[0][1], sflags);
1129 else
1131 sprintf(mvs, "%c%c%c%c%c%s%s ",
1132 mvstr[0][0], mvstr[0][1],
1133 (g->flags & capture) ? 'x' : '-',
1134 mvstr[0][2], mvstr[0][3],
1135 (mvstr[0][4] == '+') ? "+" : "",
1136 sflags);
1139 fprintf(fd, "%s%s%c%s",
1140 mvnr,
1141 (f > NO_SQUARES
1142 ? ""
1143 : (is_promoted[g->fpiece] ? "+" : "")),
1144 pxx[g->fpiece],
1145 mvs);
1147 if ((i % 10) == 0)
1148 fprintf(fd, "\n");
1151 if ((i % 10) != 1)
1152 fprintf(fd, "\n");
1154 fclose(fd);
1156 /* Game saved */
1157 ShowMessage(CP[70]);
1159 else
1161 /* ShowMessage("Could not open file"); */
1162 ShowMessage(CP[48]);
1168 void
1169 ListGame(void)
1171 FILE *fd;
1172 short i, f, t;
1173 time_t when;
1174 char fname[256], dbuf[256];
1176 if (listfile[0])
1178 strcpy(fname, listfile);
1180 else
1182 time(&when);
1183 strncpy(dbuf, ctime(&when), 20);
1184 dbuf[7] = '\0';
1185 dbuf[10] = '\0';
1186 dbuf[13] = '\0';
1187 dbuf[16] = '\0';
1188 dbuf[19] = '\0';
1190 /* use format "CLp16.Jan01-020304B" when patchlevel is 16,
1191 date is Jan 1
1192 time is 02:03:04
1193 program played white */
1195 sprintf(fname, "CLp%s.%s%s-%s%s%s%c",
1196 patchlevel, dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14,
1197 dbuf + 17, ColorStr[computer][0]);
1199 /* replace space padding with 0 */
1200 for (i = 0; fname[i] != '\0'; i++)
1202 if (fname[i] == ' ')
1203 fname[i] = '0';
1207 fd = fopen(fname, "w");
1209 if (!fd)
1211 printf(CP[219], fname);
1212 exit(1);
1215 /* fprintf(fd, "gnushogi game %d\n", u); */
1216 fprintf(fd, CP[161], version, patchlevel);
1217 fputs(CP[10], fd);
1218 fputs(CP[11], fd);
1220 for (i = 1; i <= GameCnt; i++)
1222 f = GameList[i].gmove >> 8;
1223 t = (GameList[i].gmove & 0xFF);
1224 algbr(f, t, GameList[i].flags);
1226 if (GameList[i].flags & book)
1228 fprintf(fd, "%c%c%-5s %5d Book%7ld %5ld",
1229 ((f > NO_SQUARES)
1230 ? ' '
1231 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1232 pxx[GameList[i].fpiece],
1233 ((f > NO_SQUARES)
1234 ? &mvstr[0][1] : mvstr[0]),
1235 GameList[i].score,
1236 GameList[i].nodes,
1237 GameList[i].time);
1239 else
1241 fprintf(fd, "%c%c%-5s %5d %2d %7ld %5ld",
1242 (f > NO_SQUARES
1243 ? ' '
1244 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1245 pxx[GameList[i].fpiece],
1246 (f > NO_SQUARES ? &mvstr[0][1] : mvstr[0]),
1247 GameList[i].score, GameList[i].depth,
1248 GameList[i].nodes, GameList[i].time);
1251 if ((i % 2) == 0)
1253 fprintf(fd, "\n");
1255 else
1257 fprintf(fd, " ");
1261 fprintf(fd, "\n\n");
1263 if (GameList[GameCnt].flags & draw)
1265 fprintf(fd, CP[54], DRAW);
1267 if (DRAW == CP[101])
1269 short j;
1271 fprintf(fd, "repetition by positions ");
1273 for (j = GameCnt - 1; j >= Game50; j -= 2)
1275 if (GameList[j].hashkey == hashkey &&
1276 GameList[j].hashbd == hashbd)
1277 fprintf(fd, "%d ", j);
1280 fprintf(fd, "\n");
1283 else if (GameList[GameCnt].score == -(SCORE_LIMIT + 999))
1285 fprintf(fd, "%s\n", ColorStr[player ]);
1287 else if (GameList[GameCnt].score == (SCORE_LIMIT + 998))
1289 fprintf(fd, "%s\n", ColorStr[player ^ 1]);
1292 fclose(fd);
1297 void
1298 FlagMove(char c)
1300 switch(c)
1302 case '?' :
1303 GameList[GameCnt].flags |= badmove;
1304 break;
1306 case '!' :
1307 GameList[GameCnt].flags |= goodmove;
1308 break;
1310 #ifdef EASY_OPENINGS
1311 case '~' :
1312 GameList[GameCnt].flags |= difficult;
1313 break;
1314 #endif
1322 * Undo the most recent half-move.
1325 void
1326 Undo(void)
1328 short f, t;
1330 f = GameList[GameCnt].gmove >> 8;
1331 t = GameList[GameCnt].gmove & 0x7F;
1333 if (f > NO_SQUARES)
1335 /* the move was a drop */
1336 Captured[color[t]][board[t]]++;
1337 board[t] = no_piece;
1338 color[t] = neutral;
1339 Mvboard[t]--;
1341 else
1343 if (GameList[GameCnt].flags & promote)
1344 board[f] = unpromoted[board[t]];
1345 else
1346 board[f] = board[t];
1348 color[f] = color[t];
1349 board[t] = GameList[GameCnt].piece;
1350 color[t] = GameList[GameCnt].color;
1352 if (board[t] != no_piece)
1353 Captured[color[f]][unpromoted[board[t]]]--;
1355 if (color[t] != neutral)
1356 Mvboard[t]--;
1358 Mvboard[f]--;
1361 InitializeStats();
1363 if (TCflag && (TCmoves > 1))
1364 ++TimeControl.moves[color[f]];
1366 hashkey = GameList[GameCnt].hashkey;
1367 hashbd = GameList[GameCnt].hashbd;
1368 GameCnt--;
1369 computer = computer ^ 1;
1370 opponent = opponent ^ 1;
1371 flag.mate = false;
1372 Sdepth = 0;
1373 player = player ^ 1;
1374 ShowSidetoMove();
1375 UpdateDisplay(0, 0, 1, 0);
1377 if (flag.regularstart)
1378 Book = false;
1383 void
1384 FlagString(unsigned short flags, char *s)
1386 short l, piece;
1387 *s = '\0';
1389 if (flags & promote)
1390 strcat(s, " promote");
1392 if (flags & dropmask)
1393 strcat(s, " drop:");
1395 if ((piece = (flags & pmask)))
1397 l = strlen(s);
1399 if (is_promoted[piece])
1400 s[l++] = '+';
1402 s[l++] = pxx[piece];
1403 s[l] = '\0';
1406 if (flags & capture)
1407 strcat(s, " capture");
1409 if (flags & exact)
1410 strcat(s, " exact");
1412 if (flags & tesuji)
1413 strcat(s, " tesuji");
1415 if (flags & check)
1416 strcat(s, " check");
1418 if (flags & draw)
1419 strcat(s, " draw");
1421 if (flags & stupid)
1422 strcat(s, " stupid");
1424 if (flags & questionable)
1425 strcat(s, " questionable");
1427 if (flags & kingattack)
1428 strcat(s, " kingattack");
1430 if (flags & book)
1431 strcat(s, " book");
1436 void
1437 TestSpeed(void(*f)(short side, short ply,
1438 short in_check, short blockable),
1439 unsigned j)
1441 #ifdef test
1442 unsigned jj;
1443 #endif
1445 unsigned i;
1446 long cnt, rate, t1, t2;
1448 #ifdef HAVE_GETTIMEOFDAY
1449 struct timeval tv;
1450 #endif
1452 #ifdef HAVE_GETTIMEOFDAY
1453 gettimeofday(&tv, NULL);
1454 t1 = (tv.tv_sec*100 + (tv.tv_usec/10000));
1455 #else
1456 t1 = time(0);
1457 #endif
1459 for (i = 0; i < j; i++)
1461 f(opponent, 2, -1, true);
1463 #ifdef test
1464 for (jj = TrPnt[2]; i < TrPnt[3]; jj++)
1466 if (!pick(jj, TrPnt[3] - 1))
1467 break;
1469 #endif
1472 #ifdef HAVE_GETTIMEOFDAY
1473 gettimeofday(&tv, NULL);
1474 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1475 #else
1476 t2 = time(0);
1477 #endif
1479 cnt = j * (TrPnt[3] - TrPnt[2]);
1481 if (t2 - t1)
1482 et = (t2 - t1);
1483 else
1484 et = 1;
1486 rate = (((et) ? ((cnt * 100) / et) : 0));
1488 #ifdef DYNAMIC_ZNODES
1489 if (rate > 0)
1490 znodes = rate;
1491 #endif
1493 if (NOT_CURSES)
1494 printf(CP[91], cnt, rate);
1495 else
1496 ShowNodeCnt(cnt);
1501 void
1502 TestPSpeed(short(*f) (short side), unsigned j)
1504 short i;
1505 long cnt, rate, t1, t2;
1506 #ifdef HAVE_GETTIMEOFDAY
1507 struct timeval tv;
1508 #endif
1510 #ifdef HAVE_GETTIMEOFDAY
1511 gettimeofday(&tv, NULL);
1512 t1 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1513 #else
1514 t1 = time(0);
1515 #endif
1517 for (i = 0; i < j; i++)
1518 (void) f(opponent);
1520 #ifdef HAVE_GETTIMEOFDAY
1521 gettimeofday(&tv, NULL);
1522 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1523 #else
1524 t2 = time(0);
1525 #endif
1527 cnt = j;
1529 if (t2 - t1)
1530 et = (t2 - t1);
1531 else
1532 et = 1;
1534 rate = (et) ? ((cnt * 100) / et) : 0;
1536 /* printf("Nodes= %ld Nodes/sec= %ld\n", cnt, rate); */
1538 if (NOT_CURSES)
1539 printf(CP[91], cnt, rate);
1540 else
1541 ShowNodeCnt(cnt);
1546 void
1547 SetOppTime(char *s)
1549 char *time;
1550 int m, t, sec;
1552 sec = 0;
1553 time = &s[strlen(CP[228])];
1554 t = (int)strtol(time, &time, 10);
1556 if (*time == ':')
1558 time++;
1559 sec = (int)strtol(time, &time, 10);
1562 m = (int)strtol(time, &time, 10);
1564 if (t)
1565 TimeControl.clock[opponent] = t;
1567 if (m)
1568 TimeControl.moves[opponent] = m;
1570 ElapsedTime(COMPUTE_AND_INIT_MODE);
1572 if (XSHOGI)
1574 /* just to inform xshogi about availability of otime command */
1575 printf("otime %d %d\n", t, m);
1581 void
1582 SetMachineTime(char *s)
1584 char *time;
1585 int m, t, sec;
1587 time = &s[strlen(CP[197])];
1588 sec = 0;
1589 t = (int)strtol(time, &time, 10);
1591 if (*time == ':')
1593 time++;
1594 sec = (int)strtol(time, &time, 10);
1597 m = (int)strtol(time, &time, 10);
1599 if (t)
1600 TimeControl.clock[computer] = t;
1602 if (m)
1603 TimeControl.moves[computer] = m;
1605 ElapsedTime(COMPUTE_AND_INIT_MODE);
1607 if (XSHOGI)
1609 /* just to inform xshogi about availability of time command */
1610 printf("time %d %d\n", t, m);
1618 /* FIXME! This is truly the function from hell! */
1621 * Process the user's command. If easy mode is OFF (the computer is thinking
1622 * on opponents time) and the program is out of book, then make the 'hint'
1623 * move on the board and call SelectMove() to find a response. The user
1624 * terminates the search by entering ^C (quit siqnal) before entering a
1625 * command. If the opponent does not make the hint move, then set Sdepth to
1626 * zero.
1629 void
1630 InputCommand(char *command)
1632 int eof = 0;
1633 short have_shown_prompt = false;
1634 short ok, done, is_move = false;
1635 unsigned short mv;
1636 char s[80], sx[80];
1638 ok = flag.quit = done = false;
1639 player = opponent;
1641 #if ttblsz
1642 if (TTadd > ttbllimit)
1643 ZeroTTable();
1644 #endif
1646 if ((hint > 0) && !flag.easy && !flag.force)
1649 * A hint move for the player is available. Compute a move for the
1650 * opponent in background mode assuming that the hint move will be
1651 * selected by the player.
1654 ft = time0; /* Save reference time for the player. */
1655 fflush(stdout);
1656 algbr((short) hint >> 8, (short) hint & 0xff, false);
1657 strcpy(s, mvstr[0]);
1659 #if !defined NOPOST
1660 if (flag.post)
1661 GiveHint();
1662 #endif
1664 /* do the hint move */
1665 if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv))
1667 Sdepth = 0;
1669 #ifdef QUIETBACKGROUND
1670 if (NOT_CURSES)
1672 PromptForMove();
1674 else
1676 ShowSidetoMove();
1677 ShowPrompt();
1680 have_shown_prompt = true;
1681 #endif /* QUIETBACKGROUND */
1683 /* Start computing a move until the search is interrupted. */
1685 #ifdef INTERRUPT_TEST
1686 itime0 = 0;
1687 #endif
1689 /* would love to put null move in here */
1690 /* after we make the hint move make a 2 ply search
1691 * with both plys our moves */
1692 /* think on opponents time */
1693 SelectMove(computer, BACKGROUND_MODE);
1695 #ifdef INTERRUPT_TEST
1696 ElapsedTime(COMPUTE_INTERRUPT_MODE);
1698 if (itime0 == 0)
1700 printf("searching not terminated by interrupt!\n");
1702 else
1704 printf("elapsed time from interrupt to "
1705 "terminating search: %ld\n", it);
1707 #endif
1709 /* undo the hint and carry on */
1710 VerifyMove(s, UNMAKE_MODE, &mv);
1711 Sdepth = 0;
1714 time0 = ft; /* Restore reference time for the player. */
1717 while(!(ok || flag.quit || done))
1719 player = opponent;
1721 #ifdef QUIETBACKGROUND
1722 if (!have_shown_prompt)
1724 #endif /* QUIETBACKGROUND */
1726 if (NOT_CURSES)
1728 PromptForMove();
1730 else
1732 ShowSidetoMove();
1733 ShowPrompt();
1736 #ifdef QUIETBACKGROUND
1739 have_shown_prompt = false;
1740 #endif /* QUIETBACKGROUND */
1742 if (command == NULL)
1744 if (NOT_CURSES)
1746 s[0] = sx[0] = '\0';
1748 while(!sx[0])
1749 (void)fgets(sx, 80, stdin);
1751 else
1753 fflush(stdout);
1754 eof = (getstr(sx) == ERR);
1757 else
1759 strcpy(sx, command);
1760 done = true;
1763 sscanf(sx, "%s", s);
1765 if (eof)
1766 ExitShogi();
1768 if (s[0] == '\0')
1769 continue;
1771 if (strcmp(s, CP[131]) == 0) /* bd -- display board */
1773 /* FIXME: Hack alert! */
1774 short old_xshogi = XSHOGI;
1776 if (old_xshogi)
1777 display_type = DISPLAY_RAW;
1779 ClearScreen();
1780 UpdateDisplay(0, 0, 1, 0);
1782 if (old_xshogi)
1783 display_type = DISPLAY_X;
1785 else if (strcmp(s, "post") == 0)
1787 flag.post = !flag.post;
1789 else if (strcmp(s, CP[129]) == 0)
1791 /* noop */ ; /* alg */
1793 else if ((strcmp(s, CP[180]) == 0)
1794 || (strcmp(s, CP[216]) == 0)) /* quit exit */
1796 flag.quit = true;
1798 #if !defined NOPOST
1799 else if (strcmp(s, CP[178]) == 0) /* post */
1801 flag.post = !flag.post;
1803 #endif
1804 else if ((strcmp(s, CP[191]) == 0)
1805 || (strcmp(s, CP[154]) == 0)) /* set edit */
1807 EditBoard();
1809 else if (NOT_CURSES && (strcmp(s, CP[190]) == 0)) /* setup */
1811 SetupBoard();
1813 else if (strcmp(s, CP[156]) == 0) /* first */
1815 ok = true;
1817 else if (strcmp(s, CP[162]) == 0) /* go */
1819 ok = true;
1820 flag.force = false;
1822 if (computer == black)
1824 computer = white;
1825 opponent = black;
1827 else
1829 computer = black;
1830 opponent = white;
1833 else if (strcmp(s, CP[166]) == 0) /* help */
1835 help();
1837 else if (strcmp(s, CP[221]) == 0) /* material */
1839 flag.material = !flag.material;
1841 else if (strcmp(s, CP[157]) == 0) /* force */
1843 if (XSHOGI)
1845 flag.force = true;
1846 flag.bothsides = false;
1848 else
1850 flag.force = !flag.force;
1851 flag.bothsides = false;
1854 else if (strcmp(s, CP[134]) == 0) /* book */
1856 Book = Book ? 0 : BOOKFAIL;
1858 else if (strcmp(s, CP[172]) == 0) /* new */
1860 NewGame();
1861 UpdateDisplay(0, 0, 1, 0);
1863 else if (strcmp(s, CP[171]) == 0) /* list */
1865 ListGame();
1867 else if ((strcmp(s, CP[169]) == 0)
1868 || (strcmp(s, CP[217]) == 0)) /* level clock */
1870 SelectLevel(sx);
1872 else if (strcmp(s, CP[165]) == 0) /* hash */
1874 flag.hash = !flag.hash;
1876 else if (strcmp(s, CP[227]) == 0) /* gamein */
1878 flag.gamein = !flag.gamein;
1880 else if (strcmp(s, CP[226]) == 0) /* beep */
1882 flag.beep = !flag.beep;
1884 else if (strcmp(s, CP[197]) == 0) /* time */
1886 SetMachineTime(sx);
1888 else if (strcmp(s, CP[228]) == 0) /* otime */
1890 SetOppTime(sx);
1892 else if (strcmp(s, CP[33]) == 0) /* Awindow */
1894 ChangeAlphaWindow();
1896 else if (strcmp(s, CP[39]) == 0) /* Bwindow */
1898 ChangeBetaWindow();
1900 else if (strcmp(s, CP[183]) == 0) /* rcptr */
1902 flag.rcptr = !flag.rcptr;
1904 else if (strcmp(s, CP[168]) == 0) /* hint */
1906 GiveHint();
1908 else if (strcmp(s, CP[135]) == 0) /* both */
1910 flag.bothsides = !flag.bothsides;
1911 flag.force = false;
1912 Sdepth = 0;
1913 ElapsedTime(COMPUTE_AND_INIT_MODE);
1914 SelectMove(opponent, FOREGROUND_MODE);
1915 ok = true;
1917 else if (strcmp(s, CP[185]) == 0) /* reverse */
1919 flag.reverse = !flag.reverse;
1920 ClearScreen();
1921 UpdateDisplay(0, 0, 1, 0);
1923 else if (strcmp(s, CP[195]) == 0) /* switch */
1925 computer = computer ^ 1;
1926 opponent = opponent ^ 1;
1927 xwndw = (computer == black) ? WXWNDW : BXWNDW;
1928 flag.force = false;
1929 Sdepth = 0;
1930 ok = true;
1932 else if (strcmp(s, CP[203]) == 0) /* black */
1934 computer = white;
1935 opponent = black;
1936 xwndw = WXWNDW;
1937 flag.force = false;
1938 Sdepth = 0;
1941 * ok = true; don't automatically start with black command
1944 else if (strcmp(s, CP[133]) == 0) /* white */
1946 computer = black;
1947 opponent = white;
1948 xwndw = BXWNDW;
1949 flag.force = false;
1950 Sdepth = 0;
1953 * ok = true; don't automatically start with white command
1956 else if (strcmp(s, CP[201]) == 0 && GameCnt > 0) /* undo */
1958 Undo();
1960 else if (strcmp(s, CP[184]) == 0 && GameCnt > 1) /* remove */
1962 Undo();
1963 Undo();
1965 /* CHECKME: are these next three correct? */
1966 else if (!XSHOGI && strcmp(s, CP[207]) == 0) /* xget */
1968 GetXGame();
1970 else if (!XSHOGI && strcmp(s, "xsave") == 0) /* xsave */
1972 SaveXGame();
1974 else if (!XSHOGI && strcmp(s, "bsave") == 0) /* bsave */
1976 BookSave();
1978 #ifdef EASY_OPENINGS
1979 else if ((strcmp(s, "?") == 0)
1980 || (strcmp(s, "!") == 0)
1981 || (strcmp(s, "~") == 0))
1982 #else
1983 else if ((strcmp(s, "?") == 0)
1984 || (strcmp(s, "!") == 0))
1985 #endif
1987 FlagMove(*s);
1989 else if (strcmp(s, CP[160]) == 0) /* get */
1991 GetGame();
1993 else if (strcmp(s, CP[189]) == 0) /* save */
1995 SaveGame();
1997 else if (strcmp(s, CP[151]) == 0) /* depth */
1999 ChangeSearchDepth();
2001 else if (strcmp(s, CP[164]) == 0) /* hashdepth */
2003 ChangeHashDepth();
2005 else if (strcmp(s, CP[182]) == 0) /* random */
2007 dither = DITHER;
2009 else if (strcmp(s, CP[229]) == 0) /* hard */
2011 flag.easy = false;
2013 else if (strcmp(s, CP[152]) == 0) /* easy */
2015 flag.easy = !flag.easy;
2017 else if (strcmp(s, CP[230]) == 0) /* tsume */
2019 flag.tsume = !flag.tsume;
2021 else if (strcmp(s, CP[143]) == 0) /* contempt */
2023 SetContempt();
2025 else if (strcmp(s, CP[209]) == 0) /* xwndw */
2027 ChangeXwindow();
2029 else if (strcmp(s, CP[186]) == 0) /* rv */
2031 flag.rv = !flag.rv;
2032 UpdateDisplay(0, 0, 1, 0);
2034 else if (strcmp(s, CP[145]) == 0) /* coords */
2036 flag.coords = !flag.coords;
2037 UpdateDisplay(0, 0, 1, 0);
2039 else if (strcmp(s, CP[193]) == 0) /* stars */
2041 flag.stars = !flag.stars;
2042 UpdateDisplay(0, 0, 1, 0);
2044 else if (!XSHOGI && strcmp(s, CP[5]) == 0) /* moves */
2046 short temp;
2048 #if MAXDEPTH > 3
2049 if (GameCnt > 0)
2051 extern unsigned short PrVar[MAXDEPTH];
2053 SwagHt = (GameList[GameCnt].gmove == PrVar[1])
2054 ? PrVar[2] : 0;
2056 else
2057 #endif
2058 SwagHt = 0;
2060 ShowMessage(CP[108]); /* test movelist */
2061 temp = generate_move_flags;
2062 generate_move_flags = true;
2063 TestSpeed(MoveList, 1);
2064 generate_move_flags = temp;
2065 ShowMessage(CP[107]); /* test capturelist */
2066 TestSpeed(CaptureList, 1);
2067 ShowMessage(CP[85]); /* test score position */
2068 ExaminePosition(opponent);
2069 TestPSpeed(ScorePosition, 1);
2071 else if (!XSHOGI && strcmp(s, CP[196]) == 0) /* test */
2073 #ifdef SLOW_CPU
2074 ShowMessage(CP[108]); /* test movelist */
2075 TestSpeed(MoveList, 2000);
2076 ShowMessage(CP[107]); /* test capturelist */
2077 TestSpeed(CaptureList, 3000);
2078 ShowMessage(CP[85]); /* test score position */
2079 ExaminePosition(opponent);
2080 TestPSpeed(ScorePosition, 1500);
2081 #else
2082 ShowMessage(CP[108]); /* test movelist */
2083 TestSpeed(MoveList, 20000);
2084 ShowMessage(CP[107]); /* test capturelist */
2085 TestSpeed(CaptureList, 30000);
2086 ShowMessage(CP[85]); /* test score position */
2087 ExaminePosition(opponent);
2088 TestPSpeed(ScorePosition, 15000);
2089 #endif
2091 else if (!XSHOGI && strcmp(s, CP[179]) == 0) /* p */
2093 ShowPostnValues();
2095 else if (!XSHOGI && strcmp(s, CP[148]) == 0) /* debug */
2097 DoDebug();
2099 else
2101 if (flag.mate)
2103 ok = true;
2105 else if ((ok = VerifyMove(s, VERIFY_AND_MAKE_MODE, &mv)))
2107 /* check for repetition */
2108 short rpt = repetition();
2110 if (rpt >= 3)
2112 DRAW = CP[101];
2113 ShowMessage(DRAW);
2114 GameList[GameCnt].flags |= draw;
2116 flag.mate = true;
2118 else
2120 is_move = true;
2124 Sdepth = 0;
2128 ElapsedTime(COMPUTE_AND_INIT_MODE);
2130 if (flag.force)
2132 computer = opponent;
2133 opponent = computer ^ 1;
2136 if (XSHOGI)
2138 /* add remaining time in milliseconds for xshogi */
2139 if (is_move)
2141 printf("%d. %s %ld\n",
2142 ++mycnt2, s, TimeControl.clock[player] * 10);
2145 #ifdef notdef /* optional pass best line to frontend with move */
2146 # if !defined NOPOST
2148 if (flag.post && !flag.mate)
2150 int i;
2152 printf(" %6d ", MSCORE);
2154 for (i = 1; MV[i] > 0; i++)
2156 algbr((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
2157 printf("%5s ", mvstr[0]);
2160 # endif
2161 printf("\n");
2162 #endif
2165 signal(SIGUSR1, TerminateSearch);
2171 void
2172 SetTimeControl(void)
2174 if (TCflag)
2176 TimeControl.moves[black] = TimeControl.moves[white] = TCmoves;
2177 TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100;
2178 TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100;
2180 else
2182 TimeControl.moves[black] = TimeControl.moves[white] = 0;
2183 TimeControl.clock[black] = TimeControl.clock[white] = 0;
2186 flag.onemove = (TCmoves == 1);
2187 et = 0;
2188 ElapsedTime(COMPUTE_AND_INIT_MODE);