[alt.sources.patches] GNU Chess -- new file for terminal display gnu.chess

erlkonig@walt.cc.utexas.edu (Christopher North-Keys) (12/19/89)

Archive-name: gnu-chess/erlkonig-nuxdsp.c
Original-posting-by: erlkonig@walt.cc.utexas.edu (Christopher North-Keys)
Original-subject: New file for terminal display of Gnuchess:  nuxdisp.c
Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)

[This is a patch to  from gnu.chess.]


I would have just published diffs to uxdisp.c, but the diffs ran longer
than the file.  The new module is not thoroughly tested, nor have the
features been reduced to the more elegant minimum, but it's very spiffy.
[ Produced on a Sun3/150 running SunOS 4.0.3 ]
[ Be careful to kill any .sig at the end of this posting ]

Add the following makefile targets, being sure to retain the <tabs>:


gnuchessn: gnuchess.o nuxdsp.o $(NEW)
	$(CC) $(CFLAGS) -o gnuchessn gnuchess.o nuxdsp.o $(NEW) -lcurses -ltermlib

nondsp.o: nondsp.c
	$(CC) $(CFLAGS) -c nondsp.c


#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	nuxdsp.c
# This archive created: Mon Dec 11 22:19:18 1989
echo shar: extracting nuxdsp.c '(26158 characters)'
sed 's/^XX//' << \SHAR_EOF > nuxdsp.c
XX/*
XX  ALPHA interface for CHESS
XX  
XX  Revision: 4-25-88
XX  
XX  Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
XX  Copyright (c) 1988  John Stanback
XX  
XX  Modified extensively Nov 1989 Christopher North-Keys
XX    40x24 two-colour display
XX	option for shading black squares
XX	expanded game save, list, and restore features using $HOME
XX	option to disable display of coordinates
XX	optional auto-updating of positional information
XX	optional starring of black side
XX	mass toggle for reverse-video functions
XX
XX  This file is part of CHESS.
XX  
XX  CHESS is distributed in the hope that it will be useful,
XX  but WITHOUT ANY WARRANTY.  No author or distributor
XX  accepts responsibility to anyone for the consequences of using it
XX  or for whether it serves any particular purpose or works at all,
XX  unless he says so in writing.  Refer to the CHESS General Public
XX  License for full details.
XX  
XX  Everyone is granted permission to copy, modify and redistribute
XX  CHESS, but only under the conditions described in the
XX  CHESS General Public License.   A copy of this license is
XX  supposed to have been given to you along with CHESS so you
XX  can know your rights and responsibilities.  It should be in a
XX  file named COPYING.  Among other things, the copyright notice
XX  and this notice must be preserved on all copies.
XX  */
XX
XX
XX#include <stdio.h>
XX#include <ctype.h>
XX#include <sys/param.h>
XX#include <sys/times.h>
XX#include <sys/file.h>
XX#include <sys/param.h>
XX#include <curses.h>
XX#include <signal.h>
XX#include <strings.h>
XX#include "gnuchess.h"
XX#ifdef NEWMOVE
XX#include "move.h"
XX#endif
XX
XXextern char *getenv();
XX
XX/* coordinates within a square for the following are ([1,5],[1,3]) */
XX#define SQW (5)
XX#define SQH (3)
XX#define WhiteRow "     "
XX#define WhiteHole "   "
XX#define BlackRow "/////"
XX#define BlackHole "///"
XX#define SpaceRow "     "
XX#define SpaceHole "   "
XX#define TAB (45)
XX#define VIR_C(s)  ( reverse ? 7-column[(s)] : column[(s)] )
XX#define VIR_R(s)  ( reverse ? 7-row[(s)] : row[(s)] )
XX#define VSQ_X(x)  ( reverse ? SQW + 1 - (x) : (x) )
XX#define VSQ_Y(y)  ( reverse ? SQH + 1 - (y) : (y) )
XX#define Vblack(s) ( ! ((VIR_C(s) + VIR_R(s)) % 2) )
XX/* Squares swapped */
XX#define Vcoord(s,x,y) \
XX	((SQW)*(VIR_C(s)))+(x),((SQH)*(7-VIR_R(s))+(y))
XX/* Squares and internal locations swapped */
XX#define VcoordI(s,x,y) \
XX	((SQW)*(VIR_C(s)))+(VSQ_X(x)),((SQH)*(7-VIR_R(s))+(VSQ_Y(y)))
XX/* Squares and internal rows swapped */
XX#define VcoordR(s,x,y) \
XX	((SQW)*(VIR_C(s)))+(x),((SQH)*(7-VIR_R(s))+(VSQ_Y(y)))
XX
XXstruct tms tmbuf1,tmbuf2;
XXint TerminateSearch(),Die();
XXshort PositionFlag = 0;
XXshort coords = 1;
XXshort stars  = 0;
XXshort rv     = 1;
XXshort brv    = 1;
XXshort prv    = 1;
XX
XX#define scanz fflush(stdout),scanw
XX#define printz printw
XX
XX	
XXInitialize()
XX{
XX	signal(SIGINT,Die); signal(SIGQUIT,Die);
XX	initscr();
XX	crmode();
XX}
XX
XX
XXExitChess()
XX{
XX	nocrmode();
XX	endwin();
XX	exit(0);
XX}
XX
XX
XXDie()
XX{
XX	char s[80];
XX	signal(SIGINT,SIG_IGN);
XX	signal(SIGQUIT,SIG_IGN);
XX	ShowMessage("Abort? ");
XX	scanz("%s",s);
XX	if (strcmp(s,"yes") == 0) ExitChess();
XX	signal(SIGINT,Die); signal(SIGQUIT,Die);
XX}
XX
XX
XXTerminateSearch()
XX{
XX	signal(SIGINT,SIG_IGN);
XX	signal(SIGQUIT,SIG_IGN);
XX	timeout = true;
XX	bothsides = false;
XX	signal(SIGINT,Die); signal(SIGQUIT,Die);
XX}
XX
XX
XXInputCommand()
XX
XX/*
XX  Process the users command. If easy mode is OFF (the computer is 
XX  thinking on opponents time) and the program is out of book, then make 
XX  the 'hint' move on the board and call SelectMove() to find a response. 
XX  The user terminates the search by entering ^C (quit siqnal) before 
XX  entering a command. If the opponent does not make the hint move, then 
XX  set Sdepth to zero. 
XX  */
XX
XX{
XX	short ok,i,tmp;
XX	long cnt,rate,t1,t2;
XX	unsigned short mv;
XX	char s[80];
XX	
XX	ok = quit = false;
XX	player = opponent;
XX	ShowSidetomove();
XX	ft = 0;
XX	if (hint > 0 && !easy && Book == NULL)
XX    {
XX		fflush(stdout);
XX		time0 = time((long *)0);
XX		algbr(hint>>8,hint & 0xFF,false);
XX		strcpy(s,mvstr1);
XX		tmp = epsquare;
XX		if (VerifyMove(s,1,&mv))
XX        {
XX			PromptForMove();
XX			SelectMove(computer,2);
XX			VerifyMove(mvstr1,2,&mv);
XX			if (Sdepth > 0) Sdepth--;
XX        }
XX		ft = time((long *)0) - time0;
XX		epsquare = tmp;
XX    }
XX	
XX	signal(SIGINT,Die); signal(SIGQUIT,Die);
XX	while (!(ok || quit))
XX    {
XX		PromptForMove();
XX		scanz("%s",s);
XX		player = opponent;
XX		ok = VerifyMove(s,0,&mv);
XX		if (ok && mv != hint)
XX        {
XX			Sdepth = 0;
XX			ft = 0;
XX        }
XX        
XX		if (*s == '\0') UpdateDisplay(0,0,1,0);
XX
XX		if (strcmp(s,"bd") == 0)
XX        {
XX			ClrScreen();
XX			UpdateDisplay(0,0,1,0);
XX        }
XX		if (strcmp(s,"quit") == 0) quit = true;
XX		if (strcmp(s,"post") == 0) post = !post;
XX		if (strcmp(s,"edit") == 0) EditBoard();
XX		if (strcmp(s,"go") == 0) ok = true;
XX		if (strcmp(s,"help") == 0) help();
XX		if (strcmp(s,"force") == 0) force = !force;
XX		if (strcmp(s,"book") == 0) Book = NULL;
XX		if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo();
XX		if (strcmp(s,"new") == 0) NewGame();
XX		if (strcmp(s,"list") == 0) ListGame();
XX		if (strcmp(s,"level") == 0) SelectLevel();
XX		if (strcmp(s,"hash") == 0) hashflag = !hashflag;
XX		if (strcmp(s,"beep") == 0) beep = !beep;
XX		if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow();
XX		if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow();
XX		if (strcmp(s,"hint") == 0) GiveHint();
XX		if (strcmp(s,"both") == 0)
XX        {
XX			bothsides = !bothsides;
XX			Sdepth = 0;
XX			SelectMove(opponent,1);
XX			ok = true;
XX        }
XX		if (strcmp(s,"reverse") == 0)
XX        {
XX			reverse = !reverse;
XX			ClrScreen();
XX			UpdateDisplay(0,0,1,0);
XX        }
XX		if (strcmp(s,"switch") == 0)
XX        {
XX			computer = otherside[computer];
XX			opponent = otherside[opponent];
XX			force = false;
XX			Sdepth = 0;
XX			ok = true;
XX        }
XX		if (strcmp(s,"white") == 0)  
XX        {
XX			computer = white; opponent = black;
XX			ok = true; force = false;
XX			Sdepth = 0;
XX        }
XX		if (strcmp(s,"black") == 0)
XX        {
XX			computer = black; opponent = white;
XX			ok = true; force = false;
XX			Sdepth = 0;
XX        }
XX		if (strcmp(s,"remove") == 0 && GameCnt >= 1) 
XX        {
XX			Undo(); Undo();
XX        }
XX		if (strcmp(s,"get") == 0) GetGame();
XX		if (strcmp(s,"save") == 0) SaveGame();
XX		if (strcmp(s,"depth") == 0) ChangeSearchDepth();
XX		if (strcmp(s,"random") == 0) dither = 6;
XX		if (strcmp(s,"easy") == 0) easy = !easy;
XX		if (strcmp(s,"contempt") == 0) SetContempt();
XX		if (strcmp(s,"xwndw") == 0) ChangeXwindow();
XX		if (strcmp(s,"coords") == 0)
XX		{
XX			coords = !coords;
XX			UpdateDisplay(0,0,1,0);
XX		}
XX		if (strcmp(s,"stars") == 0)
XX		{
XX			stars = !stars;
XX			UpdateDisplay(0,0,1,0);
XX		}
XX		if (strcmp(s,"test") == 0)
XX        {
XX			t1 = time(0);
XX			cnt = 0;
XX			for (i = 0; i < 10000; i++)
XX            {
XX				MoveList(opponent,2);
XX				cnt += TrPnt[3] - TrPnt[2];
XX            }
XX			t2 = time(0);
XX			rate = cnt / (t2-t1);
XX			gotoXY(TAB,24);
XX			printz("cnt= %ld  rate= %ld",cnt,rate);
XX			ClrEoln();
XX        }
XX		if (strcmp(s,"p") == 0)
XX		{
XX			if(PositionFlag = !PositionFlag);
XX			UpdateDisplay(0,0,1,0);
XX		}
XX		if (strcmp(s,"debug") == 0) DoDebug();
XX		if (strcmp(s,"rv") == 0)
XX		{
XX			rv    = !rv;
XX			brv   =  rv;
XX			prv   =  rv;
XX			stars = !rv;
XX			UpdateDisplay(0,0,1,0);
XX		}
XX		if (strcmp(s,"brv") == 0)
XX        {
XX			brv   = !brv;
XX			ClrScreen();
XX			UpdateDisplay(0,0,1,0);
XX        }
XX		if (strcmp(s,"prv") == 0)
XX        {
XX			prv   = !prv;
XX			stars = !prv;
XX			ClrScreen();
XX			UpdateDisplay(0,0,1,0);
XX        }
XX    }
XX    
XX	ClearMessage();
XX	ElapsedTime(1);
XX	if (force)
XX    {
XX		computer = opponent; opponent = otherside[computer];
XX    }
XX	(void) times(&tmbuf1);
XX	signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
XX}
XX
XX
XXEditBoard()
XX
XX/* 
XX  Set up a board position. Pieces are entered by typing the piece 
XX  followed by the location. For example, Nf3 will place a knight on 
XX  square f3. 
XX  */
XX
XX{
XX	short a,r,c,sq;
XX	char s[80];
XX	
XX	ClrScreen();
XX	UpdateDisplay(0,0,1,0);
XX	gotoXY(TAB,2); printz(".   Exit to main");
XX	gotoXY(TAB,3); printz("#   Clear board");
XX	gotoXY(TAB,4); printz("c   Change sides");
XX	gotoXY(45,8); printz("Enter piece & location: ");
XX	a = white;
XX	do
XX	{
XX		ShowMessage(a == white ? "Editing:  white" : "Editing:  black");
XX		gotoXY(73,5); ClrEoln(); scanz("%s",s);
XX		if (s[0] == '#')
XX		{
XX			for (sq = 0; sq < 64; sq++)
XX			{
XX				board[sq] = no_piece; color[sq] = neutral;
XX			}
XX			UpdateDisplay(0,0,1,0);
XX		}
XX		if (s[0] == 'c' || s[0] == 'C') a = otherside[a];
XX		c = s[1]-'a'; r = s[2]-'1';
XX		if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
XX		{
XX			sq = locn[r][c];
XX			color[sq] = a;
XX			if (s[0] == 'p') board[sq] = pawn;
XX			else if (s[0] == 'n') board[sq] = knight;
XX			else if (s[0] == 'b') board[sq] = bishop;
XX			else if (s[0] == 'r') board[sq] = rook;
XX			else if (s[0] == 'q') board[sq] = queen;
XX			else if (s[0] == 'k') board[sq] = king;
XX			else { board[sq] = no_piece; color[sq] = neutral; }
XX			DrawPiece(sq);
XX		}
XX	} while (s[0] != '.');
XX
XX	if (board[4] != king) kingmoved[white] = 10;
XX	if (board[60] != king) kingmoved[black] = 10;
XX	GameCnt = -1; Game50 = 0; Sdepth = 0;
XX	InitializeStats();
XX	ClrScreen();
XX	UpdateDisplay(0,0,1,0);
XX}
XX
XX
XXhelp()
XX{
XX	ClrScreen();
XX	gotoXY(28,1); printz("CHESS command summary");
XX	gotoXY(1,3); printz("g1f3      move from g1 to f3");
XX	gotoXY(1,4); printz("nf3       move knight to f3");
XX	gotoXY(1,5); printz("o-o       castle king side");
XX	gotoXY(1,6); printz("o-o-o     castle queen side");
XX	gotoXY(1,7); printz("edit      edit board");
XX	gotoXY(1,8); printz("switch    sides with computer");
XX	gotoXY(1,9); printz("white     computer plays white");
XX	gotoXY(1,10); printz("black     computer plays black");
XX	gotoXY(1,11); printz("reverse   board display");
XX	gotoXY(1,12); printz("both      computer match");
XX	gotoXY(1,13); printz("random    randomize play");
XX	gotoXY(1,14); printz("undo      undo last move");
XX	gotoXY(1,15); printz("brv       toggle board reverse video");
XX	gotoXY(1,16); printz("prv       toggle pieces reverse video");
XX	gotoXY(1,17); printz("rv        toggle reverse video");
XX	gotoXY(42,3); printz("level     change level");
XX	gotoXY(42,4); printz("depth     set search depth");
XX	gotoXY(42,5); printz("post      principle variation");
XX	gotoXY(42,6); printz("hint      suggest a move");
XX	gotoXY(42,7); printz("bd        redraw board");
XX	gotoXY(42,8); printz("coords    toggle coords");
XX	gotoXY(42,9); printz("stars     toggle stars");
XX	gotoXY(42,10); printz("force     enter game moves");
XX	gotoXY(42,11); printz("list      game to chess.lst");
XX	gotoXY(42,12); printz("save      game to file");
XX	gotoXY(42,13); printz("get       game from file");
XX	gotoXY(42,14); printz("new       start new game");
XX	gotoXY(42,15); printz("quit      exit CHESS");
XX	gotoXY(10,21); printz("Computer: ");
XX	if (computer == white) printz("WHITE"); else printz("BLACK");
XX	gotoXY(10,22); printz("Opponent: ");
XX	if (opponent == white) printz("WHITE"); else printz("BLACK");
XX	gotoXY(10,23); printz("Level: %ld",Level," sec.");
XX	gotoXY(10,24); printz("Easy mode: ");
XX	if (easy) printz("ON"); else printz("OFF");
XX	gotoXY(40,21); printz("Depth: %d",MaxSearchDepth);
XX	gotoXY(40,22); printz("Random: "); 
XX	if (dither) printz("ON"); else printz("OFF");
XX	gotoXY(40,23); printz("Transposition table: ");
XX	if (hashflag) printz("ON"); else printz("OFF");
XX	refresh();
XX	while (getchar() != 27);
XX	ClrScreen();
XX	UpdateDisplay(0,0,1,0);
XX}
XX
XX
XXShowDepth(ch)
XXchar ch;
XX{
XX	gotoXY(TAB,4); printz("Depth= %d%c ",Sdepth,ch); ClrEoln();
XX}
XX
XX
XXShowResults(score,bstline,ch)
XXshort score;
XXunsigned short bstline[];
XXchar ch;
XX{
XX	short d,e,ply;
XX	if (post && player == computer)
XX    {
XX		e = lpost;
XX		gotoXY(TAB,5); printz("Score= %d",score); ClrEoln();
XX		d = 8; gotoXY(TAB,d); ClrEoln();
XX		for (ply = 1; bstline[ply] > 0; ply++)
XX        {
XX			algbr(bstline[ply] >> 8,bstline[ply] & 0xFF,false);
XX			if (ply == 5 || ply == 9 || ply == 13 || ply == 17)
XX            {
XX				gotoXY(TAB,++d); ClrEoln();
XX            }
XX			printz("%5s ",mvstr1);
XX        }
XX		ClrEoln();
XX		lpost = d;
XX		while (++d <= e)
XX        {
XX			gotoXY(TAB,d); ClrEoln();
XX        }
XX    }
XX}
XX
XX
XXSearchStartStuff(side)
XXshort side;
XX{
XX	short i;
XX	signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
XX	if (player == computer)
XX		for (i = 5; i < 14; i++)
XX		{
XX			gotoXY(TAB,i); ClrEoln();
XX		}
XX}
XX
XX
XXOutputMove()
XX{
XX	if (root->flags & epmask) UpdateDisplay(0,0,1,0);
XX	else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);
XX	gotoXY(TAB,17); printz("My move is: %s",mvstr1);
XX	if (beep) putchar(7);
XX	ClrEoln();
XX	
XX	gotoXY(TAB,24);
XX	if (root->flags & draw) printz("Drawn game!");
XX	else if (root->score == -9999) printz("Human mates!");
XX	else if (root->score == 9998) printz("Computer mates!");
XX	else if (root->score < -9000) printz("Human will soon mate!");
XX	else if (root->score > 9000)  printz("Computer will soon mate!");
XX	ClrEoln();
XX	
XX	if (post)
XX    {
XX		gotoXY(TAB,22); printz("Nodes=   %6ld",NodeCnt); ClrEoln();
XX		gotoXY(TAB,23); printz("Nodes/Sec= %4ld",evrate); ClrEoln();
XX    }
XX}
XX
XX
XXElapsedTime(iop)
XX
XX/* 
XX  Determine the time that has passed since the search was started. If 
XX  the elapsed time exceeds the target (ResponseTime+ExtraTime) then set 
XX  timeout to true which will terminate the search. 
XX  */
XX
XXshort iop;
XX{
XX	et = time((long *)0) - time0;
XX	if (et < 0) et = 0;
XX	ETnodes += 50;
XX	if (et > et0 || iop == 1)
XX    {
XX		if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true;
XX		et0 = et;
XX		if (iop == 1)
XX        {
XX			time0 = time((long *)0); et0 = 0;
XX        }
XX		(void) times(&tmbuf2);
XX		cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;
XX		if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);
XX		else evrate = 0;
XX		ETnodes = NodeCnt + 50;
XX		UpdateClocks();
XX    }
XX}
XX
XX
XXUpdateClocks()
XX{
XX	short m,s;
XX	m = et/60; s = (et - 60*m);
XX	if (TCflag)
XX    {
XX		m = (TimeControl.clock[player] - et) / 60;
XX		s = TimeControl.clock[player] - et - 60*m;
XX    }
XX	if (m < 0) m = 0;
XX	if (s < 0) s = 0;
XX	if (player == white)
XX		if (reverse) gotoXY(60,2); else gotoXY(60,23);
XX	else
XX		if (reverse) gotoXY(60,23); else gotoXY(60,2);
XX	printz("%d:%2d   ",m,s);
XX	if (post)
XX    {
XX		gotoXY(70,22); printz("Nodes=   %6ld",NodeCnt);
XX		gotoXY(70,23); printz("Nodes/Sec= %4ld",evrate);
XX    }
XX	refresh();
XX}
XX
XX
XX
XXSetTimeControl()
XX{
XX	if (TCflag)
XX    {
XX		TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
XX		TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;
XX    }
XX	else
XX    {
XX		TimeControl.moves[white] = TimeControl.moves[black] = 0;
XX		TimeControl.clock[white] = TimeControl.clock[black] = 0;
XX		Level = 60*(long)TCminutes;
XX    }
XX	et = 0;
XX	ElapsedTime(1);
XX}
XX
XX
XXgotoXY(x,y)
XXshort x,y;
XX{
XX	move(y-1,x-1);
XX}
XX
XX
XXClrScreen()
XX{
XX	clear(); refresh();
XX}
XX
XX
XXClrEoln()
XX{
XX	clrtoeol(); refresh();
XX}
XX
XXDrawPiece(sq)
XXshort sq;
XX{
XX	char x;
XX
XX	gotoXY(VcoordR(sq,2,2));
XX
XX	switch(color[sq])
XX	{
XX	  case black:
XX		if(prv) standout();
XX		printz( (stars ? "=%c=" : " %c "), pxx[board[sq]] );
XX		standend();
XX		break;
XX	  case neutral:
XX		if(brv && Vblack(sq)) standout();
XX		if(brv)
XX			printz(Vblack(sq) ? SpaceHole : SpaceHole );
XX		else
XX			printz(Vblack(sq) ? BlackHole : WhiteHole );
XX		standend();
XX		break;
XX	  case white:
XX		printz( (stars ? "[%c]" : " %c "), pxx[board[sq]] );
XX		break;
XX	  default:
XX		ShowMessage("DrawPiece:  color[sq] err");
XX		break;
XX	}
XX}
XX
XXDrawSquare(sq)
XXshort sq;
XX{
XX	short r;
XX	
XX	if(brv && Vblack(sq)) standout();
XX	for(r=1; r<=3; r++)
XX	{
XX		gotoXY(Vcoord(sq,1,r));
XX		if(brv)
XX			printz(Vblack(sq) ? SpaceRow : SpaceRow );
XX		else
XX			printz(Vblack(sq) ? BlackRow : WhiteRow );
XX	}
XX	
XX	standend();
XX	
XX/* 	DrawPiece(sq); */
XX}
XX
XXDrawCoords()
XX{
XX	short z;
XX
XX	for(z=0; z<=7; z++)
XX	{
XX		short sq;
XX
XX		sq = 8 * z;
XX		gotoXY(VcoordI(sq,1,1));
XX		if (Vblack(sq) && brv) standout();
XX		printz("%d", (1 + z));
XX		standend();
XX	}
XX
XX	for(z=0; z<=7; z++) /* WARNING:  This routine is ASCII-dependent */
XX	{
XX		short sq;
XX		
XX		sq = z;
XX		gotoXY(VcoordI(sq,SQW,SQH));
XX		if (Vblack(sq) && brv) standout();		
XX		printz("%c", ('a' + z));
XX		standend();
XX	}
XX	
XX	for(z=1; z<=(8*SQH); z++)
XX	{
XX		gotoXY((8*SQW)+1,z);
XX		printz("|");
XX	}
XX}	
XX
XXUpdateDisplay(f,t,flag,iscastle)
XXshort f,t,flag,iscastle;
XX{
XX	short i,l; 
XX	if (flag)
XX    {
XX		for(i=0; i<64; i++)
XX		{
XX			DrawSquare(i);
XX			DrawPiece(i);
XX		}
XX		
XX		if(coords) DrawCoords();
XX		
XX		gotoXY(TAB,10);
XX		printz("GNUchess display (Nov 89)");
XX		
XX		gotoXY(TAB,(reverse ? 23 :  2));
XX		if (computer == black) printz("Computer"); else printz("Human   ");
XX		gotoXY(TAB,(reverse ?  2 : 23));
XX		if (computer == white) printz("Computer"); else printz("Human   ");
XX    }
XX	else
XX    {
XX		DrawPiece(f); DrawPiece(t);
XX		if (iscastle)
XX			if (t > f)
XX			{ DrawPiece(f+3); DrawPiece(t-1); }
XX			else
XX			{ DrawPiece(f-4); DrawPiece(t+1); }
XX    }
XX	if(PositionFlag) ShowPostnValues();
XX	refresh();
XX}
XX
XXShowPostnValue(sq)
XXshort sq;
XX{
XX	/* must have called ExaminePosition() first */
XX	
XX	c1 = color[sq]; c2 = otherside[c1];
XX	PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2];
XX	atk1 = atak[c1]; atk2 = atak[c2];
XX
XX	gotoXY(VcoordR(sq,2,1));
XX	if(color[sq] != neutral)
XX	{
XX		if(Vblack(sq) && brv) standout();
XX		printz("%3d",SqValue(sq,opponent));
XX	} else {
XX		if(Vblack(sq) && brv) standout();
XX		if(brv)
XX			printz( Vblack(sq) ? SpaceHole : SpaceHole );
XX		else
XX			printz( Vblack(sq) ? BlackHole : WhiteHole );
XX	}
XX	standend();
XX}
XX
XXShowPostnValues()
XX{
XX	short i;
XX
XX	ExaminePosition();
XX	for (i = 0; i < 64; i++) ShowPostnValue(i);
XX	ScorePosition(opponent,&i);
XX	gotoXY(TAB,24);
XX	printz("Score= %d",i); ClrEoln();
XX}
XX
XXGetOpenings()
XX
XX/*
XX  Read in the Opening Book file and parse the algebraic notation for a 
XX  move into an unsigned integer format indicating the from and to 
XX  square. Create a linked list of opening lines of play, with 
XX  entry->next pointing to the next line and entry->move pointing to a 
XX  chunk of memory containing the moves. More Opening lines of up to 256 
XX  half moves may be added to gnuchess.book. 
XX  */
XX
XX{
XX	FILE *fd;
XX	int c,i,j,side;
XX	struct BookEntry *entry;
XX	unsigned short mv,*mp,tmp[100];
XX	
XX	if ((fd = fopen("gnuchess.book","r")) != NULL)
XX    {
XX		Book = NULL;
XX		i = 0; side = white;
XX		while ((c = parse(fd,&mv,side)) >= 0)
XX			if (c == 1)
XX			{
XX				tmp[++i] = mv;
XX				side = otherside[side];
XX			}
XX			else if (c == 0 && i > 0)
XX			{
XX				entry = (struct BookEntry *)malloc(sizeof(struct BookEntry));
XX				mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short));
XX				entry->mv = mp;
XX				entry->next = Book;
XX				Book = entry; 
XX				for (j = 1; j <= i; j++) *(mp++) = tmp[j];
XX				*mp = 0;
XX				i = 0; side = white;
XX			}
XX		fclose(fd);
XX    }
XX}
XX
XX
XXint parse(fd,mv,side)
XXFILE *fd;
XXunsigned short *mv;
XXshort side;
XX{
XX	int c,i,r1,r2,c1,c2;
XX	char s[100];
XX	while ((c = getc(fd)) == ' ');
XX	i = 0; s[0] = c;
XX	while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd);
XX	s[++i] = '\0';
XX	if (c == EOF) return(-1);
XX	if (s[0] == '!' || i < 3)
XX    {
XX		while (c != '\n' && c != EOF) c = getc(fd);
XX		return(0);
XX    }
XX	if (s[4] == 'o')
XX		if (side == black) *mv = 0x3C3A; else *mv = 0x0402;
XX	else if (s[0] == 'o')
XX		if (side == black) *mv = 0x3C3E; else *mv = 0x0406;
XX	else
XX    {
XX		c1 = s[0] - 'a'; r1 = s[1] - '1';
XX		c2 = s[2] - 'a'; r2 = s[3] - '1';
XX		*mv = (locn[r1][c1]<<8) + locn[r2][c2];
XX    }
XX	return(1);
XX}
XX
XX
XXGetGame()
XX{
XX	FILE *fd;
XX	char fname[MAXPATHLEN], tname[MAXPATHLEN];
XX	char *tmp;
XX	int c;
XX	short sq;
XX	unsigned short m;
XX	
XX	tname[0]=0;
XX
XX	if(tmp=getenv("HOME"))
XX		strcpy(fname, tmp);
XX	else
XX		fname[0]='\0';
XX	strcat(fname, "/");
XX
XX	ShowMessage("File name: ");
XX	scanz("%s", tname);
XX
XX	if(tname[0])
XX		strcat(fname, tname);
XX	else
XX		strcat(fname, ".chess");
XX	
XX	gotoXY(1,1);  printz("%s", fname);
XX
XX	if ((fd = fopen(fname,"r")) == NULL)
XX	{
XX		ShowMessage("Fetch failed");
XX		return;
XX	} 	
XX
XX	fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50);
XX	fscanf(fd,"%hd%hd%hd%hd",
XX		   &castld[white],&castld[black],
XX		   &kingmoved[white],&kingmoved[black]);
XX	fscanf(fd,"%hd%hd",&TCflag,&OperatorTime);
XX	fscanf(fd,"%ld%ld%hd%hd",
XX		   &TimeControl.clock[white],&TimeControl.clock[black],
XX		   &TimeControl.moves[white],&TimeControl.moves[black]);
XX	for (sq = 0; sq < 64; sq++)
XX	{
XX		fscanf(fd,"%hd",&m);
XX		board[sq] = (m >> 8); color[sq] = (m & 0xFF);
XX		if (color[sq] == 0) color[sq] = neutral; else --color[sq];
XX	}
XX	GameCnt = -1; c = '?';
XX	while (c != EOF)
XX	{
XX		++GameCnt;
XX		c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove,
XX				   &GameList[GameCnt].score,&GameList[GameCnt].depth,
XX				   &GameList[GameCnt].nodes,&GameList[GameCnt].time,
XX				   &GameList[GameCnt].piece,&GameList[GameCnt].color);
XX		if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral;
XX		else --GameList[GameCnt].color;
XX	}
XX	GameCnt--;
XX	if (TimeControl.clock[white] > 0) TCflag = true;
XX	computer--; opponent--;
XX	
XX	fclose(fd);
XX
XX	InitializeStats();
XX	Sdepth = 0;
XX	ShowMessage("Fetch done.  Press <Ret>");
XX	scanz("%s",tmp);
XX	UpdateDisplay(0,0,1,0);
XX
XX}
XX
XX
XXSaveGame()
XX{
XX	FILE *fd;
XX	char fname[MAXPATHLEN], tname[MAXPATHLEN];
XX	char *tmp; 
XX	short sq,i,c;
XX	int x;
XX
XX	tname[0]=0;
XX	
XX	if(tmp=getenv("HOME"))
XX		strcpy(fname, tmp);
XX	else
XX		fname[0]='\0';
XX	strcat(fname, "/");
XX
XX	ShowMessage("File name: ");
XX	scanz("%s", tname);
XX
XX	if(tname[0])
XX		strcat(fname, tname);
XX	else
XX		strcat(fname, ".chess");
XX
XX	gotoXY(1,1);  printz("%s", fname);
XX	
XX	if(NULL == (fd = fopen(fname,"w")))
XX	{
XX		ShowMessage("Not saved");
XX		return;
XX	}
XX	
XX	fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50);
XX	fprintf(fd,"%d %d %d %d\n",
XX			castld[white],castld[black],kingmoved[white],kingmoved[black]);
XX	fprintf(fd,"%d %d\n",TCflag,OperatorTime);
XX	fprintf(fd,"%ld %ld %d %d\n",
XX			TimeControl.clock[white],TimeControl.clock[black],
XX			TimeControl.moves[white],TimeControl.moves[black]);
XX	for (sq = 0; sq < 64; sq++)
XX    {
XX		if (color[sq] == neutral) c = 0; else c = color[sq]+1;
XX		fprintf(fd,"%d\n",256*board[sq] + c);
XX    }
XX	for (i = 0; i <= GameCnt; i++)
XX    {
XX		if (GameList[i].color == neutral) c = 0;
XX		else c = GameList[i].color + 1;
XX		fprintf(fd,"%d %d %d %ld %d %d %d\n",
XX				GameList[i].gmove,GameList[i].score,GameList[i].depth,
XX				GameList[i].nodes,GameList[i].time,
XX				GameList[i].piece,c);
XX    }
XX	fclose(fd);
XX	ShowMessage("Save done.  Press <Ret>");
XX	scanz("%s",tmp);
XX	UpdateDisplay(0,0,1,0);
XX}
XX
XX
XXListGame()
XX{
XX	FILE *fd;
XX	char *fname[MAXPATHLEN];
XX	short i,f,t;
XX
XX	strcpy(fname, getenv("HOME"));	
XX	strcat(fname,"/.chess.lst");
XX
XX	if(fd = fopen(fname,"w"))
XX		ShowMessage("Writing ~/.chess.lst");
XX	else
XX	{
XX		ShowMessage("Cannot write ~/.chess.lst");
XX		return;
XX	}
XX	
XX	fprintf(fd,"\n");
XX	fprintf(fd,"       score  depth  nodes  time         ");
XX	fprintf(fd,"       score  depth  nodes  time\n");
XX	for (i = 0; i <= GameCnt; i++)
XX    {
XX		f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF);
XX		algbr(f,t,false);
XX		if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd,"         ");
XX		fprintf(fd,"%5s  %5d     %2d %6ld %5d",mvstr1,
XX				GameList[i].score,GameList[i].depth,
XX				GameList[i].nodes,GameList[i].time);
XX    }
XX	fprintf(fd,"\n\n");
XX	fclose(fd);
XX	ShowMessage("~/.chess.lst written");
XX} 
XX
XX
XXUndo()
XX
XX/*
XX  Undo the most recent half-move.
XX  */
XX
XX{
XX	short f,t;
XX	f = GameList[GameCnt].gmove>>8;
XX	t = GameList[GameCnt].gmove & 0xFF;
XX	if (board[t] == king && distance(t,f) > 1)
XX		castle(GameList[GameCnt].color,f,t,2);
XX	else
XX    {
XX		board[f] = board[t]; color[f] = color[t];
XX		board[t] = GameList[GameCnt].piece;
XX		color[t] = GameList[GameCnt].color;
XX		if (board[f] == king) --kingmoved[color[f]];
XX    }
XX	if (TCflag) ++TimeControl.moves[color[f]];
XX	GameCnt--; mate = false; Sdepth = 0;
XX	UpdateDisplay(0,0,1,0);
XX	InitializeStats();
XX}
XX
XX
XXShowMessage(s)
XXchar *s;
XX{
XX	gotoXY(TAB,6); printz("%s",s); ClrEoln();
XX}
XX
XXClearMessage()
XX{
XX	gotoXY(TAB,7); ClrEoln();
XX}
XX
XXShowSidetomove()
XX{
XX	gotoXY(TAB,14);
XX	if (player == white) printz("%2d:   WHITE",1+(GameCnt+1)/2);
XX	else printz("%2d:   BLACK",1+(GameCnt+1)/2);
XX	ClrEoln();
XX}
XX
XXPromptForMove()
XX{
XX	gotoXY(TAB,19); printz("Your move is? "); ClrEoln();
XX}
XX
XXShowCurrentMove(pnt,f,t)
XXshort pnt,f,t;
XX{
XX	algbr(f,t,false);
XX	gotoXY(TAB,7); printz("(%2d) %4s",pnt,mvstr1);
XX}
XX
XXChangeAlphaWindow()
XX{
XX	ShowMessage("window: ");
XX	scanz("%hd",&Awindow);
XX}
XX
XXChangeBetaWindow()
XX{
XX	ShowMessage("window: ");
XX	scanz("%hd",&Bwindow);
XX}
XX
XXGiveHint()
XX{
XX	char s[40];
XX	algbr((short)(hint>>8),(short)(hint & 0xFF),false);
XX	strcpy(s,"try ");
XX	strcat(s,mvstr1);
XX	ShowMessage(s);
XX}
XX
XXChangeSearchDepth()
XX{
XX	ShowMessage("depth= ");
XX	scanz("%hd",&MaxSearchDepth);
XX}
XX
XXSetContempt()
XX{
XX	ShowMessage("contempt= ");
XX	scanz("%hd",&contempt);
XX}
XX
XXChangeXwindow()
XX{
XX	ShowMessage("xwndw= ");
XX	scanz("%hd",&xwndw);
XX}
XX
XX
XXSelectLevel()
XX{
XX	ClrScreen();
XX	gotoXY(32,2); printz("CHESS");
XX	gotoXY(20,4); printz(" 1.   60 moves in   5 minutes");
XX	gotoXY(20,5); printz(" 2.   60 moves in  15 minutes");
XX	gotoXY(20,6); printz(" 3.   60 moves in  30 minutes");
XX	gotoXY(20,7); printz(" 4.   40 moves in  30 minutes");
XX	gotoXY(20,8); printz(" 5.   40 moves in  60 minutes");
XX	gotoXY(20,9); printz(" 6.   40 moves in 120 minutes");
XX	gotoXY(20,10); printz(" 7.   40 moves in 240 minutes");
XX	gotoXY(20,11); printz(" 8.    1 move  in  15 minutes");
XX	gotoXY(20,12); printz(" 9.    1 move  in  60 minutes");
XX	gotoXY(20,13); printz("10.    1 move  in 600 minutes");
XX	
XX	OperatorTime = 0; TCmoves = 60; TCminutes = 5;
XX	
XX	gotoXY(20,17); printz("Enter Level: ");
XX	refresh();
XX	scanz("%ld",&Level);
XX	switch (Level)
XX    {
XX      case 1 : TCmoves = 60; TCminutes = 5; break;
XX      case 2 : TCmoves = 60; TCminutes = 15; break;
XX      case 3 : TCmoves = 60; TCminutes = 30; break;
XX      case 4 : TCmoves = 40; TCminutes = 30; break;
XX      case 5 : TCmoves = 40; TCminutes = 60; break;
XX      case 6 : TCmoves = 40; TCminutes = 120; break;
XX      case 7 : TCmoves = 40; TCminutes = 240; break;
XX      case 8 : TCmoves = 1; TCminutes = 15; break;
XX      case 9 : TCmoves = 1; TCminutes = 60; break;
XX      case 10 : TCmoves = 1; TCminutes = 600; break;
XX    }
XX	
XX	TCflag = (TCmoves > 1);
XX	SetTimeControl();
XX	ClrScreen();
XX	UpdateDisplay(0,0,1,0);
XX}
XX
XXDoDebug()
XX{
XX	short k,p,i,tp,tc;
XX	char s[40];
XX	ExaminePosition();
XX	ShowMessage("Enter piece: ");
XX	scanz("%s",s);
XX	if (s[0] == 'w') k = white; else k = black;
XX	if (s[1] == 'p') p = pawn;
XX	else if (s[1] == 'n') p = knight;
XX	else if (s[1] == 'b') p = bishop;
XX	else if (s[1] == 'r') p = rook;
XX	else if (s[1] == 'q') p = queen;
XX	else if (s[1] == 'k') p = king;
XX	else p = no_piece;
XX	for (i = 0; i < 64; i++)
XX    {
XX		gotoXY(Vcoord(i,3,2));
XX		tp = board[i]; tc = color[i];
XX		board[i] = p; color[i] = k;
XX		c1 = k; c2 = otherside[c1];
XX		PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2];
XX		atk1 = atak[c1]; atk2 = atak[c2];
XX		printz("%3d ",SqValue(i,opponent));
XX		board[i] = tp; color[i] = tc;
XX    }
XX	ScorePosition(opponent,&i);
XX	gotoXY(TAB,24);
XX	printz("Score= %d",i); ClrEoln();
XX}
SHAR_EOF
if test 26158 -ne "`wc -c nuxdsp.c`"
then
echo shar: error transmitting nuxdsp.c '(should have been 26158 characters)'
fi
#	End of shell archive
exit 0


------------------------------------/\----------------------------------------
Seo:  Harp[@Mcc.Com]               /  \/\ ^*^           Christopher North-Keys
Tha mi gu trang a'cluich.         /    \ \         Assoc. Systems Analyst, MCC
--------------------------------(disclaimer)----------------------------------