2 * uxdsp.c - ALPHA interface for GNU SHOGI
4 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6 * GNU SHOGI is based on GNU CHESS
8 * Copyright (c) 1988,1989,1990 John Stanback
9 * Copyright (c) 1992 Free Software Foundation
11 * This file is part of GNU SHOGI.
13 * GNU Shogi is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 1, or (at your option)
18 * GNU Shogi is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GNU Shogi; see the file COPYING. If not, write to
25 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
39 #define refresh() fflush(stdout)
41 static void param (short n);
48 #define clear() cgotoxy(1,1,stdout),ccleos(stdout)
49 #define refresh() fflush(stdout)
53 #include <sys/param.h>
54 #include <sys/types.h>
66 #define VIR_C(s) ((flag.reverse) ? 8-column(s) : column(s))
67 #define VIR_R(s) ((flag.reverse) ? 8-row(s) : row(s))
69 unsigned short int MV[MAXDEPTH];
73 void TerminateSearch (int), Die (int);
79 #if !defined MSDOS && !defined THINK_C
80 signal (SIGQUIT, Die);
95 #if !defined MSDOS && !defined THINK_C
108 signal (SIGINT, SIG_IGN);
109 #if defined MSDOS || defined THINK_C
110 Sig++; /* shut up the compiler */
112 signal (SIGQUIT, SIG_IGN);
114 ShowMessage (CP[31]); /*Abort?*/
116 if (strcmp (s, CP[210]) == 0) /*yes*/
118 signal (SIGINT, Die);
119 #if !defined MSDOS && !defined THINK_C
120 signal (SIGQUIT, Die);
125 TerminateSearch (int Sig)
127 signal (SIGINT, SIG_IGN);
128 #if defined MSDOS || defined THINK_C
129 Sig++; /* shut up the compiler */
131 signal (SIGQUIT, SIG_IGN);
134 flag.musttimeout = true;
135 ShowMessage("Terminate Search");
136 flag.bothsides = false;
137 signal (SIGINT, Die);
138 #if !defined MSDOS && !defined THINK_C
139 signal (SIGQUIT, Die);
143 ShowLine (short unsigned int *bstline)
151 /*printz ("GNU Shogi ??p? command summary\n");*/
152 printz (CP[40], version, patchlevel);
153 printz ("----------------------------------------------------------------\n");
154 /*printz ("7g7f move from 7g to 7f quit Exit Chess\n");*/
156 /*printz ("S6h move silver to 6h beep turn %s\n", (flag.beep) ? "off" : "on");*/
157 printz (CP[86], (flag.beep) ? CP[92] : CP[93]);
158 /*printz ("2d2c+ move to 2c and promote\n");*/
159 printz (CP[128], (flag.material) ? CP[92] : CP[93]);
160 /*printz ("P*5e drop a pawn to 5e easy turn %s\n", (flag.easy) ? "off" : "on");*/
161 printz (CP[173], (flag.easy) ? CP[92] : CP[93]);
162 /*printz (" hash turn %s\n", (flag.hash) ? "off" : "on");*/
163 printz (CP[174], (flag.hash) ? CP[92] : CP[93]);
164 /*printz ("bd redraw board reverse board display\n");*/
166 /*printz ("list game to shogi.lst book turn %s used %d of %d\n", (Book) ? "off" : "on", book
168 printz (CP[170], (Book) ? CP[92] : CP[93], bookcount, BOOKSIZE);
169 /*printz ("undo undo last ply remove take back a move\n");*/
171 /*printz ("edit edit board force enter game moves\n");*/
173 /*printz ("switch sides with computer both computer match\n");*/
175 /*printz ("black computer plays black white computer plays white\n");*/
177 /*printz ("depth set search depth clock set time control\n");*/
179 /*printz ("hint suggest a move post turn %s principle variation\n", (flag.post) ? "off" :
181 printz (CP[177], (flag.post) ? CP[92] : CP[93]);
182 /*printz ("save game to file get game from file\n");*/
184 /*printz ("random randomize play new start new game\n");*/
187 printz (CP[47], ColorStr[computer]);
189 printz (CP[97], ColorStr[opponent]);
191 printz (CP[79], MaxResponseTime/100);
193 printz (CP[59], (flag.easy) ? CP[93] : CP[92]);
195 printz (CP[231], (flag.tsume) ? CP[93] : CP[92]);
197 printz (CP[52], MaxSearchDepth);
199 printz (CP[100], (dither) ? CP[93] : CP[92]);
201 printz (CP[112], (flag.hash) ? CP[93] : CP[92]);
205 printz (CP[110], (TCflag) ? CP[93] : CP[92],
206 TimeControl.moves[black], TimeControl.clock[black] / 100, OperatorTime, MaxSearchDepth);
209 fflush (stdin); /*what is this supposed to do??*/
213 UpdateDisplay (0, 0, 1, 0);
217 static const short x0[2] = {54, 2};
218 static const short y0[2] = {20, 4};
227 for ( side = black; side <= white; side++ )
229 short x, y, piece, cside, k;
230 cside = flag.reverse ? (side ^ 1) : side;
234 for ( piece = pawn; piece <= king; piece++ )
236 if ( n = Captured[side][piece] )
238 printz("%i%c",n,pxx[piece]);
239 if ( cside == black ) y--; else y++;
248 if ( cside == black ) y--; else y++;
259 * Set up a board position. Pieces are entered by typing the piece followed
260 * by the location. For example, N3f will place a knight on square 3f.
261 * P* will put a pawn to the captured pieces.
265 short a, r, c, sq, i;
268 flag.regularstart = true;
271 UpdateDisplay (0, 0, 1, 0);
284 printz (CP[60], ColorStr[a]); /*Editing %s*/
285 gotoXY (TAB + 24, 7);
288 if (s[0] == CP[28][0]) /*#*/
290 for (sq = 0; sq < NO_SQUARES; sq++)
292 board[sq] = no_piece;
299 if (s[0] == CP[136][0]) /*c*/
303 for (i = NO_PIECES; i > no_piece; i--)
304 if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
306 Captured[a][unpromoted[i]]++;
315 if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS))
318 for (i = NO_PIECES; i > no_piece; i--)
319 if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
326 color[sq] = ((board[sq] == no_piece) ? neutral : a);
329 } while (s[0] != CP[29][0]); /*.*/
331 for (sq = 0; sq < NO_SQUARES; sq++)
332 Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
339 UpdateDisplay (0, 0, 1, 0);
345 gotoXY (5, ((flag.reverse) ? 23 : 2));
346 printz ("%s", (computer == white) ? CP[218] : CP[74]);
347 gotoXY (5, ((flag.reverse) ? 2 : 23));
348 printz ("%s", (computer == black) ? CP[218] : CP[74]);
355 printz ("Depth= %2d%c", Sdepth, ch); /*Depth= %d%c*/
363 printz("Stage= %2d%c B= %2d W= %2d",
364 stage,flag.tsume?'T':' ',balance[black],balance[white]);
369 ShowScore (short score)
372 printz (CP[104], score);
377 ShowMessage (char *s)
392 ShowCurrentMove (short int pnt, short int f, short int t)
396 printz ("(%2d) %5s ", pnt, mvstr[0]);
403 printz (CP[69], version, patchlevel);
407 ShowSidetoMove (void)
410 printz ("%2d: %s", 1 + GameCnt / 2, ColorStr[player]);
418 printz (CP[121]); /*Your move is?*/
423 ShowNodeCnt (long int NodeCnt)
426 /* printz (CP[90], NodeCnt, (et > 100) ? NodeCnt / (et / 100) : 0); */
427 printz ("n=%ld n/s=%ld", NodeCnt, (et > 100) ? NodeCnt / (et / 100) : 0);
432 ShowResults (short int score, short unsigned int *bstline, char ch)
434 unsigned char d, ply;
441 for (ply = 1; bstline[ply] > 0; ply++)
448 algbr ((short) bstline[ply] >> 8, (short) bstline[ply] & 0xFF, false);
449 printz ("%5s ", mvstr[0]);
461 ShowPatternCount (short side, short n)
465 gotoXY(TAB+10+3*side,20);
479 printz("%c vs. %c",GameType[black],GameType[white]);
484 ShowResponseTime (void)
489 /* printz("RT=%ld TCC=%d TCL=%ld EX=%ld ET=%ld TO=%d",
490 ResponseTime,TCC,TCleft,ExtraTime,et,flag.timeout); */
491 printz("%ld,%d,%ld,%ld,%ld,%d",
492 ResponseTime,TCC,TCleft,ExtraTime,et,flag.timeout);
498 SearchStartStuff (short int side)
502 signal (SIGINT, TerminateSearch);
503 #if defined MSDOS || defined THINK_C
504 side++; /* shut up the compiler */
506 signal (SIGQUIT, TerminateSearch);
508 for (i = 4; i < 14; i++)
519 UpdateDisplay (root->f, root->t, 0, (short) root->flags);
521 if(flag.illegal){printz(CP[225]);return;}
522 printz (CP[84], mvstr[0]); /*My move is %s*/
528 if (root->flags & draw)
530 else if (root->score == -(SCORE_LIMIT+999))
532 else if (root->score == SCORE_LIMIT+998)
535 else if (root->score < -SCORE_LIMIT)
536 printz (CP[96], SCORE_LIMIT+999 + root->score - 1);
537 else if (root->score > SCORE_LIMIT)
538 printz (CP[45], SCORE_LIMIT+998 - root->score - 1);
543 register short h, l, t;
550 if (Tree[t].f || Tree[t].t)
557 ShowNodeCnt (NodeCnt);
559 printz (CP[81], t); /*Max Tree=*/
573 m = (short) ((dt = (TimeControl.clock[player] - et)) / 6000);
574 s = (short) ((dt - 6000 * (long) m) / 100);
578 m = (short) ((dt = et) / 6000);
579 s = (short) (et - 6000 * (long) m) / 100;
586 gotoXY (20, (flag.reverse) ? 2 : 23);
588 gotoXY (20, (flag.reverse) ? 23 : 2);
589 /* printz ("%d:%02d %ld ", m, s, dt); */
590 printz ("%d:%02d ", m, s);
592 ShowNodeCnt (NodeCnt);
597 gotoXY (short int x, short int y)
606 #elif defined THINK_C
607 cgotoxy (x, y, stdout);
634 #elif defined THINK_C
662 DrawPiece (short int sq)
668 #if defined(MSDOS) && !defined(SEVENBIT)
669 if (color[sq] == white)
670 x = '7'; /* print WHITE boldface, */
672 x = '1'; /* print BLACK inverted */
674 if ( is_promoted[piece] ) {
675 p = '+'; y = pxx[unpromoted[piece]];
677 p = ' '; y = pxx[piece];
679 gotoXY (8 + 5 * VIR_C (sq), 4 + 2 * (8 - VIR_R (sq)));
680 printz ("\033[%cm%c%c\033[0m", x, p, y);
682 if ( color[sq]==neutral )
684 else if ( flag.reverse ^ (color[sq]==black) ) {
690 if ( is_promoted[piece] ) {
691 p = '+'; y = pxx[unpromoted[piece]];
693 p = ' '; y = pxx[piece];
695 gotoXY (8 + 5 * VIR_C (sq), 4 + 2 * (8 - VIR_R (sq)));
696 printz ("%c%c%c%c", l, p, y, r);
701 ShowPostnValue (short int sq)
704 * must have called ExaminePosition() first
710 gotoXY (4 + 5 * VIR_C (sq), 5 + 2 * (7 - VIR_R (sq)));
711 score = ScorePosition (color[sq]);
712 if (color[sq] != neutral)
713 #if defined SAVE_SVALUE
716 printz ("%3d ", svalue[sq]);
723 ShowPostnValues (void)
727 ExaminePosition (opponent);
728 for (sq = 0; sq < NO_SQUARES; sq++)
730 score = ScorePosition (opponent);
732 printz (CP[103], score,
733 mtl[computer], pscore[computer], GameType[computer],
734 mtl[opponent], pscore[opponent], GameType[opponent]);
741 UpdateDisplay (short int f, short int t, short int redraw, short int isspec)
752 #if defined(MSDOS) && !defined(SEVENBIT)
753 printz ("\332\304\304\304\304\302\304\304\304\304\302\304\304\304\304" \
754 "\302\304\304\304\304\302\304\304\304\304\302\304\304\304\304" \
755 "\302\304\304\304\304\302\304\304\304\304\277");
757 printz (" +----+----+----+----+----+----+----+----+----+");
758 #endif /* MSDOS && !SEVENBIT */
765 z = 11 - ((i+1) / 2);
766 #if defined(MSDOS) && !defined(SEVENBIT)
767 printz ("%d \263 \263 \263 \263 \263 \263 " \
768 "\263 \263 \263", z);
770 printz (" %c | | | | | | | | | |", 'a'+9-z);
771 #endif /* MSDOS && !SEVENBIT */
774 #if defined(MSDOS) && !defined(SEVENBIT)
775 printz ("\303\304\304\304\304\305\304\304\304\304\305\304\304" \
776 "\304\304\305\304\304\304\304\305\304\304\304\304\305" \
777 "\304\304\304\304\305\304\304\304\304\305\304\304\304" \
780 printz (" +----+----+----+----+----+----+----+----+----+");
781 #endif /* MSDOS && !SEVENBIT */
783 #if defined(MSDOS) && !defined(SEVENBIT)
784 printz ("\300\304\304\304\304\301\304\304\304\304\301\304\304\304\304" \
785 "\301\304\304\304\304\301\304\304\304\304\301\304\304\304\304" \
786 "\301\304\304\304\304\301\304\304\304\304\331");
788 printz (" +----+----+----+----+----+----+----+----+----+");
789 #endif /* MSDOS && !SEVENBIT */
796 for (sq = 0; sq < NO_SQUARES; sq++)
799 else /* not redraw */
801 if ( f < NO_SQUARES )
803 DrawPiece (t & 0x7f);
805 if ( (isspec & capture) || (isspec & dropmask) || redraw )
807 for ( side = black; side <= white; side++ )
808 { short x, y, piece, cside, k;
809 cside = flag.reverse ? (side ^ 1) : side;
813 for ( piece = pawn; piece <= king; piece++ )
815 if ( n = Captured[side][piece] )
817 printz("%i%c",n,pxx[piece]);
818 if ( cside == black ) y--; else y++;
827 if ( cside == black ) y--; else y++;
837 ChangeAlphaWindow (void)
839 ShowMessage (CP[114]);
840 scanz ("%hd", &WAwindow);
841 ShowMessage (CP[34]);
842 scanz ("%hd", &BAwindow);
846 ChangeBetaWindow (void)
848 ShowMessage (CP[115]);
849 scanz ("%hd", &WBwindow);
850 ShowMessage (CP[35]);
851 scanz ("%hd", &BBwindow);
860 algbr ((short) (hint >> 8), (short) (hint & 0xFF), false);
861 strcpy (s, CP[198]); /*try*/
862 strcat (s, mvstr[0]);
866 ShowMessage (CP[223]);
870 ChangeHashDepth (void)
872 ShowMessage (CP[163]);
873 scanz ("%hd", &HashDepth);
874 ShowMessage (CP[82]);
875 scanz ("%hd", &HashMoveLimit);
879 ChangeSearchDepth (void)
881 ShowMessage (CP[150]);
882 scanz ("%hd", &MaxSearchDepth);
883 TCflag = !(MaxSearchDepth > 0);
889 ShowMessage (CP[142]);
890 scanz ("%hd", &contempt);
896 ShowMessage (CP[208]);
897 scanz ("%hd", &xwndw);
901 SelectLevel (char *sx)
907 printz (CP[41], version, patchlevel);
990 TCflag = (TCmoves > 0);
992 TimeControl.clock[black] = TimeControl.clock[white] = 0;
996 UpdateDisplay (0, 0, 1, 0);
1002 short c, p, sq, tp, tc, tsq, score;
1005 ExaminePosition (opponent);
1006 ShowMessage (CP[65]);
1009 if (s[0] == CP[9][0] || s[0] == CP[9][1]) /*b B*/
1011 if (s[0] == CP[9][2] || s[0] == CP[9][3]) /*w W*/
1013 for (p = king; p > no_piece; p--)
1014 if ((s[1] == pxx[p]) || (s[1] == qxx[p]))
1016 for (sq = 0; sq < NO_SQUARES; sq++)
1022 tsq = PieceList[c][1];
1023 PieceList[c][1] = sq;
1024 ShowPostnValue (sq);
1025 PieceList[c][1] = tsq;
1029 score = ScorePosition (opponent);
1031 printz (CP[103], score,
1032 mtl[computer], pscore[computer], GameType[computer],
1033 mtl[opponent], pscore[opponent], GameType[opponent]);
1039 DoTable (short table[NO_SQUARES])
1042 ExaminePosition (opponent);
1043 for (sq=0;sq<NO_SQUARES;sq++) {
1044 gotoXY (4 + 5 * VIR_C (sq), 5 + 2 * (7 - VIR_R (sq)));
1045 printz ("%3d ", table[sq]);