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