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.
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 8:05 pm
Location: Italy
Full name: Stefano Gemma
Contact:

Perft and mate

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?

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

Re: Perft and mate

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

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

Re: Perft and mate

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

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.

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

Re: Perft and mate

Ok... but perft 2 gives 34 moves.

plattyaj

Re: Perft and mate

stegemma wrote:Ok... but perft 2 gives 34 moves.
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

plattyaj wrote:
stegemma wrote:Ok... but perft 2 gives 34 moves.
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.

Sven

plattyaj

Re: Perft and mate

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:

plattyaj wrote: