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