Reintroduce printf in Raw_help.
[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("----------------------------------------------------------------\n");
311     printf("7g7f      move from 7g to 7f      quit      Exit Shogi\n");
312     printf("S6h       move silver to 6h       beep      turn %s\n",
313            (flag.beep) ? "OFF" : "ON");
314     printf("2d2c+     move to 2c and promote  material  turn %s\n",
315            (flag.material) ? "OFF" : "ON");
316     printf("P*5e      drop pawn to 5e         easy      turn %s\n",
317            (flag.easy) ? "OFF" : "ON");
318     printf("tsume     toggle tsume mode       hash      turn %s\n",
319            (flag.hash) ? "OFF" : "ON");
320     printf("bd        redraw board            reverse   board display\n");
321     printf("list      game to shogi.lst       book      turn %s used %d of %d\n",
322            (Book) ? "OFF" : "ON", bookcount, booksize);
323     printf("undo      undo last ply           remove    take back a move\n");
324     printf("edit      edit board              force     toggle manual move mode\n");
325     printf("switch    sides with computer     both      computer match\n");
326     printf("black     computer plays black    white     computer plays white\n");
327     printf("depth     set search depth        clock     set time control\n");
328     printf("post      principle variation     hint      suggest a move\n");
329     printf("save      game to file            get       game from file\n");
330     printf("xsave     pos. to xshogi file     xget      pos. from xshogi file\n");
331     printf("random    randomize play          new       start new game\n");
332     printf("----------------------------------------------------------------\n");
333     printf("Computer: %-12s Opponent:            %s\n",
334            ColorStr[computer], ColorStr[opponent]);
335     printf("Depth:    %-12d Response time:       %ld sec\n",
336            MaxSearchDepth, MaxResponseTime/100);
337     printf("Random:   %-12s Easy mode:           %s\n",
338            (dither) ? "ON" : "OFF", (flag.easy) ? "ON" : "OFF");
339     printf("Beep:     %-12s Transposition file:  %s\n",
340            (flag.beep) ? "ON" : "OFF", (flag.hash) ? "ON" : "OFF");
341     printf("Tsume:    %-12s Force:               %s\n",
342            (flag.tsume) ? "ON" : "OFF", (flag.force) ? "ON" : "OFF");
343     printf("Time Control %s %d moves %ld sec %d add %d depth\n",
344            (TCflag) ? "ON" : "OFF",
345            TimeControl.moves[black], TimeControl.clock[black] / 100,
346            TCadd/100, MaxSearchDepth);
347 }
348
349
350 /*
351  * Set up a board position. Pieces are entered by typing the piece followed
352  * by the location. For example, Nf3 will place a knight on square f3.
353  */
354 void
355 Raw_EditBoard(void)
356 {
357     short a, r, c, sq, i, found;
358     char s[80];
359
360     flag.regularstart = true;
361     Book = BOOKFAIL;
362     Raw_ClearScreen();
363     Raw_UpdateDisplay(0, 0, 1, 0);
364     fputs(".   Exit to main\n", stdout);
365     fputs("#   Clear board\n", stdout);
366     fputs("c   Change sides\n", stdout);
367     fputs("enter piece & location: \n", stdout);
368
369     a = black;
370
371     do
372     {
373         scanf("%s", s);
374         found = 0;
375
376         if (s[0] == '#')
377         {
378             for (sq = 0; sq < NO_SQUARES; sq++)
379             {
380                 board[sq] = no_piece;
381                 color[sq] = neutral;
382             }
383
384             ClearCaptured();
385         }
386
387         if (s[0] == 'c')
388             a = otherside[a];
389
390         if (s[1] == '*')
391         {
392             for (i = pawn; i <= king; i++)
393             {
394                 if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
395                 {
396                     Captured[a][i]++;
397                     found = 1;
398                     break;
399                 }
400             }
401
402             c = -1;
403             r = -1;
404         }
405         else
406         {
407             c = COL_NAME(s[1]);
408             r = ROW_NAME(s[2]);
409         }
410
411         if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS))
412         {
413             sq = locn(r, c);
414             color[sq] = a;
415             board[sq] = no_piece;
416
417             for (i = no_piece; i <= king; i++)
418             {
419                 if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
420                 {
421                     if (s[3] == '+')
422                         board[sq] = promoted[i];
423                     else
424                         board[sq] = i;
425
426                     found = 1;
427                     break;
428                 }
429             }
430
431             if (found == 0)
432                 color[sq] = neutral;
433         }
434     }
435     while (s[0] != '.');
436
437     for (sq = 0; sq < NO_SQUARES; sq++)
438         Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
439
440     GameCnt = 0;
441     Game50 = 1;
442     ZeroRPT();
443     Sdepth = 0;
444     InitializeStats();
445     Raw_ClearScreen();
446     Raw_UpdateDisplay(0, 0, 1, 0);
447 }
448
449
450 /*
451  * Set up a board position.
452  * Nine lines of nine characters are used to setup the board. 9a-1a is the
453  * first line. White pieces are  represented  by  uppercase characters.
454  */
455 void
456 Raw_SetupBoard(void)
457 {
458     short r, c, sq, i;
459     char ch;
460     char s[80];
461
462     NewGame();
463
464     fgets(s, 80, stdin);            /* skip "setup" command */
465
466     for (r = NO_ROWS - 1; r >= 0; r--)
467     {
468         fgets(s, 80, stdin);
469
470         for (c = 0; c <= (NO_COLS - 1); c++)
471         {
472             ch = s[c];
473             sq = locn(r, c);
474             color[sq] = neutral;
475             board[sq] = no_piece;
476
477             for (i = no_piece; i <= king; i++)
478             {
479                 if (ch == pxx[i])
480                 {
481                     color[sq] = white;
482                     board[sq] = i;
483                     break;
484                 }
485                 else if (ch == qxx[i])
486                 {
487                     color[sq] = black;
488                     board[sq] = i;
489                     break;
490                 }
491             }
492         }
493     }
494
495     for (sq = 0; sq < NO_SQUARES; sq++)
496         Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
497
498     InitializeStats();
499     Raw_ClearScreen();
500     Raw_UpdateDisplay(0, 0, 1, 0);
501     fputs("Setup successful\n", stdout);
502 }
503
504
505 void
506 Raw_SearchStartStuff(short side)
507 {
508     if (flag.post)
509     {
510         printf("\nMove# %d    Target = %ld    Clock: %ld\n",
511                GameCnt/2 + 1,
512                ResponseTime, TimeControl.clock[side]);
513     }
514 }
515
516
517 void
518 Raw_OutputMove(void)
519 {
520     if (flag.illegal)
521     {
522         printf("Illegal position.\n");
523         return;
524     }
525
526     if (mvstr[0][0] == '\0')
527         goto nomove;
528
529     if (XSHOGI)
530     {
531         /* add remaining time in milliseconds to xshogi */
532         printf("%d. ... %s %ld\n", ++mycnt1, mvstr[0],
533                (TimeControl.clock[player] - et) * 10);
534     }
535     else
536     {
537         printf("%d. ... %s\n", ++mycnt1, mvstr[0]);
538     }
539
540  nomove:
541     if ((root->flags & draw) || (root->score == -(SCORE_LIMIT + 999))
542         || (root->score == (SCORE_LIMIT + 998)))
543         goto summary;
544
545     if (flag.post)
546     {
547         short h, l, t;
548
549         h = TREE;
550         l = 0;
551         t = TREE >> 1;
552
553         while (l != t)
554         {
555             if (Tree[t].f || Tree[t].t)
556                 l = t;
557             else
558                 h = t;
559
560             t = (l + h) >> 1;
561         }
562
563         printf("Gen %ld Node %ld Tree %d Eval %ld Rate %ld EC %d/%d RS hi %ld lo %ld \n", GenCnt, NodeCnt, t, EvalNodes,
564                (et > 100) ? (NodeCnt / (et / 100)) : 0,
565                EADD, EGET, reminus, replus);
566
567         printf("Hin/Hout/Tcol/Coll/Fin/Fout = %ld/%ld/%ld/%ld/%ld/%ld\n",
568                HashAdd, HashCnt, THashCol, HashCol, FHashCnt, FHashAdd);
569     }
570
571     Raw_UpdateDisplay(root->f, root->t, 0, root->flags);
572
573     if (!XSHOGI)
574     {
575         printf("My move is: %5s\n", mvstr[0]);
576
577         if (flag.beep)
578             printf("%c", 7);
579     }
580
581  summary:
582     if (root->flags & draw)
583     {
584         fputs("Drawn game!\n", stdout);
585     }
586     else if (root->score == -(SCORE_LIMIT + 999))
587     {
588         printf("%s mates!\n", ColorStr[opponent]);
589     }
590     else if (root->score == (SCORE_LIMIT + 998))
591     {
592         printf("%s mates!\n", ColorStr[computer]);
593     }
594 #ifdef VERYBUGGY
595     else if (!barebones && (root->score < -SCORE_LIMIT))
596     {
597         printf("%s has a forced mate in %d moves!\n",
598                ColorStr[opponent], SCORE_LIMIT + 999 + root->score - 1);
599     }
600     else if (!barebones && (root->score > SCORE_LIMIT))
601     {
602         printf("%s has a forced mate in %d moves!\n",
603                ColorStr[computer], SCORE_LIMIT + 998 - root->score - 1);
604     }
605 #endif /* VERYBUGGY */
606 }
607
608
609 void
610 Raw_UpdateClocks(void)
611 {
612 }
613
614
615 void
616 Raw_UpdateDisplay(short f, short t, short redraw, short isspec)
617 {
618
619     short r, c, l, m;
620
621     if (redraw && !XSHOGI)
622     {
623         printf("\n");
624         r = (short)(TimeControl.clock[black] / 6000);
625         c = (short)((TimeControl.clock[black] % 6000) / 100);
626         l = (short)(TimeControl.clock[white] / 6000);
627         m = (short)((TimeControl.clock[white] % 6000) / 100);
628         printf("Black %d:%02d  White %d:%02d\n", r, c, l, m);
629         printf("\n");
630
631         for (r = (NO_ROWS - 1); r >= 0; r--)
632         {
633             for (c = 0; c <= (NO_COLS - 1); c++)
634             {
635                 char pc;
636                 l = ((flag.reverse)
637                      ? locn((NO_ROWS - 1) - r, (NO_COLS - 1) - c)
638                      : locn(r, c));
639                 pc = (is_promoted[board[l]] ? '+' : ' ');
640
641                 if (color[l] == neutral)
642                     printf(" -");
643                 else if (color[l] == black)
644                     printf("%c%c", pc, qxx[board[l]]);
645                 else
646                     printf("%c%c", pc, pxx[board[l]]);
647             }
648
649             printf("\n");
650         }
651
652         printf("\n");
653         {
654             short side;
655
656             for (side = black; side <= white; side++)
657             {
658                 short piece, c;
659                 printf((side == black)?"black ":"white ");
660
661                 for (piece = pawn; piece <= king; piece++)
662                 {
663                     if ((c = Captured[side][piece]))
664                         printf("%i%c ", c, pxx[piece]);
665                 }
666
667                 printf("\n");
668             }
669         }
670     }
671 }
672
673
674 void
675 Raw_ChangeAlphaWindow(void)
676 {
677     printf("WAwindow: ");
678     scanf("%hd", &WAwindow);
679     printf("BAwindow: ");
680     scanf("%hd", &BAwindow);
681 }
682
683
684 void
685 Raw_ChangeBetaWindow(void)
686 {
687     printf("WBwindow: ");
688     scanf("%hd", &WBwindow);
689     printf("BBwindow: ");
690     scanf("%hd", &BBwindow);
691 }
692
693
694 void
695 Raw_GiveHint(void)
696 {
697     if (hint)
698     {
699         algbr((short) (hint >> 8), (short) (hint & 0xFF), false);
700         printf("Hint: %s\n", mvstr[0]);
701     }
702     else
703         fputs("I have no idea.\n", stdout);
704 }
705
706
707 void
708 Raw_SelectLevel(char *sx)
709 {
710     /* FIXME: NO_SQUARES is nonsense here */
711     char T[NO_SQUARES + 1], *p;
712
713     strncpy(T, sx, NO_SQUARES);
714     T[NO_SQUARES] = '\0';
715
716     /* if line empty, ask for input */
717     if (!T[0])
718     {
719         fputs("Enter #moves #minutes: ", stdout);
720         fgets(T, NO_SQUARES + 1, stdin);
721     }
722
723     /* skip blackspace */
724     for (p = T; *p == ' '; p++) ;
725
726     /* could be moves or a fischer clock */
727     if (*p == 'f')
728     {
729         /* its a fischer clock game */
730         char *q;
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         char *q;
741         TCadd = 0;
742         TCmoves = (short)strtol(p, &q, 10);
743         TCminutes = (short)strtol(q, &q, 10);
744
745         if (*q == ':')
746             TCseconds = (short)strtol(q + 1, (char **) NULL, 10);
747         else
748             TCseconds = 0;
749
750 #ifdef OPERATORTIME
751         fputs("Operator time (hundredths) = ", stdout);
752         scanf("%hd", &OperatorTime);
753 #endif
754
755         if (TCmoves == 0)
756         {
757             TCflag = false;
758             MaxResponseTime = TCminutes*60L * 100L + TCseconds * 100L;
759             TCminutes = TCseconds = 0;
760         }
761         else
762         {
763             TCflag = true;
764             MaxResponseTime = 0;
765         }
766     }
767
768     TimeControl.clock[black] = TimeControl.clock[white] = 0;
769     SetTimeControl();
770
771     if (XSHOGI)
772     {
773         printf("Clocks: %ld %ld\n",
774                TimeControl.clock[black] * 10,
775                TimeControl.clock[white] * 10);
776     }
777 }
778
779
780 void
781 Raw_ChangeSearchDepth(void)
782 {
783     printf("depth = ");
784     scanf("%hd", &MaxSearchDepth);
785     TCflag = !(MaxSearchDepth > 0);
786 }
787
788
789 void
790 Raw_ChangeHashDepth(void)
791 {
792     printf("hashdepth = ");
793     scanf("%hd", &HashDepth);
794     printf("MoveLimit = ");
795     scanf("%hd", &HashMoveLimit);
796 }
797
798
799 void
800 Raw_SetContempt(void)
801 {
802     printf("contempt = ");
803     scanf("%hd", &contempt);
804 }
805
806
807 void
808 Raw_ChangeXwindow(void)
809 {
810     printf("xwndw = ");
811     scanf("%hd", &xwndw);
812 }
813
814
815 /*
816  * Raw_ShowPostnValue(short sq)
817  * must have called ExaminePosition() first
818  */
819 void
820 Raw_ShowPostnValue(short sq)
821 {
822     (void) 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 };