bf3f4c1cd1fa58ebe2f282a30d9bfedabf2853f5
[gnushogi.git] / gnushogi / rawdsp.c
1 /*
2  * FILE: rawdsp.c
3  *
4  * ----------------------------------------------------------------------
5  * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6  * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
7  *
8  * GNU SHOGI is based on GNU CHESS
9  *
10  * Copyright (c) 1988, 1989, 1990 John Stanback
11  * Copyright (c) 1992 Free Software Foundation
12  *
13  * This file is part of GNU SHOGI.
14  *
15  * GNU Shogi is free software; you can redistribute it and/or modify it
16  * under the terms of the GNU General Public License as published by the
17  * Free Software Foundation; either version 3 of the License,
18  * or (at your option) any later version.
19  *
20  * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
21  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with GNU Shogi; see the file COPYING. If not, see
27  * <http://www.gnu.org/licenses/>.
28  * ----------------------------------------------------------------------
29  *
30  */
31
32 #include <ctype.h>
33 #include <signal.h>
34 #include <stdarg.h>
35 #include <stdio.h>
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/file.h>
39 #ifndef WIN32
40 #include <poll.h>
41 #include <unistd.h>
42 #endif
43
44 #include "gnushogi.h"
45
46 unsigned short MV[MAXDEPTH];
47 int MSCORE;
48
49 int mycnt1, mycnt2;
50 char *DRAW;
51 extern char *InPtr;
52 extern short pscore[];
53
54 /****************************************
55  * forward declarations
56  ****************************************/
57
58 void Raw_UpdateDisplay(short f, short t, short redraw, short isspec);
59
60 /****************************************
61  * Trivial output functions.
62  ****************************************/
63
64 void
65 Raw_ClearScreen(void)
66 {
67     if (!barebones && !XSHOGI)
68         printf("\n");
69 }
70
71
72 void
73 Raw_ShowPrompt(void)
74 {
75     if (!barebones && !XSHOGI)
76     {
77         fputs("\nYour move is? ", stdout);
78     }
79 }
80
81
82 void
83 Raw_ShowCurrentMove(short pnt, short f, short t)
84 {
85 }
86
87
88 void
89 Raw_ShowDepth(char ch)
90 {
91     if (!barebones && !XSHOGI)
92     {
93         printf("Depth= %d%c ", Sdepth, ch);
94         printf("\n");
95     }
96 }
97
98
99 void
100 Raw_ShowGameType(void)
101 {
102     if (flag.post)
103         printf("%c vs. %c\n", GameType[black], GameType[white]);
104 }
105
106
107 void
108 Raw_ShowLine(unsigned short *bstline)
109 {
110     int i;
111
112     for (i = 1; bstline[i] > 0; i++)
113     {
114         if ((i > 1) && (i % 8 == 1))
115             printf("\n                          ");
116
117         algbr((short)(bstline[i] >> 8), (short)(bstline[i] & 0xFF), false);
118         printf("%5s ", mvstr[0]);
119     }
120
121     printf("\n");
122 }
123
124
125 void
126 Raw_ShowMessage(char *s)
127 {
128     if (!XSHOGI)
129         printf("%s\n", s);
130 }
131
132
133 void
134 Raw_AlwaysShowMessage(const char *format, ...)
135 {
136     va_list ap;
137     va_start(ap, format);
138     vprintf(format, ap);
139     printf("\n");
140     va_end(ap);
141 }
142
143
144 void
145 Raw_Printf(const char *format, ...)
146 {
147     va_list ap;
148     va_start(ap, format);
149     vprintf(format, ap);
150     va_end(ap);
151 }
152
153
154 void
155 Raw_doRequestInputString(const char* fmt, char* buffer)
156 {
157     scanf(fmt, buffer);
158 }
159
160
161 int
162 Raw_GetString(char* sx)
163 {
164     int eof = 0;
165     char *nl;
166     sx[0] = '\0';
167
168     while(!eof && !sx[0])
169         eof = (fgets(sx, 80, stdin) == NULL);
170
171     /* remove any trailing newline */
172     nl = strchr(sx, '\n');
173     if (nl)
174         nl[0] = '\0';
175
176     return eof;
177 }
178
179
180 void
181 Raw_ShowNodeCnt(long NodeCnt)
182 {
183     printf("Nodes = %ld Nodes/sec = %ld\n",
184            NodeCnt, (((et) ? ((NodeCnt * 100) / et) : 0)));
185 }
186
187
188 void
189 Raw_ShowPatternCount(short side, short n)
190 {
191     if (flag.post)
192         printf("%s matches %d pattern(s)\n", ColorStr[side], n);
193 }
194
195
196 void
197 Raw_ShowResponseTime(void)
198 {
199 }
200
201
202 void
203 Raw_ShowResults(short score, unsigned short *bstline, char ch)
204 {
205     if (flag.post  && !XSHOGI)
206     {
207         ElapsedTime(2);
208         printf("%2d%c %6d %4ld %8ld  ",
209                Sdepth, ch, score, et / 100, NodeCnt);
210         Raw_ShowLine(bstline);
211     }
212 }
213
214
215 void
216 Raw_ShowSidetoMove(void)
217 {
218 }
219
220
221 void
222 Raw_ShowStage(void)
223 {
224     printf("stage = %d\n", stage);
225     printf("balance[black] = %d balance[white] = %d\n",
226            balance[black], balance[white]);
227 }
228
229 /****************************************
230  * End of trivial output routines.
231  ****************************************/
232
233 void
234 Raw_Initialize(void)
235 {
236     mycnt1 = mycnt2 = 0;
237
238     if (XSHOGI)
239     {
240 #ifdef WIN32
241         /* needed because of inconsistency between MSVC run-time system and gcc includes */
242         setbuf(stdout, NULL);
243 #else
244 #ifdef HAVE_SETLINEBUF
245         setlinebuf(stdout);
246 #else
247 #  ifdef HAVE_SETVBUF
248         setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
249 #  else
250 #    error "Need setlinebuf() or setvbuf() to compile gnushogi!"
251 #  endif
252 #endif
253 #endif
254         printf("GNU Shogi %s\n", PACKAGE_VERSION);
255     }
256
257     if (hard_time_limit)
258     {
259         if (!TCflag && (MaxResponseTime == 0))
260             MaxResponseTime = 15L * 100L;
261     }
262 }
263
264
265 void
266 Raw_ExitShogi(void)
267 {
268     /* CHECKME: what purpose does this next statement serve? */
269     signal(SIGTERM, SIG_IGN);
270
271     if (!nolist)
272         ListGame();
273
274     exit(0);
275 }
276
277
278 void
279 Raw_Die(int sig)
280 {
281     char s[80];
282
283     Raw_ShowMessage("Abort? ");
284     scanf("%s", s);
285
286     if (strcmp(s, "yes") == 0)
287         Raw_ExitShogi();
288 }
289
290
291 void
292 Raw_TerminateSearch(int sig)
293 {
294 #ifdef INTERRUPT_TEST
295     ElapsedTime(INIT_INTERRUPT_MODE);
296 #endif
297
298     if (!flag.timeout)
299         flag.back = true; /* previous: flag.timeout = true; */
300
301     flag.bothsides = false;
302 }
303
304
305 void
306 Raw_help(void)
307 {
308     Raw_ClearScreen();
309     printf("GNU Shogi %s command summary\n", PACKAGE_VERSION);
310     printf("----------------------------------"
311            "------------------------------\n");
312     fputs ("7g7f      move from 7g to 7f      quit      Exit Shogi\n", stdout);
313     printf("S6h       move silver to 6h       beep      turn %s\n", (flag.beep) ? "OFF" : "ON");
314     printf("2d2c+     move to 2c and promote  material  turn %s\n", (flag.material) ? "OFF" : "ON");
315     printf("P*5e      drop pawn to 5e         easy      turn %s\n", (flag.easy) ? "OFF" : "ON");
316     printf("tsume     toggle tsume mode       hash      turn %s\n", (flag.hash) ? "OFF" : "ON");
317     fputs ("bd        redraw board            reverse   board display\n", stdout);
318     printf("list      game to shogi.lst       book      turn %s used %d of %d\n", (Book) ? "OFF" : "ON", bookcount, booksize);
319     fputs ("undo      undo last ply           remove    take back a move\n", stdout);
320     fputs ("edit      edit board              force     toggle manual move mode\n", stdout);
321     fputs ("switch    sides with computer     both      computer match\n", stdout);
322     fputs ("black     computer plays black    white     computer plays white\n", stdout);
323     fputs ("depth     set search depth        clock     set time control\n", stdout);
324     fputs ("post      principle variation     hint      suggest a move\n", stdout);
325     fputs ("save      game to file            get       game from file\n", stdout);
326     printf("xsave     pos. to xshogi file     xget"
327            "      pos. from xshogi file\n");
328     fputs("random    randomize play          new       start new game\n", stdout);
329     printf("--------------------------------"
330            "--------------------------------\n");
331     printf("Computer: %-12s Opponent:            %s\n",
332            ColorStr[computer], ColorStr[opponent]);
333     printf("Depth:    %-12d Response time:       %ld sec\n",
334            MaxSearchDepth, MaxResponseTime/100);
335     printf("Random:   %-12s Easy mode:           %s\n",
336            (dither) ? "ON" : "OFF", (flag.easy) ? "ON" : "OFF");
337     printf("Beep:     %-12s Transposition file:  %s\n",
338            (flag.beep) ? "ON" : "OFF", (flag.hash) ? "ON" : "OFF");
339     printf("Tsume:    %-12s Force:               %s\n",
340            (flag.tsume) ? "ON" : "OFF", (flag.force) ? "ON" : "OFF");
341     printf("Time Control %s %d moves %ld sec %d add %d depth\n",
342            (TCflag) ? "ON" : "OFF",
343            TimeControl.moves[black], TimeControl.clock[black] / 100,
344            TCadd/100, MaxSearchDepth);
345 }
346
347
348 /*
349  * Set up a board position. Pieces are entered by typing the piece followed
350  * by the location. For example, Nf3 will place a knight on square f3.
351  */
352 void
353 Raw_EditBoard(void)
354 {
355     short a, r, c, sq, i, found;
356     char s[80];
357
358     flag.regularstart = true;
359     Book = BOOKFAIL;
360     Raw_ClearScreen();
361     Raw_UpdateDisplay(0, 0, 1, 0);
362     fputs(".   Exit to main\n", stdout);
363     fputs("#   Clear board\n", stdout);
364     fputs("c   Change sides\n", stdout);
365     fputs("enter piece & location: \n", stdout);
366
367     a = black;
368
369     do
370     {
371         scanf("%s", s);
372         found = 0;
373
374         if (s[0] == '#')
375         {
376             for (sq = 0; sq < NO_SQUARES; sq++)
377             {
378                 board[sq] = no_piece;
379                 color[sq] = neutral;
380             }
381
382             ClearCaptured();
383         }
384
385         if (s[0] == 'c')
386             a = otherside[a];
387
388         if (s[1] == '*')
389         {
390             for (i = pawn; i <= king; i++)
391             {
392                 if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
393                 {
394                     Captured[a][i]++;
395                     found = 1;
396                     break;
397                 }
398             }
399
400             c = -1;
401             r = -1;
402         }
403         else
404         {
405             c = COL_NAME(s[1]);
406             r = ROW_NAME(s[2]);
407         }
408
409         if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS))
410         {
411             sq = locn(r, c);
412             color[sq] = a;
413             board[sq] = no_piece;
414
415             for (i = no_piece; i <= king; i++)
416             {
417                 if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
418                 {
419                     if (s[3] == '+')
420                         board[sq] = promoted[i];
421                     else
422                         board[sq] = i;
423
424                     found = 1;
425                     break;
426                 }
427             }
428
429             if (found == 0)
430                 color[sq] = neutral;
431         }
432     }
433     while (s[0] != '.');
434
435     for (sq = 0; sq < NO_SQUARES; sq++)
436         Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
437
438     GameCnt = 0;
439     Game50 = 1;
440     ZeroRPT();
441     Sdepth = 0;
442     InitializeStats();
443     Raw_ClearScreen();
444     Raw_UpdateDisplay(0, 0, 1, 0);
445 }
446
447
448 /*
449  * Set up a board position.
450  * Nine lines of nine characters are used to setup the board. 9a-1a is the
451  * first line. White pieces are  represented  by  uppercase characters.
452  */
453 void
454 Raw_SetupBoard(void)
455 {
456     short r, c, sq, i;
457     char ch;
458     char s[80];
459
460     NewGame();
461
462     fgets(s, 80, stdin);            /* skip "setup" command */
463
464     for (r = NO_ROWS - 1; r >= 0; r--)
465     {
466         fgets(s, 80, stdin);
467
468         for (c = 0; c <= (NO_COLS - 1); c++)
469         {
470             ch = s[c];
471             sq = locn(r, c);
472             color[sq] = neutral;
473             board[sq] = no_piece;
474
475             for (i = no_piece; i <= king; i++)
476             {
477                 if (ch == pxx[i])
478                 {
479                     color[sq] = white;
480                     board[sq] = i;
481                     break;
482                 }
483                 else if (ch == qxx[i])
484                 {
485                     color[sq] = black;
486                     board[sq] = i;
487                     break;
488                 }
489             }
490         }
491     }
492
493     for (sq = 0; sq < NO_SQUARES; sq++)
494         Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
495
496     InitializeStats();
497     Raw_ClearScreen();
498     Raw_UpdateDisplay(0, 0, 1, 0);
499     fputs("Setup successful\n", stdout);
500 }
501
502
503 void
504 Raw_SearchStartStuff(short side)
505 {
506     if (flag.post)
507     {
508         printf("\nMove# %d    Target = %ld    Clock: %ld\n",
509                GameCnt/2 + 1,
510                ResponseTime, TimeControl.clock[side]);
511     }
512 }
513
514
515 void
516 Raw_OutputMove(void)
517 {
518     if (flag.illegal)
519     {
520         printf("Illegal position.\n");
521         return;
522     }
523
524     if (mvstr[0][0] == '\0')
525         goto nomove;
526
527     if (XSHOGI)
528     {
529         /* add remaining time in milliseconds to xshogi */
530         printf("%d. ... %s %ld\n", ++mycnt1, mvstr[0],
531                (TimeControl.clock[player] - et) * 10);
532     }
533     else
534     {
535         printf("%d. ... %s\n", ++mycnt1, mvstr[0]);
536     }
537
538  nomove:
539     if ((root->flags & draw) || (root->score == -(SCORE_LIMIT + 999))
540         || (root->score == (SCORE_LIMIT + 998)))
541         goto summary;
542
543     if (flag.post)
544     {
545         short h, l, t;
546
547         h = TREE;
548         l = 0;
549         t = TREE >> 1;
550
551         while (l != t)
552         {
553             if (Tree[t].f || Tree[t].t)
554                 l = t;
555             else
556                 h = t;
557
558             t = (l + h) >> 1;
559         }
560
561         printf("Gen %ld Node %ld Tree %d Eval %ld Rate %ld EC %d/%d RS hi %ld lo %ld \n", GenCnt, NodeCnt, t, EvalNodes,
562                (et > 100) ? (NodeCnt / (et / 100)) : 0,
563                EADD, EGET, reminus, replus);
564
565         printf("Hin/Hout/Tcol/Coll/Fin/Fout = %ld/%ld/%ld/%ld/%ld/%ld\n",
566                HashAdd, HashCnt, THashCol, HashCol, FHashCnt, FHashAdd);
567     }
568
569     Raw_UpdateDisplay(root->f, root->t, 0, root->flags);
570
571     if (!XSHOGI)
572     {
573         printf("My move is: %5s\n", mvstr[0]);
574
575         if (flag.beep)
576             printf("%c", 7);
577     }
578
579  summary:
580     if (root->flags & draw)
581     {
582         fputs("Drawn game!\n", stdout);
583     }
584     else if (root->score == -(SCORE_LIMIT + 999))
585     {
586         printf("%s mates!\n", ColorStr[opponent]);
587     }
588     else if (root->score == (SCORE_LIMIT + 998))
589     {
590         printf("%s mates!\n", ColorStr[computer]);
591     }
592 #ifdef VERYBUGGY
593     else if (!barebones && (root->score < -SCORE_LIMIT))
594     {
595         printf("%s has a forced mate in %d moves!\n",
596                ColorStr[opponent], SCORE_LIMIT + 999 + root->score - 1);
597     }
598     else if (!barebones && (root->score > SCORE_LIMIT))
599     {
600         printf("%s has a forced mate in %d moves!\n",
601                ColorStr[computer], SCORE_LIMIT + 998 - root->score - 1);
602     }
603 #endif /* VERYBUGGY */
604 }
605
606
607 void
608 Raw_UpdateClocks(void)
609 {
610 }
611
612
613 void
614 Raw_UpdateDisplay(short f, short t, short redraw, short isspec)
615 {
616
617     short r, c, l, m;
618
619     if (redraw && !XSHOGI)
620     {
621         printf("\n");
622         r = (short)(TimeControl.clock[black] / 6000);
623         c = (short)((TimeControl.clock[black] % 6000) / 100);
624         l = (short)(TimeControl.clock[white] / 6000);
625         m = (short)((TimeControl.clock[white] % 6000) / 100);
626         printf("Black %d:%02d  White %d:%02d\n", r, c, l, m);
627         printf("\n");
628
629         for (r = (NO_ROWS - 1); r >= 0; r--)
630         {
631             for (c = 0; c <= (NO_COLS - 1); c++)
632             {
633                 char pc;
634                 l = ((flag.reverse)
635                      ? locn((NO_ROWS - 1) - r, (NO_COLS - 1) - c)
636                      : locn(r, c));
637                 pc = (is_promoted[board[l]] ? '+' : ' ');
638
639                 if (color[l] == neutral)
640                     printf(" -");
641                 else if (color[l] == black)
642                     printf("%c%c", pc, qxx[board[l]]);
643                 else
644                     printf("%c%c", pc, pxx[board[l]]);
645             }
646
647             printf("\n");
648         }
649
650         printf("\n");
651         {
652             short side;
653
654             for (side = black; side <= white; side++)
655             {
656                 short piece, c;
657                 printf((side == black)?"black ":"white ");
658
659                 for (piece = pawn; piece <= king; piece++)
660                 {
661                     if ((c = Captured[side][piece]))
662                         printf("%i%c ", c, pxx[piece]);
663                 }
664
665                 printf("\n");
666             }
667         }
668     }
669 }
670
671
672 void
673 Raw_ChangeAlphaWindow(void)
674 {
675     printf("WAwindow: ");
676     scanf("%hd", &WAwindow);
677     printf("BAwindow: ");
678     scanf("%hd", &BAwindow);
679 }
680
681
682 void
683 Raw_ChangeBetaWindow(void)
684 {
685     printf("WBwindow: ");
686     scanf("%hd", &WBwindow);
687     printf("BBwindow: ");
688     scanf("%hd", &BBwindow);
689 }
690
691
692 void
693 Raw_GiveHint(void)
694 {
695     if (hint)
696     {
697         algbr((short) (hint >> 8), (short) (hint & 0xFF), false);
698         printf("Hint: %s\n", mvstr[0]);
699     }
700     else
701         fputs("I have no idea.\n", stdout);
702 }
703
704
705 void
706 Raw_SelectLevel(char *sx)
707 {
708     /* FIXME: NO_SQUARES is nonsense here */
709     char T[NO_SQUARES + 1], *p;
710
711     strncpy(T, sx, NO_SQUARES);
712     T[NO_SQUARES] = '\0';
713
714     /* if line empty, ask for input */
715     if (!T[0])
716     {
717         fputs("Enter #moves #minutes: ", stdout);
718         fgets(T, NO_SQUARES + 1, stdin);
719     }
720
721     /* skip blackspace */
722     for (p = T; *p == ' '; p++) ;
723
724     /* could be moves or a fischer clock */
725     if (*p == 'f')
726     {
727         /* its a fischer clock game */
728         char *q;
729         p++;
730         TCminutes = (short)strtol(p, &q, 10);
731         TCadd = (short)strtol(q, NULL, 10) *100;
732         TCseconds = 0;
733         TCmoves = 50;
734     }
735     else
736     {
737         /* regular game */
738         char *q;
739         TCadd = 0;
740         TCmoves = (short)strtol(p, &q, 10);
741         TCminutes = (short)strtol(q, &q, 10);
742
743         if (*q == ':')
744             TCseconds = (short)strtol(q + 1, (char **) NULL, 10);
745         else
746             TCseconds = 0;
747
748 #ifdef OPERATORTIME
749         fputs("Operator time (hundredths) = ", stdout);
750         scanf("%hd", &OperatorTime);
751 #endif
752
753         if (TCmoves == 0)
754         {
755             TCflag = false;
756             MaxResponseTime = TCminutes*60L * 100L + TCseconds * 100L;
757             TCminutes = TCseconds = 0;
758         }
759         else
760         {
761             TCflag = true;
762             MaxResponseTime = 0;
763         }
764     }
765
766     TimeControl.clock[black] = TimeControl.clock[white] = 0;
767     SetTimeControl();
768
769     if (XSHOGI)
770     {
771         printf("Clocks: %ld %ld\n",
772                TimeControl.clock[black] * 10,
773                TimeControl.clock[white] * 10);
774     }
775 }
776
777
778 void
779 Raw_ChangeSearchDepth(void)
780 {
781     printf("depth = ");
782     scanf("%hd", &MaxSearchDepth);
783     TCflag = !(MaxSearchDepth > 0);
784 }
785
786
787 void
788 Raw_ChangeHashDepth(void)
789 {
790     printf("hashdepth = ");
791     scanf("%hd", &HashDepth);
792     printf("MoveLimit = ");
793     scanf("%hd", &HashMoveLimit);
794 }
795
796
797 void
798 Raw_SetContempt(void)
799 {
800     printf("contempt = ");
801     scanf("%hd", &contempt);
802 }
803
804
805 void
806 Raw_ChangeXwindow(void)
807 {
808     printf("xwndw = ");
809     scanf("%hd", &xwndw);
810 }
811
812
813 /*
814  * Raw_ShowPostnValue(short sq)
815  * must have called ExaminePosition() first
816  */
817 void
818 Raw_ShowPostnValue(short sq)
819 {
820     (void) ScorePosition(color[sq]);
821
822     if (color[sq] != neutral)
823     {
824 #if defined SAVE_SVALUE
825         printf("???%c ", (color[sq] == white)?'b':'w');
826 #else
827         printf("%3d%c ", svalue[sq], (color[sq] == white)?'b':'w');
828 #endif
829     }
830     else
831     {
832         printf(" *   ");
833     }
834 }
835
836
837 void
838 Raw_DoDebug(void)
839 {
840     short c, p, sq, tp, tc, tsq, score, j, k;
841     char s[40];
842
843     ExaminePosition(opponent);
844     Raw_ShowMessage("Enter piece: ");
845     scanf("%s", s);
846     c = neutral;
847
848     if ((s[0] == 'b') || (s[0] == 'B'))
849         c = black;
850
851     if ((s[0] == 'w') || (s[0] == 'W'))
852         c = white;
853
854     for (p = king; p > no_piece; p--)
855     {
856         if ((s[1] == pxx[p]) || (s[1] == qxx[p]))
857             break;
858     }
859
860     if (p > no_piece)
861     {
862         for (j = (NO_ROWS - 1); j >= 0; j--)
863         {
864             for (k = 0; k < (NO_COLS); k++)
865             {
866                 sq = j*(NO_COLS) + k;
867                 tp = board[sq];
868                 tc = color[sq];
869                 board[sq] = p;
870                 color[sq] = c;
871                 tsq = PieceList[c][1];
872                 PieceList[c][1] = sq;
873                 Raw_ShowPostnValue(sq);
874                 PieceList[c][1] = tsq;
875                 board[sq] = tp;
876                 color[sq] = tc;
877             }
878
879             printf("\n");
880         }
881     }
882
883     score = ScorePosition(opponent);
884
885     for (j = (NO_ROWS - 1); j >= 0; j--)
886     {
887         for (k = 0; k < (NO_COLS); k++)
888         {
889             sq = j*(NO_COLS) + k;
890
891             if (color[sq] != neutral)
892             {
893 #if defined SAVE_SVALUE
894                 printf("%?????%c ", (color[sq] == white)?'b':'w');
895 #else
896                 printf("%5d%c ", svalue[sq], (color[sq] == white)?'b':'w');
897 #endif
898             }
899             else
900             {
901                 printf("    *  ");
902             }
903         }
904
905         printf("\n");
906     }
907
908     printf("stage = %d\n", stage);
909     printf("S%d m%d ps%d gt%c m%d ps%d gt%c", score,
910            mtl[computer], pscore[computer], GameType[computer],
911            mtl[opponent], pscore[opponent], GameType[opponent]);
912 }
913
914
915 void
916 Raw_DoTable(short table[NO_SQUARES])
917 {
918     short  sq, j, k;
919     ExaminePosition(opponent);
920
921     for (j = (NO_ROWS - 1); j >= 0; j--)
922     {
923         for (k = 0; k < NO_COLS; k++)
924         {
925             sq = j*(NO_ROWS) + k;
926             printf("%3d ", table[sq]);
927         }
928
929         printf("\n");
930     }
931 }
932
933
934 void
935 Raw_ShowPostnValues(void)
936 {
937     short sq, score, j, k;
938     ExaminePosition(opponent);
939
940     for (j = (NO_ROWS - 1); j >= 0; j--)
941     {
942         for (k = 0; k < NO_COLS; k++)
943         {
944             sq = j * NO_COLS + k;
945             Raw_ShowPostnValue(sq);
946         }
947
948         printf("\n");
949     }
950
951     score = ScorePosition(opponent);
952     printf("S%d m%d ps%d gt%c m%d ps%d gt%c", score,
953            mtl[computer], pscore[computer], GameType[computer],
954            mtl[opponent], pscore[opponent], GameType[opponent]);
955     printf("\nhung black %d hung white %d\n", hung[black], hung[white]);
956 }
957
958
959 void
960 Raw_PollForInput(void)
961 {
962 #ifdef WIN32
963     DWORD cnt;
964     if (!PeekNamedPipe(GetStdHandle(STD_INPUT_HANDLE), NULL, 0, NULL, &cnt, NULL))
965         cnt = 1;
966 #else
967     static struct pollfd pollfds[1] = { [0] = { .fd = STDIN_FILENO,
968                                                 .events = POLLIN } };
969     int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0);
970     if (cnt < 0) {
971         perror("polling standard input");
972         Raw_ExitShogi();
973     }
974 #endif
975     if (cnt) { /* if anything to read, or error occured */
976         if (!flag.timeout)
977             flag.back = true; /* previous: flag.timeout = true; */
978         flag.bothsides = false;
979     }
980 }
981
982 struct display raw_display =
983 {
984     .ChangeAlphaWindow    = Raw_ChangeAlphaWindow,
985     .ChangeBetaWindow     = Raw_ChangeBetaWindow,
986     .ChangeHashDepth      = Raw_ChangeHashDepth,
987     .ChangeSearchDepth    = Raw_ChangeSearchDepth,
988     .ChangeXwindow        = Raw_ChangeXwindow,
989     .ClearScreen          = Raw_ClearScreen,
990     .DoDebug              = Raw_DoDebug,
991     .DoTable              = Raw_DoTable,
992     .EditBoard            = Raw_EditBoard,
993     .ExitShogi            = Raw_ExitShogi,
994     .GiveHint             = Raw_GiveHint,
995     .Initialize           = Raw_Initialize,
996     .ShowNodeCnt          = Raw_ShowNodeCnt,
997     .OutputMove           = Raw_OutputMove,
998     .PollForInput         = Raw_PollForInput,
999     .SetContempt          = Raw_SetContempt,
1000     .SearchStartStuff     = Raw_SearchStartStuff,
1001     .SelectLevel          = Raw_SelectLevel,
1002     .ShowCurrentMove      = Raw_ShowCurrentMove,
1003     .ShowDepth            = Raw_ShowDepth,
1004     .ShowGameType         = Raw_ShowGameType,
1005     .ShowLine             = Raw_ShowLine,
1006     .ShowMessage          = Raw_ShowMessage,
1007     .AlwaysShowMessage    = Raw_AlwaysShowMessage,
1008     .Printf               = Raw_Printf,
1009     .doRequestInputString = Raw_doRequestInputString,
1010     .GetString            = Raw_GetString,
1011     .SetupBoard           = Raw_SetupBoard,
1012     .ShowPatternCount     = Raw_ShowPatternCount,
1013     .ShowPostnValue       = Raw_ShowPostnValue,
1014     .ShowPostnValues      = Raw_ShowPostnValues,
1015     .ShowPrompt           = Raw_ShowPrompt,
1016     .ShowResponseTime     = Raw_ShowResponseTime,
1017     .ShowResults          = Raw_ShowResults,
1018     .ShowSidetoMove       = Raw_ShowSidetoMove,
1019     .ShowStage            = Raw_ShowStage,
1020     .TerminateSearch      = Raw_TerminateSearch,
1021     .UpdateClocks         = Raw_UpdateClocks,
1022     .UpdateDisplay        = Raw_UpdateDisplay,
1023     .help                 = Raw_help,
1024 };