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