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>
49 int InBackground = false;
55 movealgbr(short m, char *s)
58 short piece = 0, flag = 0;
71 piece = f - NO_SQUARES;
73 if (piece > NO_PIECES)
76 flag = (dropmask | piece);
123 #endif /* BOOKTEST */
129 * Generate move strings in different formats.
132 * - f piece to be moved
133 * - 0 < f < NO_SQUARES source square
134 * - NO_SQUARES <= f NO_SQUARES + 2*NO_PIECES dropped piece modulo NO_PIECES
135 * - t & 0x7f target square
136 * - t & 0x80 promotion flag
137 * - flag FIXME: must be zero ?
144 algbr(short f, short t, short flag)
150 piece = f - NO_SQUARES;
152 if (f > (NO_SQUARES + NO_PIECES))
155 flag = (dropmask | piece);
164 if ((f == t) && ((f != 0) || (t != 0)))
167 Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
170 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
172 else if ((flag & dropmask) != 0)
174 short piece = flag & pmask;
176 mvstr[0][0] = pxx[piece];
178 mvstr[0][2] = cxx[column(t)];
179 mvstr[0][3] = rxx[row(t)];
181 strcpy(mvstr[1], mvstr[0]);
182 strcpy(mvstr[2], mvstr[0]);
183 strcpy(mvstr[3], mvstr[0]);
185 else if ((f != 0) || (t != 0))
187 /* algebraic notation */
188 mvstr[0][0] = cxx[column(f)];
189 mvstr[0][1] = rxx[row(f)];
190 mvstr[0][2] = cxx[column(t)];
191 mvstr[0][3] = rxx[row(t)];
192 mvstr[0][4] = mvstr[3][0] = '\0';
193 mvstr[1][0] = pxx[board[f]];
195 mvstr[2][0] = mvstr[1][0];
196 mvstr[2][1] = mvstr[0][1];
198 mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */
199 mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */
200 mvstr[2][4] = mvstr[1][3] = '\0';
201 strcpy(mvstr[3], mvstr[2]);
202 mvstr[3][1] = mvstr[0][0];
206 strcat(mvstr[0], "+");
207 strcat(mvstr[1], "+");
208 strcat(mvstr[2], "+");
209 strcat(mvstr[3], "+");
214 mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
221 * Compare the string 's' to the list of legal moves available for the
222 * opponent. If a match is found, make the move on the board.
226 VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
228 static short pnt, tempb, tempc, tempsf, tempst, cnt;
229 static struct leaf xnode;
231 short i, l, local_flags;
234 /* check and remove quality flags */
235 for (i = local_flags = 0, l = strlen(s); i < l; i++)
240 local_flags |= badmove;
245 local_flags |= goodmove;
251 local_flags |= difficult;
260 if (iop == UNMAKE_MODE)
262 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
268 if (iop == VERIFY_AND_MAKE_MODE)
269 generate_move_flags = true;
271 MoveList(opponent, 2, -1, true);
272 generate_move_flags = false;
275 while (pnt < TrPnt[3])
278 algbr(node->f, node->t, (short) node->flags);
280 if ((strcmp(s, mvstr[0]) == 0)
281 || (strcmp(s, mvstr[1]) == 0)
282 || (strcmp(s, mvstr[2]) == 0)
283 || (strcmp(s, mvstr[3]) == 0))
290 if ((cnt == 1) && (xnode.score > DONTUSE))
294 MakeMove(opponent, &xnode, &tempb, &tempc,
295 &tempsf, &tempst, &INCscore);
297 if (SqAttacked(PieceList[opponent][0], computer, &blocked))
299 UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
300 AlwaysShowMessage(CP[77], s);
305 if (iop == VERIFY_AND_TRY_MODE)
308 UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
309 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
310 GameList[GameCnt].nodes = 0;
311 ElapsedTime(COMPUTE_AND_INIT_MODE);
312 GameList[GameCnt].time = (short) (et + 50)/100;
313 GameList[GameCnt].flags |= local_flags;
317 TimeControl.clock[opponent] -= et;
318 timeopp[oppptr] = et;
319 --TimeControl.moves[opponent];
322 *mv = (xnode.f << 8) | xnode.t;
323 algbr(xnode.f, xnode.t, false);
325 /* in force mode, check for mate conditions */
328 if (IsCheckmate(opponent ^ 1, -1, -1))
332 sprintf(buf, "%s mates!\n", ColorStr[opponent]);
342 AlwaysShowMessage(CP[76], s);
344 if (!barebones && (cnt > 1))
346 sprintf(buffer, CP[32], s);
356 parser(char *f, int side, short *fpiece)
364 for (i = 1, *fpiece = no_piece; i < NO_PIECES; i++)
366 if (f[0] == pxx[i] || f[0] == qxx[i])
368 *fpiece = (p ? promoted[i] : unpromoted[i]);
373 if (f[1] == '*' || f[1] == '\'')
378 return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
386 p = (f[5] == '+') ? 0x80 : 0;
388 return (locn(r1, c1) << 8) | locn(r2, c2) | p;
396 while (*InPtr != ' ')
399 while (*InPtr == ' ')
408 while (*InPtr == ' ')
424 strcpy(fname, savefile);
426 /* Enter file name */
428 RequestInputString(fname, sizeof(fname)-1);
432 if (fname[0] == '\0')
433 strcpy(fname, CP[137]);
435 if ((fd = fopen(fname, "r")) != NULL)
438 fgets(fname, 256, fd);
439 computer = opponent = black;
448 /* FIXME: write a skipn() function so that we can get
449 * 3 skips by doing skipn(3) */
453 Game50 = atoi(InPtr);
455 flag.force = (*InPtr == 'f');
456 fgets(fname, 256, fd); /* empty */
457 fgets(fname, 256, fd);
460 TCflag = atoi(InPtr);
464 OperatorTime = atoi(InPtr);
465 fgets(fname, 256, fd);
468 TimeControl.clock[black] = atol(InPtr);
471 TimeControl.moves[black] = atoi(InPtr);
472 fgets(fname, 256, fd);
475 TimeControl.clock[white] = atol(InPtr);
478 TimeControl.moves[white] = atoi(InPtr);
479 fgets(fname, 256, fd); /* empty */
481 for (i = NO_ROWS - 1; i > -1; i--)
483 fgets(fname, 256, fd);
487 for (j = 0; j < NO_COLS; j++)
489 sq = i * NO_COLS + j;
495 board[sq] = no_piece;
500 for (c = 0; c < NO_PIECES; c++)
505 board[sq] = promoted[c];
507 board[sq] = unpromoted[c];
513 for (c = 0; c < NO_PIECES; c++)
518 board[sq] = promoted[c];
520 board[sq] = unpromoted[c];
528 Mvboard[sq] = atoi(InPtr);
533 fgets(fname, 256, fd); /* empty */
534 fgets(fname, 256, fd); /* 9 8 7 ... */
535 fgets(fname, 256, fd); /* empty */
536 fgets(fname, 256, fd); /* p l n ... */
539 for (side = 0; side <= 1; side++)
541 fgets(fname, 256, fd);
545 Captured[side][pawn] = atoi(InPtr);
547 Captured[side][lance] = atoi(InPtr);
549 Captured[side][knight] = atoi(InPtr);
551 Captured[side][silver] = atoi(InPtr);
553 Captured[side][gold] = atoi(InPtr);
555 Captured[side][bishop] = atoi(InPtr);
557 Captured[side][rook] = atoi(InPtr);
559 Captured[side][king] = atoi(InPtr);
563 flag.regularstart = true;
565 fgets(fname, 256, fd); /* empty */
566 fgets(fname, 256, fd); /* move score ... */
568 while (fgets(fname, 256, fd))
577 g = &GameList[GameCnt];
578 g->gmove = parser(InPtr, side, &g->fpiece);
580 g->score = atoi(InPtr);
582 g->depth = atoi(InPtr);
584 g->nodes = atol(InPtr);
586 g->time = atol(InPtr);
588 g->flags = c = atoi(InPtr);
590 g->hashkey = strtol(InPtr, (char **) NULL, 16);
592 g->hashbd = strtol(InPtr, (char **) NULL, 16);
600 for (piece = no_piece, i = 0; i < NO_PIECES; i++)
602 if (pxx[i] == *InPtr)
610 g->color = ((*InPtr == CP[119][0]) ? white : black);
612 g->piece = (*InPtr == '+'
614 : unpromoted[piece]);
623 if (TimeControl.clock[black] > 0)
631 UpdateDisplay(0, 0, 1, 0);
643 short sq, i, c, f, t;
646 char empty[2] = "\n";
649 strcpy(fname, savefile);
651 /* Enter file name */
653 RequestInputString(fname, sizeof(fname)-1);
656 if (fname[0] == '\0') /* shogi.000 */
657 strcpy(fname, CP[137]);
659 if ((fd = fopen(fname, "w")) != NULL)
664 if (computer == white)
667 if (computer == black)
670 fprintf(fd, CP[37], w, b, Game50,
671 flag.force ? "force" : "");
673 fprintf(fd, CP[111], TCflag, OperatorTime);
675 TimeControl.clock[black], TimeControl.moves[black],
676 TimeControl.clock[white], TimeControl.moves[white]);
679 for (i = NO_ROWS - 1; i > -1; i--)
681 fprintf(fd, "%c ", ROW_NAME(i));
683 for (c = 0; c < NO_COLS; c++)
685 sq = i * NO_COLS + c;
687 p = is_promoted[piece] ? '+' : ' ';
688 fprintf(fd, "%c", p);
704 fprintf(fd, "%c", p);
709 for (f = i * NO_COLS; f < i * NO_COLS + NO_ROWS; f++)
710 fprintf(fd, " %d", Mvboard[f]);
716 fprintf(fd, " 9 8 7 6 5 4 3 2 1\n"); /* FIXME */
718 fprintf(fd, " p l n s g b r k\n");
720 for (side = 0; side <= 1; side++)
722 fprintf(fd, "%c", (side == black) ? 'B' : 'W');
723 fprintf(fd, " %2d", Captured[side][pawn]);
724 fprintf(fd, " %2d", Captured[side][lance]);
725 fprintf(fd, " %2d", Captured[side][knight]);
726 fprintf(fd, " %2d", Captured[side][silver]);
727 fprintf(fd, " %2d", Captured[side][gold]);
728 fprintf(fd, " %2d", Captured[side][bishop]);
729 fprintf(fd, " %2d", Captured[side][rook]);
730 fprintf(fd, " %2d", Captured[side][king]);
737 for (i = 1; i <= GameCnt; i++)
739 struct GameRec *g = &GameList[i];
742 t = (g->gmove & 0xFF);
743 algbr(f, t, g->flags);
745 fprintf(fd, "%c%c%-5s %6d %5d %7ld %6ld %5d 0x%08lx 0x%08lx",
748 : (is_promoted[g->fpiece] ? '+' : ' ')),
750 ((f > NO_SQUARES) ? &mvstr[0][1] : mvstr[0]),
752 g->nodes, g->time, g->flags,
753 g->hashkey, g->hashbd);
755 if (g->piece != no_piece)
757 fprintf(fd, " %c %s %c\n",
758 pxx[g->piece], ColorStr[g->color],
759 (is_promoted[g->piece] ? '+' : ' '));
774 /* ShowMessage("Could not open file"); */
782 * GetXGame, SaveXGame and BookGame used to only be defined if
783 * xshogi wasn't defined -- wonder why?
795 /* Enter file name */
797 RequestInputString(fname, sizeof(fname)-1);
799 if (fname[0] == '\0') /* XSHOGI.position.read */
800 strcpy(fname, CP[205]);
802 if ((fd = fopen(fname, "r")) != NULL)
805 flag.regularstart = false;
808 /* xshogi position file ... */
809 fgets(fname, 256, fd);
814 if (strcmp(fname, CP[206]))
818 /* -- empty line -- */
819 fgets(fname, 256, fd);
820 /* -- empty line -- */
821 fgets(fname, 256, fd);
823 for (i = NO_ROWS - 1; i > -1; i--)
825 fgets(fname, 256, fd);
828 for (j = 0; j < NO_COLS; j++)
830 sq = i * NO_COLS + j;
836 board[sq] = no_piece;
841 for (c = 0; c < NO_PIECES; c++)
846 board[sq] = promoted[c];
848 board[sq] = unpromoted[c];
854 for (c = 0; c < NO_PIECES; c++)
859 board[sq] = promoted[c];
861 board[sq] = unpromoted[c];
874 for (side = 0; side <= 1; side++)
876 fgets(fname, 256, fd);
878 Captured[side][pawn] = atoi(InPtr);
880 Captured[side][lance] = atoi(InPtr);
882 Captured[side][knight] = atoi(InPtr);
884 Captured[side][silver] = atoi(InPtr);
886 Captured[side][gold] = atoi(InPtr);
888 Captured[side][bishop] = atoi(InPtr);
890 Captured[side][rook] = atoi(InPtr);
892 Captured[side][king] = atoi(InPtr);
895 if (fgets(fname, 256, fd) != NULL && strncmp(fname, "white", 5) == 0)
908 UpdateDisplay(0, 0, 1, 0);
923 /* Enter file name */
925 RequestInputString(fname, sizeof(fname)-1);
927 if (fname[0] == '\0') /* XSHOGI.position.read */
928 strcpy(fname, CP[205]);
930 if ((fd = fopen(fname, "w")) != NULL)
932 /* xshogi position file ... */
933 fputs("# xshogi position file -- \n", fd);
934 /* -- empty line -- */
936 /* -- empty line -- */
939 for (i = NO_ROWS - 1; i > -1; i--)
943 for (j = 0; j < NO_COLS; j++)
945 sq = i * NO_COLS + j;
947 isp = is_promoted[piece];
948 *p = (isp ? '+' : ' ');
951 if (piece == no_piece)
953 else if (color[sq] == white)
966 for (side = 0; side <= 1; side++)
968 sprintf(fname, "%d %d %d %d %d %d %d %d\n",
969 Captured[side][pawn],
970 Captured[side][lance],
971 Captured[side][knight],
972 Captured[side][silver],
973 Captured[side][gold],
974 Captured[side][bishop],
975 Captured[side][rook],
976 Captured[side][king]);
981 if (computer == black)
982 fputs("white to play\n", fd);
984 fputs("black to play\n", fd);
995 char fname[256], sflags[4];
999 strcpy(fname, savefile);
1001 /* Enter file name */
1002 ShowMessage(CP[63]);
1003 RequestInputString(fname, sizeof(fname)-1);
1006 if (fname[0] == '\0')
1009 if ((fd = fopen(fname, "a")) != NULL)
1013 for (i = 1; i <= GameCnt; i++)
1015 struct GameRec *g = &GameList[i];
1016 char mvnr[20], mvs[20];
1019 sprintf(mvnr, "%d.", (i + 1)/2);
1024 t = (g->gmove & 0xFF);
1025 algbr(f, t, g->flags);
1028 /* determine move quality string */
1029 if (g->flags & goodmove)
1032 if (g->flags & badmove)
1035 #ifdef EASY_OPENINGS
1036 if (g->flags & difficult)
1042 /* determine move string */
1045 sprintf(mvs, "%s%s ", &mvstr[0][1], sflags);
1049 sprintf(mvs, "%c%c%c%c%c%s%s ",
1050 mvstr[0][0], mvstr[0][1],
1051 (g->flags & capture) ? 'x' : '-',
1052 mvstr[0][2], mvstr[0][3],
1053 (mvstr[0][4] == '+') ? "+" : "",
1057 fprintf(fd, "%s%s%c%s",
1061 : (is_promoted[g->fpiece] ? "+" : "")),
1075 ShowMessage(CP[70]);
1079 /* ShowMessage("Could not open file"); */
1080 ShowMessage(CP[48]);
1092 char fname[256], dbuf[256];
1096 strcpy(fname, listfile);
1101 strncpy(dbuf, ctime(&when), 20);
1108 /* use format "CLp16.Jan01-020304B" when patchlevel is 16,
1111 program played white */
1113 sprintf(fname, "CLp%s.%s%s-%s%s%s%c",
1114 patchlevel, dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14,
1115 dbuf + 17, ColorStr[computer][0]);
1117 /* replace space padding with 0 */
1118 for (i = 0; fname[i] != '\0'; i++)
1120 if (fname[i] == ' ')
1125 fd = fopen(fname, "w");
1129 printf(CP[219], fname);
1133 /* fprintf(fd, "gnushogi game %d\n", u); */
1134 fprintf(fd, CP[161], version, patchlevel);
1138 for (i = 1; i <= GameCnt; i++)
1140 f = GameList[i].gmove >> 8;
1141 t = (GameList[i].gmove & 0xFF);
1142 algbr(f, t, GameList[i].flags);
1144 if (GameList[i].flags & book)
1146 fprintf(fd, "%c%c%-5s %5d Book%7ld %5ld",
1149 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1150 pxx[GameList[i].fpiece],
1152 ? &mvstr[0][1] : mvstr[0]),
1159 fprintf(fd, "%c%c%-5s %5d %2d %7ld %5ld",
1162 : (is_promoted[GameList[i].fpiece] ? '+' : ' ')),
1163 pxx[GameList[i].fpiece],
1164 (f > NO_SQUARES ? &mvstr[0][1] : mvstr[0]),
1165 GameList[i].score, GameList[i].depth,
1166 GameList[i].nodes, GameList[i].time);
1179 fprintf(fd, "\n\n");
1181 if (GameList[GameCnt].flags & draw)
1183 fprintf(fd, CP[54], DRAW);
1185 if (DRAW == CP[101])
1189 fprintf(fd, "repetition by positions ");
1191 for (j = GameCnt - 1; j >= Game50; j -= 2)
1193 if (GameList[j].hashkey == hashkey &&
1194 GameList[j].hashbd == hashbd)
1195 fprintf(fd, "%d ", j);
1201 else if (GameList[GameCnt].score == -(SCORE_LIMIT + 999))
1203 fprintf(fd, "%s\n", ColorStr[player ]);
1205 else if (GameList[GameCnt].score == (SCORE_LIMIT + 998))
1207 fprintf(fd, "%s\n", ColorStr[player ^ 1]);
1221 GameList[GameCnt].flags |= badmove;
1225 GameList[GameCnt].flags |= goodmove;
1228 #ifdef EASY_OPENINGS
1230 GameList[GameCnt].flags |= difficult;
1240 * Undo the most recent half-move.
1248 f = GameList[GameCnt].gmove >> 8;
1249 t = GameList[GameCnt].gmove & 0x7F;
1253 /* the move was a drop */
1254 Captured[color[t]][board[t]]++;
1255 board[t] = no_piece;
1261 if (GameList[GameCnt].flags & promote)
1262 board[f] = unpromoted[board[t]];
1264 board[f] = board[t];
1266 color[f] = color[t];
1267 board[t] = GameList[GameCnt].piece;
1268 color[t] = GameList[GameCnt].color;
1270 if (board[t] != no_piece)
1271 Captured[color[f]][unpromoted[board[t]]]--;
1273 if (color[t] != neutral)
1281 if (TCflag && (TCmoves > 1))
1282 ++TimeControl.moves[color[f]];
1284 hashkey = GameList[GameCnt].hashkey;
1285 hashbd = GameList[GameCnt].hashbd;
1287 computer = computer ^ 1;
1288 opponent = opponent ^ 1;
1291 player = player ^ 1;
1293 UpdateDisplay(0, 0, 1, 0);
1295 if (flag.regularstart)
1302 FlagString(unsigned short flags, char *s)
1307 if (flags & promote)
1308 strcat(s, " promote");
1310 if (flags & dropmask)
1311 strcat(s, " drop:");
1313 if ((piece = (flags & pmask)))
1317 if (is_promoted[piece])
1320 s[l++] = pxx[piece];
1324 if (flags & capture)
1325 strcat(s, " capture");
1328 strcat(s, " exact");
1331 strcat(s, " tesuji");
1334 strcat(s, " check");
1340 strcat(s, " stupid");
1342 if (flags & questionable)
1343 strcat(s, " questionable");
1345 if (flags & kingattack)
1346 strcat(s, " kingattack");
1355 TestSpeed(void(*f)(short side, short ply,
1356 short in_check, short blockable),
1366 #ifdef HAVE_GETTIMEOFDAY
1370 #ifdef HAVE_GETTIMEOFDAY
1371 gettimeofday(&tv, NULL);
1372 t1 = (tv.tv_sec*100 + (tv.tv_usec/10000));
1377 for (i = 0; i < j; i++)
1379 f(opponent, 2, -1, true);
1382 for (jj = TrPnt[2]; i < TrPnt[3]; jj++)
1384 if (!pick(jj, TrPnt[3] - 1))
1390 #ifdef HAVE_GETTIMEOFDAY
1391 gettimeofday(&tv, NULL);
1392 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1397 cnt = j * (TrPnt[3] - TrPnt[2]);
1410 TestPSpeed(short(*f) (short side), unsigned j)
1414 #ifdef HAVE_GETTIMEOFDAY
1418 #ifdef HAVE_GETTIMEOFDAY
1419 gettimeofday(&tv, NULL);
1420 t1 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1425 for (i = 0; i < j; i++)
1428 #ifdef HAVE_GETTIMEOFDAY
1429 gettimeofday(&tv, NULL);
1430 t2 = (tv.tv_sec * 100 + (tv.tv_usec / 10000));
1454 time = &s[strlen(CP[228])];
1455 t = (int)strtol(time, &time, 10);
1460 sec = (int)strtol(time, &time, 10);
1463 m = (int)strtol(time, &time, 10);
1466 TimeControl.clock[opponent] = t;
1469 TimeControl.moves[opponent] = m;
1471 ElapsedTime(COMPUTE_AND_INIT_MODE);
1475 /* just to inform xshogi about availability of otime command */
1476 printf("otime %d %d\n", t, m);
1483 SetMachineTime(char *s)
1488 time = &s[strlen(CP[197])];
1490 t = (int)strtol(time, &time, 10);
1495 sec = (int)strtol(time, &time, 10);
1498 m = (int)strtol(time, &time, 10);
1501 TimeControl.clock[computer] = t;
1504 TimeControl.moves[computer] = m;
1506 ElapsedTime(COMPUTE_AND_INIT_MODE);
1510 /* just to inform xshogi about availability of time command */
1511 printf("time %d %d\n", t, m);
1519 /* FIXME! This is truly the function from hell! */
1522 * Process the user's command. If easy mode is OFF (the computer is thinking
1523 * on opponents time) and the program is out of book, then make the 'hint'
1524 * move on the board and call SelectMove() to find a response. The user
1525 * terminates the search by entering ^C (quit siqnal) before entering a
1526 * command. If the opponent does not make the hint move, then set Sdepth to
1531 InputCommand(char *command)
1534 short have_shown_prompt = false;
1535 short ok, done, is_move = false;
1539 ok = flag.quit = done = false;
1543 if (TTadd > ttbllimit)
1547 if ((hint > 0) && !flag.easy && !flag.force)
1550 * A hint move for the player is available. Compute a move for the
1551 * opponent in background mode assuming that the hint move will be
1552 * selected by the player.
1555 ft = time0; /* Save reference time for the player. */
1557 algbr((short) hint >> 8, (short) hint & 0xff, false);
1558 strcpy(s, mvstr[0]);
1565 /* do the hint move */
1566 if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv))
1570 #ifdef QUIETBACKGROUND
1572 have_shown_prompt = true;
1573 #endif /* QUIETBACKGROUND */
1575 /* Start computing a move until the search is interrupted. */
1577 #ifdef INTERRUPT_TEST
1581 /* would love to put null move in here */
1582 /* after we make the hint move make a 2 ply search
1583 * with both plys our moves */
1584 /* think on opponents time */
1585 SelectMove(computer, BACKGROUND_MODE);
1587 #ifdef INTERRUPT_TEST
1588 ElapsedTime(COMPUTE_INTERRUPT_MODE);
1592 printf("searching not terminated by interrupt!\n");
1596 printf("elapsed time from interrupt to "
1597 "terminating search: %ld\n", it);
1601 /* undo the hint and carry on */
1602 VerifyMove(s, UNMAKE_MODE, &mv);
1606 time0 = ft; /* Restore reference time for the player. */
1609 while(!(ok || flag.quit || done))
1613 #ifdef QUIETBACKGROUND
1614 if (!have_shown_prompt)
1616 #endif /* QUIETBACKGROUND */
1620 #ifdef QUIETBACKGROUND
1623 have_shown_prompt = false;
1624 #endif /* QUIETBACKGROUND */
1626 if (command == NULL) {
1630 eof = GetString(sx);
1632 strcpy(sx, command);
1636 sscanf(sx, "%s", s);
1644 if (strcmp(s, CP[131]) == 0) /* bd -- display board */
1646 /* FIXME: Hack alert! */
1647 short old_xshogi = XSHOGI;
1650 display_type = DISPLAY_RAW;
1653 UpdateDisplay(0, 0, 1, 0);
1656 display_type = DISPLAY_X;
1658 else if (strcmp(s, "post") == 0)
1660 flag.post = !flag.post;
1662 else if (strcmp(s, CP[129]) == 0)
1664 /* noop */ ; /* alg */
1666 else if ((strcmp(s, CP[180]) == 0)
1667 || (strcmp(s, CP[216]) == 0)) /* quit exit */
1672 else if (strcmp(s, CP[178]) == 0) /* post */
1674 flag.post = !flag.post;
1677 else if ((strcmp(s, CP[191]) == 0)
1678 || (strcmp(s, CP[154]) == 0)) /* set edit */
1682 else if (NOT_CURSES && (strcmp(s, CP[190]) == 0)) /* setup */
1686 else if (strcmp(s, CP[156]) == 0) /* first */
1690 else if (strcmp(s, CP[162]) == 0) /* go */
1695 if (computer == black)
1706 else if (strcmp(s, CP[166]) == 0) /* help */
1710 else if (strcmp(s, CP[221]) == 0) /* material */
1712 flag.material = !flag.material;
1714 else if (strcmp(s, CP[157]) == 0) /* force */
1719 flag.bothsides = false;
1723 flag.force = !flag.force;
1724 flag.bothsides = false;
1727 else if (strcmp(s, CP[134]) == 0) /* book */
1729 Book = Book ? 0 : BOOKFAIL;
1731 else if (strcmp(s, CP[172]) == 0) /* new */
1734 UpdateDisplay(0, 0, 1, 0);
1736 else if (strcmp(s, CP[171]) == 0) /* list */
1740 else if ((strcmp(s, CP[169]) == 0)
1741 || (strcmp(s, CP[217]) == 0)) /* level clock */
1745 else if (strcmp(s, CP[165]) == 0) /* hash */
1747 flag.hash = !flag.hash;
1749 else if (strcmp(s, CP[227]) == 0) /* gamein */
1751 flag.gamein = !flag.gamein;
1753 else if (strcmp(s, CP[226]) == 0) /* beep */
1755 flag.beep = !flag.beep;
1757 else if (strcmp(s, CP[197]) == 0) /* time */
1761 else if (strcmp(s, CP[228]) == 0) /* otime */
1765 else if (strcmp(s, CP[33]) == 0) /* Awindow */
1767 ChangeAlphaWindow();
1769 else if (strcmp(s, CP[39]) == 0) /* Bwindow */
1773 else if (strcmp(s, CP[183]) == 0) /* rcptr */
1775 flag.rcptr = !flag.rcptr;
1777 else if (strcmp(s, CP[168]) == 0) /* hint */
1781 else if (strcmp(s, CP[135]) == 0) /* both */
1783 flag.bothsides = !flag.bothsides;
1786 ElapsedTime(COMPUTE_AND_INIT_MODE);
1787 SelectMove(opponent, FOREGROUND_MODE);
1790 else if (strcmp(s, CP[185]) == 0) /* reverse */
1792 flag.reverse = !flag.reverse;
1794 UpdateDisplay(0, 0, 1, 0);
1796 else if (strcmp(s, CP[195]) == 0) /* switch */
1798 computer = computer ^ 1;
1799 opponent = opponent ^ 1;
1800 xwndw = (computer == black) ? WXWNDW : BXWNDW;
1805 else if (strcmp(s, CP[203]) == 0) /* black */
1814 * ok = true; don't automatically start with black command
1817 else if (strcmp(s, CP[133]) == 0) /* white */
1826 * ok = true; don't automatically start with white command
1829 else if (strcmp(s, CP[201]) == 0 && GameCnt > 0) /* undo */
1833 else if (strcmp(s, CP[184]) == 0 && GameCnt > 1) /* remove */
1838 /* CHECKME: are these next three correct? */
1839 else if (!XSHOGI && strcmp(s, CP[207]) == 0) /* xget */
1843 else if (!XSHOGI && strcmp(s, "xsave") == 0) /* xsave */
1847 else if (!XSHOGI && strcmp(s, "bsave") == 0) /* bsave */
1851 #ifdef EASY_OPENINGS
1852 else if ((strcmp(s, "?") == 0)
1853 || (strcmp(s, "!") == 0)
1854 || (strcmp(s, "~") == 0))
1856 else if ((strcmp(s, "?") == 0)
1857 || (strcmp(s, "!") == 0))
1862 else if (strcmp(s, CP[160]) == 0) /* get */
1866 else if (strcmp(s, CP[189]) == 0) /* save */
1870 else if (strcmp(s, CP[151]) == 0) /* depth */
1872 ChangeSearchDepth();
1874 else if (strcmp(s, CP[164]) == 0) /* hashdepth */
1878 else if (strcmp(s, CP[182]) == 0) /* random */
1882 else if (strcmp(s, CP[229]) == 0) /* hard */
1886 else if (strcmp(s, CP[152]) == 0) /* easy */
1888 flag.easy = !flag.easy;
1890 else if (strcmp(s, CP[230]) == 0) /* tsume */
1892 flag.tsume = !flag.tsume;
1894 else if (strcmp(s, CP[143]) == 0) /* contempt */
1898 else if (strcmp(s, CP[209]) == 0) /* xwndw */
1902 else if (strcmp(s, CP[186]) == 0) /* rv */
1905 UpdateDisplay(0, 0, 1, 0);
1907 else if (strcmp(s, CP[145]) == 0) /* coords */
1909 flag.coords = !flag.coords;
1910 UpdateDisplay(0, 0, 1, 0);
1912 else if (strcmp(s, CP[193]) == 0) /* stars */
1914 flag.stars = !flag.stars;
1915 UpdateDisplay(0, 0, 1, 0);
1917 else if (!XSHOGI && strcmp(s, CP[5]) == 0) /* moves */
1924 extern unsigned short PrVar[MAXDEPTH];
1926 SwagHt = (GameList[GameCnt].gmove == PrVar[1])
1933 ShowMessage(CP[108]); /* test movelist */
1934 temp = generate_move_flags;
1935 generate_move_flags = true;
1936 TestSpeed(MoveList, 1);
1937 generate_move_flags = temp;
1938 ShowMessage(CP[107]); /* test capturelist */
1939 TestSpeed(CaptureList, 1);
1940 ShowMessage(CP[85]); /* test score position */
1941 ExaminePosition(opponent);
1942 TestPSpeed(ScorePosition, 1);
1944 else if (!XSHOGI && strcmp(s, CP[196]) == 0) /* test */
1947 ShowMessage(CP[108]); /* test movelist */
1948 TestSpeed(MoveList, 2000);
1949 ShowMessage(CP[107]); /* test capturelist */
1950 TestSpeed(CaptureList, 3000);
1951 ShowMessage(CP[85]); /* test score position */
1952 ExaminePosition(opponent);
1953 TestPSpeed(ScorePosition, 1500);
1955 ShowMessage(CP[108]); /* test movelist */
1956 TestSpeed(MoveList, 20000);
1957 ShowMessage(CP[107]); /* test capturelist */
1958 TestSpeed(CaptureList, 30000);
1959 ShowMessage(CP[85]); /* test score position */
1960 ExaminePosition(opponent);
1961 TestPSpeed(ScorePosition, 15000);
1964 else if (!XSHOGI && strcmp(s, CP[179]) == 0) /* p */
1968 else if (!XSHOGI && strcmp(s, CP[148]) == 0) /* debug */
1978 else if ((ok = VerifyMove(s, VERIFY_AND_MAKE_MODE, &mv)))
1980 /* check for repetition */
1981 short rpt = repetition();
1987 GameList[GameCnt].flags |= draw;
2001 ElapsedTime(COMPUTE_AND_INIT_MODE);
2005 computer = opponent;
2006 opponent = computer ^ 1;
2011 /* add remaining time in milliseconds for xshogi */
2014 printf("%d. %s %ld\n",
2015 ++mycnt2, s, TimeControl.clock[player] * 10);
2018 #ifdef notdef /* optional pass best line to frontend with move */
2019 # if !defined NOPOST
2021 if (flag.post && !flag.mate)
2025 printf(" %6d ", MSCORE);
2027 for (i = 1; MV[i] > 0; i++)
2029 algbr((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
2030 printf("%5s ", mvstr[0]);
2043 SetTimeControl(void)
2047 TimeControl.moves[black] = TimeControl.moves[white] = TCmoves;
2048 TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100;
2049 TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100;
2053 TimeControl.moves[black] = TimeControl.moves[white] = 0;
2054 TimeControl.clock[black] = TimeControl.clock[white] = 0;
2057 flag.onemove = (TCmoves == 1);
2059 ElapsedTime(COMPUTE_AND_INIT_MODE);