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