Difference between revisions of "Perft"

From Chessprogramming wiki
Jump to: navigation, search
Line 81: Line 81:
 
=Publications=  
 
=Publications=  
 
* [[Aart Bik]] ('''2012'''). ''Computing Deep Perft and Divide Numbers for Checkers''. [[ICGA Journal#35_4|ICGA Journal, Vol. 35, No. 4]] » [[Checkers]]
 
* [[Aart Bik]] ('''2012'''). ''Computing Deep Perft and Divide Numbers for Checkers''. [[ICGA Journal#35_4|ICGA Journal, Vol. 35, No. 4]] » [[Checkers]]
* [[Daniel Shawul|Daniel S. Abdi]] ('''2013'''). ''Monte carlo methods for estimating game tree size''. [https://dl.dropboxusercontent.com/u/55295461/perft/perft.pdf pdf] <ref>[http://www.talkchess.com/forum/viewtopic.php?t=47740&topic_view=flat&start=11 Re: MC methods] by [[Daniel Shawul]], [[CCC]], April 13, 2013</ref> » [[Monte-Carlo Tree Search]]
+
* [[Daniel Shawul|Daniel S. Abdi]] ('''2013'''). ''Monte carlo methods for estimating game tree size''. <ref>[http://www.talkchess.com/forum/viewtopic.php?t=47740&topic_view=flat&start=11 Re: MC methods] by [[Daniel Shawul]], [[CCC]], April 13, 2013</ref> » [[Monte-Carlo Tree Search]]
  
 
=Perft in other Games=  
 
=Perft in other Games=  
Line 89: Line 89:
  
 
=Forum Posts=  
 
=Forum Posts=  
<ref>[https://www.stmintz.com/ccc/index.php?terms=perft&search=1 Perft], search the [[CCC|CCC Archives]]</ref>
+
==1998 ...==
 +
* [https://groups.google.com/d/msg/rec.games.chess.computer/2nqtCdHC-r0/ENqomE2u51kJ Re: complete opening tree stats] by [[Robert Hyatt]], [[Computer Chess Forums|rgcc]], February 05, 1998
 
==2000 ...==  
 
==2000 ...==  
 
* [https://www.stmintz.com/ccc/index.php?id=107258 Testing speed of "position visiting"] by [[Tom Kerrigan]], [[CCC]], April 23, 2000
 
* [https://www.stmintz.com/ccc/index.php?id=107258 Testing speed of "position visiting"] by [[Tom Kerrigan]], [[CCC]], April 23, 2000
 +
* [https://groups.google.com/d/msg/rec.games.chess.computer/ek5fbFf4ajc/lrPxv2kDHgkJ Experiments with crafty perft command] by Guy Macon, [[Computer Chess Forums|rgcc]], December 10, 2000
 
* [https://www.stmintz.com/ccc/index.php?id=198498 Who is the champion in calculating perft?] by [[Uri Blass]], [[CCC]], November 22, 2001
 
* [https://www.stmintz.com/ccc/index.php?id=198498 Who is the champion in calculating perft?] by [[Uri Blass]], [[CCC]], November 22, 2001
 
* [https://www.stmintz.com/ccc/index.php?id=234025 Perft 5,6 {Fastest program is List}] by [[Dann Corbit]], [[CCC]], June 04, 2002 » [[List (Program)|List]]
 
* [https://www.stmintz.com/ccc/index.php?id=234025 Perft 5,6 {Fastest program is List}] by [[Dann Corbit]], [[CCC]], June 04, 2002 » [[List (Program)|List]]
 
* [https://www.stmintz.com/ccc/index.php?id=275133 Perft revisited] by [[Normand M. Blais]], [[CCC]], January 05, 2003
 
* [https://www.stmintz.com/ccc/index.php?id=275133 Perft revisited] by [[Normand M. Blais]], [[CCC]], January 05, 2003
 +
* [https://www.stmintz.com/ccc/index.php?id=276596 perft question] by [[Joel Veness]], [[CCC]], January 12, 2003
 
* [https://www.stmintz.com/ccc/index.php?id=326134 Highest perft for initial position?] by [[Albert Bertilsson]], [[CCC]], November 07, 2003
 
* [https://www.stmintz.com/ccc/index.php?id=326134 Highest perft for initial position?] by [[Albert Bertilsson]], [[CCC]], November 07, 2003
 
* [https://www.stmintz.com/ccc/index.php?id=335026 Distributed perft project] by [[Albert Bertilsson]], [[CCC]], December 09, 2003
 
* [https://www.stmintz.com/ccc/index.php?id=335026 Distributed perft project] by [[Albert Bertilsson]], [[CCC]], December 09, 2003
Line 100: Line 103:
 
* [https://www.stmintz.com/ccc/index.php?id=335527 Distributed perft, current standings and trends] by [[Albert Bertilsson]], [[CCC]], December 12, 2003
 
* [https://www.stmintz.com/ccc/index.php?id=335527 Distributed perft, current standings and trends] by [[Albert Bertilsson]], [[CCC]], December 12, 2003
 
* [https://www.stmintz.com/ccc/index.php?id=336985 Hashing in distributed perft] by [[Steffen A. Jakob|Steffen Jakob]], [[CCC]], December 19, 2003
 
* [https://www.stmintz.com/ccc/index.php?id=336985 Hashing in distributed perft] by [[Steffen A. Jakob|Steffen Jakob]], [[CCC]], December 19, 2003
 +
* [https://www.stmintz.com/ccc/index.php?id=386249 perft records] by [[Peter Fendrich]], [[CCC]], September 06, 2004
 
* [https://www.stmintz.com/ccc/index.php?id=388806 perft results (how accurate is accurate enough ?)] by [[Roman Hartmann]], [[CCC]], September 23, 2004
 
* [https://www.stmintz.com/ccc/index.php?id=388806 perft results (how accurate is accurate enough ?)] by [[Roman Hartmann]], [[CCC]], September 23, 2004
 
* [https://www.stmintz.com/ccc/index.php?id=394229 FRC Perft] by Jürgen Suntinger, [[CCC]], November 02, 2004
 
* [https://www.stmintz.com/ccc/index.php?id=394229 FRC Perft] by Jürgen Suntinger, [[CCC]], November 02, 2004
Line 165: Line 169:
 
* [http://www.talkchess.com/forum/viewtopic.php?t=61119 yet another attempt on Perft(14)] by [[Ankan Banerjee]], [[CCC]], August 13, 2016
 
* [http://www.talkchess.com/forum/viewtopic.php?t=61119 yet another attempt on Perft(14)] by [[Ankan Banerjee]], [[CCC]], August 13, 2016
 
: [http://www.talkchess.com/forum/viewtopic.php?t=61119&start=30 Re: yet another attempt on Perft(14)] by [[Ankan Banerjee]], [[CCC]], September 09, 2016  
 
: [http://www.talkchess.com/forum/viewtopic.php?t=61119&start=30 Re: yet another attempt on Perft(14)] by [[Ankan Banerjee]], [[CCC]], September 09, 2016  
'''2017'''
+
'''2017 ...'''
 
* [http://www.open-chess.org/viewtopic.php?f=5&t=3063 Perft results?] by notachessplayer, [[Computer Chess Forums|OpenChess Forum]], January 01, 2017
 
* [http://www.open-chess.org/viewtopic.php?f=5&t=3063 Perft results?] by notachessplayer, [[Computer Chess Forums|OpenChess Forum]], January 01, 2017
 
* [http://www.talkchess.com/forum/viewtopic.php?t=64983 perft(15)] by [[Ankan Banerjee]], [[CCC]], August 25, 2017 » [[Perft#15|Perft(15)]]
 
* [http://www.talkchess.com/forum/viewtopic.php?t=64983 perft(15)] by [[Ankan Banerjee]], [[CCC]], August 25, 2017 » [[Perft#15|Perft(15)]]
 
: [http://www.talkchess.com/forum/viewtopic.php?t=64983&start=4 Re: perft(15)] by [[Ankan Banerjee]], [[CCC]], August 25, 2017  
 
: [http://www.talkchess.com/forum/viewtopic.php?t=64983&start=4 Re: perft(15)] by [[Ankan Banerjee]], [[CCC]], August 25, 2017  
 
: [http://www.talkchess.com/forum/viewtopic.php?t=64983&start=9 Re: Perft(15): comparison of estimates with Ankan's result] by [[Ankan Banerjee]], [[CCC]], August 26, 2017  
 
: [http://www.talkchess.com/forum/viewtopic.php?t=64983&start=9 Re: Perft(15): comparison of estimates with Ankan's result] by [[Ankan Banerjee]], [[CCC]], August 26, 2017  
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=70530 No standard specification for Perft] by [[Michael Sherwin]], [[CCC]], April 19, 2019
  
 
=External Links=  
 
=External Links=  

Revision as of 08:46, 25 April 2019

Home * Board Representation * Move Generation * Perft

Perft, (performance test, move path enumeration)
a debugging function to walk the move generation tree of strictly legal moves to count all the leaf nodes of a certain depth, which can be compared to predetermined values and used to isolate bugs. In perft, nodes are only counted at the end after the last makemove. Thus "higher" terminal nodes (e.g. mate or stalemate) are not counted, instead the number of move paths of a certain depth. Perft ignores draws by repetition, by the fifty-move rule and by insufficient material. By recording the amount of time taken for each iteration, it's possible to compare the performance of different move generators or the same generator on different machines, though this must be done with caution since there are variations to perft.

Perft function

A simple perft function in C looks as follows:

typedef unsigned long long u64;

u64 Perft(int depth)
{
    MOVE move_list[256];
    int n_moves, i;
    u64 nodes = 0;

    if (depth == 0) return 1;

    n_moves = GenerateLegalMoves(move_list);
    for (i = 0; i < n_moves; i++) {
        MakeMove(move_list[i]);
        nodes += Perft(depth - 1);
        UndoMove(move_list[i]);
    }
    return nodes;
}

Bulk-counting

Instead of counting nodes at "depth 0", legal move generators can take advantage of the fact that the number of moves generated at "depth 1" represents the accurate perft value for that branch. Therefore they can skip the last makemove/undomove, which gives much faster results and is a better indicator of the raw move generator speed (versus move generator + make/unmake). However, this can cause some confusion when comparing perft values. Assuming the above code used a legal move generator, it would only need the following modification:

...
//__/* DELETE: if (depth == 0) return 1; */__//

n_moves = GenerateMoves(move_list);

__if (depth == 1) return n_moves;__
...

Hashing

Perft can receive another speed boost by hashing node counts, with a small chance for inaccurate results. Sometimes this is used as a sanity check to make sure the hash table and keys are working correctly.

Perft function with pseudo move generator

To generate legal moves some programs have to make moves first, call the function IsIncheck and then undo those moves. That makes above Perft function to make and undo moves twice for all moves. Bellow code can avoid that problem and run much faster:

typedef unsigned long long u64;

u64 Perft(int depth)
{
    MOVE move_list[256];
    int n_moves, i;
    u64 nodes = 0;

    if (depth == 0) return 1;

    n_moves = GenerateMoves(move_list);
    for (i = 0; i < n_moves; i++) {
        MakeMove(move_list[i]);
        if (!IsIncheck())
            nodes += Perft(depth - 1);
        UndoMove(move_list[i]);
    }
    return nodes;
}

Perft History

Supposably, perft was first implemented within the Cobol program RSCE-1 by R.C. Smith, submitted to the USCF for evaluation, and subject of an 1978 Computerworld article [1] . RSCE-1's purpose was not to play chess games, but position analysis, to find forced mates, and to perform a move path enumeration of up to three plies, with the perft(3) result of 8,902 from the initial position already mentioned [2] . Ken Thompson may have calculated perft(3) and perft(4) earlier than this date with Belle. Steven Edwards was the first to compute perft(5) through perft(9), and has since been actively involved in Perft computations.

In December 2003, Albert Bertilsson started a distributed project [3] to calculate perft(11) of the initial position, taking over a week to calculate [4] . Exact Perft numbers have been computed and verified up to a depth of 13 by Edwards and are now available in the On-Line Encyclopedia of Integer Sequences [5] , and are given under Initial Position Summary. A so far unverified claim for perft(14) of 61,885,021,521,585,529,237 was given by Peter Österlund in April 2013 [6], while Daniel Shawul proposed Perft estimation applying Monte carlo methods [7] [8]. In August 2017, Ankan Banerjee, who already confirmed Peter Österlund's perft(14) in September 2016 [9], computed perft(15) of 2,015,099,950,053,364,471,960 with his GPU perft program [10], running it several days two times with different zobrist keys on a cluster of Nvidia DGX-1 server systems [11]. His program starts exploring the tree in depth first manner on CPU. When a certain depth is reached a GPU function (kernel) is launched to compute perft of the subtree in breadth first manner [12]. Ankan Banerjee dedicated his computations in honor to Steven Edwards - whose tireless efforts for verifying perft(14) encouraged him to verify perft(14) and take up the challenge to compute perft(15) [13].

Divide

The Divide command is often implemented as a variation of perft, listing all moves and for each move, the perft of the decremented depth. However, some programs already give "divided" output for perft.

See also

Publications

Perft in other Games

Forum Posts

1998 ...

2000 ...

2005 ...

2010 ...

2011

2012

2013

Re: Perft(14) estimates thread by Peter Österlund, CCC, April 02, 2013 » 61,885,021,521,585,529,237
MC methods by Daniel Shawul, CCC, April 11, 2013 » Monte-Carlo Tree Search
Re: MC methods by Daniel Shawul, CCC, April 13, 2013

2014

2015 ...

2016

Re: yet another attempt on Perft(14) by Ankan Banerjee, CCC, September 09, 2016

2017 ...

Re: perft(15) by Ankan Banerjee, CCC, August 25, 2017
Re: Perft(15): comparison of estimates with Ankan's result by Ankan Banerjee, CCC, August 26, 2017

External Links

Implementations

Video Tutorial

References

Up one level