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
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
41 #include <sys/param.h>
42 #include <sys/types.h>
50 int InBackground = false;
56 movealgbr(short m, char *s)
59 short piece = 0, flag = 0;
72 piece = f - NO_SQUARES;
74 if (piece > NO_PIECES)
77 flag = (dropmask | piece);
124 #endif /* BOOKTEST */
130 * Generate move strings in different formats.
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 ?
145 algbr(short f, short t, short flag)
151 piece = f - NO_SQUARES;
153 if (f > (NO_SQUARES + NO_PIECES))
156 flag = (dropmask | piece);
165 if ((f == t) && ((f != 0) || (t != 0)))
168 Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
171 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
173 else if ((flag & dropmask) != 0)
175 short piece = flag & pmask;
177 mvstr[0][0] = pxx[piece];
179 mvstr[0][2] = cxx[column(t)];
180 mvstr[0][3] = rxx[row(t)];
182 strcpy(mvstr[1], mvstr[0]);
183 strcpy(mvstr[2], mvstr[0]);
184 strcpy(mvstr[3], mvstr[0]);
186 else if ((f != 0) || (t != 0))
188 /* algebraic notation */
189 mvstr[0][0] = cxx[column(f)];
190 mvstr[0][1] = rxx[row(f)];
191 mvstr[0][2] = cxx[column(t)];
192 mvstr[0][3] = rxx[row(t)];
193 mvstr[0][4] = mvstr[3][0] = '\0';
194 mvstr[1][0] = pxx[board[f]];
196 mvstr[2][0] = mvstr[1][0];
197 mvstr[2][1] = mvstr[0][1];
199 mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */
200 mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */
201 mvstr[2][4] = mvstr[1][3] = '\0';
202 strcpy(mvstr[3], mvstr[2]);
203 mvstr[3][1] = mvstr[0][0];
207 strcat(mvstr[0], "+");
208 strcat(mvstr[1], "+");
209 strcat(mvstr[2], "+");
210 strcat(mvstr[3], "+");
215 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
222 * Compare the string 's' to the list of legal moves available for the
223 * opponent. If a match is found, make the move on the board.
227 VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
229 static short pnt, tempb, tempc, tempsf, tempst, cnt;
230 static struct leaf xnode;
232 short i, l, local_flags;
235 /* check and remove quality flags */
236 for (i = local_flags = 0, l = strlen(s); i < l; i++)
241 local_flags |= badmove;
246 local_flags |= goodmove;
252 local_flags |= difficult;
261 if (iop == UNMAKE_MODE)
263 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
269 if (iop == VERIFY_AND_MAKE_MODE)
270 generate_move_flags = true;
272 MoveList(opponent, 2, -1, true);
273 generate_move_flags = false;
276 while (pnt < TrPnt[3])
279 algbr(node->f, node->t, (short) node->flags);
281 if ((strcmp(s, mvstr[0]) == 0)
282 || (strcmp(s, mvstr[1]) == 0)
283 || (strcmp(s, mvstr[2]) == 0)
284 || (strcmp(s, mvstr[3]) == 0))
291 if ((cnt == 1) && (xnode.score > DONTUSE))
295 MakeMove(opponent, &xnode, &tempb, &tempc,
296 &tempsf, &tempst, &INCscore);
298 if (SqAttacked(PieceList[opponent][0], computer, &blocked))
300 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
301 AlwaysShowMessage(CP[77], s);
306 if (iop == VERIFY_AND_TRY_MODE)
309 UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
310 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
311 GameList[GameCnt].nodes = 0;
312 ElapsedTime(COMPUTE_AND_INIT_MODE);
313 GameList[GameCnt].time = (short) (et + 50)/100;
314 GameList[GameCnt].flags |= local_flags;
318 TimeControl.clock[opponent] -= et;
319 timeopp[oppptr] = et;
320 --TimeControl.moves[opponent];
323 *mv = (xnode.f << 8) | xnode.t;
324 algbr(xnode.f, xnode.t, false);
326 /* in force mode, check for mate conditions */
329 if (IsCheckmate(opponent ^ 1, -1, -1))
333 sprintf(buf, "%s mates!\n", ColorStr[opponent]);
343 AlwaysShowMessage(CP[76], s);
345 if (!barebones && (cnt > 1))
347 sprintf(buffer, CP[32], s);
357 parser(char *f, int side, short *fpiece)
365 for (i = 1, *fpiece = no_piece; i < NO_PIECES; i++)
367 if (f[0] == pxx[i] || f[0] == qxx[i])
369 *fpiece = (p ? promoted[i] : unpromoted[i]);
374 if (f[1] == '*' || f[1] == '\'')
379 return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
387 p = (f[5] == '+') ? 0x80 : 0;
389 return (locn(r1, c1) << 8) | locn(r2, c2) | p;
397 while (*InPtr != ' ')
400 while (*InPtr == ' ')
409 while (*InPtr == ' ')
425 strcpy(fname, savefile);
427 /* Enter file name */
429 RequestInputString(fname, sizeof(fname)-1);
433 if (fname[0] == '\0')
434 strcpy(fname, CP[137]);
436 if ((fd = fopen(fname, "r")) != NULL)
439 fgets(fname, 256, fd);
440 computer = opponent = black;
449 /* FIXME: write a skipn() function so that we can get
450 * 3 skips by doing skipn(3) */
454 Game50 = atoi(InPtr);
456 flag.force = (*InPtr == 'f');
457 fgets(fname, 256, fd); /* empty */
458 fgets(fname, 256, fd);
461 TCflag = atoi(InPtr);
465 OperatorTime = atoi(InPtr);
466 fgets(fname, 256, fd);
469 TimeControl.clock[black] = atol(InPtr);
472 TimeControl.moves[black] = atoi(InPtr);
473 fgets(fname, 256, fd);
476 TimeControl.clock[white] = atol(InPtr);
479 TimeControl.moves[white] = atoi(InPtr);
480 fgets(fname, 256, fd); /* empty */
482 for (i = NO_ROWS - 1; i > -1; i--)
484 fgets(fname, 256, fd);
488 for (j = 0; j < NO_COLS; j++)
490 sq = i * NO_COLS + j;
496 board[sq] = no_piece;
501 for (c = 0; c < NO_PIECES; c++)
506 board[sq] = promoted[c];
508 board[sq] = unpromoted[c];
514 for (c = 0; c < NO_PIECES; c++)
519 board[sq] = promoted[c];
521 board[sq] = unpromoted[c];
529 Mvboard[sq] = atoi(InPtr);
534 fgets(fname, 256, fd); /* empty */
535 fgets(fname, 256, fd); /* 9 8 7 ... */
536 fgets(fname, 256, fd); /* empty */
537 fgets(fname, 256, fd); /* p l n ... */
540 for (side = 0; side <= 1; side++)
542 fgets(fname, 256, fd);
546 Captured[side][pawn] = atoi(InPtr);
548 Captured[side][lance] = atoi(InPtr);
550 Captured[side][knight] = atoi(InPtr);
552 Captured[side][silver] = atoi(InPtr);
554 Captured[side][gold] = atoi(InPtr);
556 Captured[side][bishop] = atoi(InPtr);
558 Captured[side][rook] = atoi(InPtr);
560 Captured[side][king] = atoi(InPtr);
564 flag.regularstart = true;
566 fgets(fname, 256, fd); /* empty */
567 fgets(fname, 256, fd); /* move score ... */
569 while (fgets(fname, 256, fd))
578 g = &GameList[GameCnt];
579 g->gmove = parser(InPtr, side, &g->fpiece);
581 g->score = atoi(InPtr);
583 g->depth = atoi(InPtr);
585 g->nodes = atol(InPtr);
587 g->time = atol(InPtr);
589 g->flags = c = atoi(InPtr);
591 g->hashkey = strtol(InPtr, (char **) NULL, 16);
593 g->hashbd = strtol(InPtr, (char **) NULL, 16);
601 for (piece = no_piece, i = 0; i < NO_PIECES; i++)
603 if (pxx[i] == *InPtr)
611 g->color = ((*InPtr == CP[119][0]) ? white : black);
613 g->piece = (*InPtr == '+'
615 : unpromoted[piece]);
624 if (TimeControl.clock[black] > 0)
632 UpdateDisplay(0, 0, 1, 0);
644 short sq, i, c, f, t;
647 char empty[2] = "\n";
650 strcpy(fname, savefile);
652 /* Enter file name */
654 RequestInputString(fname, sizeof(fname)-1);
657 if (fname[0] == '\0') /* shogi.000 */
658 strcpy(fname, CP[137]);
660 if ((fd = fopen(fname, "w")) != NULL)
665 if (computer == white)
668 if (computer == black)
671 fprintf(fd, CP[37], w, b, Game50,
672 flag.force ? "force" : "");
674 fprintf(fd, CP[111], TCflag, OperatorTime);
676 TimeControl.clock[black], TimeControl.moves[black],
677 TimeControl.clock[white], TimeControl.moves[white]);
680 for (i = NO_ROWS - 1; i > -1; i--)
682 fprintf(fd, "%c ", ROW_NAME(i));
684 for (c = 0; c < NO_COLS; c++)
686 sq = i * NO_COLS + c;
688 p = is_promoted[piece] ? '+' : ' ';
689 fprintf(fd, "%c", p);
705 fprintf(fd, "%c", p);
710 for (f = i * NO_COLS; f < i * NO_COLS + NO_ROWS; f++)
711 fprintf(fd, " %d", Mvboard[f]);
717 fprintf(fd, " 9 8 7 6 5 4 3 2 1\n"); /* FIXME */
719 fprintf(fd, " p l n s g b r k\n");
721 for (side = 0; side <= 1; side++)
723 fprintf(fd, "%c", (side == black) ? 'B' : 'W');
724 fprintf(fd, " %2d", Captured[side][pawn]);
725 fprintf(fd, " %2d", Captured[side][lance]);
726 fprintf(fd, " %2d", Captured[side][knight]);
727 fprintf(fd, " %2d", Captured[side][silver]);
728 fprintf(fd, " %2d", Captured[side][gold]);
729 fprintf(fd, " %2d", Captured[side][bishop]);
730 fprintf(fd, " %2d", Captured[side][rook]);
731 fprintf(fd, " %2d", Captured[side][king]);
738 for (i = 1; i <= GameCnt; i++)
740 struct GameRec *g = &GameList[i];
743 t = (g->gmove & 0xFF);
744 algbr(f, t, g->flags);
746 fprintf(fd, "%c%c%-5s %6d %5d %7ld %6ld %5d 0x%08lx 0x%08lx",
749 : (is_promoted[g->fpiece] ? '+' : ' ')),
751 ((f > NO_SQUARES) ? &mvstr[0][1] : mvstr[0]),
753 g->nodes, g->time, g->flags,
754 g->hashkey, g->hashbd);
756 if (g->piece != no_piece)
758 fprintf(fd, " %c %s %c\n",
759 pxx[g->piece], ColorStr[g->color],
760 (is_promoted[g->piece] ? '+' : ' '));
775 /* ShowMessage("Could not open file"); */
783 * GetXGame, SaveXGame and BookGame used to only be defined if
784 * xshogi wasn't defined -- wonder why?
796 /* Enter file name */
798 RequestInputString(fname, sizeof(fname)-1);
800 if (fname[0] == '\0') /* XSHOGI.position.read */
801 strcpy(fname, CP[205]);
803 if ((fd = fopen(fname, "r")) != NULL)
806 flag.regularstart = false;
809 /* xshogi position file ... */
810 fgets(fname, 256, fd);
815 if (strcmp(fname, CP[206]))
819 /* -- empty line -- */
820 fgets(fname, 256, fd);
821 /* -- empty line -- */
822 fgets(fname, 256, fd);
824 for (i = NO_ROWS - 1; i > -1; i--)
826 fgets(fname, 256, fd);
829 for (j = 0; j < NO_COLS; j++)
831 sq = i * NO_COLS + j;
837 board[sq] = no_piece;
842 for (c = 0; c < NO_PIECES; c++)
847 board[sq] = promoted[c];
849 board[sq] = unpromoted[c];
855 for (c = 0; c < NO_PIECES; c++)
860 board[sq] = promoted[c];
862 board[sq] = unpromoted[c];
875 for (side = 0; side <= 1; side++)
877 fgets(fname, 256, fd);
879 Captured[side][pawn] = atoi(InPtr);
881 Captured[side][lance] = atoi(InPtr);
883 Captured[side][knight] = atoi(InPtr);
885 Captured[side][silver] = atoi(InPtr);
887 Captured[side][gold] = atoi(InPtr);
889 Captured[side][bishop] = atoi(InPtr);
891 Captured[side][rook] = atoi(InPtr);
893 Captured[side][king] = atoi(InPtr);
896 if (fgets(fname, 256, fd) != NULL && strncmp(fname, "white", 5) == 0)
909 UpdateDisplay(0, 0, 1, 0);
924 /* Enter file name */
926 RequestInputString(fname, sizeof(fname)-1);
928 if (fname[0] == '\0') /* XSHOGI.position.read */
929 strcpy(fname, CP[205]);
931 if ((fd = fopen(fname, "w")) != NULL)
933 /* xshogi position file ... */
934 fputs("# xshogi position file -- \n", fd);
935 /* -- empty line -- */
937 /* -- empty line -- */
940 for (i = NO_ROWS - 1; i > -1; i--)
944 for (j = 0; j < NO_COLS; j++)
946 sq = i * NO_COLS + j;
948 isp = is_promoted[piece];
949 *p = (isp ? '+' : ' ');
952 if (piece == no_piece)
954 else if (color[sq] == white)
967 for (side = 0; side <= 1; side++)
969 sprintf(fname, "%d %d %d %d %d %d %d %d\n",
970 Captured[side][pawn],
971 Captured[side][lance],
972 Captured[side][knight],
973 Captured[side][silver],
974 Captured[side][gold],
975 Captured[side][bishop],
976 Captured[side][rook],
977 Captured[side][king]);
982 if (computer == black)
983 fputs("white to play\n", fd);
985 fputs("black to play\n", fd);
996 char fname[256], sflags[4];
1000 strcpy(fname, savefile);
1002 /* Enter file name */
1003 ShowMessage(CP[63]);
1004 RequestInputString(fname, sizeof(fname)-1);
1007 if (fname[0] == '\0')
1010 if ((fd = fopen(fname, "a")) != NULL)
1014 for (i = 1; i <= GameCnt; i++)
1016 struct GameRec *g = &GameList[i];
1017 char mvnr[20], mvs[20];
1020 sprintf(mvnr, "%d.", (i + 1)/2);
1025 t = (g->gmove & 0xFF);
1026 algbr(f, t, g->flags);
1029 /* determine move quality string */
1030 if (g->flags & goodmove)
1033 if (g->flags & badmove)
1036 #ifdef EASY_OPENINGS
1037 if (g->flags & difficult)
1043 /* determine move string */
1046 sprintf(mvs, "%s%s ", &mvstr[0][1], sflags);
1050 sprintf(mvs, "%c%c%c%c%c%s%s ",
1051 mvstr[0][0], mvstr[0][1],
1052 (g->flags & capture) ? 'x' : '-',
1053 mvstr[0][2], mvstr[0][3],
1054 (mvstr[0][4] == '+') ? "+" : "",
1058 fprintf(fd, "%s%s%c%s",
1062 : (is_promoted[g->fpiece] ? "+" : "")),
1076 ShowMessage(CP[70]);
1080 /* ShowMessage("Could not open file"); */
1081 ShowMessage(CP[48]);
1093 char fname[256], dbuf[256];
1097 strcpy(fname, listfile);
1102 strncpy(dbuf, ctime(&when), 20);
1109 /* use format "CLp16.Jan01-020304B" when patchlevel is 16,
1112 program played white */
1114 sprintf(fname, "CLp%s.%s%s-%s%s%s%c",
1115 patchlevel, dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14,
1116 dbuf + 17, ColorStr[computer][0]);
1118 /* replace space padding with 0 */
1119 for (i = 0; fname[i] != '\0'; i++)
1121 if (fname[i] == ' ')
1126 fd = fopen(fname, "w");
1130 printf(CP[219], fname);
1134 /* fprintf(fd, "gnushogi game %d\n", u); */
1135 fprintf(fd, CP[161], version, patchlevel);
1139 for (i = 1; i <= GameCnt; i++)
1141 f = GameList[i].gmove >> 8;
1142 t = (GameList[i].gmove & 0xFF);
1143 algbr(f, t, GameList[i].flags);
1145 if (GameList[i].flags & book)
1147 fprintf(fd, "%c%c%-5s %5d Book%7ld %5ld",
1150 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1151 pxx[GameList[i].fpiece],
1153 ? &mvstr[0][1] : mvstr[0]),
1160 fprintf(fd, "%c%c%-5s %5d %2d %7ld %5ld",
1163 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1164 pxx[GameList[i].fpiece],
1165 (f > NO_SQUARES ? &mvstr[0][1] : mvstr[0]),
1166 GameList[i].score, GameList[i].depth,
1167 GameList[i].nodes, GameList[i].time);
1180 fprintf(fd, "\n\n");
1182 if (GameList[GameCnt].flags & draw)
1184 fprintf(fd, CP[54], DRAW);
1186 if (DRAW == CP[101])
1190 fprintf(fd, "repetition by positions ");
1192 for (j = GameCnt - 1; j >= Game50; j -= 2)
1194 if (GameList[j].hashkey == hashkey &&
1195 GameList[j].hashbd == hashbd)
1196 fprintf(fd, "%d ", j);
1202 else if (GameList[GameCnt].score == -(SCORE_LIMIT + 999))
1204 fprintf(fd, "%s\n", ColorStr[player ]);
1206 else if (GameList[GameCnt].score == (SCORE_LIMIT + 998))
1208 fprintf(fd, "%s\n", ColorStr[player ^ 1]);
1222 GameList[GameCnt].flags |= badmove;
1226 GameList[GameCnt].flags |= goodmove;
1229 #ifdef EASY_OPENINGS
1231 GameList[GameCnt].flags |= difficult;
1241 * Undo the most recent half-move.
1249 f = GameList[GameCnt].gmove >> 8;
1250 t = GameList[GameCnt].gmove & 0x7F;
1254 /* the move was a drop */
1255 Captured[color[t]][board[t]]++;
1256 board[t] = no_piece;
1262 if (GameList[GameCnt].flags & promote)
1263 board[f] = unpromoted[board[t]];
1265 board[f] = board[t];
1267 color[f] = color[t];
1268 board[t] = GameList[GameCnt].piece;
1269 color[t] = GameList[GameCnt].color;
1271 if (board[t] != no_piece)
1272 Captured[color[f]][unpromoted[board[t]]]--;
1274 if (color[t] != neutral)
1282 if (TCflag && (TCmoves > 1))
1283 ++TimeControl.moves[color[f]];
1285 hashkey = GameList[GameCnt].hashkey;
1286 hashbd = GameList[GameCnt].hashbd;
1288 computer = computer ^ 1;
1289 opponent = opponent ^ 1;
1292 player = player ^ 1;
1294 UpdateDisplay(0, 0, 1, 0);
1296 if (flag.regularstart)
1303 FlagString(unsigned short flags, char *s)
1308 if (flags & promote)
1309 strcat(s, " promote");
1311 if (flags & dropmask)
1312 strcat(s, " drop:");
1314 if ((piece = (flags & pmask)))
1318 if (is_promoted[piece])
1321 s[l++] = pxx[piece];
1325 if (flags & capture)
1326 strcat(s, " capture");
1329 strcat(s, " exact");
1332 strcat(s, " tesuji");
1335 strcat(s, " check");
1341 strcat(s, " stupid");
1343 if (flags & questionable)
1344 strcat(s, " questionable");
1346 if (flags & kingattack)
1347 strcat(s, " kingattack");
1356 TestSpeed(void(*f)(short side, short ply,
1357 short in_check, short blockable),
1367 #ifdef HAVE_GETTIMEOFDAY
1371 #ifdef HAVE_GETTIMEOFDAY
1372 gettimeofday(&tv, NULL);
1373 t1 = (tv.tv_sec*100 + (tv.tv_usec/10000));
1378 for (i = 0; i < j; i++)
1380 f(opponent, 2, -1, true);
1383 for (jj = TrPnt[2]; i < TrPnt[3]; jj++)
1385 if (!pick(jj, TrPnt[3] - 1))
1391 #ifdef HAVE_GETTIMEOFDAY
1392 gettimeofday(&tv, NULL);
1393 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1398 cnt = j * (TrPnt[3] - TrPnt[2]);
1411 TestPSpeed(short(*f) (short side), unsigned j)
1415 #ifdef HAVE_GETTIMEOFDAY
1419 #ifdef HAVE_GETTIMEOFDAY
1420 gettimeofday(&tv, NULL);
1421 t1 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1426 for (i = 0; i < j; i++)
1429 #ifdef HAVE_GETTIMEOFDAY
1430 gettimeofday(&tv, NULL);
1431 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1455 time = &s[strlen(CP[228])];
1456 t = (int)strtol(time, &time, 10);
1461 sec = (int)strtol(time, &time, 10);
1464 m = (int)strtol(time, &time, 10);
1467 TimeControl.clock[opponent] = t;
1470 TimeControl.moves[opponent] = m;
1472 ElapsedTime(COMPUTE_AND_INIT_MODE);
1476 /* just to inform xshogi about availability of otime command */
1477 printf("otime %d %d\n", t, m);
1484 SetMachineTime(char *s)
1489 time = &s[strlen(CP[197])];
1491 t = (int)strtol(time, &time, 10);
1496 sec = (int)strtol(time, &time, 10);
1499 m = (int)strtol(time, &time, 10);
1502 TimeControl.clock[computer] = t;
1505 TimeControl.moves[computer] = m;
1507 ElapsedTime(COMPUTE_AND_INIT_MODE);
1511 /* just to inform xshogi about availability of time command */
1512 printf("time %d %d\n", t, m);
1520 /* FIXME! This is truly the function from hell! */
1523 * Process the user's command. If easy mode is OFF (the computer is thinking
1524 * on opponents time) and the program is out of book, then make the 'hint'
1525 * move on the board and call SelectMove() to find a response. The user
1526 * terminates the search by entering ^C (quit siqnal) before entering a
1527 * command. If the opponent does not make the hint move, then set Sdepth to
1532 InputCommand(char *command)
1535 short have_shown_prompt = false;
1536 short ok, done, is_move = false;
1540 ok = flag.quit = done = false;
1544 if (TTadd > ttbllimit)
1548 if ((hint > 0) && !flag.easy && !flag.force)
1551 * A hint move for the player is available. Compute a move for the
1552 * opponent in background mode assuming that the hint move will be
1553 * selected by the player.
1556 ft = time0; /* Save reference time for the player. */
1558 algbr((short) hint >> 8, (short) hint & 0xff, false);
1559 strcpy(s, mvstr[0]);
1566 /* do the hint move */
1567 if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv))
1571 #ifdef QUIETBACKGROUND
1582 have_shown_prompt = true;
1583 #endif /* QUIETBACKGROUND */
1585 /* Start computing a move until the search is interrupted. */
1587 #ifdef INTERRUPT_TEST
1591 /* would love to put null move in here */
1592 /* after we make the hint move make a 2 ply search
1593 * with both plys our moves */
1594 /* think on opponents time */
1595 SelectMove(computer, BACKGROUND_MODE);
1597 #ifdef INTERRUPT_TEST
1598 ElapsedTime(COMPUTE_INTERRUPT_MODE);
1602 printf("searching not terminated by interrupt!\n");
1606 printf("elapsed time from interrupt to "
1607 "terminating search: %ld\n", it);
1611 /* undo the hint and carry on */
1612 VerifyMove(s, UNMAKE_MODE, &mv);
1616 time0 = ft; /* Restore reference time for the player. */
1619 while(!(ok || flag.quit || done))
1623 #ifdef QUIETBACKGROUND
1624 if (!have_shown_prompt)
1626 #endif /* QUIETBACKGROUND */
1638 #ifdef QUIETBACKGROUND
1641 have_shown_prompt = false;
1642 #endif /* QUIETBACKGROUND */
1644 if (command == NULL)
1648 s[0] = sx[0] = '\0';
1650 while(!eof && !sx[0])
1651 eof = (fgets(sx, 80, stdin) == NULL);
1656 eof = (getstr(sx) == ERR);
1661 strcpy(sx, command);
1665 sscanf(sx, "%s", s);
1673 if (strcmp(s, CP[131]) == 0) /* bd -- display board */
1675 /* FIXME: Hack alert! */
1676 short old_xshogi = XSHOGI;
1679 display_type = DISPLAY_RAW;
1682 UpdateDisplay(0, 0, 1, 0);
1685 display_type = DISPLAY_X;
1687 else if (strcmp(s, "post") == 0)
1689 flag.post = !flag.post;
1691 else if (strcmp(s, CP[129]) == 0)
1693 /* noop */ ; /* alg */
1695 else if ((strcmp(s, CP[180]) == 0)
1696 || (strcmp(s, CP[216]) == 0)) /* quit exit */
1701 else if (strcmp(s, CP[178]) == 0) /* post */
1703 flag.post = !flag.post;
1706 else if ((strcmp(s, CP[191]) == 0)
1707 || (strcmp(s, CP[154]) == 0)) /* set edit */
1711 else if (NOT_CURSES && (strcmp(s, CP[190]) == 0)) /* setup */
1715 else if (strcmp(s, CP[156]) == 0) /* first */
1719 else if (strcmp(s, CP[162]) == 0) /* go */
1724 if (computer == black)
1735 else if (strcmp(s, CP[166]) == 0) /* help */
1739 else if (strcmp(s, CP[221]) == 0) /* material */
1741 flag.material = !flag.material;
1743 else if (strcmp(s, CP[157]) == 0) /* force */
1748 flag.bothsides = false;
1752 flag.force = !flag.force;
1753 flag.bothsides = false;
1756 else if (strcmp(s, CP[134]) == 0) /* book */
1758 Book = Book ? 0 : BOOKFAIL;
1760 else if (strcmp(s, CP[172]) == 0) /* new */
1763 UpdateDisplay(0, 0, 1, 0);
1765 else if (strcmp(s, CP[171]) == 0) /* list */
1769 else if ((strcmp(s, CP[169]) == 0)
1770 || (strcmp(s, CP[217]) == 0)) /* level clock */
1774 else if (strcmp(s, CP[165]) == 0) /* hash */
1776 flag.hash = !flag.hash;
1778 else if (strcmp(s, CP[227]) == 0) /* gamein */
1780 flag.gamein = !flag.gamein;
1782 else if (strcmp(s, CP[226]) == 0) /* beep */
1784 flag.beep = !flag.beep;
1786 else if (strcmp(s, CP[197]) == 0) /* time */
1790 else if (strcmp(s, CP[228]) == 0) /* otime */
1794 else if (strcmp(s, CP[33]) == 0) /* Awindow */
1796 ChangeAlphaWindow();
1798 else if (strcmp(s, CP[39]) == 0) /* Bwindow */
1802 else if (strcmp(s, CP[183]) == 0) /* rcptr */
1804 flag.rcptr = !flag.rcptr;
1806 else if (strcmp(s, CP[168]) == 0) /* hint */
1810 else if (strcmp(s, CP[135]) == 0) /* both */
1812 flag.bothsides = !flag.bothsides;
1815 ElapsedTime(COMPUTE_AND_INIT_MODE);
1816 SelectMove(opponent, FOREGROUND_MODE);
1819 else if (strcmp(s, CP[185]) == 0) /* reverse */
1821 flag.reverse = !flag.reverse;
1823 UpdateDisplay(0, 0, 1, 0);
1825 else if (strcmp(s, CP[195]) == 0) /* switch */
1827 computer = computer ^ 1;
1828 opponent = opponent ^ 1;
1829 xwndw = (computer == black) ? WXWNDW : BXWNDW;
1834 else if (strcmp(s, CP[203]) == 0) /* black */
1843 * ok = true; don't automatically start with black command
1846 else if (strcmp(s, CP[133]) == 0) /* white */
1855 * ok = true; don't automatically start with white command
1858 else if (strcmp(s, CP[201]) == 0 && GameCnt > 0) /* undo */
1862 else if (strcmp(s, CP[184]) == 0 && GameCnt > 1) /* remove */
1867 /* CHECKME: are these next three correct? */
1868 else if (!XSHOGI && strcmp(s, CP[207]) == 0) /* xget */
1872 else if (!XSHOGI && strcmp(s, "xsave") == 0) /* xsave */
1876 else if (!XSHOGI && strcmp(s, "bsave") == 0) /* bsave */
1880 #ifdef EASY_OPENINGS
1881 else if ((strcmp(s, "?") == 0)
1882 || (strcmp(s, "!") == 0)
1883 || (strcmp(s, "~") == 0))
1885 else if ((strcmp(s, "?") == 0)
1886 || (strcmp(s, "!") == 0))
1891 else if (strcmp(s, CP[160]) == 0) /* get */
1895 else if (strcmp(s, CP[189]) == 0) /* save */
1899 else if (strcmp(s, CP[151]) == 0) /* depth */
1901 ChangeSearchDepth();
1903 else if (strcmp(s, CP[164]) == 0) /* hashdepth */
1907 else if (strcmp(s, CP[182]) == 0) /* random */
1911 else if (strcmp(s, CP[229]) == 0) /* hard */
1915 else if (strcmp(s, CP[152]) == 0) /* easy */
1917 flag.easy = !flag.easy;
1919 else if (strcmp(s, CP[230]) == 0) /* tsume */
1921 flag.tsume = !flag.tsume;
1923 else if (strcmp(s, CP[143]) == 0) /* contempt */
1927 else if (strcmp(s, CP[209]) == 0) /* xwndw */
1931 else if (strcmp(s, CP[186]) == 0) /* rv */
1934 UpdateDisplay(0, 0, 1, 0);
1936 else if (strcmp(s, CP[145]) == 0) /* coords */
1938 flag.coords = !flag.coords;
1939 UpdateDisplay(0, 0, 1, 0);
1941 else if (strcmp(s, CP[193]) == 0) /* stars */
1943 flag.stars = !flag.stars;
1944 UpdateDisplay(0, 0, 1, 0);
1946 else if (!XSHOGI && strcmp(s, CP[5]) == 0) /* moves */
1953 extern unsigned short PrVar[MAXDEPTH];
1955 SwagHt = (GameList[GameCnt].gmove == PrVar[1])
1962 ShowMessage(CP[108]); /* test movelist */
1963 temp = generate_move_flags;
1964 generate_move_flags = true;
1965 TestSpeed(MoveList, 1);
1966 generate_move_flags = temp;
1967 ShowMessage(CP[107]); /* test capturelist */
1968 TestSpeed(CaptureList, 1);
1969 ShowMessage(CP[85]); /* test score position */
1970 ExaminePosition(opponent);
1971 TestPSpeed(ScorePosition, 1);
1973 else if (!XSHOGI && strcmp(s, CP[196]) == 0) /* test */
1976 ShowMessage(CP[108]); /* test movelist */
1977 TestSpeed(MoveList, 2000);
1978 ShowMessage(CP[107]); /* test capturelist */
1979 TestSpeed(CaptureList, 3000);
1980 ShowMessage(CP[85]); /* test score position */
1981 ExaminePosition(opponent);
1982 TestPSpeed(ScorePosition, 1500);
1984 ShowMessage(CP[108]); /* test movelist */
1985 TestSpeed(MoveList, 20000);
1986 ShowMessage(CP[107]); /* test capturelist */
1987 TestSpeed(CaptureList, 30000);
1988 ShowMessage(CP[85]); /* test score position */
1989 ExaminePosition(opponent);
1990 TestPSpeed(ScorePosition, 15000);
1993 else if (!XSHOGI && strcmp(s, CP[179]) == 0) /* p */
1997 else if (!XSHOGI && strcmp(s, CP[148]) == 0) /* debug */
2007 else if ((ok = VerifyMove(s, VERIFY_AND_MAKE_MODE, &mv)))
2009 /* check for repetition */
2010 short rpt = repetition();
2016 GameList[GameCnt].flags |= draw;
2030 ElapsedTime(COMPUTE_AND_INIT_MODE);
2034 computer = opponent;
2035 opponent = computer ^ 1;
2040 /* add remaining time in milliseconds for xshogi */
2043 printf("%d. %s %ld\n",
2044 ++mycnt2, s, TimeControl.clock[player] * 10);
2047 #ifdef notdef /* optional pass best line to frontend with move */
2048 # if !defined NOPOST
2050 if (flag.post && !flag.mate)
2054 printf(" %6d ", MSCORE);
2056 for (i = 1; MV[i] > 0; i++)
2058 algbr((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
2059 printf("%5s ", mvstr[0]);
2072 SetTimeControl(void)
2076 TimeControl.moves[black] = TimeControl.moves[white] = TCmoves;
2077 TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100;
2078 TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100;
2082 TimeControl.moves[black] = TimeControl.moves[white] = 0;
2083 TimeControl.clock[black] = TimeControl.clock[white] = 0;
2086 flag.onemove = (TCmoves == 1);
2088 ElapsedTime(COMPUTE_AND_INIT_MODE);