about perft, what is the proper way of doing it?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

spirch
Posts: 95
Joined: Fri Nov 09, 2012 12:36 am

about perft, what is the proper way of doing it?

Post by spirch »

I saw that some peoples does the action of move/undo of the last depth and some people just count the number of valid move of the last depth without doing them.

nodes/sec are day and night between the two

what is the proper/correct way?
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: about perft, what is the proper way of doing it?

Post by syzygy »

spirch wrote:I saw that some peoples does the action of move/undo of the last depth and some people just count the number of valid move of the last depth without doing them.

nodes/sec are day and night between the two

what is the proper/correct way?
Do what you like? There is no official perft competition with official rules that you have to adhere to. Both will give the same counts when done correctly.

If you want to compare the speed of your move generation and make/unmake to a particular other program, then it's best to do it the way that other program does it.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: about perft, what is the proper way of doing it?

Post by Sven »

spirch wrote:I saw that some peoples does the action of move/undo of the last depth and some people just count the number of valid move of the last depth without doing them.

nodes/sec are day and night between the two

what is the proper/correct way?
As Ronald already stated, both ways are proper and correct. What most people do in "perft" is actually bulk counting, i.e. counting all legal moves of the last ply. For this to be more efficient than the straightforward make/unmake you need to implement a way to test move legality without making/unmaking all moves, otherwise there is no saving of course. The trick is that only few moves can be illegal when assuming the usual way of pseudo-legal move generation:
- check evasions,
- king moves (incl. castling),
- ep captures,
- moves of pinned pieces.
Only for these moves a make/unmake would be needed for legality testing (and depending on your program's intelligence even some of these can be tested quicker than by make/unmake, e.g. king moves by only testing attacks to the target square).

One advantage of a fast "perft" during development of your basic engine functionality (board, move generation, make/unmake etc.) is that you get your verification results more quickly so you are slightly more productive than with a slow perft.

In any case I propose that you let your program explicitly state the meaning of your results regarding speed, i.e. print both "nodes per second" and "leaves per second" in the output.

Sven
spirch
Posts: 95
Joined: Fri Nov 09, 2012 12:36 am

Re: about perft, what is the proper way of doing it?

Post by spirch »

I'm going to do that, explicitly state what my numbers mean.

thanks.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: about perft, what is the proper way of doing it?

Post by hgm »

There is a difference between ´nodes per second´ and ´moves per second´. I always thought the best comparison with an engine is when you do not make/unmake the last ply. Because in engines your tree also ends with generating moves, then concluding that you have no non-futile non-bad captures, so you won´t make any of them.