Long-dead code removal: unused macro
[gnushogi.git] / gnushogi / rawdsp.c
blobac2fcfaaeb2df968c5e4ccd41a09bf5413a4536d
1 /*
2 * FILE: rawdsp.c
4 * ----------------------------------------------------------------------
5 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
7 * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
9 * GNU SHOGI is based on GNU CHESS
11 * Copyright (c) 1988, 1989, 1990 John Stanback
12 * Copyright (c) 1992 Free Software Foundation
14 * This file is part of GNU SHOGI.
16 * GNU Shogi is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 3 of the License,
19 * or (at your option) any later version.
21 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
22 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * for more details.
26 * You should have received a copy of the GNU General Public License along
27 * with GNU Shogi; see the file COPYING. If not, see
28 * <http://www.gnu.org/licenses/>.
29 * ----------------------------------------------------------------------
33 #include "gnushogi.h"
35 #include <ctype.h>
36 #include <signal.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/file.h>
42 #ifndef WIN32
43 #include <poll.h>
44 #include <unistd.h>
45 #endif
47 /****************************************
48 * forward declarations
49 ****************************************/
51 static void Raw_UpdateDisplay(short f, short t, short redraw, short isspec);
53 /****************************************
54 * Trivial output functions.
55 ****************************************/
57 static void
58 Raw_ClearScreen(void)
60 if (!XSHOGI)
61 printf("\n");
65 static void
66 Raw_ShowPrompt(void)
68 if (!XSHOGI)
69 fputs("\nYour move is? ", stdout);
73 static void
74 Raw_ShowCurrentMove(short pnt, short f, short t)
79 static void
80 Raw_ShowDepth(char ch)
82 if (!XSHOGI)
83 printf("Depth= %d%c \n", Sdepth, ch);
87 static void
88 Raw_ShowGameType(void)
90 if (flag.post)
91 printf("%c vs. %c\n", GameType[black], GameType[white]);
95 static void
96 Raw_ShowLine(unsigned short *bstline)
98 int i;
100 for (i = 1; bstline[i] > 0; i++)
102 if ((i > 1) && (i % 8 == 1))
103 printf("\n ");
105 algbr((short)(bstline[i] >> 8), (short)(bstline[i] & 0xFF), 0);
106 printf("%5s ", mvstr[0]);
109 printf("\n");
113 static void
114 Raw_ShowMessage(char *format, ...)
116 if (XSHOGI)
117 return;
118 va_list ap;
119 va_start(ap, format);
120 vprintf(format, ap);
121 printf("\n");
122 va_end(ap);
126 static void
127 Raw_AlwaysShowMessage(const char *format, ...)
129 va_list ap;
130 va_start(ap, format);
131 vprintf(format, ap);
132 printf("\n");
133 va_end(ap);
137 static void
138 Raw_Printf(const char *format, ...)
140 va_list ap;
141 va_start(ap, format);
142 vprintf(format, ap);
143 va_end(ap);
147 static void
148 Raw_doRequestInputString(const char* fmt, char* buffer)
150 scanf(fmt, buffer);
154 static int
155 Raw_GetString(char* sx)
157 int eof = 0;
158 char *nl;
159 sx[0] = '\0';
161 while(!eof && !sx[0])
162 eof = (fgets(sx, 80, stdin) == NULL);
164 /* remove any trailing newline */
165 nl = strchr(sx, '\n');
166 if (nl)
167 nl[0] = '\0';
169 return eof;
173 static void
174 Raw_ShowNodeCnt(long NodeCnt)
176 printf("Nodes = %ld Nodes/sec = %ld\n",
177 NodeCnt, (((et) ? ((NodeCnt * 100) / et) : 0)));
181 static void
182 Raw_ShowPatternCount(short side, short n)
184 if (flag.post)
185 printf("%s%s matches %d pattern(s)\n", xboard ? "# " : "" , ColorStr[side], n);
189 static void
190 Raw_ShowResponseTime(void)
195 static void
196 Raw_ShowResults(short score, unsigned short *bstline, char ch)
198 if (flag.post && (xboard || !XSHOGI))
200 ElapsedTime(2);
201 printf("%2d%c %6d %4ld %8ld ",
202 Sdepth, ch, score, et / 100, NodeCnt);
203 Raw_ShowLine(bstline);
208 static void
209 Raw_ShowSidetoMove(void)
214 static void
215 Raw_ShowStage(void)
217 printf("stage = %d\n", stage);
218 printf("balance[black] = %d balance[white] = %d\n",
219 balance[black], balance[white]);
222 /****************************************
223 * End of trivial output routines.
224 ****************************************/
226 static void
227 Raw_Initialize(void)
229 mycnt1 = mycnt2 = 0;
231 if (XSHOGI)
233 #ifdef WIN32
234 /* needed because of inconsistency between MSVC run-time system and gcc includes */
235 setbuf(stdout, NULL);
236 #else
237 #ifdef HAVE_SETVBUF
238 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
239 #else
240 # ifdef HAVE_SETLINEBUF
241 setlinebuf(stdout);
242 # else
243 # error "Need setvbuf() or setlinebuf() to compile gnushogi!"
244 # endif
245 #endif
246 #endif
247 printf("GNU Shogi %s\n", PACKAGE_VERSION);
250 if (hard_time_limit)
252 if (!TCflag && (MaxResponseTime == 0))
253 MaxResponseTime = 15L * 100L;
258 static void
259 Raw_ExitShogi(void)
261 /* CHECKME: what purpose does this next statement serve? */
262 signal(SIGTERM, SIG_IGN);
264 if (!nolist)
265 ListGame();
267 exit(0);
271 static void
272 Raw_TerminateSearch(int sig)
274 #ifdef INTERRUPT_TEST
275 ElapsedTime(INIT_INTERRUPT_MODE);
276 #endif
278 if (!flag.timeout)
279 flag.back = true; /* previous: flag.timeout = true; */
281 flag.bothsides = false;
285 static void
286 Raw_help(void)
288 Raw_ClearScreen();
289 printf("GNU Shogi %s command summary\n", PACKAGE_VERSION);
290 printf("----------------------------------------------------------------\n");
291 printf("7g7f move from 7g to 7f quit Exit Shogi\n");
292 printf("S6h move silver to 6h beep turn %s\n",
293 (flag.beep) ? "OFF" : "ON");
294 printf("2d2c+ move to 2c and promote\n");
295 printf("P*5e drop pawn to 5e easy turn %s\n",
296 (flag.easy) ? "OFF" : "ON");
297 printf("tsume toggle tsume mode hash turn %s\n",
298 (flag.hash) ? "OFF" : "ON");
299 printf("bd redraw board reverse board display\n");
300 printf("list game to shogi.lst book turn %s used %d of %d\n",
301 (Book) ? "OFF" : "ON", bookcount, booksize);
302 printf("undo undo last ply remove take back a move\n");
303 printf("edit edit board force toggle manual move mode\n");
304 printf("switch sides with computer both computer match\n");
305 printf("black computer plays black white computer plays white\n");
306 printf("sd set search depth clock set time control\n");
307 printf("post principle variation hint suggest a move\n");
308 printf("save game to file get game from file\n");
309 printf("xsave pos. to xshogi file xget pos. from xshogi file\n");
310 printf("random randomize play new start new game\n");
311 printf("setup first \n");
312 printf("go computer plays now\n");
313 printf("level time control gamein \n");
314 printf("time set engine clock otime set opponent clock\n");
315 printf("Awindow Bwindow \n");
316 printf("rcptr turn %3s bsave book save\n",
317 flag.rcptr ? "OFF" : "ON ");
318 printf("hashdepth hard turn easy OFF\n");
319 printf("contempt xwndw \n");
320 printf("moves \n");
321 printf("test p \n");
322 printf("debug depth alias for 'sd'\n");
323 printf("----------------------------------------------------------------\n");
324 printf("Computer: %-12s Opponent: %s\n",
325 ColorStr[computer], ColorStr[opponent]);
326 printf("Depth: %-12d Response time: %ld sec\n",
327 MaxSearchDepth, MaxResponseTime/100);
328 printf("Random: %-12s Easy mode: %s\n",
329 (dither) ? "ON" : "OFF", (flag.easy) ? "ON" : "OFF");
330 printf("Beep: %-12s Transposition file: %s\n",
331 (flag.beep) ? "ON" : "OFF", (flag.hash) ? "ON" : "OFF");
332 printf("Tsume: %-12s Force: %s\n",
333 (flag.tsume) ? "ON" : "OFF", (flag.force) ? "ON" : "OFF");
334 printf("Time Control %s %d moves %ld sec %d add %d depth\n",
335 (TCflag) ? "ON" : "OFF",
336 TimeControl.moves[black], TimeControl.clock[black] / 100,
337 TCadd/100, MaxSearchDepth);
342 * Set up a board position. Pieces are entered by typing the piece followed
343 * by the location. For example, Nf3 will place a knight on square f3.
345 static void
346 Raw_EditBoard(void)
348 short a, r, c, sq, i, found;
349 char s[80];
351 flag.regularstart = true;
352 Book = BOOKFAIL;
353 Raw_ClearScreen();
354 Raw_UpdateDisplay(0, 0, 1, 0);
355 printf(". Exit to main\n");
356 printf("# Clear board\n");
357 printf("c Change sides\n");
358 printf("enter piece & location:\n");
360 a = black;
362 while(1)
364 scanf("%s", s);
365 found = 0;
367 if (s[0] == '.')
368 break;
370 if (s[0] == '#')
372 for (sq = 0; sq < NO_SQUARES; sq++)
374 board[sq] = no_piece;
375 color[sq] = neutral;
378 ClearCaptured();
379 continue;
382 if (s[0] == 'c') {
383 a = otherside[a];
384 continue;
387 if (s[1] == '*')
389 for (i = pawn; i <= king; i++)
391 if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
393 Captured[a][i]++;
394 found = 1;
395 break;
398 if (!found)
399 printf("# Invalid piece type '%c'\n", s[0]);
400 continue;
403 c = COL_NUM(s[1]);
404 r = ROW_NUM(s[2]);
406 if ((c < 0) || (c >= NO_COLS) || (r < 0) || (r >= NO_ROWS)) {
407 printf("# Out-of-board position '%c%c'\n", s[1], s[2]);
408 continue;
411 sq = locn(r, c);
413 for (i = no_piece; i <= king; i++)
415 if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
417 color[sq] = a;
418 if (s[3] == '+')
419 board[sq] = promoted[i];
420 else
421 board[sq] = i;
423 found = 1;
424 break;
428 if (!found)
429 printf("# Invalid piece type '%c'\n", s[0]);
432 for (sq = 0; sq < NO_SQUARES; sq++)
433 Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
435 GameCnt = 0;
436 Game50 = 1;
437 ZeroRPT();
438 Sdepth = 0;
439 InitializeStats();
440 Raw_ClearScreen();
441 Raw_UpdateDisplay(0, 0, 1, 0);
446 * Set up a board position.
447 * Nine lines of nine characters are used to setup the board. 9a-1a is the
448 * first line. White pieces are represented by uppercase characters.
450 static void
451 Raw_SetupBoard(void)
453 short r, c, sq, i;
454 char ch;
455 char s[80];
457 NewGame();
459 fgets(s, 80, stdin); /* skip "setup" command */
461 for (r = NO_ROWS - 1; r >= 0; r--)
463 fgets(s, 80, stdin);
465 for (c = 0; c <= (NO_COLS - 1); c++)
467 ch = s[c];
468 sq = locn(r, c);
469 color[sq] = neutral;
470 board[sq] = no_piece;
472 for (i = no_piece; i <= king; i++)
474 if (ch == pxx[i])
476 color[sq] = white;
477 board[sq] = i;
478 break;
480 else if (ch == qxx[i])
482 color[sq] = black;
483 board[sq] = i;
484 break;
490 for (sq = 0; sq < NO_SQUARES; sq++)
491 Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
493 InitializeStats();
494 Raw_ClearScreen();
495 Raw_UpdateDisplay(0, 0, 1, 0);
496 fputs("Setup successful\n", stdout);
500 static void
501 Raw_SearchStartStuff(short side)
503 if (flag.post)
505 printf("\nMove# %d Target = %ld Clock: %ld\n",
506 GameCnt/2 + 1,
507 ResponseTime, TimeControl.clock[side]);
512 static void
513 Raw_OutputMove(void)
515 if (flag.illegal)
517 printf("Illegal position.\n");
518 return;
521 if (mvstr[0][0] == '\0')
522 goto nomove;
524 mycnt1++;
525 if (XSHOGI && xboard) /* xboard: print move in XBoard format, with 'move' prefix */
526 printf("move %s\n", mvstr[0]);
527 else if (XSHOGI)
528 /* add remaining time in milliseconds to xshogi */
529 printf("%d. ... %s %ld\n", mycnt1, mvstr[0],
530 (TimeControl.clock[player] - et) * 10);
531 else
532 printf("%d. ... %s\n", mycnt1, mvstr[0]);
534 nomove:
535 if ((root->flags & draw) || (root->score == -(SCORE_LIMIT + 999))
536 || (root->score == (SCORE_LIMIT + 998)))
537 goto summary;
539 if (flag.post)
541 short h, l, t;
543 h = TREE;
544 l = 0;
545 t = TREE >> 1;
547 while (l != t)
549 if (Tree[t].f || Tree[t].t)
550 l = t;
551 else
552 h = t;
554 t = (l + h) >> 1;
557 printf("Gen %ld Node %ld Tree %d Eval %ld Rate %ld EC %d/%d RS hi %ld lo %ld \n", GenCnt, NodeCnt, t, EvalNodes,
558 (et > 100) ? (NodeCnt / (et / 100)) : 0,
559 EADD, EGET, reminus, replus);
561 printf("Hin/Hout/Tcol/Coll/Fin/Fout = %ld/%ld/%ld/%ld/%ld/%ld\n",
562 HashAdd, HashCnt, THashCol, HashCol, FHashCnt, FHashAdd);
565 Raw_UpdateDisplay(root->f, root->t, 0, root->flags);
567 if (!XSHOGI)
569 printf("My move is: %5s\n", mvstr[0]);
571 if (flag.beep)
572 printf("%c", 7);
575 summary:
576 if (root->flags & draw)
577 fputs("Drawn game!\n", stdout);
578 else if (root->score == -(SCORE_LIMIT + 999))
579 printf("%s mates!\n", ColorStr[opponent]);
580 else if (root->score == (SCORE_LIMIT + 998))
581 printf("%s mates!\n", ColorStr[computer]);
582 #ifdef VERYBUGGY
583 else if (!XSHOGI && (root->score < -SCORE_LIMIT))
584 printf("%s%s has a forced mate in %d moves!\n", xboard ? "# " : "",
585 ColorStr[opponent], SCORE_LIMIT + 999 + root->score - 1);
586 else if (!XSHOGI && (root->score > SCORE_LIMIT))
587 printf("%s%s has a forced mate in %d moves!\n", xboard ? "# " : "",
588 ColorStr[computer], SCORE_LIMIT + 998 - root->score - 1);
589 #endif /* VERYBUGGY */
593 static void
594 Raw_UpdateClocks(void)
599 static void
600 Raw_UpdateDisplay(short f, short t, short redraw, short isspec)
603 short r, c, l, m;
605 if (redraw && !XSHOGI)
607 printf("\n");
608 r = (short)(TimeControl.clock[black] / 6000);
609 c = (short)((TimeControl.clock[black] % 6000) / 100);
610 l = (short)(TimeControl.clock[white] / 6000);
611 m = (short)((TimeControl.clock[white] % 6000) / 100);
612 printf("Black %d:%02d White %d:%02d\n", r, c, l, m);
613 printf("\n");
615 for (r = (NO_ROWS - 1); r >= 0; r--)
617 for (c = 0; c <= (NO_COLS - 1); c++)
619 char pc;
620 l = ((flag.reverse)
621 ? locn((NO_ROWS - 1) - r, (NO_COLS - 1) - c)
622 : locn(r, c));
623 pc = (is_promoted[board[l]] ? '+' : ' ');
625 if (color[l] == neutral)
626 printf(" -");
627 else if (color[l] == black)
628 printf("%c%c", pc, qxx[board[l]]);
629 else
630 printf("%c%c", pc, pxx[board[l]]);
633 printf("\n");
636 printf("\n");
638 short side;
640 for (side = black; side <= white; side++)
642 short piece, c;
643 printf((side == black)?"black ":"white ");
645 for (piece = pawn; piece <= king; piece++)
647 if ((c = Captured[side][piece]))
648 printf("%i%c ", c, pxx[piece]);
651 printf("\n");
658 static void
659 Raw_ChangeAlphaWindow(void)
661 printf("WAwindow: ");
662 scanf("%hd", &WAwindow);
663 printf("BAwindow: ");
664 scanf("%hd", &BAwindow);
668 static void
669 Raw_ChangeBetaWindow(void)
671 printf("WBwindow: ");
672 scanf("%hd", &WBwindow);
673 printf("BBwindow: ");
674 scanf("%hd", &BBwindow);
678 static void
679 Raw_GiveHint(void)
681 if (hint)
683 algbr((short) (hint >> 8), (short) (hint & 0xFF), 0);
684 printf("Hint: %s\n", mvstr[0]);
686 else
687 fputs("I have no idea.\n", stdout);
691 static void
692 Raw_SelectLevel(char *sx)
694 /* FIXME: NO_SQUARES is nonsense here */
695 char T[NO_SQUARES + 1], *p;
697 strncpy(T, sx, NO_SQUARES);
698 T[NO_SQUARES] = '\0';
701 if (!xboard) {
702 /* if line empty, ask for input */
703 if (!T[0])
705 fputs("Enter #moves #minutes: ", stdout);
706 fgets(T, NO_SQUARES + 1, stdin);
709 /* skip blackspace */
710 for (p = T; *p == ' '; p++) ;
712 /* could be moves or a fischer clock */
713 if (*p == 'f')
715 /* its a fischer clock game */
716 char *q;
717 p++;
718 TCminutes = (short)strtol(p, &q, 10);
719 TCadd = (short)strtol(q, NULL, 10) *100;
720 TCseconds = 0;
721 TCmoves = 50;
723 else
725 /* regular game */
726 char *q;
727 TCadd = 0;
728 TCmoves = (short)strtol(p, &q, 10);
729 TCminutes = (short)strtol(q, &q, 10);
731 if (*q == ':')
732 TCseconds = (short)strtol(q + 1, (char **) NULL, 10);
733 else
734 TCseconds = 0;
736 #ifdef OPERATORTIME
737 fputs("Operator time (hundredths) = ", stdout);
738 scanf("%hd", &OperatorTime);
739 #endif
741 if (TCmoves == 0)
743 TCflag = false;
744 MaxResponseTime = TCminutes*60L * 100L + TCseconds * 100L;
745 TCminutes = TCseconds = 0;
747 else
749 TCflag = true;
750 MaxResponseTime = 0;
753 } else {
754 int min, sec=0, inc, mps;
755 /* parse regular "level MPS TC INC" command of WB protocol */
756 if (sscanf(sx, "%d %d %d", &mps, &min, &inc) != 3)
757 sscanf(sx, "%d %d:%d %d", &mps, &min, &sec, &inc);
758 TCminutes = min; TCseconds = sec;
759 TCadd = inc*100; TCmoves = mps ? mps : 50;
760 MaxResponseTime = 0; TCflag = true;
763 TimeControl.clock[black] = TimeControl.clock[white] = 0;
764 SetTimeControl();
766 if (XSHOGI)
768 printf("Clocks: %ld %ld\n",
769 TimeControl.clock[black] * 10,
770 TimeControl.clock[white] * 10);
775 static void
776 Raw_ChangeSearchDepth(char *sx)
778 char buf[80+1];
779 strncpy(buf, sx, 80); buf[80] = '\0';
780 /* if line empty, ask for input */
781 if (!buf[0]) {
782 printf("depth = ");
783 fgets(buf, 80+1, stdin);
785 sscanf(buf, "%hd", &MaxSearchDepth);
786 TCflag = !(MaxSearchDepth > 0);
790 static void
791 Raw_ChangeHashDepth(void)
793 printf("hashdepth = ");
794 scanf("%hd", &HashDepth);
795 printf("MoveLimit = ");
796 scanf("%hd", &HashMoveLimit);
800 static void
801 Raw_SetContempt(void)
803 printf("contempt = ");
804 scanf("%hd", &contempt);
808 static void
809 Raw_ChangeXwindow(void)
811 printf("xwndw = ");
812 scanf("%hd", &xwndw);
817 * Raw_ShowPostnValue(short sq)
818 * must have called ExaminePosition() first
820 static void
821 Raw_ShowPostnValue(short sq)
823 (void) ScorePosition(color[sq]);
825 if (color[sq] != neutral)
827 #if defined SAVE_SVALUE
828 printf("???%c ", (color[sq] == white)?'b':'w');
829 #else
830 printf("%3d%c ", svalue[sq], (color[sq] == white)?'b':'w');
831 #endif
833 else
835 printf(" * ");
840 static void
841 Raw_DoDebug(void)
843 short c, p, sq, tp, tc, tsq, score, j, k;
844 char s[40];
846 ExaminePosition(opponent);
847 Raw_ShowMessage("Enter piece: ");
848 scanf("%s", s);
849 c = neutral;
851 if ((s[0] == 'b') || (s[0] == 'B'))
852 c = black;
854 if ((s[0] == 'w') || (s[0] == 'W'))
855 c = white;
857 for (p = king; p > no_piece; p--)
859 if ((s[1] == pxx[p]) || (s[1] == qxx[p]))
860 break;
863 if (p > no_piece)
865 for (j = (NO_ROWS - 1); j >= 0; j--)
867 for (k = 0; k < (NO_COLS); k++)
869 sq = j*(NO_COLS) + k;
870 tp = board[sq];
871 tc = color[sq];
872 board[sq] = p;
873 color[sq] = c;
874 tsq = PieceList[c][1];
875 PieceList[c][1] = sq;
876 Raw_ShowPostnValue(sq);
877 PieceList[c][1] = tsq;
878 board[sq] = tp;
879 color[sq] = tc;
882 printf("\n");
886 score = ScorePosition(opponent);
888 for (j = (NO_ROWS - 1); j >= 0; j--)
890 for (k = 0; k < (NO_COLS); k++)
892 sq = j*(NO_COLS) + k;
894 if (color[sq] != neutral)
896 #if defined SAVE_SVALUE
897 printf("%?????%c ", (color[sq] == white)?'b':'w');
898 #else
899 printf("%5d%c ", svalue[sq], (color[sq] == white)?'b':'w');
900 #endif
902 else
904 printf(" * ");
908 printf("\n");
911 printf("stage = %d\n", stage);
912 printf("S%d m%d ps%d gt%c m%d ps%d gt%c", score,
913 mtl[computer], pscore[computer], GameType[computer],
914 mtl[opponent], pscore[opponent], GameType[opponent]);
918 static void
919 Raw_DoTable(short table[NO_SQUARES])
921 short sq, j, k;
922 ExaminePosition(opponent);
924 for (j = (NO_ROWS - 1); j >= 0; j--)
926 for (k = 0; k < NO_COLS; k++)
928 sq = j*(NO_ROWS) + k;
929 printf("%3d ", table[sq]);
932 printf("\n");
937 static void
938 Raw_ShowPostnValues(void)
940 short sq, score, j, k;
941 ExaminePosition(opponent);
943 for (j = (NO_ROWS - 1); j >= 0; j--)
945 for (k = 0; k < NO_COLS; k++)
947 sq = j * NO_COLS + k;
948 Raw_ShowPostnValue(sq);
951 printf("\n");
954 score = ScorePosition(opponent);
955 printf("S%d m%d ps%d gt%c m%d ps%d gt%c", score,
956 mtl[computer], pscore[computer], GameType[computer],
957 mtl[opponent], pscore[opponent], GameType[opponent]);
958 printf("\nhung black %d hung white %d\n", hung[black], hung[white]);
962 static void
963 Raw_PollForInput(void)
965 #ifdef WIN32
966 DWORD cnt;
967 if (!PeekNamedPipe(GetStdHandle(STD_INPUT_HANDLE), NULL, 0, NULL, &cnt, NULL))
968 cnt = 1;
969 #else
970 static struct pollfd pollfds[1] = { [0] = { .fd = STDIN_FILENO,
971 .events = POLLIN } };
972 int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0);
973 if (cnt < 0) {
974 perror("polling standard input");
975 Raw_ExitShogi();
977 #endif
978 if (cnt) { /* if anything to read, or error occured */
979 if (!flag.timeout)
980 flag.back = true; /* previous: flag.timeout = true; */
981 flag.bothsides = false;
985 struct display raw_display =
987 .ChangeAlphaWindow = Raw_ChangeAlphaWindow,
988 .ChangeBetaWindow = Raw_ChangeBetaWindow,
989 .ChangeHashDepth = Raw_ChangeHashDepth,
990 .ChangeSearchDepth = Raw_ChangeSearchDepth,
991 .ChangeXwindow = Raw_ChangeXwindow,
992 .ClearScreen = Raw_ClearScreen,
993 .DoDebug = Raw_DoDebug,
994 .DoTable = Raw_DoTable,
995 .EditBoard = Raw_EditBoard,
996 .ExitShogi = Raw_ExitShogi,
997 .GiveHint = Raw_GiveHint,
998 .Initialize = Raw_Initialize,
999 .ShowNodeCnt = Raw_ShowNodeCnt,
1000 .OutputMove = Raw_OutputMove,
1001 .PollForInput = Raw_PollForInput,
1002 .SetContempt = Raw_SetContempt,
1003 .SearchStartStuff = Raw_SearchStartStuff,
1004 .SelectLevel = Raw_SelectLevel,
1005 .ShowCurrentMove = Raw_ShowCurrentMove,
1006 .ShowDepth = Raw_ShowDepth,
1007 .ShowGameType = Raw_ShowGameType,
1008 .ShowLine = Raw_ShowLine,
1009 .ShowMessage = Raw_ShowMessage,
1010 .AlwaysShowMessage = Raw_AlwaysShowMessage,
1011 .Printf = Raw_Printf,
1012 .doRequestInputString = Raw_doRequestInputString,
1013 .GetString = Raw_GetString,
1014 .SetupBoard = Raw_SetupBoard,
1015 .ShowPatternCount = Raw_ShowPatternCount,
1016 .ShowPostnValue = Raw_ShowPostnValue,
1017 .ShowPostnValues = Raw_ShowPostnValues,
1018 .ShowPrompt = Raw_ShowPrompt,
1019 .ShowResponseTime = Raw_ShowResponseTime,
1020 .ShowResults = Raw_ShowResults,
1021 .ShowSidetoMove = Raw_ShowSidetoMove,
1022 .ShowStage = Raw_ShowStage,
1023 .TerminateSearch = Raw_TerminateSearch,
1024 .UpdateClocks = Raw_UpdateClocks,
1025 .UpdateDisplay = Raw_UpdateDisplay,
1026 .help = Raw_help,