PV from TT

Discussion of chess software programming and technical issues.

Moderator: Ras

lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

PV from TT

Post by lauriet »

Hi, can someone explain how to get the PV from the TT.
Thanks

Laurie
Robert Pope
Posts: 570
Joined: Sat Mar 25, 2006 8:27 pm
Location: USA
Full name: Robert Pope

Re: PV from TT

Post by Robert Pope »

1. Look up present position in TT and extract best move. If not found, end.
2. Make best move
3. Goto 1.
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: PV from TT

Post by lauriet »

Thanks Robert, but we all know goto's are bad practice. Would you like to repost without the goto ? :wink:
User avatar
Ras
Posts: 2757
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: PV from TT

Post by Ras »

lauriet wrote:but we all know goto's are bad practice.
So let's do this in structured programming, including a clean break for every case:

Code: Select all

int state = 0;
do {
    switch (state)
    {
        case 0:
             Look up present position in TT and extract best move.
             If not found, return(something).
             state = 1;
             break;
        case 1:
            Make best move;
            state = 0;
            break;
    }
} while 1;
:wink:
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: PV from TT

Post by lauriet »

How about:


goto 1

1: Look up present position in TT, goto 5

2: goto end.

3: make move goto 1

5: if found then Extract move, goto 3 else goto 2

end.

:lol:
Joost Buijs
Posts: 1690
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: PV from TT

Post by Joost Buijs »

You can also try to do it recursively which is IMO the cleanest way to do it.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: PV from TT

Post by Sven »

lauriet wrote:Thanks Robert, but we all know goto's are bad practice. Would you like to repost without the goto ? :wink:
In C++ it might look like this:

Code: Select all

void pvFromTT(Board & b, TTHashTable & tt, PV & pv)
{
    for (TTEntry * e = tt.lookup(b.ttHashKey()); e != 0; e = tt.lookup(b.ttHashKey())) {
        pv.append(e->bestMove);
        b.makeMove(e->bestMove);
    }
    for (int i = int(pv.size()) - 1; i >= 0; i--) {
        b.unmakeMove(pv[i]);
    }
}
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: PV from TT

Post by Evert »

Note that you don't actually need to make the move (which should be checked for legality), you just need to update the hash key.
User avatar
Volker Annuss
Posts: 181
Joined: Mon Sep 03, 2007 9:15 am

Re: PV from TT

Post by Volker Annuss »

Don't forget repetitions. They could result in an infinite loop.

Code: Select all

do
{
    Look up present position in TT and extract best move.
    if not found, return(something).
    Make best move;
} while not repetition detected;