Perft and mate

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 8:05 pm
Location: Italy
Full name: Stefano Gemma
Contact:

Perft and mate

Post by stegemma » Sun Aug 16, 2009 12:44 pm

I've used the perft function of Crafty, to debug my new engine Freccia. One thing that i have noticed is that perft command just counts the moves at the final node. If, suppose, we want the perft at ply 6 we don't count any move that ends the game before that ply, like a mate in 2 does, for sample. Maybe perft is to be considered somehow... imperfect? :wink:

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

Re: Perft and mate

Post by hgm » Sun Aug 16, 2009 1:23 pm

Well, this is how perft(N) is defined: the number of N-move sequences. A mate-in-2 is not 6-move sequence.

User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 8:05 pm
Location: Italy
Full name: Stefano Gemma
Contact:

Re: Perft and mate

Post by stegemma » Tue Aug 18, 2009 8:01 am

Ok, but i suppose a position in wich the mate is not forced so that you have some variation with mate in less than N plies and other moves that reach N plies. In this situation, perft does'nt count any variation that ends before N plies, for mate or stale mate. I think that perft would'nt give the best count for this positions. Maybe counting all plies or all moves could be better?

plattyaj

Re: Perft and mate

Post by plattyaj » Tue Aug 18, 2009 11:16 am

stegemma wrote:Ok, but i suppose a position in wich the mate is not forced so that you have some variation with mate in less than N plies and other moves that reach N plies. In this situation, perft does'nt count any variation that ends before N plies, for mate or stale mate. I think that perft would'nt give the best count for this positions. Maybe counting all plies or all moves could be better?
I think you are misunderstanding what perft is. It is not a search, it is purely move generation of legal moves. Take a very simple case:

[D]1k6/6R1/1K6/8/8/8/8/8 w - - 0 14

perft 1 gives 19 nodes. Of those one is mate.

Now perft 2 gives a total of 53 nodes. One of those can only be seen to depth 1 since it's mate but the rest are the replies to the other 18 moves.

It doesn't matter to perft that a search can give up once it's found Rg8# because that's not what it's there for.

Andy.

User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 8:05 pm
Location: Italy
Full name: Stefano Gemma
Contact:

Re: Perft and mate

Post by stegemma » Tue Aug 18, 2009 2:40 pm

Ok... but perft 2 gives 34 moves. :wink:

plattyaj

Re: Perft and mate

Post by plattyaj » Tue Aug 18, 2009 2:55 pm

stegemma wrote:Ok... but perft 2 gives 34 moves. :wink:
I don't know if there is a "standard" but I add all moves at ply 1 to those at ply 2, etc.. 19+34 = 53.

Andy.

Sven
Posts: 3833
Joined: Thu May 15, 2008 7:57 pm
Location: Berlin, Germany
Full name: Sven Schüle
Contact:

Re: Perft and mate

Post by Sven » Tue Aug 18, 2009 5:01 pm

plattyaj wrote:
stegemma wrote:Ok... but perft 2 gives 34 moves. :wink:
I don't know if there is a "standard" but I add all moves at ply 1 to those at ply 2, etc.. 19+34 = 53.

Andy.
It is not about "standard vs. non-standard" but about "correct vs. incorrect". The correct way is to count exactly all nodes at depth N. So in the given case, perft(2) = 34. Everything else is wrong.

Note also that perft counts nodes, not moves. You can of course view it as counting the number of move paths exactly of length N.

See also this thread.

Sven

plattyaj

Re: Perft and mate

Post by plattyaj » Tue Aug 18, 2009 5:11 pm

Sven Schüle wrote:See also this thread
Thanks - that thread is somewhat newer than my implementation - if I remember right when I added it, some engines did it one way and some another. I'll add it to the long list of things to change ;)

Andy.

Sven
Posts: 3833
Joined: Thu May 15, 2008 7:57 pm
Location: Berlin, Germany
Full name: Sven Schüle
Contact:

Re: Perft and mate

Post by Sven » Tue Aug 18, 2009 5:18 pm

plattyaj wrote:
Sven Schüle wrote:See also this thread
Thanks - that thread is somewhat newer than my implementation - if I remember right when I added it, some engines did it one way and some another. I'll add it to the long list of things to change ;)
You should perhaps put it to the very top of that list ... With your current implementation, how can you compare your perft numbers with those published in the web?

Sven

plattyaj

Re: Perft and mate

Post by plattyaj » Tue Aug 18, 2009 5:41 pm

Sven Schüle wrote:You should perhaps put it to the very top of that list ... With your current implementation, how can you compare your perft numbers with those published in the web?
Well, when I first compared them they had totals as well as by-ply so it was easy. Now I have to use math to add them up and make sure they compare.

Andy.

Post Reply