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