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