home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
game
/
uchess-2.89.lha
/
UChess
/
src
/
nondsp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-29
|
24KB
|
1,153 lines
/*
* nondsp.c - UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
*
* Copyright (c) 1988,1989,1990 John Stanback
* Copyright (c) 1992 Free Software Foundation
*
* This file is part of GNU CHESS.
*
* GNU Chess is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Chess is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Chess; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <ctype.h>
#include <signal.h>
#ifdef AMIGA
void mysprintf(char *,char *,int);
void mysprintf4(char *,char *,int);
void mysprintf3(char *,char *,int,int);
void algbr2 (short, short, short);
#define __USE_SYSBASE
#include <exec/types.h>
#include <exec/exec.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#endif
char __far HintString[80];
#define SIGQUIT SIGINT
#include "gnuchess.h"
#ifdef MSDOS
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#else
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*
#include <sys/param.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
*/
#endif
extern int __aligned thinkahead;
extern INTSIZE __aligned amigaboard[64],amigacolor[64];
extern short int ISZERO;
char __aligned __far IllegalString[40];
extern int AmigaStarted;
extern int __aligned global_tmp_score;
extern int __aligned previous_score;
int __aligned IllegalMove=0;
int __aligned Mate=0;
int __aligned DrawnGame=0;
char __far __aligned MateString[40]={0};
extern long OrigResponse;
#ifdef DEBUG
INTSIZE int __aligned debuglevel = 0;
#endif /* DEBUG */
unsigned INTSIZE int __aligned MV[MAXDEPTH];
int __aligned MSCORE;
#if defined CHESSTOOL || defined XBOARD
INTSIZE int __aligned chesstool = 1;
#else
INTSIZE int __aligned chesstool = 0;
#endif /* CHESSTOOL */
extern char __aligned mvstrhint[8][8];
extern char mvstr[8][8];
int __aligned mycnt1, mycnt2;
char __aligned *DRAW;
extern char *InPtr;
extern INTSIZE int pscore[];
void mysprintf4(ostr,fstr,num)
char *ostr,*fstr;
int num;
{ // formats string "Tgt:%d xxx"
int index;
int thou,hun,ten,one,rem;
ostr[0] = fstr[0];
ostr[1] = fstr[1];
ostr[2] = fstr[2];
ostr[3] = fstr[3];
ostr[4] = 0;
if (num < 0)
{
num = -num;
index = 5;
strcat(ostr,"-");
}
else
{
index = 4;
}
thou = num / 1000;
rem = num-(num / 1000)*1000;
hun = (rem / 100);
rem = rem-(hun * 100);
ten = rem / 10;
rem = rem-(ten * 10);
one = rem;
if (thou)
{
ostr[index++] = thou+'0';
}
if ((hun)||(thou))
{
ostr[index++] = hun+'0';
}
if ((ten)||(hun)||(thou))
{
ostr[index++] = ten+'0';
}
ostr[index++] = one+'0';
ostr[index] = 0;
strcat(ostr,&fstr[6]);
}
void mysprintf3(ostr,fstr,num,num2)
char *ostr,*fstr;
int num,num2;
{ // formats string "D%d S%d "
int index;
int thou,hun,ten,one,rem;
ostr[0] = fstr[0]; // get the D
ostr[1] = 0;
if (num < 0)
{
num = -num;
index = 2;
strcat(ostr,"-");
}
else
{
index = 1;
}
thou = num / 1000;
rem = num-(num / 1000)*1000;
hun = (rem / 100);
rem = rem-(hun * 100);
ten = rem / 10;
rem = rem-(ten * 10);
one = rem;
if (thou)
{
ostr[index++] = thou+'0';
}
if ((hun)||(thou))
{
ostr[index++] = hun+'0';
}
if ((ten)||(hun)||(thou))
{
ostr[index++] = ten+'0';
}
ostr[index++] = one+'0';
ostr[index++] = fstr[3];
ostr[index++] = fstr[4];
if (num2 < 0)
{
num2 = -num2;
ostr[index++] = '-';
}
thou = num2 / 1000;
rem = num2-(num2 / 1000)*1000;
hun = (rem / 100);
rem = rem-(hun * 100);
ten = rem / 10;
rem = rem-(ten * 10);
one = rem;
if (thou)
{
ostr[index++] = thou+'0';
}
if ((hun)||(thou))
{
ostr[index++] = hun+'0';
}
if ((ten)||(hun)||(thou))
{
ostr[index++] = ten+'0';
}
ostr[index++] = one+'0';
ostr[index] = 0;
strcat(ostr,&fstr[7]);
}
void
Initialize (void)
{
mycnt1 = mycnt2 = 0;
#if defined CHESSTOOL || defined XBOARD
#ifndef SYSV
/* setlinebuf (stdout);*/
#else
/* setvbuf (stdout, NULL, _IOLBF, BUFSIZ);*/
#endif
/* printf (CP[43]);*/ /*Chess*/
if (!TCflag && (MaxResponseTime == 0))
MaxResponseTime = 15L*100L;
#endif /* CHESSTOOL */
}
void DoAMove(void);
void DoAMove()
{
char astr[40];
int r,c,l;
char piece;
r = mvstr[0][3] - '1';
c = mvstr[0][2] - 'a';
l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
if (color[l] == neutral)
{
//DisplayBeep(0L);
//Delay(25L);
//DisplayBeep(0L);
//Delay(25L);
//DisplayBeep(0L);
//Delay(25L);
piece = ' ';
}
else if (color[l] == white)
piece = qxx[board[l]]; /* white are lower case pieces */
else
piece = pxx[board[l]]; /* black are upper case pieces */
if (computer == black)
{
mysprintf(astr,"%d: ",GameCnt>>1);
strcat(astr,mvstr[0]);
}
else
{
mysprintf(astr,"%d: ",(GameCnt+1)>>1);
strcat(astr,mvstr[0]);
}
DisplayComputerMove(astr);
if (piece != ' ')
AnimateAmigaMove(mvstr[0],piece);
}
void
ExitChess (void)
{
/* signal (SIGTERM, SIG_IGN);*/
ListGame (0L);
#ifdef AMIGA
if (AmigaStarted)
AmigaShutDown();
#endif
exit (0);
}
#ifndef MSDOS /* never called!!! */
#ifndef AMIGA
void
Die (int sig)
{
char s[80];
ShowMessage (CP[31]); /*Abort?*/
scanz ("%s", s);
if (strcmp (s, CP[210]) == 0) /*yes*/
ExitChess ();
}
#endif
#endif /* MSDOS */
void
TerminateSearch (int sig)
{
#ifdef MSDOS
sig++; /* shut up the compiler */
#endif /* MSDOS */
if (!flag.timeout)
flag.musttimeout = true;
flag.bothsides = false;
}
void
help (void)
{
#ifndef AMIGA
ClrScreen ();
/*printz ("CHESS command summary\n");*/
printz (CP[40]);
printz ("----------------------------------------------------------------\n");
/*printz ("g1f3 move from g1 to f3 quit Exit Chess\n");*/
printz (CP[158]);
/*printz ("Nf3 move knight to f3 beep turn %s\n", (flag.beep) ? "off" : "on");*/
printz (CP[86], (flag.beep) ? CP[92] : CP[93]);
/*printz ("a7a8q promote pawn to queen\n");*/
printz (CP[128], (flag.material) ? CP[92] : CP[93]);
/*printz ("o-o castle king side easy turn %s\n", (flag.easy) ? "off" : "on");*/
printz (CP[173], (flag.easy) ? CP[92] : CP[93]);
/*printz ("o-o-o castle queen side hash turn %s\n", (flag.hash) ? "off" : "on");*/
printz (CP[174], (flag.hash) ? CP[92] : CP[93]);
/*printz ("bd redraw board reverse board display\n");*/
printz (CP[130]);
/*printz ("list game to chess.lst book turn %s used %d of %d\n", (Book) ? "off" : "on", bookcount, BOOKSIZE);*/
printz (CP[170], (Book) ? CP[92] : CP[93], bookcount, BOOKSIZE);
/*printz ("undo undo last ply remove take back a move\n");*/
printz (CP[200]);
/*printz ("edit edit board force enter game moves\n");*/
printz (CP[153]);
/*printz ("switch sides with computer both computer match\n");*/
printz (CP[194]);
/*printz ("white computer plays white black computer plays black\n");*/
printz (CP[202]);
/*printz ("depth set search depth clock set time control\n");*/
printz (CP[149]);
/*printz ("post principle variation hint suggest a move\n");*/
printz (CP[177]);
/*printz ("save game to file get game from file\n");*/
printz (CP[188]);
/*printz ("random randomize play new start new game\n");*/
printz (CP[181]);
printz ("----------------------------------------------------------------\n");
/*printz ("Computer: %-12s Opponent: %s\n",*/
printz (CP[46],