Threefold repetition and transposition table

Code, algorithms, languages, construction...
Post Reply
szacun
Posts: 2
Joined: Thu Jan 09, 2014 9:34 pm
Real Name: Marcin

Threefold repetition and transposition table

Post by szacun » Thu Jan 09, 2014 9:52 pm

Hi! I am writing my own engine, and i have just implemented transposition table, and now i have a problem with threefold repetion.

This is a snippet from my alphabeta function:

Code: Select all

if (CountRepetitions(currentBoardHash) >= 3) // threefold repetition
             return DRAW;

int tableScore = transpositionTable.getScore(currentBoardHash,  depth, alpha, beta)
if (tableScore != UNKNOW_VALUE)
    return (tableScore)
In my transposition table i use "replace if deeper" replacement scheme. The problem is: When a position is encountered for a first time, and it is evaluated, result is written into transposition table. Later, when the position happens for a second time on board, program takes previously calculated value from transposition table and returns it, without being aware of danger of draw, when he realizes that a draw will happen, it is far too late. This is clearly visible during endgame, when program is trying to checkmate opponent, he can easly force a draw because of threefold repetition.

I've been thinking about this for a while but i haven't came up with anything. Can you please give me some hints how to deal with this problem?

hyatt
Posts: 1242
Joined: Thu Jun 10, 2010 2:13 am
Real Name: Bob Hyatt (Robert M. Hyatt)
Location: University of Alabama at Birmingham
Contact:

Re: Threefold repetition and transposition table

Post by hyatt » Thu Jan 09, 2014 11:15 pm

This is just ONE of the issues related to draws and the ttable.. When you get close to a 50 move draw, the ttable can make you miss detecting the draw and walks you right into it. Just like the repetition issue. Normally you check for repetitions before probing the hash table, and it tends to reduce at least this part of the problem significantly.

szacun
Posts: 2
Joined: Thu Jan 09, 2014 9:34 pm
Real Name: Marcin

Re: Threefold repetition and transposition table

Post by szacun » Fri Jan 10, 2014 1:16 am

I am checking for repetitions before looking into hash table, but if the same situations happens for a second time, there is no repetition and program returns what is in ttable. Do you mean to use ttable only is such a situation on board has never occured before, and otherwise just evalute position normally?

hyatt
Posts: 1242
Joined: Thu Jun 10, 2010 2:13 am
Real Name: Bob Hyatt (Robert M. Hyatt)
Location: University of Alabama at Birmingham
Contact:

Re: Threefold repetition and transposition table

Post by hyatt » Fri Jan 10, 2014 10:44 pm

szacun wrote:I am checking for repetitions before looking into hash table, but if the same situations happens for a second time, there is no repetition and program returns what is in ttable. Do you mean to use ttable only is such a situation on board has never occured before, and otherwise just evalute position normally?

Normally everyone counts the second repetition as a 3-fold repetition. The thinking is if you can force the same position twice, you can force it a 3rd time. Lets you spot repetitions in the search much faster. In the real game state you obviously check for 3 when making moves and claiming draws, but in the search, 2 is "enough".

Post Reply