No standard specification for Perft

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Re: No standard specification for Perft

Post by hgm »

If you want perft to be a representative measure of the speed of an engine it should indeed focus more on capture-only generation. Perthaps it would be useful to define a function perft(N, M) which does N ply of full-width search followed by M ply of captures only.

Most people use perft only for testing correctness, however, to see if they get the right numbers.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: No standard specification for Perft

Post by Michael Sherwin »

hgm wrote: Fri Apr 19, 2019 10:47 pm If you want perft to be a representative measure of the speed of an engine it should indeed focus more on capture-only generation. Perthaps it would be useful to define a function perft(N, M) which does N ply of full-width search followed by M ply of captures only.

Most people use perft only for testing correctness, however, to see if they get the right numbers.
And it would be useful to have an accurate count of the capture only nodes as well.
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: No standard specification for Perft

Post by lucasart »

Michael Sherwin wrote: Sat Apr 20, 2019 12:43 am
hgm wrote: Fri Apr 19, 2019 10:47 pm If you want perft to be a representative measure of the speed of an engine it should indeed focus more on capture-only generation. Perthaps it would be useful to define a function perft(N, M) which does N ply of full-width search followed by M ply of captures only.

Most people use perft only for testing correctness, however, to see if they get the right numbers.
And it would be useful to have an accurate count of the capture only nodes as well.
why?

perft is not a goal in itself. playing chess is the goal (or variants if that's your thing).

the only purpose of perft is to serve as unit test for the move generation (and move play/undo etc.).

in which valid use case do you need perft captures, that can't be verified by normal perft?
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: No standard specification for Perft

Post by Michael Sherwin »

lucasart wrote: Sat Apr 20, 2019 3:46 am
Michael Sherwin wrote: Sat Apr 20, 2019 12:43 am
hgm wrote: Fri Apr 19, 2019 10:47 pm If you want perft to be a representative measure of the speed of an engine it should indeed focus more on capture-only generation. Perthaps it would be useful to define a function perft(N, M) which does N ply of full-width search followed by M ply of captures only.

Most people use perft only for testing correctness, however, to see if they get the right numbers.
And it would be useful to have an accurate count of the capture only nodes as well.
why?

perft is not a goal in itself. playing chess is the goal (or variants if that's your thing).

the only purpose of perft is to serve as unit test for the move generation (and move play/undo etc.).

in which valid use case do you need perft captures, that can't be verified by normal perft?
If an engine has a separate capture generator it might be good to see if the engine produces correct node counts there as well. And like HGM said it would be a way of testing engine performance minus eval more realistically.
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: No standard specification for Perft

Post by hgm »

Exactly. If the engine uses a completely different move generator in QS, a perft of the full-width search would not test it at all.

For those who do want to use perft for comparing efficency of various move-generation algorithms and board representations: note that a real engine usually does not make the moves it generates in a leave node (and that most nodes are typically leaf nodes). It purely generates the moves to make sure none of those is worth making (i.e. one of the generated moves stands a chance of bringing the score above alpha).
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: No standard specification for Perft

Post by lucasart »

Michael Sherwin wrote: Sat Apr 20, 2019 6:26 am
lucasart wrote: Sat Apr 20, 2019 3:46 am
Michael Sherwin wrote: Sat Apr 20, 2019 12:43 am
hgm wrote: Fri Apr 19, 2019 10:47 pm If you want perft to be a representative measure of the speed of an engine it should indeed focus more on capture-only generation. Perthaps it would be useful to define a function perft(N, M) which does N ply of full-width search followed by M ply of captures only.

Most people use perft only for testing correctness, however, to see if they get the right numbers.
And it would be useful to have an accurate count of the capture only nodes as well.
why?

perft is not a goal in itself. playing chess is the goal (or variants if that's your thing).

the only purpose of perft is to serve as unit test for the move generation (and move play/undo etc.).

in which valid use case do you need perft captures, that can't be verified by normal perft?
If an engine has a separate capture generator it might be good to see if the engine produces correct node counts there as well. And like HGM said it would be a way of testing engine performance minus eval more realistically.
Well, you must be doing it wrong, if you need to duplicate movegen code like this… Fix that instead of blaming perft.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: No standard specification for Perft

Post by hgm »

Well, you must be doing it wrong, if you use the same move generator for a different purpose...
Uri Blass
Posts: 10282
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: No standard specification for Perft

Post by Uri Blass »

hgm wrote: Fri Apr 19, 2019 10:47 pm If you want perft to be a representative measure of the speed of an engine it should indeed focus more on capture-only generation. Perthaps it would be useful to define a function perft(N, M) which does N ply of full-width search followed by M ply of captures only.

Most people use perft only for testing correctness, however, to see if they get the right numbers.
Does Captures only include promotions and if yes does it include all promotions or only promotions to queen?

I am not sure if it is the best idea to have a capture generator that include all captures.
For example maybe it is better to have a capture generator that does not generate QxP or RxP when the pawn is defended by another pawn.
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: No standard specification for Perft

Post by Joost Buijs »

Uri Blass wrote: Sat Apr 20, 2019 11:07 am
hgm wrote: Fri Apr 19, 2019 10:47 pm If you want perft to be a representative measure of the speed of an engine it should indeed focus more on capture-only generation. Perthaps it would be useful to define a function perft(N, M) which does N ply of full-width search followed by M ply of captures only.

Most people use perft only for testing correctness, however, to see if they get the right numbers.
Does Captures only include promotions and if yes does it include all promotions or only promotions to queen?

I am not sure if it is the best idea to have a capture generator that include all captures.
For example maybe it is better to have a capture generator that does not generate QxP or RxP when the pawn is defended by another pawn.
It depends, usually generating all captures is faster than generating only winning captures. It is probably better to handle this with SEE().

My engine includes promotions in the capture generator, but I can choose which pieces to promote to. In quiescence I only promote to queen, and in my regular search I never promote to bishop because that is clearly a waste of time.

In my opinion perft() is a handy tool to check whether move generation and move do/undo are correctly functioning, and as a bonus it tells you also something about the move system performance. I don't see much speed difference between bulk counting or not because checking move legality costs considerably more time as move do/undo (at least in my engine this is the case).
mar
Posts: 2555
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: No standard specification for Perft

Post by mar »

Joost Buijs wrote: Sat Apr 20, 2019 1:04 pm in my regular search I never promote to bishop because that is clearly a waste of time.
Is this really worth it? I always consider all legal moves in search and never even considered doing anything like that. Besides there are other ways to avoid wasting time on bishop underpromotions rather than completely pruning them.
There is a really really tiny fraction of games where it could matter, of course nothing that can be reliably measured.
And for analysis of course (but true, nobody would use my engine for analysis anyway :)
Martin Sedlak