forked from len0rd/rockbox
Patch #4736 for Chessbox from Miguel A. Arévalo - Added support for user interaction while thinking, you can force move now with PLAY and quit with OFF (iRiver example). Yield only on Search as any Evaluate will be preceded by a Search. Plus some minor code policing from me to remove tabs in both the patch and the original code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8896 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
8dccb294a8
commit
7ceadd79db
3 changed files with 350 additions and 317 deletions
|
@ -279,7 +279,8 @@ void CopyBoard( short a[64] , short b[64] );
|
|||
void OpeningBook ( void );
|
||||
int search ( short side, short ply, short depth,
|
||||
short alpha, short beta,
|
||||
unsigned short bstline[], short *rpt );
|
||||
unsigned short bstline[], short *rpt,
|
||||
void (*callback)(void) );
|
||||
int evaluate ( short side, short xside, short ply, short depth,
|
||||
short alpha, short beta );
|
||||
int ProbeTTable ( short side, short depth,
|
||||
|
@ -333,9 +334,6 @@ short pscore[3];
|
|||
xside = otherside[side];
|
||||
pscore[white] = pscore[black] = 0;
|
||||
|
||||
/* ok, I will yield here for lower levels */
|
||||
rb->yield();
|
||||
|
||||
for (c1 = white; c1 <= black; c1++)
|
||||
{
|
||||
c2 = otherside[c1];
|
||||
|
@ -1018,8 +1016,7 @@ register int sq;
|
|||
/* ............ MOVE GENERATION & SEARCH ROUTINES .............. */
|
||||
|
||||
|
||||
int SelectMove(side,iop)
|
||||
short side,iop;
|
||||
int SelectMove( short side, short iop , void (*callback)(void))
|
||||
|
||||
/*
|
||||
Select a move by calling function search() at progressively deeper
|
||||
|
@ -1078,21 +1075,21 @@ static short i,alpha,beta,score,tempb,tempc,tempsf,tempst,xside,rpt;
|
|||
{
|
||||
Sdepth++;
|
||||
/*ShowDepth(' ');*/
|
||||
score = search(side,1,Sdepth,alpha,beta,PrVar,&rpt);
|
||||
score = search(side,1,Sdepth,alpha,beta,PrVar,&rpt,callback);
|
||||
for (i = 1; i <= Sdepth; i++) killr0[i] = PrVar[i];
|
||||
if (score < alpha && !timeout)
|
||||
{
|
||||
/*ShowDepth('-');*/
|
||||
ExtraTime = 10*ResponseTime;
|
||||
ZeroTTable();
|
||||
score = search(side,1,Sdepth,-9000,beta,PrVar,&rpt);
|
||||
score = search(side,1,Sdepth,-9000,beta,PrVar,&rpt,callback);
|
||||
}
|
||||
if (score > beta && !timeout && !(root->flags & exact))
|
||||
{
|
||||
/*ShowDepth('+');*/
|
||||
ExtraTime = 0;
|
||||
ZeroTTable();
|
||||
score = search(side,1,Sdepth,alpha,9000,PrVar,&rpt);
|
||||
score = search(side,1,Sdepth,alpha,9000,PrVar,&rpt,callback);
|
||||
}
|
||||
score = root->score;
|
||||
if (!timeout)
|
||||
|
@ -1209,9 +1206,9 @@ struct BookEntry *p;
|
|||
}\
|
||||
}
|
||||
|
||||
int search(side,ply,depth,alpha,beta,bstline,rpt)
|
||||
short side,ply,depth,alpha,beta,*rpt;
|
||||
unsigned short bstline[];
|
||||
int search( short side, short ply, short depth,
|
||||
short alpha, short beta, unsigned short bstline[], short *rpt,
|
||||
void (*callback)(void) )
|
||||
|
||||
/*
|
||||
Perform an alpha-beta search to determine the score for the current
|
||||
|
@ -1238,8 +1235,10 @@ short xside,pbst,d,e,cf,score,rcnt;
|
|||
unsigned short mv,nxtline[maxdepth];
|
||||
struct leaf *node,tmp;
|
||||
|
||||
/* ok, I will yield here for higher levels */
|
||||
/* this is the only place we need to yield */
|
||||
rb->yield();
|
||||
/* and check for user interaction */
|
||||
callback();
|
||||
|
||||
NodeCnt++;
|
||||
xside = otherside[side];
|
||||
|
@ -1308,7 +1307,7 @@ struct leaf *node,tmp;
|
|||
PawnThreat[ply] = (node->flags & pwnthrt);
|
||||
Tscore[ply] = node->score;
|
||||
node->score = -search(xside,ply+1,depth-1,-beta,-alpha,
|
||||
nxtline,&rcnt);
|
||||
nxtline,&rcnt,callback);
|
||||
if (abs(node->score) > 9000) node->flags |= exact;
|
||||
else if (rcnt == 1) node->score /= 2;
|
||||
if (rcnt >= 2 || GameCnt-Game50 > 99 ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue