home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
game
/
think
/
uchess
/
src
/
search.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-04
|
55KB
|
1,971 lines
// about splitting the search into a new thread, perhaps
// the best place to check the msg queue is in UpdateClocks,
// called from ElapsedTime, you would set a flag in here
// before you call each ElapsedTime, telling the system
// to check the msg queue in there for any new moves
//char strx[40];
#define CLEARHISTBETWEENMOVES // old way to handle hist table
/*
* search.c - C source for GNU 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 "gnuchess.h"
#define PTRHEIGHT 55
extern UWORD chip myPointer[];
#include <proto/intuition.h>
extern struct Window __aligned *wG;
extern int __aligned SupervisorMode;
#define ZEROALLBETWEENPLY 1
#ifdef QUIETBACKGROUND
short __aligned background = 0;
#endif /* QUIETBACKGROUND */
static short int __aligned DepthBeyond;
short __aligned Threat[MAXDEPTH];
unsigned short int __aligned PrVar[MAXDEPTH];
extern short int ISZERO;
extern long EADD,EGET;
extern char mvstr[8][8];
extern short int recycle;
extern int __aligned GetEntryDone;
extern int trying_again;
short int __aligned myflagdeepnull=0xff;
int got_20000=0;
short __aligned ThreatSave[MAXDEPTH]; /* tom@izf.tno.nl */
extern short __aligned QueenCheck[MAXDEPTH]; /* tom@izf.tno.nl */
#if defined NULLMOVE || defined DEEPNULL
short int __aligned no_null;
short int __aligned null; /* Null-move already made or not */
short int __aligned PVari; /* Is this the PV */
#endif
#ifdef DEBUG40
extern int whichway;
#endif
#ifdef DEBUG
unsigned short __aligned DBLINE[MAXDEPTH];
struct leaf __aligned *dbptr;
#endif
short __aligned start_stage;
short __aligned thrashing_tt; /* must we recycle slots at random. TomV */
short int __aligned zwndw;
#include "ataks3.h"
#define __USE_SYSBASE
#include <proto/exec.h>
extern long OrigResponse;
extern int global_tmp_score;
extern int previous_score;
short __aligned myflagpvs=true;
int __aligned backsrchaborted=0;
int __aligned Sdepth2=0;
extern int MoveNowOK;
extern int procpri;
extern struct Process *myproc;
extern struct MsgPort *InThreadPort;
extern struct myMsgStruct Global_Message;
int __aligned RealThink=0;
#ifdef SPEED_PRECALC
unsigned short __aligned PreCalcedHint;
unsigned short __aligned PreCalcedMove;
int DoPreCalc (unsigned INTSIZE *, INTSIZE);
#endif
int __aligned Castled[2]={0,0};
int __aligned myEnPassant[2]={0,0};
#include "ttable.c"
short int __inline repetition (void);
#include "debug41.h"
/* ............ MOVE GENERATION & SEARCH ROUTINES .............. */
//#define STRAIGHT4PL70 1 // for repetiton code
#ifndef STRAIGHT4PL70
// improved Kong Sian Repetition
short int __inline
repetition ()
/* Check for draw by threefold repetition. */
{
register short i, cnt;
cnt = 0;
/* try to avoid work */
if (GameCnt > Game50 + 3)
for (i = GameCnt; i >= Game50; i--)
if (hashbd == GameList[i].hashbd && hashkey == GameList[i].hashkey)
cnt++;
return cnt;
}
#else // straight 4pl70 repetition
short int __inline
repetition ()
/* Check for draw by threefold repetition. */
{
register SHORT i, c, cnt;
register SHORT m;
SHORT b[64];
cnt = c = 0;
/* try to avoid work */
if (GameCnt > Game50 + 3)
{
ClearMem(b,sizeof(b));
for (i = GameCnt; i >= Game50; i--)
{
m = GameList[i].gmove;
/* does piece exist on diff board? */
if (b[m & 0x3f])
{
/* does diffs cancel out, piece back? */
if ((b[m >> 8] += b[m & 0x3f]) == 0)
--c;
b[m & 0x3f] = 0;
}
else
{
/* create diff */
++c;
/* does diff cancel out another diff? */
if (!(b[m >> 8] -= (b[m & 0x3f] = board[m & 0x3f] +
(color[m & 0x3f] << 8))))
--c;
}
/* if diff count is 0 we have a repetition */
if (c == 0)
if ((i ^ GameCnt) & 1)
cnt++;
}
}
return cnt;
}
#endif // striaght 4pl70 repetition
int plyscore, globalscore;
int
pick (short int p1, short int p2)
/*
* Find the best move in the tree between indexes p1 and p2. Swap the best
* move into the p1 element.
*
*/
{
register struct leaf *p, *q, *r, *k;
register s0;
struct leaf temp;
k = p = &Tree[p1];
q = &Tree[p2];
s0 = p->score;
for (r = p + 1; r <= q; r++)
if (r->score != 9999 && (r->score) > s0) // this is the PL70 way!
// if ((r->score) > s0)
{
s0 = (r->score);
p = r;
}
if (p != k)
{
temp = *p;
*p = *k;
*k = temp;
return true;
}
return false;
}
#ifdef DEBUG
unsigned short trace[MAXDEPTH];
char traceline[256];
unsigned short tracelog[MAXDEPTH];
int tracen = 0;
int traceflag = 0;
int traceply = 0;
#endif
int __aligned bookflag = false;
int __aligned Jscore = 0;
static int __aligned TCcount, TCleft;
void
SelectMove (short int side, short int iop)
/*
* Select a move by calling function search() at progressively deeper ply
* until time is up or a mate or draw is reached. An alpha-beta window of
* -Awindow to +Bwindow points is set around the score returned from the
* previous iteration. If Sdepth != 0 then the program has correctly
* predicted the opponents move and the search will start at a depth of
* Sdepth+1 rather than a depth of 1.
*/
{
static short int i, tempb, tempc, tempsf, tempst, xside, rpt;
static short int alpha, beta, score;
static struct GameRec *g;
int earlyflag;
#ifndef CLEARHISTBETWEENMOVES // old way to handle hist table
int cnt;
ULONG *tmphistptr;
#endif
char mystr[32];
short InChkDummy;
short start_score;
#ifdef DEBUG
if(debuglevel & (512|1024)){
char b[32];
short c1,c2,r1,r2;
tracen=0;
traceflag = false;
traceply = 0;
tracelog[0]=0;
while(true){
/*printf("debug?");
gets(b);*/
if(b[0] == 'p')traceply = atoi(&b[1]);
else
if(b[0] == '\0')break;
else{
c1 = b[0] - 'a';
r1 = b[1] - '1';
c2 = b[2] - 'a';
r2 = b[3] - '1';
trace[++tracen] = (locn (r1, c1) << 8) | locn (r2, c2);
}
if(tracen == 0 && traceply >0)traceflag = true;
}
}
#endif
// InitializeStats(); // MY FIX FOR UNDO PROBLEMS!!! TMP!!!
if (!SupervisorMode)
SetPointer(wG,myPointer,PTRHEIGHT,0x10L,0L,0L);
got_20000 = 0;
if (iop != 2)
{
RealThink = 1;
if (!GetEntryDone)
{
Global_Message.myData = 1L;
Forbid();
PutMsg(InThreadPort,(struct Message *)&Global_Message);
Permit();
GetEntryDone = 1;
}
}
else
RealThink = 0;
start_again:
flag.timeout = false;
flag.back = flag.musttimeout = false;
INCscore = 0; // new from 4pl70, do I want this?
xside = side ^ 1;
recycle = (GameCnt % rehash) - rehash;
/* if background mode set to infinite */
if (iop == 2)
{
Sdepth2 = 0;
(void)SetTaskPri((struct Task *)myproc,0);
OrigResponse = ResponseTime = 9999999;
#ifdef QUIETBACKGROUND
background = true;
#endif /* QUIETBACKGROUND */
}
else
{
player = side;
if (TCflag)
{
TCcount = 0;
#ifdef QUIETBACKGROUND
background = false;
#endif /* QUIETBACKGROUND */
if (TimeControl.moves[side] < 1)
TimeControl.moves[side] = 1;
/* special case time per move specified */
if (flag.onemove)
{
OrigResponse = ResponseTime = TimeControl.clock[side] - 100;
TCleft = 0;
}
else
{
/* calculate avg time per move remaining */
TimeControl.clock[side] += TCadd;
ResponseTime = (TimeControl.clock[side]) / (((TimeControl.moves[side]) * 2) + 1);
TCleft = (int)ResponseTime / 3;
ResponseTime +=