games@tekred.TEK.COM (06/11/88)
Submitted by: John Stanback <jhs@hpltbm.HP.COM>
Comp.sources.games: Volume 4, Issue 39
Archive-name: gnuchess2/Part03
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 3 (of 4)."
# Contents: nondsp.c uxdsp.c
# Wrapped by billr@saab on Fri Jun 10 17:01:31 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f nondsp.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"nondsp.c\"
else
echo shar: Extracting \"nondsp.c\" \(19702 characters\)
sed "s/^X//" >nondsp.c <<'END_OF_nondsp.c'
X/*
X UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
X
X Revision: 4-25-88
X
X Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
X Copyright (c) 1988 John Stanback
X
X This file is part of CHESS.
X
X CHESS is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY. No author or distributor
X accepts responsibility to anyone for the consequences of using it
X or for whether it serves any particular purpose or works at all,
X unless he says so in writing. Refer to the CHESS General Public
X License for full details.
X
X Everyone is granted permission to copy, modify and redistribute
X CHESS, but only under the conditions described in the
X CHESS General Public License. A copy of this license is
X supposed to have been given to you along with CHESS so you
X can know your rights and responsibilities. It should be in a
X file named COPYING. Among other things, the copyright notice
X and this notice must be preserved on all copies.
X*/
X
X
X#include <stdio.h>
X#include <ctype.h>
X#ifdef MSDOS
X#include <dos.h>
X#include <stdlib.h>
X#include <time.h>
X#else
X#include <sys/param.h>
X#include <sys/times.h>
X#include <sys/file.h>
X#include <signal.h>
Xstruct tms tmbuf1,tmbuf2;
Xint TerminateSearch(),Die();
X#endif MSDOS
X
X#include "gnuchess.h"
X
X#define printz printf
X#define scanz scanf
Xint mycnt1,mycnt2;
X
X
XInitialize()
X{
X mycnt1 = mycnt2 = 0;
X#ifndef MSDOS
X signal(SIGINT,Die); signal(SIGQUIT,Die);
X#endif
X#ifdef CHESSTOOL
X/*
X setlinebuf(stdout);
X*/
X setvbuf(stdout,NULL,_IOLBF,BUFSIZ);
X printf("Chess\n");
X if (Level == 0 && !TCflag) Level = 15;
X#endif CHESSTOOL
X}
X
XExitChess()
X{
X ListGame();
X exit(0);
X}
X
X#ifndef MSDOS
XDie()
X{
Xchar s[80];
X signal(SIGINT,SIG_IGN);
X signal(SIGQUIT,SIG_IGN);
X printz("Abort? ");
X scanz("%s",s);
X if (strcmp(s,"yes") == 0) ExitChess();
X signal(SIGINT,Die); signal(SIGQUIT,Die);
X}
X
XTerminateSearch()
X{
X signal(SIGINT,SIG_IGN);
X signal(SIGQUIT,SIG_IGN);
X timeout = true;
X bothsides = false;
X signal(SIGINT,Die); signal(SIGQUIT,Die);
X}
X#endif MSDOS
X
X
XInputCommand()
X
X/*
X Process the users command. If easy mode is OFF (the computer is
X thinking on opponents time) and the program is out of book, then make
X the 'hint' move on the board and call SelectMove() to find a response.
X The user terminates the search by entering ^C (quit siqnal) before
X entering a command. If the opponent does not make the hint move, then
X set Sdepth to zero.
X*/
X
X{
Xint i;
Xshort ok,tmp;
Xlong cnt,rate,t1,t2;
Xunsigned short mv;
Xchar s[80];
X
X ok = quit = false;
X player = opponent;
X ft = 0;
X if (hint > 0 && !easy && Book == NULL)
X {
X fflush(stdout);
X time0 = time((long *)0);
X algbr(hint>>8,hint & 0xFF,false);
X strcpy(s,mvstr1);
X tmp = epsquare;
X if (VerifyMove(s,1,&mv))
X {
X SelectMove(computer,2);
X VerifyMove(mvstr1,2,&mv);
X if (Sdepth > 0) Sdepth--;
X }
X ft = time((long *)0) - time0;
X epsquare = tmp;
X }
X
X#ifndef MSDOS
X signal(SIGINT,Die); signal(SIGQUIT,Die);
X#endif
X while (!(ok || quit))
X {
X PromptForMove();
X i = scanz("%s",s);
X if (i == EOF || s[0] == 0) ExitChess();
X player = opponent;
X ok = VerifyMove(s,0,&mv);
X if (ok && mv != hint)
X {
X Sdepth = 0;
X ft = 0;
X }
X
X if (strcmp(s,"bd") == 0)
X {
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X }
X if (strcmp(s,"quit") == 0) quit = true;
X if (strcmp(s,"post") == 0) post = !post;
X if (strcmp(s,"edit") == 0) EditBoard();
X if (strcmp(s,"go") == 0) ok = true;
X if (strcmp(s,"help") == 0) help();
X if (strcmp(s,"force") == 0) force = !force;
X if (strcmp(s,"book") == 0) Book = NULL;
X if (strcmp(s,"new") == 0) NewGame();
X if (strcmp(s,"list") == 0) ListGame();
X if (strcmp(s,"level") == 0) SelectLevel();
X if (strcmp(s,"hash") == 0) hashflag = !hashflag;
X if (strcmp(s,"beep") == 0) beep = !beep;
X if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow();
X if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow();
X if (strcmp(s,"rcptr") == 0) rcptr = !rcptr;
X if (strcmp(s,"hint") == 0) GiveHint();
X if (strcmp(s,"zero") == 0) ZeroTTable();
X if (strcmp(s,"both") == 0)
X {
X bothsides = !bothsides;
X Sdepth = 0;
X SelectMove(opponent,1);
X ok = true;
X }
X if (strcmp(s,"reverse") == 0)
X {
X reverse = !reverse;
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X }
X if (strcmp(s,"switch") == 0)
X {
X computer = otherside[computer];
X opponent = otherside[opponent];
X force = false;
X Sdepth = 0;
X ok = true;
X }
X if (strcmp(s,"white") == 0)
X {
X computer = white; opponent = black;
X ok = true; force = false;
X Sdepth = 0;
X }
X if (strcmp(s,"black") == 0)
X {
X computer = black; opponent = white;
X ok = true; force = false;
X Sdepth = 0;
X }
X if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo();
X if (strcmp(s,"remove") == 0 && GameCnt >= 1)
X {
X Undo(); Undo();
X }
X if (strcmp(s,"get") == 0) GetGame();
X if (strcmp(s,"save") == 0) SaveGame();
X if (strcmp(s,"depth") == 0) ChangeSearchDepth();
X if (strcmp(s,"random") == 0) dither = 6;
X if (strcmp(s,"easy") == 0) easy = !easy;
X if (strcmp(s,"contempt") == 0) SetContempt();
X if (strcmp(s,"xwndw") == 0) ChangeXwindow();
X if (strcmp(s,"test") == 0)
X {
X t1 = time(0);
X cnt = 0;
X for (i = 0; i < 10000; i++)
X {
X MoveList(opponent,2);
X cnt += TrPnt[3] - TrPnt[2];
X }
X t2 = time(0);
X rate = cnt / (t2-t1);
X printz("cnt= %ld rate= %ld\n",cnt,rate);
X }
X }
X
X ElapsedTime(1);
X if (force)
X {
X computer = opponent; opponent = otherside[computer];
X }
X#ifndef MSDOS
X (void) times(&tmbuf1);
X#ifdef CHESSTOOL
X printf("%d. %s\n",++mycnt2,s);
X#endif CHESSTOOL
X signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
X#endif MSDOS
X}
X
X
Xhelp()
X{
X ClrScreen();
X printz("CHESS command summary\n");
X printz("g1f3 move from g1 to f3\n");
X printz("nf3 move knight to f3\n");
X printz("o-o castle king side\n");
X printz("o-o-o castle queen side\n");
X printz("edit edit board\n");
X printz("switch sides with computer\n");
X printz("white computer plays white\n");
X printz("black computer plays black\n");
X printz("reverse board display\n");
X printz("both computer match\n");
X printz("random randomize play\n");
X printz("undo undo last move\n");
X printz("time change level\n");
X printz("depth set search depth\n");
X printz("post principle variation\n");
X printz("hint suggest a move\n");
X printz("bd redraw board\n");
X printz("clock set time control\n");
X printz("force enter game moves\n");
X printz("list game to chess.lst\n");
X printz("save game to file\n");
X printz("get game from file\n");
X printz("new start new game\n");
X printz("quit exit CHESS\n");
X printz("Computer: ");
X if (computer == white) printz("WHITE\n"); else printz("BLACK\n");
X printz("Opponent: ");
X if (opponent == white) printz("WHITE\n"); else printz("BLACK\n");
X printz("Response time: %ld \n",Level);
X printz("Easy mode: ");
X if (easy) printz("ON\n"); else printz("OFF\n");
X printz("Depth: %d\n",MaxSearchDepth);
X printz("Random: ");
X if (dither) printz("ON\n"); else printz("OFF\n");
X printz("Transposition table: ");
X if (hashflag) printz("ON\n"); else printz("OFF\n");
X UpdateDisplay(0,0,1,0);
X}
X
X
XEditBoard()
X
X/*
X Set up a board position. Pieces are entered by typing the piece
X followed by the location. For example, Nf3 will place a knight on
X square f3.
X*/
X
X{
Xshort a,r,c,sq;
Xchar s[80];
X
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X printz(". exit to main\n");
X printz("# clear board\n");
X printz("enter piece & location: \n");
X
X a = white;
X do
X {
X scanz("%s",s);
X if (s[0] == '#')
X {
X for (sq = 0; sq < 64; sq++)
X {
X board[sq] = no_piece; color[sq] = neutral;
X }
X UpdateDisplay(0,0,1,0);
X }
X if (s[0] == 'c' || s[0] == 'C') a = otherside[a];
X c = s[1]-'a'; r = s[2]-'1';
X if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
X {
X sq = locn[r][c];
X color[sq] = a;
X if (s[0] == 'p') board[sq] = pawn;
X else if (s[0] == 'n') board[sq] = knight;
X else if (s[0] == 'b') board[sq] = bishop;
X else if (s[0] == 'r') board[sq] = rook;
X else if (s[0] == 'q') board[sq] = queen;
X else if (s[0] == 'k') board[sq] = king;
X else { board[sq] = no_piece; color[sq] = neutral; }
X }
X }
X while (s[0] != '.');
X if (board[4] != king) kingmoved[white] = 10;
X if (board[60] != king) kingmoved[black] = 10;
X GameCnt = -1; Game50 = 0; Sdepth = 0;
X InitializeStats();
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X}
X
X
XShowDepth(ch)
Xchar ch;
X{
X}
X
XShowResults(score,bstline,ch)
Xshort score;
Xunsigned short bstline[];
Xchar ch;
X{
X#ifndef CHESSTOOL
Xregister int i;
X printz("%2d%c %5d %4ld %7ld ",Sdepth,ch,score,et,NodeCnt);
X for (i = 1; bstline[i] > 0; i++)
X {
X algbr((short)(bstline[i] >> 8),(short)(bstline[i] & 0xFF),false);
X if (i == 9 || i == 17) printz("\n ");
X printz("%5s ",mvstr1);
X }
X printz("\n");
X#endif
X}
X
X
XSearchStartStuff(side)
Xshort side;
X{
X#ifndef MSDOS
X signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
X#endif MSDOS
X#ifndef CHESSTOOL
X printz("\nMove# %d Target= %ld Clock: %ld\n",
X TCmoves-TimeControl.moves[side]+1,
X ResponseTime,TimeControl.clock[side]);
X#endif
X}
X
X
XOutputMove()
X{
X#ifdef CHESSTOOL
X printz("%d. ... %s\n",++mycnt1,mvstr1);
X if (root->flags & draw)
X {
X printz("Draw\n");
X ListGame();
X exit(0);
X }
X if (root->score == -9999)
X {
X if (opponent == white) printz("White\n"); else printz("Black\n");
X ListGame();
X exit(0);
X }
X if (root->score == 9998)
X {
X if (computer == white) printz("White\n"); else printz("Black\n");
X ListGame();
X exit(0);
X }
X#else
X printz("Nodes= %ld Eval= %ld Hash= %ld Rate= %ld ",
X NodeCnt,EvalNodes,HashCnt,evrate);
X printz("CPU= %.2ld:%.2ld.%.2ld\n\n",
X cputimer/6000,(cputimer % 6000)/100,cputimer % 100);
X
X if (root->flags & epmask) UpdateDisplay(0,0,1,0);
X else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);
X printz("My move is: %s\n\n",mvstr1);
X if (beep) printz("%c",7);
X
X if (root->flags & draw) printz("Draw game!\n");
X else if (root->score == -9999) printz("opponent mates!\n");
X else if (root->score == 9998) printz("computer mates!\n");
X else if (root->score < -9000) printz("opponent will soon mate!\n");
X else if (root->score > 9000) printz("computer will soon mate!\n");
X#endif CHESSTOOL
X}
X
X
XElapsedTime(iop)
Xshort iop;
X
X/*
X Determine the time that has passed since the search was started. If
X the elapsed time exceeds the target (ResponseTime+ExtraTime) then set
X timeout to true which will terminate the search.
X*/
X
X{
X et = time((long *)0) - time0;
X if (et < 0) et = 0;
X ETnodes += 50;
X if (et > et0 || iop == 1)
X {
X if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true;
X et0 = et;
X if (iop == 1)
X {
X time0 = time((long *)0); et0 = 0;
X }
X#ifdef MSDOS
X cputimer = 100*et;
X if (et > 0) evrate = NodeCnt/(et+ft); else evrate = 0;
X if (kbhit() && Sdepth > 1)
X {
X timeout = true;
X bothsides = false;
X }
X#else
X (void) times(&tmbuf2);
X cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;
X if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);
X else evrate = 0;
X#endif MSDOS
X ETnodes = NodeCnt + 50;
X }
X}
X
X
XSetTimeControl()
X{
X if (TCflag)
X {
X TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
X TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;
X }
X else
X {
X TimeControl.moves[white] = TimeControl.moves[black] = 0;
X TimeControl.clock[white] = TimeControl.clock[black] = 0;
X Level = 60*(long)TCminutes;
X }
X et = 0;
X ElapsedTime(1);
X}
X
X
XClrScreen()
X{
X#ifndef CHESSTOOL
X printz("\n");
X#endif
X}
X
X
XUpdateDisplay(f,t,flag,iscastle)
Xshort f,t,flag,iscastle;
X{
X#ifndef CHESSTOOL
Xshort r,c,l;
X if (flag)
X {
X printz("\n");
X for (r = 7; r >= 0; r--)
X {
X for (c = 0; c <= 7; c++)
X {
X if (reverse) l = locn[7-r][7-c]; else l = locn[r][c];
X if (color[l] == neutral) printz(" -");
X else if (color[l] == white) printz(" %c",qxx[board[l]]);
X else printz(" %c",pxx[board[l]]);
X }
X printz("\n");
X }
X printz("\n");
X }
X#endif CHESSTOOL
X}
X
X
XGetOpenings()
X
X/*
X Read in the Opening Book file and parse the algebraic notation for a
X move into an unsigned integer format indicating the from and to
X square. Create a linked list of opening lines of play, with
X entry->next pointing to the next line and entry->move pointing to a
X chunk of memory containing the moves. More Opening lines of up to 256
X half moves may be added to gnuchess.book.
X*/
X
X{
XFILE *fd;
Xint c,i,j,side;
Xchar buffr[2048];
Xstruct BookEntry *entry;
Xunsigned short mv,*mp,tmp[100];
X
X if ((fd = fopen("gnuchess.book","r")) != NULL)
X {
X setvbuf(fd,buffr,_IOFBF,2048);
X Book = NULL;
X i = 0; side = white;
X while ((c = parse(fd,&mv,side)) >= 0)
X if (c == 1)
X {
X tmp[++i] = mv;
X side = otherside[side];
X }
X else if (c == 0 && i > 0)
X {
X entry = (struct BookEntry *)malloc(sizeof(struct BookEntry));
X mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short));
X entry->mv = mp;
X entry->next = Book;
X Book = entry;
X for (j = 1; j <= i; j++) *(mp++) = tmp[j];
X *mp = 0;
X i = 0; side = white;
X }
X fclose(fd);
X }
X}
X
X
Xint parse(fd,mv,side)
XFILE *fd;
Xunsigned short *mv;
Xshort side;
X{
Xint c,i,r1,r2,c1,c2;
Xchar s[100];
X while ((c = getc(fd)) == ' ');
X i = 0; s[0] = c;
X while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd);
X s[++i] = '\0';
X if (c == EOF) return(-1);
X if (s[0] == '!' || i < 3)
X {
X while (c != '\n' && c != EOF) c = getc(fd);
X return(0);
X }
X if (s[4] == 'o')
X if (side == black) *mv = 0x3C3A; else *mv = 0x0402;
X else if (s[0] == 'o')
X if (side == black) *mv = 0x3C3E; else *mv = 0x0406;
X else
X {
X c1 = s[0] - 'a'; r1 = s[1] - '1';
X c2 = s[2] - 'a'; r2 = s[3] - '1';
X *mv = (locn[r1][c1]<<8) + locn[r2][c2];
X }
X return(1);
X}
X
X
XGetGame()
X{
XFILE *fd;
Xchar fname[40];
Xint c;
Xshort sq;
Xunsigned short m;
X
X printz("Enter file name: ");
X scanz("%s",fname);
X if (fname[0] == '\0') strcpy(fname,"chess.000");
X if ((fd = fopen(fname,"r")) != NULL)
X {
X fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50);
X fscanf(fd,"%hd%hd%hd%hd",
X &castld[white],&castld[black],
X &kingmoved[white],&kingmoved[black]);
X fscanf(fd,"%hd%hd",&TCflag,&OperatorTime);
X fscanf(fd,"%ld%ld%hd%hd",
X &TimeControl.clock[white],&TimeControl.clock[black],
X &TimeControl.moves[white],&TimeControl.moves[black]);
X for (sq = 0; sq < 64; sq++)
X {
X fscanf(fd,"%hd",&m);
X board[sq] = (m >> 8); color[sq] = (m & 0xFF);
X if (color[sq] == 0) color[sq] = neutral; else --color[sq];
X }
X GameCnt = -1; c = '?';
X while (c != EOF)
X {
X ++GameCnt;
X c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove,
X &GameList[GameCnt].score,&GameList[GameCnt].depth,
X &GameList[GameCnt].nodes,&GameList[GameCnt].time,
X &GameList[GameCnt].piece,&GameList[GameCnt].color);
X if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral;
X else --GameList[GameCnt].color;
X }
X GameCnt--;
X if (TimeControl.clock[white] > 0) TCflag = true;
X computer--; opponent--;
X }
X fclose(fd);
X InitializeStats();
X UpdateDisplay(0,0,1,0);
X Sdepth = 0;
X}
X
X
XSaveGame()
X{
XFILE *fd;
Xchar fname[40];
Xshort sq,i,c;
X
X printz("Enter file name: ");
X scanz("%s",fname);
X
X if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000");
X fd = fopen(fname,"w");
X fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50);
X fprintf(fd,"%d %d %d %d\n",
X castld[white],castld[black],kingmoved[white],kingmoved[black]);
X fprintf(fd,"%d %d\n",TCflag,OperatorTime);
X fprintf(fd,"%ld %ld %d %d\n",
X TimeControl.clock[white],TimeControl.clock[black],
X TimeControl.moves[white],TimeControl.moves[black]);
X for (sq = 0; sq < 64; sq++)
X {
X if (color[sq] == neutral) c = 0; else c = color[sq]+1;
X fprintf(fd,"%d\n",256*board[sq] + c);
X }
X for (i = 0; i <= GameCnt; i++)
X {
X if (GameList[i].color == neutral) c = 0;
X else c = GameList[i].color + 1;
X fprintf(fd,"%d %d %d %ld %d %d %d\n",
X GameList[i].gmove,GameList[i].score,GameList[i].depth,
X GameList[i].nodes,GameList[i].time,
X GameList[i].piece,c);
X }
X fclose(fd);
X}
X
X
XListGame()
X{
XFILE *fd;
Xshort i,f,t;
X fd = fopen("chess.lst","w");
X fprintf(fd,"\n");
X fprintf(fd," score depth nodes time ");
X fprintf(fd," score depth nodes time\n");
X for (i = 0; i <= GameCnt; i++)
X {
X f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF);
X algbr(f,t,false);
X if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd," ");
X fprintf(fd,"%5s %5d %2d %6ld %5d",mvstr1,
X GameList[i].score,GameList[i].depth,
X GameList[i].nodes,GameList[i].time);
X }
X fprintf(fd,"\n\n");
X fclose(fd);
X}
X
X
XUndo()
X
X/*
X Undo the most recent half-move.
X*/
X
X{
Xshort f,t;
X f = GameList[GameCnt].gmove>>8;
X t = GameList[GameCnt].gmove & 0xFF;
X if (board[t] == king && distance(t,f) > 1)
X castle(GameList[GameCnt].color,f,t,2);
X else
X {
X board[f] = board[t]; color[f] = color[t];
X board[t] = GameList[GameCnt].piece;
X color[t] = GameList[GameCnt].color;
X if (board[f] == king) --kingmoved[color[f]];
X }
X if (TCflag) ++TimeControl.moves[color[f]];
X GameCnt--; mate = false; Sdepth = 0;
X UpdateDisplay(0,0,1,0);
X InitializeStats();
X}
X
X
XShowMessage(s)
Xchar *s;
X{
X#ifndef CHESSTOOL
X printz("%s\n",s);
X#endif CHESSTOOL
X}
X
XShowSidetomove()
X{
X}
X
XPromptForMove()
X{
X#ifndef CHESSTOOL
X printz("\nYour move is? ");
X#endif CHESSTOOL
X}
X
X
XShowCurrentMove(pnt,f,t)
Xshort pnt,f,t;
X{
X}
X
XChangeAlphaWindow()
X{
X printz("window: ");
X scanz("%hd",&Awindow);
X}
X
XChangeBetaWindow()
X{
X printz("window: ");
X scanz("%hd",&Bwindow);
X}
X
XGiveHint()
X{
X algbr((short)(hint>>8),(short)(hint & 0xFF),false);
X printz("try %s\n",mvstr1);
X}
X
X
XSelectLevel()
X{
X OperatorTime = 30000;
X printz("Enter #moves #minutes: ");
X scanz("%hd %hd",&TCmoves,&TCminutes);
X printz("Operator time= ");
X scanz("%hd",&OperatorTime);
X TCflag = (TCmoves > 1);
X SetTimeControl();
X}
X
X
XChangeSearchDepth()
X{
X printz("depth= ");
X scanz("%hd",&MaxSearchDepth);
X}
X
XSetContempt()
X{
X printz("contempt= ");
X scanz("%hd",&contempt);
X}
X
XChangeXwindow()
X{
X printz("xwndw= ");
X scanz("%hd",&xwndw);
X}
END_OF_nondsp.c
if test 19702 -ne `wc -c <nondsp.c`; then
echo shar: \"nondsp.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f uxdsp.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"uxdsp.c\"
else
echo shar: Extracting \"uxdsp.c\" \(23942 characters\)
sed "s/^X//" >uxdsp.c <<'END_OF_uxdsp.c'
X/*
X ALPHA interface for CHESS
X
X Revision: 4-25-88
X
X Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
X Copyright (c) 1988 John Stanback
X
X This file is part of CHESS.
X
X CHESS is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY. No author or distributor
X accepts responsibility to anyone for the consequences of using it
X or for whether it serves any particular purpose or works at all,
X unless he says so in writing. Refer to the CHESS General Public
X License for full details.
X
X Everyone is granted permission to copy, modify and redistribute
X CHESS, but only under the conditions described in the
X CHESS General Public License. A copy of this license is
X supposed to have been given to you along with CHESS so you
X can know your rights and responsibilities. It should be in a
X file named COPYING. Among other things, the copyright notice
X and this notice must be preserved on all copies.
X*/
X/*
X minor addition to the help screen by Bill Randle, 6-10-88
X*/
X
X
X#include <stdio.h>
X#include <ctype.h>
X#include <sys/param.h>
X#include <sys/times.h>
X#include <sys/file.h>
X#include <curses.h>
X#include <signal.h>
X#include "gnuchess.h"
X
Xstruct tms tmbuf1,tmbuf2;
Xint TerminateSearch(),Die();
X
X#define scanz fflush(stdout),scanw
X#define printz printw
X
X
XInitialize()
X{
X signal(SIGINT,Die); signal(SIGQUIT,Die);
X initscr();
X crmode();
X}
X
X
XExitChess()
X{
X nocrmode();
X endwin();
X exit(0);
X}
X
X
XDie()
X{
Xchar s[80];
X signal(SIGINT,SIG_IGN);
X signal(SIGQUIT,SIG_IGN);
X ShowMessage("Abort? ");
X scanz("%s",s);
X if (strcmp(s,"yes") == 0) ExitChess();
X signal(SIGINT,Die); signal(SIGQUIT,Die);
X}
X
X
XTerminateSearch()
X{
X signal(SIGINT,SIG_IGN);
X signal(SIGQUIT,SIG_IGN);
X timeout = true;
X bothsides = false;
X signal(SIGINT,Die); signal(SIGQUIT,Die);
X}
X
X
XInputCommand()
X
X/*
X Process the users command. If easy mode is OFF (the computer is
X thinking on opponents time) and the program is out of book, then make
X the 'hint' move on the board and call SelectMove() to find a response.
X The user terminates the search by entering ^C (quit siqnal) before
X entering a command. If the opponent does not make the hint move, then
X set Sdepth to zero.
X*/
X
X{
Xshort ok,i,tmp;
Xlong cnt,rate,t1,t2;
Xunsigned short mv;
Xchar s[80];
X
X ok = quit = false;
X player = opponent;
X ShowSidetomove();
X ft = 0;
X if (hint > 0 && !easy && Book == NULL)
X {
X fflush(stdout);
X time0 = time((long *)0);
X algbr(hint>>8,hint & 0xFF,false);
X strcpy(s,mvstr1);
X tmp = epsquare;
X if (VerifyMove(s,1,&mv))
X {
X PromptForMove();
X SelectMove(computer,2);
X VerifyMove(mvstr1,2,&mv);
X if (Sdepth > 0) Sdepth--;
X }
X ft = time((long *)0) - time0;
X epsquare = tmp;
X }
X
X signal(SIGINT,Die); signal(SIGQUIT,Die);
X while (!(ok || quit))
X {
X PromptForMove();
X scanz("%s",s);
X player = opponent;
X ok = VerifyMove(s,0,&mv);
X if (ok && mv != hint)
X {
X Sdepth = 0;
X ft = 0;
X }
X
X if (strcmp(s,"bd") == 0)
X {
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X }
X if (strcmp(s,"quit") == 0) quit = true;
X if (strcmp(s,"post") == 0) post = !post;
X if (strcmp(s,"edit") == 0) EditBoard();
X if (strcmp(s,"go") == 0) ok = true;
X if (strcmp(s,"help") == 0) help();
X if (strcmp(s,"force") == 0) force = !force;
X if (strcmp(s,"book") == 0) Book = NULL;
X if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo();
X if (strcmp(s,"new") == 0) NewGame();
X if (strcmp(s,"list") == 0) ListGame();
X if (strcmp(s,"level") == 0) SelectLevel();
X if (strcmp(s,"hash") == 0) hashflag = !hashflag;
X if (strcmp(s,"beep") == 0) beep = !beep;
X if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow();
X if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow();
X if (strcmp(s,"hint") == 0) GiveHint();
X if (strcmp(s,"both") == 0)
X {
X bothsides = !bothsides;
X Sdepth = 0;
X SelectMove(opponent,1);
X ok = true;
X }
X if (strcmp(s,"reverse") == 0)
X {
X reverse = !reverse;
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X }
X if (strcmp(s,"switch") == 0)
X {
X computer = otherside[computer];
X opponent = otherside[opponent];
X force = false;
X Sdepth = 0;
X ok = true;
X }
X if (strcmp(s,"white") == 0)
X {
X computer = white; opponent = black;
X ok = true; force = false;
X Sdepth = 0;
X }
X if (strcmp(s,"black") == 0)
X {
X computer = black; opponent = white;
X ok = true; force = false;
X Sdepth = 0;
X }
X if (strcmp(s,"remove") == 0 && GameCnt >= 1)
X {
X Undo(); Undo();
X }
X if (strcmp(s,"get") == 0) GetGame();
X if (strcmp(s,"save") == 0) SaveGame();
X if (strcmp(s,"depth") == 0) ChangeSearchDepth();
X if (strcmp(s,"random") == 0) dither = 6;
X if (strcmp(s,"easy") == 0) easy = !easy;
X if (strcmp(s,"contempt") == 0) SetContempt();
X if (strcmp(s,"xwndw") == 0) ChangeXwindow();
X if (strcmp(s,"test") == 0)
X {
X t1 = time(0);
X cnt = 0;
X for (i = 0; i < 10000; i++)
X {
X MoveList(opponent,2);
X cnt += TrPnt[3] - TrPnt[2];
X }
X t2 = time(0);
X rate = cnt / (t2-t1);
X gotoXY(50,24);
X printz("cnt= %ld rate= %ld",cnt,rate);
X ClrEoln();
X }
X if (strcmp(s,"p") == 0) ShowPostnValues();
X if (strcmp(s,"debug") == 0) DoDebug();
X }
X
X ClearMessage();
X ElapsedTime(1);
X if (force)
X {
X computer = opponent; opponent = otherside[computer];
X }
X (void) times(&tmbuf1);
X signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
X}
X
X
XEditBoard()
X
X/*
X Set up a board position. Pieces are entered by typing the piece
X followed by the location. For example, Nf3 will place a knight on
X square f3.
X*/
X
X{
Xshort a,r,c,sq;
Xchar s[80];
X
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X gotoXY(50,2); printz(". Exit to main");
X gotoXY(50,3); printz("# Clear board");
X gotoXY(49,5); printz("Enter piece & location: ");
X a = white;
X do
X {
X gotoXY(73,5); ClrEoln(); scanz("%s",s);
X if (s[0] == '#')
X {
X for (sq = 0; sq < 64; sq++)
X {
X board[sq] = no_piece; color[sq] = neutral;
X }
X UpdateDisplay(0,0,1,0);
X }
X if (s[0] == 'c' || s[0] == 'C') a = otherside[a];
X c = s[1]-'a'; r = s[2]-'1';
X if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
X {
X sq = locn[r][c];
X color[sq] = a;
X if (s[0] == 'p') board[sq] = pawn;
X else if (s[0] == 'n') board[sq] = knight;
X else if (s[0] == 'b') board[sq] = bishop;
X else if (s[0] == 'r') board[sq] = rook;
X else if (s[0] == 'q') board[sq] = queen;
X else if (s[0] == 'k') board[sq] = king;
X else { board[sq] = no_piece; color[sq] = neutral; }
X DrawPiece(sq);
X }
X }
X while (s[0] != '.');
X if (board[4] != king) kingmoved[white] = 10;
X if (board[60] != king) kingmoved[black] = 10;
X GameCnt = -1; Game50 = 0; Sdepth = 0;
X InitializeStats();
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X}
X
X
Xhelp()
X{
X ClrScreen();
X gotoXY(28,1); printz("CHESS command summary");
X gotoXY(1,3); printz("g1f3 move from g1 to f3");
X gotoXY(1,4); printz("nf3 move knight to f3");
X gotoXY(1,5); printz("o-o castle king side");
X gotoXY(1,6); printz("o-o-o castle queen side");
X gotoXY(1,7); printz("edit edit board");
X gotoXY(1,8); printz("switch sides with computer");
X gotoXY(1,9); printz("white computer plays white");
X gotoXY(1,10); printz("black computer plays black");
X gotoXY(1,11); printz("reverse board display");
X gotoXY(1,12); printz("both computer match");
X gotoXY(1,13); printz("random randomize play");
X gotoXY(1,14); printz("undo undo last move");
X gotoXY(42,3); printz("level change level");
X gotoXY(42,4); printz("depth set search depth");
X gotoXY(42,5); printz("post principle variation");
X gotoXY(42,6); printz("hint suggest a move");
X gotoXY(42,7); printz("bd redraw board");
X gotoXY(42,8); printz("force enter game moves");
X gotoXY(42,9); printz("list game to chess.lst");
X gotoXY(42,10); printz("save game to file");
X gotoXY(42,11); printz("get game from file");
X gotoXY(42,12); printz("new start new game");
X gotoXY(42,13); printz("quit exit CHESS");
X gotoXY(10,21); printz("Computer: ");
X if (computer == white) printz("WHITE"); else printz("BLACK");
X gotoXY(10,22); printz("Opponent: ");
X if (opponent == white) printz("WHITE"); else printz("BLACK");
X gotoXY(10,23); printz("Level: %ld",Level);
X gotoXY(10,24); printz("Easy mode: ");
X if (easy) printz("ON"); else printz("OFF");
X gotoXY(40,21); printz("Depth: %d",MaxSearchDepth);
X gotoXY(40,22); printz("Random: ");
X if (dither) printz("ON"); else printz("OFF");
X gotoXY(40,23); printz("Transposition table: ");
X if (hashflag) printz("ON"); else printz("OFF");
X gotoXY(40,24); printz("(press ESC to continue)");
X refresh();
X while (getch() != 27);
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X}
X
X
XShowDepth(ch)
Xchar ch;
X{
X if (player == computer)
X {
X gotoXY(50,4); printz("Depth= %d%c ",Sdepth,ch); ClrEoln();
X }
X}
X
X
XShowResults(score,bstline,ch)
Xshort score;
Xunsigned short bstline[];
Xchar ch;
X{
Xshort d,e,ply;
X if (post && player == computer)
X {
X e = lpost;
X gotoXY(50,5); printz("Score= %d",score); ClrEoln();
X d = 8; gotoXY(50,d); ClrEoln();
X for (ply = 1; bstline[ply] > 0; ply++)
X {
X algbr(bstline[ply] >> 8,bstline[ply] & 0xFF,false);
X if (ply == 5 || ply == 9 || ply == 13 || ply == 17)
X {
X gotoXY(50,++d); ClrEoln();
X }
X printz("%5s ",mvstr1);
X }
X ClrEoln();
X lpost = d;
X while (++d <= e)
X {
X gotoXY(50,d); ClrEoln();
X }
X }
X}
X
X
XSearchStartStuff(side)
Xshort side;
X{
Xshort i;
X signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
X if (player == computer)
X {
X for (i = 5; i < 14; i++)
X {
X gotoXY(50,i); ClrEoln();
X }
X gotoXY(50,22); ClrEoln();
X gotoXY(50,23); ClrEoln();
X }
X}
X
X
XOutputMove()
X{
X if (root->flags & epmask) UpdateDisplay(0,0,1,0);
X else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);
X gotoXY(50,17); printz("My move is: %s",mvstr1);
X if (beep) putchar(7);
X ClrEoln();
X
X gotoXY(50,24);
X if (root->flags & draw) printz("Draw game!");
X else if (root->score == -9999) printz("opponent mates!");
X else if (root->score == 9998) printz("computer mates!");
X else if (root->score < -9000) printz("opponent will soon mate!");
X else if (root->score > 9000) printz("computer will soon mate!");
X ClrEoln();
X
X if (post && player == computer)
X {
X gotoXY(50,22); printz("Nodes= %6ld",NodeCnt); ClrEoln();
X gotoXY(50,23); printz("Nodes/Sec= %4ld",evrate); ClrEoln();
X }
X}
X
X
XElapsedTime(iop)
X
X/*
X Determine the time that has passed since the search was started. If
X the elapsed time exceeds the target (ResponseTime+ExtraTime) then set
X timeout to true which will terminate the search.
X*/
X
Xshort iop;
X{
X et = time((long *)0) - time0;
X if (et < 0) et = 0;
X ETnodes += 50;
X if (et > et0 || iop == 1)
X {
X if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true;
X et0 = et;
X if (iop == 1)
X {
X time0 = time((long *)0); et0 = 0;
X }
X (void) times(&tmbuf2);
X cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;
X if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);
X else evrate = 0;
X ETnodes = NodeCnt + 50;
X UpdateClocks();
X }
X}
X
X
XUpdateClocks()
X{
Xshort m,s;
X m = et/60; s = (et - 60*m);
X if (TCflag)
X {
X m = (TimeControl.clock[player] - et) / 60;
X s = TimeControl.clock[player] - et - 60*m;
X }
X if (m < 0) m = 0;
X if (s < 0) s = 0;
X if (player == white)
X if (reverse) gotoXY(20,2); else gotoXY(20,23);
X else
X if (reverse) gotoXY(20,23); else gotoXY(20,2);
X printz("%d:%2d ",m,s);
X refresh();
X}
X
X
X
XSetTimeControl()
X{
X if (TCflag)
X {
X TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
X TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;
X }
X else
X {
X TimeControl.moves[white] = TimeControl.moves[black] = 0;
X TimeControl.clock[white] = TimeControl.clock[black] = 0;
X Level = 60*(long)TCminutes;
X }
X et = 0;
X ElapsedTime(1);
X}
X
X
XgotoXY(x,y)
Xshort x,y;
X{
X move(y-1,x-1);
X}
X
X
XClrScreen()
X{
X clear(); refresh();
X}
X
X
XClrEoln()
X{
X clrtoeol(); refresh();
X}
X
X
XDrawPiece(sq)
Xshort sq;
X{
Xshort r,c; char x;
X if (reverse) r = 7-row[sq]; else r = row[sq];
X if (reverse) c = 7-column[sq]; else c = column[sq];
X if (color[sq] == black) x = '*'; else x = ' ';
X gotoXY(5+5*c,5+2*(7-r)); printz("%c%c ",x,pxx[board[sq]]);
X}
X
X
XUpdateDisplay(f,t,flag,iscastle)
Xshort f,t,flag,iscastle;
X{
Xshort i,l,z;
X if (flag)
X {
X gotoXY(56,2); printz("CHESS");
X i = 3;
X gotoXY(3,++i);
X printz("|----|----|----|----|----|----|----|----|");
X while (i<19)
X {
X gotoXY(1,++i);
X if (reverse) z = (i/2)-1; else z = 10-(i/2);
X printz("%d | | | | | | | | |",z);
X gotoXY(3,++i);
X if (i < 19)
X printz("+----+----+----+----+----+----+----+----+");
X }
X printz("|----|----|----|----|----|----|----|----|");
X gotoXY(3,21);
X if (reverse) printz(" h g f e d c b a");
X else printz(" a b c d e f g h");
X if (reverse) gotoXY(5,23); else gotoXY(5,2);
X if (computer == black) printz("Computer"); else printz("Human ");
X if (reverse) gotoXY(5,2); else gotoXY(5,23);
X if (computer == white) printz("Computer"); else printz("Human ");
X for (l = 0; l < 64; l++) DrawPiece(l);
X }
X else
X {
X DrawPiece(f); DrawPiece(t);
X if (iscastle)
X if (t > f)
X { DrawPiece(f+3); DrawPiece(t-1); }
X else
X { DrawPiece(f-4); DrawPiece(t+1); }
X }
X refresh();
X}
X
X
XGetOpenings()
X
X/*
X Read in the Opening Book file and parse the algebraic notation for a
X move into an unsigned integer format indicating the from and to
X square. Create a linked list of opening lines of play, with
X entry->next pointing to the next line and entry->move pointing to a
X chunk of memory containing the moves. More Opening lines of up to 256
X half moves may be added to gnuchess.book.
X*/
X
X{
XFILE *fd;
Xint c,i,j,side;
Xstruct BookEntry *entry;
Xunsigned short mv,*mp,tmp[100];
X
X if ((fd = fopen("gnuchess.book","r")) != NULL)
X {
X Book = NULL;
X i = 0; side = white;
X while ((c = parse(fd,&mv,side)) >= 0)
X if (c == 1)
X {
X tmp[++i] = mv;
X side = otherside[side];
X }
X else if (c == 0 && i > 0)
X {
X entry = (struct BookEntry *)malloc(sizeof(struct BookEntry));
X mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short));
X entry->mv = mp;
X entry->next = Book;
X Book = entry;
X for (j = 1; j <= i; j++) *(mp++) = tmp[j];
X *mp = 0;
X i = 0; side = white;
X }
X fclose(fd);
X }
X}
X
X
Xint parse(fd,mv,side)
XFILE *fd;
Xunsigned short *mv;
Xshort side;
X{
Xint c,i,r1,r2,c1,c2;
Xchar s[100];
X while ((c = getc(fd)) == ' ');
X i = 0; s[0] = c;
X while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd);
X s[++i] = '\0';
X if (c == EOF) return(-1);
X if (s[0] == '!' || i < 3)
X {
X while (c != '\n' && c != EOF) c = getc(fd);
X return(0);
X }
X if (s[4] == 'o')
X if (side == black) *mv = 0x3C3A; else *mv = 0x0402;
X else if (s[0] == 'o')
X if (side == black) *mv = 0x3C3E; else *mv = 0x0406;
X else
X {
X c1 = s[0] - 'a'; r1 = s[1] - '1';
X c2 = s[2] - 'a'; r2 = s[3] - '1';
X *mv = (locn[r1][c1]<<8) + locn[r2][c2];
X }
X return(1);
X}
X
X
XGetGame()
X{
XFILE *fd;
Xchar fname[40];
Xint c;
Xshort sq;
Xunsigned short m;
X
X ShowMessage("File name: ");
X scanz("%s",fname);
X if (fname[0] == '\0') strcpy(fname,"chess.000");
X if ((fd = fopen(fname,"r")) != NULL)
X {
X fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50);
X fscanf(fd,"%hd%hd%hd%hd",
X &castld[white],&castld[black],
X &kingmoved[white],&kingmoved[black]);
X fscanf(fd,"%hd%hd",&TCflag,&OperatorTime);
X fscanf(fd,"%ld%ld%hd%hd",
X &TimeControl.clock[white],&TimeControl.clock[black],
X &TimeControl.moves[white],&TimeControl.moves[black]);
X for (sq = 0; sq < 64; sq++)
X {
X fscanf(fd,"%hd",&m);
X board[sq] = (m >> 8); color[sq] = (m & 0xFF);
X if (color[sq] == 0) color[sq] = neutral; else --color[sq];
X }
X GameCnt = -1; c = '?';
X while (c != EOF)
X {
X ++GameCnt;
X c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove,
X &GameList[GameCnt].score,&GameList[GameCnt].depth,
X &GameList[GameCnt].nodes,&GameList[GameCnt].time,
X &GameList[GameCnt].piece,&GameList[GameCnt].color);
X if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral;
X else --GameList[GameCnt].color;
X }
X GameCnt--;
X if (TimeControl.clock[white] > 0) TCflag = true;
X computer--; opponent--;
X }
X fclose(fd);
X InitializeStats();
X UpdateDisplay(0,0,1,0);
X Sdepth = 0;
X}
X
X
XSaveGame()
X{
XFILE *fd;
Xchar fname[40];
Xshort sq,i,c;
X
X ShowMessage("File name: ");
X scanz("%s",fname);
X
X if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000");
X fd = fopen(fname,"w");
X fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50);
X fprintf(fd,"%d %d %d %d\n",
X castld[white],castld[black],kingmoved[white],kingmoved[black]);
X fprintf(fd,"%d %d\n",TCflag,OperatorTime);
X fprintf(fd,"%ld %ld %d %d\n",
X TimeControl.clock[white],TimeControl.clock[black],
X TimeControl.moves[white],TimeControl.moves[black]);
X for (sq = 0; sq < 64; sq++)
X {
X if (color[sq] == neutral) c = 0; else c = color[sq]+1;
X fprintf(fd,"%d\n",256*board[sq] + c);
X }
X for (i = 0; i <= GameCnt; i++)
X {
X if (GameList[i].color == neutral) c = 0;
X else c = GameList[i].color + 1;
X fprintf(fd,"%d %d %d %ld %d %d %d\n",
X GameList[i].gmove,GameList[i].score,GameList[i].depth,
X GameList[i].nodes,GameList[i].time,
X GameList[i].piece,c);
X }
X fclose(fd);
X}
X
X
XListGame()
X{
XFILE *fd;
Xshort i,f,t;
X fd = fopen("chess.lst","w");
X fprintf(fd,"\n");
X fprintf(fd," score depth nodes time ");
X fprintf(fd," score depth nodes time\n");
X for (i = 0; i <= GameCnt; i++)
X {
X f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF);
X algbr(f,t,false);
X if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd," ");
X fprintf(fd,"%5s %5d %2d %6ld %5d",mvstr1,
X GameList[i].score,GameList[i].depth,
X GameList[i].nodes,GameList[i].time);
X }
X fprintf(fd,"\n\n");
X fclose(fd);
X}
X
X
XUndo()
X
X/*
X Undo the most recent half-move.
X*/
X
X{
Xshort f,t;
X f = GameList[GameCnt].gmove>>8;
X t = GameList[GameCnt].gmove & 0xFF;
X if (board[t] == king && distance(t,f) > 1)
X castle(GameList[GameCnt].color,f,t,2);
X else
X {
X board[f] = board[t]; color[f] = color[t];
X board[t] = GameList[GameCnt].piece;
X color[t] = GameList[GameCnt].color;
X if (board[f] == king) --kingmoved[color[f]];
X }
X if (TCflag) ++TimeControl.moves[color[f]];
X GameCnt--; mate = false; Sdepth = 0;
X UpdateDisplay(0,0,1,0);
X InitializeStats();
X}
X
X
XShowMessage(s)
Xchar *s;
X{
X gotoXY(50,24); printz("%s",s); ClrEoln();
X}
X
XClearMessage()
X{
X gotoXY(50,24); ClrEoln();
X}
X
XShowSidetomove()
X{
X gotoXY(50,14);
X if (player == white) printz("%2d: WHITE",1+(GameCnt+1)/2);
X else printz("%2d: BLACK",1+(GameCnt+1)/2);
X ClrEoln();
X}
X
XPromptForMove()
X{
X gotoXY(50,19); printz("Your move is? "); ClrEoln();
X}
X
XShowCurrentMove(pnt,f,t)
Xshort pnt,f,t;
X{
X if (post && player == computer)
X {
X algbr(f,t,false);
X gotoXY(50,7); printz("(%2d) %4s",pnt,mvstr1);
X }
X}
X
XChangeAlphaWindow()
X{
X ShowMessage("window: ");
X scanz("%hd",&Awindow);
X}
X
XChangeBetaWindow()
X{
X ShowMessage("window: ");
X scanz("%hd",&Bwindow);
X}
X
XGiveHint()
X{
Xchar s[40];
X algbr((short)(hint>>8),(short)(hint & 0xFF),false);
X strcpy(s,"try ");
X strcat(s,mvstr1);
X ShowMessage(s);
X}
X
XChangeSearchDepth()
X{
X ShowMessage("depth= ");
X scanz("%hd",&MaxSearchDepth);
X}
X
XSetContempt()
X{
X ShowMessage("contempt= ");
X scanz("%hd",&contempt);
X}
X
XChangeXwindow()
X{
X ShowMessage("xwndw= ");
X scanz("%hd",&xwndw);
X}
X
X
XSelectLevel()
X{
X ClrScreen();
X gotoXY(32,2); printz("CHESS");
X gotoXY(20,4); printz(" 1. 60 moves in 5 minutes");
X gotoXY(20,5); printz(" 2. 60 moves in 15 minutes");
X gotoXY(20,6); printz(" 3. 60 moves in 30 minutes");
X gotoXY(20,7); printz(" 4. 40 moves in 30 minutes");
X gotoXY(20,8); printz(" 5. 40 moves in 60 minutes");
X gotoXY(20,9); printz(" 6. 40 moves in 120 minutes");
X gotoXY(20,10); printz(" 7. 40 moves in 240 minutes");
X gotoXY(20,11); printz(" 8. 1 move in 15 minutes");
X gotoXY(20,12); printz(" 9. 1 move in 60 minutes");
X gotoXY(20,13); printz("10. 1 move in 600 minutes");
X
X OperatorTime = 0; TCmoves = 60; TCminutes = 5;
X gotoXY(20,17); printz("Enter Level: ");
X refresh();
X scanz("%ld",&Level);
X switch (Level)
X {
X case 1 : TCmoves = 60; TCminutes = 5; break;
X case 2 : TCmoves = 60; TCminutes = 15; break;
X case 3 : TCmoves = 60; TCminutes = 30; break;
X case 4 : TCmoves = 40; TCminutes = 30; break;
X case 5 : TCmoves = 40; TCminutes = 60; break;
X case 6 : TCmoves = 40; TCminutes = 120; break;
X case 7 : TCmoves = 40; TCminutes = 240; break;
X case 8 : TCmoves = 1; TCminutes = 15; break;
X case 9 : TCmoves = 1; TCminutes = 60; break;
X case 10 : TCmoves = 1; TCminutes = 600; break;
X }
X TCflag = (TCmoves > 1);
X SetTimeControl();
X ClrScreen();
X UpdateDisplay(0,0,1,0);
X}
X
X
XShowPostnValues()
X{
Xshort i,r,c;
X ExaminePosition();
X for (i = 0; i < 64; i++)
X {
X if (reverse) r = 7-row[i]; else r = row[i];
X if (reverse) c = 7-column[i]; else c = column[i];
X gotoXY(4+5*c,5+2*(7-r));
X c1 = color[i]; c2 = otherside[c1];
X PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2];
X atk1 = atak[c1]; atk2 = atak[c2];
X if (color[i] == neutral) printz(" ");
X else printz("%3d ",SqValue(i,opponent));
X }
X ScorePosition(opponent,&i);
X gotoXY(50,24);
X printz("Score= %d",i); ClrEoln();
X}
X
X
XDoDebug()
X{
Xshort k,p,i,r,c,tp,tc;
Xchar s[40];
X ExaminePosition();
X ShowMessage("Enter piece: ");
X scanz("%s",s);
X if (s[0] == 'w') k = white; else k = black;
X if (s[1] == 'p') p = pawn;
X else if (s[1] == 'n') p = knight;
X else if (s[1] == 'b') p = bishop;
X else if (s[1] == 'r') p = rook;
X else if (s[1] == 'q') p = queen;
X else if (s[1] == 'k') p = king;
X else p = no_piece;
X for (i = 0; i < 64; i++)
X {
X if (reverse) r = 7-row[i]; else r = row[i];
X if (reverse) c = 7-column[i]; else c = column[i];
X gotoXY(4+5*c,5+2*(7-r));
X tp = board[i]; tc = color[i];
X board[i] = p; color[i] = k;
X c1 = k; c2 = otherside[c1];
X PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2];
X atk1 = atak[c1]; atk2 = atak[c2];
X printz("%3d ",SqValue(i,opponent));
X board[i] = tp; color[i] = tc;
X }
X ScorePosition(opponent,&i);
X gotoXY(50,24);
X printz("Score= %d",i); ClrEoln();
X}
END_OF_uxdsp.c
if test 23942 -ne `wc -c <uxdsp.c`; then
echo shar: \"uxdsp.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 3 \(of 4\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 4 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0