Hi, can someone explain how to get the PV from the TT.
Thanks
Laurie
PV from TT
Moderator: Ras
-
Robert Pope
- Posts: 570
- Joined: Sat Mar 25, 2006 8:27 pm
- Location: USA
- Full name: Robert Pope
Re: PV from TT
1. Look up present position in TT and extract best move. If not found, end.
2. Make best move
3. Goto 1.
2. Make best move
3. Goto 1.
-
lauriet
- Posts: 199
- Joined: Sun Nov 03, 2013 9:32 am
Re: PV from TT
Thanks Robert, but we all know goto's are bad practice. Would you like to repost without the goto ? 
-
Ras
- Posts: 2757
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: PV from TT
So let's do this in structured programming, including a clean break for every case:lauriet wrote:but we all know goto's are bad practice.
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;-
lauriet
- Posts: 199
- Joined: Sun Nov 03, 2013 9:32 am
Re: PV from TT
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.

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.
-
Joost Buijs
- Posts: 1690
- Joined: Thu Jul 16, 2009 10:47 am
- Location: Almere, The Netherlands
Re: PV from TT
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
In C++ it might look like this:lauriet wrote:Thanks Robert, but we all know goto's are bad practice. Would you like to repost without the goto ?
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]);
}
}-
Evert
- Posts: 2929
- Joined: Sat Jan 22, 2011 12:42 am
- Location: NL
Re: PV from TT
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.
-
Volker Annuss
- Posts: 181
- Joined: Mon Sep 03, 2007 9:15 am
Re: PV from TT
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;