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