Changes

Jump to: navigation, search

Principal Variation

15,345 bytes added, 21:18, 29 April 2018
Created page with "'''Home * Search * Principal Variation''' FILE:Principle variation 16bit.PNG|border|right|thumb|link=https://en.wikipedia.org/wiki/Variation_%28game_tree%..."
'''[[Main Page|Home]] * [[Search]] * Principal Variation'''

[[FILE:Principle variation 16bit.PNG|border|right|thumb|link=https://en.wikipedia.org/wiki/Variation_%28game_tree%29|Variation (game tree), PV of a [[Minimax]] tree in blue <ref>[https://en.wikipedia.org/wiki/Variation_%28game_tree%29 Variation (game tree) from Wikipedia]</ref> ]]

The '''Principal variation''' (PV) is a [[Move List|sequence of moves]] that programs consider [[Best Move|best]] and therefore expect to be played. All the [[Node|nodes]] included by the PV are [[Node Types#PV|PV-nodes]]. Inside an [[Iterative Deepening|iterative deepening]] framework, it is the most important [[Move Ordering|move ordering]] consideration to play the PV collected during the current [[Iteration|iteration]], as the very first left moves of the next iteration. Although not needed for pure chess playing, most engines print the Principal Variation every time it changes or a new depth is reached for analyzing purposes. There are several implementations to determine the PV - most notably the three mentioned below, which were often controversial discussed in [[Computer Chess Forums]] with all their pros and contras <ref>[https://www.stmintz.com/ccc/index.php?id=387179 triangular pv vs. hash move pv] by [[Stuart Cracraft]], [[CCC]], September 11, 2004</ref> <ref>[http://www.talkchess.com/forum/viewtopic.php?t=29730 Extracting PV from TT] by Colin, [[CCC]], September 12, 2009</ref> .

=Transposition Table=
The [[Best Move|best moves]] from the [[Exact Score|exact]] entries of the [[Transposition Table|Transposition table]] may reveal the PV without (much) extra effort.
* '''Pro''': implementation without extra effort
* '''Contra''': dependent on the replacement scheme, TT-overwrites may shorten the PV
<span id="CollectionDuringSearch"></span>
=Collection during search=
PV-Tables (or [[Refutation Table|Refutation Tables]]) are used to collect and propagate [[Best Move|best moves]] and the PV up to the [[Root|root]] similar to the best score.
* '''Pro''': easy implementation; does not risk the cut PV lines in case of PV overwrites
* '''Contra''': slows down search a little; PV might be cut in case of TT-cutoffs

==Triangular PV-Table==
A [[Triangular PV-Table]] is the most dense implementation of a pre-allocated PV-Table, taking into account that the farther the root the shorter the maximal PVs along the maximum search depth. The space advantage requires a more complicated index scheme though.
<span id="PVListontheStack"></span>
==PV-List on the Stack==
A simple implementation with a linked PV-List on the [[Stack|stack]] is described on [[Bruce Moreland]]'s Computer Chess Pages <ref>[http://web.archive.org/web/20040427013839/brucemo.com/compchess/programming/pv.htm Collecting the Principal Variation] from [[Bruce Moreland|Bruce Moreland's]] [http://web.archive.org/web/20040403211728/brucemo.com/compchess/programming/index.htm Programming Topics]</ref> :
<pre>
typedef struct LINE {
int cmove; // Number of moves in the line.
MOVE argmove[moveMAX]; // The line.
} LINE;

int AlphaBeta(int depth, int alpha, int beta, LINE * pline) {

LINE line;
if (depth == 0) {
pline->cmove = 0;
return Evaluate();
}
GenerateLegalMoves();
while (MovesLeft()) {

MakeNextMove();
val = -AlphaBeta(depth - 1, -beta, -alpha, &line);
UnmakeMove();

if (val >= beta) return beta;
if (val > alpha) {
alpha = val;
pline->argmove[0] = ThisMove();
memcpy(pline->argmove + 1, line.argmove, line.cmove * sizeof(MOVE));
pline->cmove = line.cmove + 1;
}
}
return alpha;
}
</pre>

LINE (a buffer that holds the PV) is created at the beginning of every node and a pointer to it is passed to every child nodes. If one of those raise [[Alpha|alpha]] (become a new PV node) they copy their own PV - which is created in the same way as described now - into the pointer received from their parent node. Iteratively this returns the whole Principal Variation. Generally memcpy <ref>[http://www.cplusplus.com/reference/clibrary/cstring/memcpy/ memcpy - C++ Reference]</ref> is an expensive instruction but as alpha is raised only very rarely this does not harm performance too much. The main downside is the allocation of the struct LINE every node which might be dangerous for deep searches with a small stack available.
<span id="SeparateTT"></span>
=Separate PV TT=
No matter how the PV is determined, the issue of short principal variations due to [[Exact Score|exact score]] hits with sufficient draft from the [[Transposition Table|Transposition table]] at [[Node Types#PV|PV-nodes]] is one reason, why many programs ignore those matches and continue searching that node. Despite the search overhead seems tiny, since PV-nodes are rare, even more with exact hits, there are other solutions to address the short PV problem, which looses the information of the path that leads to that score, in conjunction with a more difficult [[Debugging|debugging]] task.

Programs like [[Glass]] use a separate transposition table exclusively for PV-nodes - however similar results may be achieved with TT multi-tiers or bucket systems and replacement schemes taking care of exact scores of stored PV-nodes. [[Robert Hyatt]] had the idea to take the 64 bit hash signature, squash it to something relatively small like 12-16 bits and use that as an index into a PV-holder table <ref>[http://www.talkchess.com/forum/viewtopic.php?topic_view=threads&p=369163&t=35982 Re: Full Principal Variation Retrieval] by [[Robert Hyatt]], [[CCC]], September 07, 2010</ref> <ref>[http://www.talkchess.com/forum/viewtopic.php?t=36099 working!] by [[Robert Hyatt]], [[CCC]], September 17, 2010</ref> <ref>[http://www.talkchess.com/forum/viewtopic.php?topic_view=threads&p=409570&t=39289 Re: Hashing the PV] by [[Robert Hyatt]], [[CCC]], June 06, 2011</ref> <ref> [[Robert Hyatt]] ('''2014'''). ''A Solution to Short PVs Caused by Exact Hash Matches''. [[ICGA Journal#37_3|ICGA Journal, Vol. 37, No. 3]]</ref>. As an alternative, [[Steven Edwards]] proposed a structure of [https://en.wikipedia.org/wiki/Binary_tree binary trees] to recover the PV without any danger of overwriting causing a loss of information <ref>[http://talkchess.com/forum/viewtopic.php?topic_view=threads&t=38776 An alternative means of PV recovery] by [[Steven Edwards]], [[CCC]], April 17, 2011</ref>.
* '''Pro''': almost always full length PV returned
* '''Contra''': may slow down the search a little and has some space requirement
<span id="MultiPV"></span>
=Multiple PVs=
Multiple PVs, that is collecting not only one PV of the best move and testing others don't improve [[Alpha|alpha]], but collecting and reporting multiple PVs of one or more next best moves for analyzing purposes, requires a less efficient [[Root|root]] search, where subsequent moves are searched with a wider [[Window|alpha-beta window]].

=See also=
* [[Best Move]]
* [[Hash Move]]
* [[Move List]]
* [[Move Ordering]]
* [[Principal Variation Search]]
* [[PV Extensions]]
* [[PV-Move]]
* [[Node Types#PV|PV-Nodes]]
* [[Transposition Table]]
* [[Triangular PV-Table]]

=Publications=
* [[Selim Akl]], [[Monroe Newborn]] ('''1977'''). ''The Principal Continuation and the Killer Heuristic''. 1977 ACM Annual Conference Proceedings, pp. 466-473. ACM, Seattle, WA.
* [[Robert Hyatt]] ('''2014'''). ''A Solution to Short PVs Caused by Exact Hash Matches''. [[ICGA Journal#37_3|ICGA Journal, Vol. 37, No. 3]] » [[Principal Variation#SeparateTT|Separate TT for the PV]]

=Forum Posts=
==1995 ...==
* [https://www.stmintz.com/ccc/index.php?id=10903 pv score oscillation] by [[Will Singleton|Willie Wood]], [[CCC]], October 18, 1997
* [https://www.stmintz.com/ccc/index.php?id=20265 Storing the PV in a search routine] by [[Scott Gasch]], [[CCC]], June 09, 1998
* [https://www.stmintz.com/ccc/index.php?id=74 PV verification heuristic] by Peter Jacobi, [[CCC]], July 05, 1998
* [https://www.stmintz.com/ccc/index.php?id=21808 Re: PV verification heuristic] by [[Robert Hyatt]], [[CCC]], July 06, 1998
* [https://www.stmintz.com/ccc/index.php?id=60833 Building the Principal Variation in MTD(f) searches] by [[Andrew Williams]], [[CCC]], July 18, 1999 » [[MTD(f)]]
==2000 ...==
* [https://www.stmintz.com/ccc/index.php?id=95696 Getting a PV using MTD(f)] by [[Tijs van Dam]], [[CCC]], February 08, 2000 » [[MTD(f)]]
* [https://groups.google.com/d/msg/rec.games.chess.computer/Prqz2SzYuoc/4SkqqUYhrIsJ MTD(f) and PV] by [[David Rasmussen]], [[Computer Chess Forums|rgcc]], March 09, 2000 » [[MTD(f)]]
* [https://www.stmintz.com/ccc/index.php?id=142037 PV update after retrieval from hash table] by [[Leen Ammeraal]], [[CCC]], November 30, 2000
* [https://groups.google.com/d/msg/rec.games.chess.computer/AEFIYBEvCFA/66YpNnmDYiUJ MTD(f) and the PV] by Adrian Jackson, [[Computer Chess Forums|rgcc]], March 16, 2001 » [[MTD(f)]]
* [https://www.stmintz.com/ccc/index.php?id=203949 Principal Variation] by [[Benny Antonsson]], [[CCC]], December 28, 2001
* [https://www.stmintz.com/ccc/index.php?id=207580 Problem with short PV] by [[Benny Antonsson]], [[CCC]], January 15, 2002
* [https://www.stmintz.com/ccc/index.php?id=140514 Where is Principal Variation?] by [[Severi Salminen]], [[CCC]], November 22, 2000
* [https://www.stmintz.com/ccc/index.php?id=251543 calculating the PV using MTD] by [[Fabien Letouzey]], [[CCC]], September 11, 2002 » [[MTD(f)]]
* [https://www.stmintz.com/ccc/index.php?id=277422 Returning PV from hash table] by [[Nathan Thom]], [[CCC]], January 15, 2003
* [https://www.stmintz.com/ccc/index.php?id=354012 Fruit - Question for Fabien] by [[Dan Honeycutt]], [[CCC]], March 11, 2004 » [[Fruit]], [[Node Types]], [[Transposition Table]], [[Principal Variation Search]]
* [https://www.stmintz.com/ccc/index.php?id=360837 My fail soft reduces quality of collected PV. Help needed] by [[Volker Böhm]], [[CCC]], April 20, 2004 » [[Fail-Soft]]
* [https://www.stmintz.com/ccc/index.php?id=387179 triangular pv vs. hash move pv] by [[Stuart Cracraft]], [[CCC]], September 11, 2004
==2005 ...==
* [http://www.open-aurec.com/wbforum/viewtopic.php?f=4&t=4710 PV based decisions] by [[Mark Lefler]], [[Computer Chess Forums|Winboard Forum]], April 27, 2006
* [http://www.talkchess.com/forum/viewtopic.php?t=27113 Thinker output] by [[Matthias Gemuh]], [[CCC]], March 22, 2009 » [[Thinker]]
* [http://www.talkchess.com/forum/viewtopic.php?t=29730 Extracting PV from TT] by Colin, [[CCC]], September 12, 2009
==2010 ...==
* [http://www.open-chess.org/viewtopic.php?f=5&t=434 Taken from CCC (Stockfish & mainlines)] by [[Ed Schroder|Rebel]], [[Computer Chess Forums|OpenChess Programming Forum]], July 12, 2010
* [http://www.talkchess.com/forum/viewtopic.php?t=35982 Full Principal Variation Retrieval] by [[Hieu Nguyen]], [[CCC]], September 06, 2010
: [http://www.talkchess.com/forum/viewtopic.php?topic_view=threads&p=369163&t=35982 Re: Full Principal Variation Retrieval] by [[Robert Hyatt]], [[CCC]], September 07, 2010 » [[Principal Variation#SeparateTT|Separate TT for the PV]]
* [http://www.talkchess.com/forum/viewtopic.php?t=36099 working!] by [[Robert Hyatt]], [[CCC]], September 17, 2010 » [[Principal Variation#SeparateTT|Separate TT for the PV]]
* [http://www.talkchess.com/forum/viewtopic.php?t=38404 Root node search] by [[Onno Garms]], [[CCC]], March 13, 2011 » [[Onno]], [[Root]]
* [http://www.talkchess.com/forum/viewtopic.php?t=38776 An alternative means of PV recovery] by [[Steven Edwards]], [[CCC]], April 17, 2011
* [http://www.talkchess.com/forum/viewtopic.php?t=39289 Hashing the PV] by [[Stef Luijten]], [[CCC]], June 06, 2011
* [http://www.talkchess.com/forum/viewtopic.php?t=39340 UCI multipv question] by [[Martin Sedlak]], [[CCC]], June 11, 2011 » [[UCI]]
* [http://www.talkchess.com/forum/viewtopic.php?t=42037 About UCI multipv] by [[Fermin Serrano]], [[CCC]], January 17, 2012 » [[UCI]]
* [http://www.talkchess.com/forum/viewtopic.php?t=44487 Null move in PV] by [[Harm Geert Muller]], [[CCC]], July 18, 2012 » [[Null Move]]
* [http://www.talkchess.com/forum/viewtopic.php?t=47573 triangular pv] by [[Daniel Shawul]], [[CCC]], March 22, 2013 » [[Triangular PV-Table#PVinPVS|PV Array in PVS]]
* [http://www.talkchess.com/forum/viewtopic.php?t=48315 Hash cutoffs and analysis] by [[Harm Geert Muller]], [[CCC]], June 17, 2013 » [[Transposition Table]]
* [http://www.talkchess.com/forum/viewtopic.php?t=49012 Hashed PVs] by [[Natale Galioto]], [[CCC]], August 19, 2013
* [http://www.talkchess.com/forum/viewtopic.php?t=49854 Stockfish search] by [[Harm Geert Muller]], [[CCC]], October 28, 2013 » [[Stockfish]]
* [http://www.talkchess.com/forum/viewtopic.php?t=51370 TT with Null Move Cuts A PV Node/Line] by [[Cheney Nattress]], [[CCC]], February 21, 2014 » [[Transposition Table]], [[Null Move Pruning]], [[Node Types#PV|PV-node]]
* [http://www.talkchess.com/forum/viewtopic.php?t=54063 Cache over-writing and PV's] by Forrest Hoch, [[CCC]], October 16, 2014 » [[Transposition Table#ReplacementStrategies|Transposition Table | Replacement Strategies]]
* [http://www.talkchess.com/forum/viewtopic.php?t=54750 Stockfish and accurate PV] by [[Matthew Lai]], [[CCC]], December 25, 2014 » [[Stockfish]]
==2015 ...==
* [http://www.talkchess.com/forum/viewtopic.php?t=57108 epd multipv] by [[J. Wesley Cleveland]], [[CCC]], July 28, 2015 » [[Extended Position Description]]
* [http://www.talkchess.com/forum/viewtopic.php?t=60529 help me test multipv] by [[Alexandru Mosoi]], [[CCC]], June 19, 2016
* [http://www.talkchess.com/forum/viewtopic.php?t=60866 Collecting the pv in Search] by [[David Cimbalista]], [[CCC]], July 19, 2016
* [http://www.talkchess.com/forum/viewtopic.php?t=60971 Implementing Multi pv] by Charles Thomas, [[CCC]], July 29, 2016
* [http://www.talkchess.com/forum/viewtopic.php?t=61796 Collecting PVs of Qsearch ?] by [[Mahmoud Uthman]], [[CCC]], October 22, 2016 » [[Triangular PV-Table]], [[Quiescence Search]]
* [http://www.open-chess.org/viewtopic.php?f=5&t=3038 Extracting Principal Variation during search] by Dabil, [[Computer Chess Forums|OpenChess Forum]], November 18, 2016
* [http://www.open-chess.org/viewtopic.php?f=5&t=3072 capturing PV in QSearch] by thevinenator, [[Computer Chess Forums|OpenChess Forum]], January 20, 2017 » [[Triangular PV-Table]], [[Quiescence Search]]
* [http://www.talkchess.com/forum/viewtopic.php?t=63801 multi-pv analysis] by [[Gregory Strong]], [[CCC]], April 23, 2017 [[Principal Variation#MultiPV|Multi-PV]]
* [http://www.talkchess.com/forum/viewtopic.php?t=64256 Collecting PV in a PVS search ?] by [[Mahmoud Uthman]], [[CCC]], June 11, 2017 » [[Triangular PV-Table]]
* [http://www.talkchess.com/forum/viewtopic.php?t=65874 Why PVs aren't displayed -- Robert Hourdart in TCEC chat] by Thomas Ewers, [[CCC]], December 01, 2017

=External Links=
* [http://web.archive.org/web/20040427013839/brucemo.com/compchess/programming/pv.htm Collecting the Principal Variation] from [[Bruce Moreland|Bruce Moreland's]] [http://web.archive.org/web/20040403211728/brucemo.com/compchess/programming/index.htm Programming Topics]
* [https://en.wikipedia.org/wiki/Variation_%28game_tree%29 Variation (game tree) from Wikipedia]

=References=
<references />

'''[[Search|Up one Level]]'''

Navigation menu