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);
304 /* Illegal move in check */
310 /* Illegal move in check */
311 sprintf(buffer, CP[77], s);
319 if (iop == VERIFY_AND_TRY_MODE)
322 UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
323 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
324 GameList[GameCnt].nodes = 0;
325 ElapsedTime(COMPUTE_AND_INIT_MODE);
326 GameList[GameCnt].time = (short) (et + 50)/100;
327 GameList[GameCnt].flags |= local_flags;
331 TimeControl.clock[opponent] -= et;
332 timeopp[oppptr] = et;
333 --TimeControl.moves[opponent];
336 *mv = (xnode.f << 8) | xnode.t;
337 algbr(xnode.f, xnode.t, false);
339 /* in force mode, check for mate conditions */
342 if (IsCheckmate(opponent ^ 1, -1, -1))
346 sprintf(buf, "%s mates!\n", ColorStr[opponent]);
364 sprintf(buffer, CP[76], s);
368 if (!barebones && (cnt > 1))
370 sprintf(buffer, CP[32], s);
380 parser(char *f, int side, short *fpiece)
388 for (i = 1, *fpiece = no_piece; i < NO_PIECES; i++)
390 if (f[0] == pxx[i] || f[0] == qxx[i])
392 *fpiece = (p ? promoted[i] : unpromoted[i]);
397 if (f[1] == '*' || f[1] == '\'')
402 return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
410 p = (f[5] == '+') ? 0x80 : 0;
412 return (locn(r1, c1) << 8) | locn(r2, c2) | p;
420 while (*InPtr != ' ')
423 while (*InPtr == ' ')
432 while (*InPtr == ' ')
448 strcpy(fname, savefile);
450 /* Enter file name */
452 RequestInputString(fname, sizeof(fname)-1);
456 if (fname[0] == '\0')
457 strcpy(fname, CP[137]);
459 if ((fd = fopen(fname, "r")) != NULL)
462 fgets(fname, 256, fd);
463 computer = opponent = black;
472 /* FIXME: write a skipn() function so that we can get
473 * 3 skips by doing skipn(3) */
477 Game50 = atoi(InPtr);
479 flag.force = (*InPtr == 'f');
480 fgets(fname, 256, fd); /* empty */
481 fgets(fname, 256, fd);
484 TCflag = atoi(InPtr);
488 OperatorTime = atoi(InPtr);
489 fgets(fname, 256, fd);
492 TimeControl.clock[black] = atol(InPtr);
495 TimeControl.moves[black] = atoi(InPtr);
496 fgets(fname, 256, fd);
499 TimeControl.clock[white] = atol(InPtr);
502 TimeControl.moves[white] = atoi(InPtr);
503 fgets(fname, 256, fd); /* empty */
505 for (i = NO_ROWS - 1; i > -1; i--)
507 fgets(fname, 256, fd);
511 for (j = 0; j < NO_COLS; j++)
513 sq = i * NO_COLS + j;
519 board[sq] = no_piece;
524 for (c = 0; c < NO_PIECES; c++)
529 board[sq] = promoted[c];
531 board[sq] = unpromoted[c];
537 for (c = 0; c < NO_PIECES; c++)
542 board[sq] = promoted[c];
544 board[sq] = unpromoted[c];
552 Mvboard[sq] = atoi(InPtr);
557 fgets(fname, 256, fd); /* empty */
558 fgets(fname, 256, fd); /* 9 8 7 ... */
559 fgets(fname, 256, fd); /* empty */
560 fgets(fname, 256, fd); /* p l n ... */
563 for (side = 0; side <= 1; side++)
565 fgets(fname, 256, fd);
569 Captured[side][pawn] = atoi(InPtr);
571 Captured[side][lance] = atoi(InPtr);
573 Captured[side][knight] = atoi(InPtr);
575 Captured[side][silver] = atoi(InPtr);
577 Captured[side][gold] = atoi(InPtr);
579 Captured[side][bishop] = atoi(InPtr);
581 Captured[side][rook] = atoi(InPtr);
583 Captured[side][king] = atoi(InPtr);
587 flag.regularstart = true;
589 fgets(fname, 256, fd); /* empty */
590 fgets(fname, 256, fd); /* move score ... */
592 while (fgets(fname, 256, fd))
601 g = &GameList[GameCnt];
602 g->gmove = parser(InPtr, side, &g->fpiece);
604 g->score = atoi(InPtr);
606 g->depth = atoi(InPtr);
608 g->nodes = atol(InPtr);
610 g->time = atol(InPtr);
612 g->flags = c = atoi(InPtr);
614 g->hashkey = strtol(InPtr, (char **) NULL, 16);
616 g->hashbd = strtol(InPtr, (char **) NULL, 16);
624 for (piece = no_piece, i = 0; i < NO_PIECES; i++)
626 if (pxx[i] == *InPtr)
634 g->color = ((*InPtr == CP[119][0]) ? white : black);
636 g->piece = (*InPtr == '+'
638 : unpromoted[piece]);
647 if (TimeControl.clock[black] > 0)
655 UpdateDisplay(0, 0, 1, 0);
667 short sq, i, c, f, t;
670 char empty[2] = "\n";
673 strcpy(fname, savefile);
675 /* Enter file name */
677 RequestInputString(fname, sizeof(fname)-1);
680 if (fname[0] == '\0') /* shogi.000 */
681 strcpy(fname, CP[137]);
683 if ((fd = fopen(fname, "w")) != NULL)
688 if (computer == white)
691 if (computer == black)
694 fprintf(fd, CP[37], w, b, Game50,
695 flag.force ? "force" : "");
697 fprintf(fd, CP[111], TCflag, OperatorTime);
699 TimeControl.clock[black], TimeControl.moves[black],
700 TimeControl.clock[white], TimeControl.moves[white]);
703 for (i = NO_ROWS - 1; i > -1; i--)
705 fprintf(fd, "%c ", ROW_NAME(i));
707 for (c = 0; c < NO_COLS; c++)
709 sq = i * NO_COLS + c;
711 p = is_promoted[piece] ? '+' : ' ';
712 fprintf(fd, "%c", p);
728 fprintf(fd, "%c", p);
733 for (f = i * NO_COLS; f < i * NO_COLS + NO_ROWS; f++)
734 fprintf(fd, " %d", Mvboard[f]);
740 fprintf(fd, " 9 8 7 6 5 4 3 2 1\n"); /* FIXME */
742 fprintf(fd, " p l n s g b r k\n");
744 for (side = 0; side <= 1; side++)
746 fprintf(fd, "%c", (side == black) ? 'B' : 'W');
747 fprintf(fd, " %2d", Captured[side][pawn]);
748 fprintf(fd, " %2d", Captured[side][lance]);
749 fprintf(fd, " %2d", Captured[side][knight]);
750 fprintf(fd, " %2d", Captured[side][silver]);
751 fprintf(fd, " %2d", Captured[side][gold]);
752 fprintf(fd, " %2d", Captured[side][bishop]);
753 fprintf(fd, " %2d", Captured[side][rook]);
754 fprintf(fd, " %2d", Captured[side][king]);
761 for (i = 1; i <= GameCnt; i++)
763 struct GameRec *g = &GameList[i];
766 t = (g->gmove & 0xFF);
767 algbr(f, t, g->flags);
769 fprintf(fd, "%c%c%-5s %6d %5d %7ld %6ld %5d 0x%08lx 0x%08lx",
772 : (is_promoted[g->fpiece] ? '+' : ' ')),
774 ((f > NO_SQUARES) ? &mvstr[0][1] : mvstr[0]),
776 g->nodes, g->time, g->flags,
777 g->hashkey, g->hashbd);
779 if (g->piece != no_piece)
781 fprintf(fd, " %c %s %c\n",
782 pxx[g->piece], ColorStr[g->color],
783 (is_promoted[g->piece] ? '+' : ' '));
798 /* ShowMessage("Could not open file"); */
806 * GetXGame, SaveXGame and BookGame used to only be defined if
807 * xshogi wasn't defined -- wonder why?
819 /* Enter file name */
821 RequestInputString(fname, sizeof(fname)-1);
823 if (fname[0] == '\0') /* XSHOGI.position.read */
824 strcpy(fname, CP[205]);
826 if ((fd = fopen(fname, "r")) != NULL)
829 flag.regularstart = false;
832 /* xshogi position file ... */
833 fgets(fname, 256, fd);
838 if (strcmp(fname, CP[206]))
842 /* -- empty line -- */
843 fgets(fname, 256, fd);
844 /* -- empty line -- */
845 fgets(fname, 256, fd);
847 for (i = NO_ROWS - 1; i > -1; i--)
849 fgets(fname, 256, fd);
852 for (j = 0; j < NO_COLS; j++)
854 sq = i * NO_COLS + j;
860 board[sq] = no_piece;
865 for (c = 0; c < NO_PIECES; c++)
870 board[sq] = promoted[c];
872 board[sq] = unpromoted[c];
878 for (c = 0; c < NO_PIECES; c++)
883 board[sq] = promoted[c];
885 board[sq] = unpromoted[c];
898 for (side = 0; side <= 1; side++)
900 fgets(fname, 256, fd);
902 Captured[side][pawn] = atoi(InPtr);
904 Captured[side][lance] = atoi(InPtr);
906 Captured[side][knight] = atoi(InPtr);
908 Captured[side][silver] = atoi(InPtr);
910 Captured[side][gold] = atoi(InPtr);
912 Captured[side][bishop] = atoi(InPtr);
914 Captured[side][rook] = atoi(InPtr);
916 Captured[side][king] = atoi(InPtr);
919 if (fgets(fname, 256, fd) != NULL && strncmp(fname, "white", 5) == 0)
932 UpdateDisplay(0, 0, 1, 0);
947 /* Enter file name */
949 RequestInputString(fname, sizeof(fname)-1);
951 if (fname[0] == '\0') /* XSHOGI.position.read */
952 strcpy(fname, CP[205]);
954 if ((fd = fopen(fname, "w")) != NULL)
956 /* xshogi position file ... */
957 fputs("# xshogi position file -- \n", fd);
958 /* -- empty line -- */
960 /* -- empty line -- */
963 for (i = NO_ROWS - 1; i > -1; i--)
967 for (j = 0; j < NO_COLS; j++)
969 sq = i * NO_COLS + j;
971 isp = is_promoted[piece];
972 *p = (isp ? '+' : ' ');
975 if (piece == no_piece)
977 else if (color[sq] == white)
990 for (side = 0; side <= 1; side++)
992 sprintf(fname, "%d %d %d %d %d %d %d %d\n",
993 Captured[side][pawn],
994 Captured[side][lance],
995 Captured[side][knight],
996 Captured[side][silver],
997 Captured[side][gold],
998 Captured[side][bishop],
999 Captured[side][rook],
1000 Captured[side][king]);
1005 if (computer == black)
1006 fputs("white to play\n", fd);
1008 fputs("black to play\n", fd);
1019 char fname[256], sflags[4];
1023 strcpy(fname, savefile);
1025 /* Enter file name */
1026 ShowMessage(CP[63]);
1027 RequestInputString(fname, sizeof(fname)-1);
1030 if (fname[0] == '\0')
1033 if ((fd = fopen(fname, "a")) != NULL)
1037 for (i = 1; i <= GameCnt; i++)
1039 struct GameRec *g = &GameList[i];
1040 char mvnr[20], mvs[20];
1043 sprintf(mvnr, "%d.", (i + 1)/2);
1048 t = (g->gmove & 0xFF);
1049 algbr(f, t, g->flags);
1052 /* determine move quality string */
1053 if (g->flags & goodmove)
1056 if (g->flags & badmove)
1059 #ifdef EASY_OPENINGS
1060 if (g->flags & difficult)
1066 /* determine move string */
1069 sprintf(mvs, "%s%s ", &mvstr[0][1], sflags);
1073 sprintf(mvs, "%c%c%c%c%c%s%s ",
1074 mvstr[0][0], mvstr[0][1],
1075 (g->flags & capture) ? 'x' : '-',
1076 mvstr[0][2], mvstr[0][3],
1077 (mvstr[0][4] == '+') ? "+" : "",
1081 fprintf(fd, "%s%s%c%s",
1085 : (is_promoted[g->fpiece] ? "+" : "")),
1099 ShowMessage(CP[70]);
1103 /* ShowMessage("Could not open file"); */
1104 ShowMessage(CP[48]);
1116 char fname[256], dbuf[256];
1120 strcpy(fname, listfile);
1125 strncpy(dbuf, ctime(&when), 20);
1132 /* use format "CLp16.Jan01-020304B" when patchlevel is 16,
1135 program played white */
1137 sprintf(fname, "CLp%s.%s%s-%s%s%s%c",
1138 patchlevel, dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14,
1139 dbuf + 17, ColorStr[computer][0]);
1141 /* replace space padding with 0 */
1142 for (i = 0; fname[i] != '\0'; i++)
1144 if (fname[i] == ' ')
1149 fd = fopen(fname, "w");
1153 printf(CP[219], fname);
1157 /* fprintf(fd, "gnushogi game %d\n", u); */
1158 fprintf(fd, CP[161], version, patchlevel);
1162 for (i = 1; i <= GameCnt; i++)
1164 f = GameList[i].gmove >> 8;
1165 t = (GameList[i].gmove & 0xFF);
1166 algbr(f, t, GameList[i].flags);
1168 if (GameList[i].flags & book)
1170 fprintf(fd, "%c%c%-5s %5d Book%7ld %5ld",
1173 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1174 pxx[GameList[i].fpiece],
1176 ? &mvstr[0][1] : mvstr[0]),
1183 fprintf(fd, "%c%c%-5s %5d %2d %7ld %5ld",
1186 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1187 pxx[GameList[i].fpiece],
1188 (f > NO_SQUARES ? &mvstr[0][1] : mvstr[0]),
1189 GameList[i].score, GameList[i].depth,
1190 GameList[i].nodes, GameList[i].time);
1203 fprintf(fd, "\n\n");
1205 if (GameList[GameCnt].flags & draw)
1207 fprintf(fd, CP[54], DRAW);
1209 if (DRAW == CP[101])
1213 fprintf(fd, "repetition by positions ");
1215 for (j = GameCnt - 1; j >= Game50; j -= 2)
1217 if (GameList[j].hashkey == hashkey &&
1218 GameList[j].hashbd == hashbd)
1219 fprintf(fd, "%d ", j);
1225 else if (GameList[GameCnt].score == -(SCORE_LIMIT + 999))
1227 fprintf(fd, "%s\n", ColorStr[player ]);
1229 else if (GameList[GameCnt].score == (SCORE_LIMIT + 998))
1231 fprintf(fd, "%s\n", ColorStr[player ^ 1]);
1245 GameList[GameCnt].flags |= badmove;
1249 GameList[GameCnt].flags |= goodmove;
1252 #ifdef EASY_OPENINGS
1254 GameList[GameCnt].flags |= difficult;
1264 * Undo the most recent half-move.
1272 f = GameList[GameCnt].gmove >> 8;
1273 t = GameList[GameCnt].gmove & 0x7F;
1277 /* the move was a drop */
1278 Captured[color[t]][board[t]]++;
1279 board[t] = no_piece;
1285 if (GameList[GameCnt].flags & promote)
1286 board[f] = unpromoted[board[t]];
1288 board[f] = board[t];
1290 color[f] = color[t];
1291 board[t] = GameList[GameCnt].piece;
1292 color[t] = GameList[GameCnt].color;
1294 if (board[t] != no_piece)
1295 Captured[color[f]][unpromoted[board[t]]]--;
1297 if (color[t] != neutral)
1305 if (TCflag && (TCmoves > 1))
1306 ++TimeControl.moves[color[f]];
1308 hashkey = GameList[GameCnt].hashkey;
1309 hashbd = GameList[GameCnt].hashbd;
1311 computer = computer ^ 1;
1312 opponent = opponent ^ 1;
1315 player = player ^ 1;
1317 UpdateDisplay(0, 0, 1, 0);
1319 if (flag.regularstart)
1326 FlagString(unsigned short flags, char *s)
1331 if (flags & promote)
1332 strcat(s, " promote");
1334 if (flags & dropmask)
1335 strcat(s, " drop:");
1337 if ((piece = (flags & pmask)))
1341 if (is_promoted[piece])
1344 s[l++] = pxx[piece];
1348 if (flags & capture)
1349 strcat(s, " capture");
1352 strcat(s, " exact");
1355 strcat(s, " tesuji");
1358 strcat(s, " check");
1364 strcat(s, " stupid");
1366 if (flags & questionable)
1367 strcat(s, " questionable");
1369 if (flags & kingattack)
1370 strcat(s, " kingattack");
1379 TestSpeed(void(*f)(short side, short ply,
1380 short in_check, short blockable),
1390 #ifdef HAVE_GETTIMEOFDAY
1394 #ifdef HAVE_GETTIMEOFDAY
1395 gettimeofday(&tv, NULL);
1396 t1 = (tv.tv_sec*100 + (tv.tv_usec/10000));
1401 for (i = 0; i < j; i++)
1403 f(opponent, 2, -1, true);
1406 for (jj = TrPnt[2]; i < TrPnt[3]; jj++)
1408 if (!pick(jj, TrPnt[3] - 1))
1414 #ifdef HAVE_GETTIMEOFDAY
1415 gettimeofday(&tv, NULL);
1416 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1421 cnt = j * (TrPnt[3] - TrPnt[2]);
1434 TestPSpeed(short(*f) (short side), unsigned j)
1438 #ifdef HAVE_GETTIMEOFDAY
1442 #ifdef HAVE_GETTIMEOFDAY
1443 gettimeofday(&tv, NULL);
1444 t1 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1449 for (i = 0; i < j; i++)
1452 #ifdef HAVE_GETTIMEOFDAY
1453 gettimeofday(&tv, NULL);
1454 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1478 time = &s[strlen(CP[228])];
1479 t = (int)strtol(time, &time, 10);
1484 sec = (int)strtol(time, &time, 10);
1487 m = (int)strtol(time, &time, 10);
1490 TimeControl.clock[opponent] = t;
1493 TimeControl.moves[opponent] = m;
1495 ElapsedTime(COMPUTE_AND_INIT_MODE);
1499 /* just to inform xshogi about availability of otime command */
1500 printf("otime %d %d\n", t, m);
1507 SetMachineTime(char *s)
1512 time = &s[strlen(CP[197])];
1514 t = (int)strtol(time, &time, 10);
1519 sec = (int)strtol(time, &time, 10);
1522 m = (int)strtol(time, &time, 10);
1525 TimeControl.clock[computer] = t;
1528 TimeControl.moves[computer] = m;
1530 ElapsedTime(COMPUTE_AND_INIT_MODE);
1534 /* just to inform xshogi about availability of time command */
1535 printf("time %d %d\n", t, m);
1543 /* FIXME! This is truly the function from hell! */
1546 * Process the user's command. If easy mode is OFF (the computer is thinking
1547 * on opponents time) and the program is out of book, then make the 'hint'
1548 * move on the board and call SelectMove() to find a response. The user
1549 * terminates the search by entering ^C (quit siqnal) before entering a
1550 * command. If the opponent does not make the hint move, then set Sdepth to
1555 InputCommand(char *command)
1558 short have_shown_prompt = false;
1559 short ok, done, is_move = false;
1563 ok = flag.quit = done = false;
1567 if (TTadd > ttbllimit)
1571 if ((hint > 0) && !flag.easy && !flag.force)
1574 * A hint move for the player is available. Compute a move for the
1575 * opponent in background mode assuming that the hint move will be
1576 * selected by the player.
1579 ft = time0; /* Save reference time for the player. */
1581 algbr((short) hint >> 8, (short) hint & 0xff, false);
1582 strcpy(s, mvstr[0]);
1589 /* do the hint move */
1590 if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv))
1594 #ifdef QUIETBACKGROUND
1605 have_shown_prompt = true;
1606 #endif /* QUIETBACKGROUND */
1608 /* Start computing a move until the search is interrupted. */
1610 #ifdef INTERRUPT_TEST
1614 /* would love to put null move in here */
1615 /* after we make the hint move make a 2 ply search
1616 * with both plys our moves */
1617 /* think on opponents time */
1618 SelectMove(computer, BACKGROUND_MODE);
1620 #ifdef INTERRUPT_TEST
1621 ElapsedTime(COMPUTE_INTERRUPT_MODE);
1625 printf("searching not terminated by interrupt!\n");
1629 printf("elapsed time from interrupt to "
1630 "terminating search: %ld\n", it);
1634 /* undo the hint and carry on */
1635 VerifyMove(s, UNMAKE_MODE, &mv);
1639 time0 = ft; /* Restore reference time for the player. */
1642 while(!(ok || flag.quit || done))
1646 #ifdef QUIETBACKGROUND
1647 if (!have_shown_prompt)
1649 #endif /* QUIETBACKGROUND */
1661 #ifdef QUIETBACKGROUND
1664 have_shown_prompt = false;
1665 #endif /* QUIETBACKGROUND */
1667 if (command == NULL)
1671 s[0] = sx[0] = '\0';
1673 while(!eof && !sx[0])
1674 eof = (fgets(sx, 80, stdin) == NULL);
1679 eof = (getstr(sx) == ERR);
1684 strcpy(sx, command);
1688 sscanf(sx, "%s", s);
1696 if (strcmp(s, CP[131]) == 0) /* bd -- display board */
1698 /* FIXME: Hack alert! */
1699 short old_xshogi = XSHOGI;
1702 display_type = DISPLAY_RAW;
1705 UpdateDisplay(0, 0, 1, 0);
1708 display_type = DISPLAY_X;
1710 else if (strcmp(s, "post") == 0)
1712 flag.post = !flag.post;
1714 else if (strcmp(s, CP[129]) == 0)
1716 /* noop */ ; /* alg */
1718 else if ((strcmp(s, CP[180]) == 0)
1719 || (strcmp(s, CP[216]) == 0)) /* quit exit */
1724 else if (strcmp(s, CP[178]) == 0) /* post */
1726 flag.post = !flag.post;
1729 else if ((strcmp(s, CP[191]) == 0)
1730 || (strcmp(s, CP[154]) == 0)) /* set edit */
1734 else if (NOT_CURSES && (strcmp(s, CP[190]) == 0)) /* setup */
1738 else if (strcmp(s, CP[156]) == 0) /* first */
1742 else if (strcmp(s, CP[162]) == 0) /* go */
1747 if (computer == black)
1758 else if (strcmp(s, CP[166]) == 0) /* help */
1762 else if (strcmp(s, CP[221]) == 0) /* material */
1764 flag.material = !flag.material;
1766 else if (strcmp(s, CP[157]) == 0) /* force */
1771 flag.bothsides = false;
1775 flag.force = !flag.force;
1776 flag.bothsides = false;
1779 else if (strcmp(s, CP[134]) == 0) /* book */
1781 Book = Book ? 0 : BOOKFAIL;
1783 else if (strcmp(s, CP[172]) == 0) /* new */
1786 UpdateDisplay(0, 0, 1, 0);
1788 else if (strcmp(s, CP[171]) == 0) /* list */
1792 else if ((strcmp(s, CP[169]) == 0)
1793 || (strcmp(s, CP[217]) == 0)) /* level clock */
1797 else if (strcmp(s, CP[165]) == 0) /* hash */
1799 flag.hash = !flag.hash;
1801 else if (strcmp(s, CP[227]) == 0) /* gamein */
1803 flag.gamein = !flag.gamein;
1805 else if (strcmp(s, CP[226]) == 0) /* beep */
1807 flag.beep = !flag.beep;
1809 else if (strcmp(s, CP[197]) == 0) /* time */
1813 else if (strcmp(s, CP[228]) == 0) /* otime */
1817 else if (strcmp(s, CP[33]) == 0) /* Awindow */
1819 ChangeAlphaWindow();
1821 else if (strcmp(s, CP[39]) == 0) /* Bwindow */
1825 else if (strcmp(s, CP[183]) == 0) /* rcptr */
1827 flag.rcptr = !flag.rcptr;
1829 else if (strcmp(s, CP[168]) == 0) /* hint */
1833 else if (strcmp(s, CP[135]) == 0) /* both */
1835 flag.bothsides = !flag.bothsides;
1838 ElapsedTime(COMPUTE_AND_INIT_MODE);
1839 SelectMove(opponent, FOREGROUND_MODE);
1842 else if (strcmp(s, CP[185]) == 0) /* reverse */
1844 flag.reverse = !flag.reverse;
1846 UpdateDisplay(0, 0, 1, 0);
1848 else if (strcmp(s, CP[195]) == 0) /* switch */
1850 computer = computer ^ 1;
1851 opponent = opponent ^ 1;
1852 xwndw = (computer == black) ? WXWNDW : BXWNDW;
1857 else if (strcmp(s, CP[203]) == 0) /* black */
1866 * ok = true; don't automatically start with black command
1869 else if (strcmp(s, CP[133]) == 0) /* white */
1878 * ok = true; don't automatically start with white command
1881 else if (strcmp(s, CP[201]) == 0 && GameCnt > 0) /* undo */
1885 else if (strcmp(s, CP[184]) == 0 && GameCnt > 1) /* remove */
1890 /* CHECKME: are these next three correct? */
1891 else if (!XSHOGI && strcmp(s, CP[207]) == 0) /* xget */
1895 else if (!XSHOGI && strcmp(s, "xsave") == 0) /* xsave */
1899 else if (!XSHOGI && strcmp(s, "bsave") == 0) /* bsave */
1903 #ifdef EASY_OPENINGS
1904 else if ((strcmp(s, "?") == 0)
1905 || (strcmp(s, "!") == 0)
1906 || (strcmp(s, "~") == 0))
1908 else if ((strcmp(s, "?") == 0)
1909 || (strcmp(s, "!") == 0))
1914 else if (strcmp(s, CP[160]) == 0) /* get */
1918 else if (strcmp(s, CP[189]) == 0) /* save */
1922 else if (strcmp(s, CP[151]) == 0) /* depth */
1924 ChangeSearchDepth();
1926 else if (strcmp(s, CP[164]) == 0) /* hashdepth */
1930 else if (strcmp(s, CP[182]) == 0) /* random */
1934 else if (strcmp(s, CP[229]) == 0) /* hard */
1938 else if (strcmp(s, CP[152]) == 0) /* easy */
1940 flag.easy = !flag.easy;
1942 else if (strcmp(s, CP[230]) == 0) /* tsume */
1944 flag.tsume = !flag.tsume;
1946 else if (strcmp(s, CP[143]) == 0) /* contempt */
1950 else if (strcmp(s, CP[209]) == 0) /* xwndw */
1954 else if (strcmp(s, CP[186]) == 0) /* rv */
1957 UpdateDisplay(0, 0, 1, 0);
1959 else if (strcmp(s, CP[145]) == 0) /* coords */
1961 flag.coords = !flag.coords;
1962 UpdateDisplay(0, 0, 1, 0);
1964 else if (strcmp(s, CP[193]) == 0) /* stars */
1966 flag.stars = !flag.stars;
1967 UpdateDisplay(0, 0, 1, 0);
1969 else if (!XSHOGI && strcmp(s, CP[5]) == 0) /* moves */
1976 extern unsigned short PrVar[MAXDEPTH];
1978 SwagHt = (GameList[GameCnt].gmove == PrVar[1])
1985 ShowMessage(CP[108]); /* test movelist */
1986 temp = generate_move_flags;
1987 generate_move_flags = true;
1988 TestSpeed(MoveList, 1);
1989 generate_move_flags = temp;
1990 ShowMessage(CP[107]); /* test capturelist */
1991 TestSpeed(CaptureList, 1);
1992 ShowMessage(CP[85]); /* test score position */
1993 ExaminePosition(opponent);
1994 TestPSpeed(ScorePosition, 1);
1996 else if (!XSHOGI && strcmp(s, CP[196]) == 0) /* test */
1999 ShowMessage(CP[108]); /* test movelist */
2000 TestSpeed(MoveList, 2000);
2001 ShowMessage(CP[107]); /* test capturelist */
2002 TestSpeed(CaptureList, 3000);
2003 ShowMessage(CP[85]); /* test score position */
2004 ExaminePosition(opponent);
2005 TestPSpeed(ScorePosition, 1500);
2007 ShowMessage(CP[108]); /* test movelist */
2008 TestSpeed(MoveList, 20000);
2009 ShowMessage(CP[107]); /* test capturelist */
2010 TestSpeed(CaptureList, 30000);
2011 ShowMessage(CP[85]); /* test score position */
2012 ExaminePosition(opponent);
2013 TestPSpeed(ScorePosition, 15000);
2016 else if (!XSHOGI && strcmp(s, CP[179]) == 0) /* p */
2020 else if (!XSHOGI && strcmp(s, CP[148]) == 0) /* debug */
2030 else if ((ok = VerifyMove(s, VERIFY_AND_MAKE_MODE, &mv)))
2032 /* check for repetition */
2033 short rpt = repetition();
2039 GameList[GameCnt].flags |= draw;
2053 ElapsedTime(COMPUTE_AND_INIT_MODE);
2057 computer = opponent;
2058 opponent = computer ^ 1;
2063 /* add remaining time in milliseconds for xshogi */
2066 printf("%d. %s %ld\n",
2067 ++mycnt2, s, TimeControl.clock[player] * 10);
2070 #ifdef notdef /* optional pass best line to frontend with move */
2071 # if !defined NOPOST
2073 if (flag.post && !flag.mate)
2077 printf(" %6d ", MSCORE);
2079 for (i = 1; MV[i] > 0; i++)
2081 algbr((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
2082 printf("%5s ", mvstr[0]);
2095 SetTimeControl(void)
2099 TimeControl.moves[black] = TimeControl.moves[white] = TCmoves;
2100 TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100;
2101 TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100;
2105 TimeControl.moves[black] = TimeControl.moves[white] = 0;
2106 TimeControl.clock[black] = TimeControl.clock[white] = 0;
2109 flag.onemove = (TCmoves == 1);
2111 ElapsedTime(COMPUTE_AND_INIT_MODE);