Article View: gnu.chess
Article #5095Bug fix for PutInTTable ()
From: Chua Kong Sian
Date: Wed, 09 Feb 1994 07:31
Date: Wed, 09 Feb 1994 07:31
111 lines
3558 bytes
3558 bytes
There is a bug in PutInTTable() with respect to storing mates. This only
show up when a fail high occurs and the score is > 9000. This shows up
when testing gnuchess on the following test position.
White computer Black Human 1 eps 0 # To move Black correct g1f2
Castled White false Black false # ep
TimeControl 0 Operator Time 0
White Clock 6000 Moves 1
Black Clock 6000 Moves 1
0 ........ 10 10 10 10 10 10 10 10
1 .......P 10 10 10 10 10 10 10 10
2 ......PK 10 10 10 10 10 10 10 10
3 .p....R. 10 10 10 10 10 10 10 10
4 ..p..qbk 10 10 10 10 10 10 10 10
5 r......p 10 10 10 10 10 10 10 10
6 ......R. 10 10 10 10 10 10 10 10
7 ......Q. 10 10 10 10 10 10 10 10
abcdefgh
move score depth nodes time flags capture color
Black has the move in this position. Gnu will find Qf2+ (which leads to
mate), but quickly changes it mind to Qe1+ (which it thinks will also lead
to mate, but which doesn't!). The reason this happens is because in
PutInTTable () the score is adjusted for mates before checking with beta.
Now if beta happens to be > 9000, then it is possible then a lowerbound
will be found when in actual fact, it is a truescore (because score is
incremented, but not beta). The fix is to only adjust the mate score if
it is a truescore and not before. This is done in the new PutInTTable()
below.
PS. If this sounds like Greek, just replace the PutInTTable() function
with the one below.
inline
int
PutInTTable (short side,
short score,
short depth,
short ply,
short alpha,
short beta,
unsigned short mv)
/*
* Store the current board position in the transposition table.
*/
{
register struct hashentry *ptbl;
register /*unsigned*/ short i = 0; /*to match new type of rehash --tpm*/
ptbl = &ttable[side][hashkey % ttblsize];
while (true)
{
if (ptbl->depth == 0 || ptbl->hashbd == hashbd)
break;
if (++i > rehash)
{
#ifndef BAREBONES
THashCol++;
#endif
ptbl += recycle;
break;
}
ptbl++;
}
TTadd++;
#ifndef BAREBONES
HashAdd++;
#endif
ptbl->hashbd = hashbd;
ptbl->depth = (unsigned char) depth;
ptbl->mv = mv;
#ifdef DEBUG
if (debuglevel & 32)
{
algbr (mv >> 8, mv & 0xff, 0);
printf ("-add-> h=%lx d=%d s=%d p=%d a=%d b=%d %s\n", hashbd, depth,
score , ply, alpha, beta, mvstr);
}
#endif
if (score > beta)
{
ptbl->flags = lowerbound;
ptbl->score = beta + 1;
}
else
{
ptbl->flags = truescore;
/* adjust score so moves to mate is from this ply */
if (score > 9000)
score += ply;
else if (score < -9000)
score -= ply;
ptbl->score = score;
}
#ifdef HASHTEST
for (i = 0; i < 32; i++)
{
ptbl->bd[i] = CB (i);
}
#endif /* HASHTEST */
return true;
}
Technical Details
Message-ID:
<2ja3go$g50@nuscc.nus.sg>Path:
arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!raffles.technet.sg!nuscc.nus.sg!nsrccksShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d71d,9401090fb19bcaad,start X-Google-Attributes: gid10d71d,public X-Google-ArrivalTime: 1994-02-08 23:31:36 PST Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!raffles.technet.sg!nuscc.nus.sg!nsrccks From: nsrccks@leonis.nus.sg (Chua Kong Sian) Newsgroups: gnu.chess Subject: Bug fix for PutInTTable () Date: 9 Feb 1994 07:31:36 GMT Organization: National University of Singapore Lines: 113 Message-ID: <2ja3go$g50@nuscc.nus.sg> NNTP-Posting-Host: leonis.nus.sg X-Newsreader: TIN [version 1.2 PL0]