Best way to debug perft?

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

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:

Re: Best way to debug perft?

Post by stegemma » Tue Jan 26, 2016 7:58 am

Just take a look at this thread:

http://www.talkchess.com/forum/viewtopi ... ght=qperft

I've successfully compiled Muller's qperft in C++ and linked directly to my engine, when I was testing my perft (now I've removed the code from my engine).

I don't know if it works for C# too but maybe you can get a DLL from this code, on Windows.
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com

Meni Rosenfeld
Posts: 10
Joined: Wed Mar 11, 2015 8:42 pm

Re: Best way to debug perft?

Post by Meni Rosenfeld » Wed Jan 27, 2016 5:34 pm


User avatar
Luis Babboni
Posts: 422
Joined: Sat Feb 28, 2015 3:37 pm
Location: Argentina

Re: Best way to debug perft?

Post by Luis Babboni » Thu Feb 25, 2016 10:40 pm

Hello,

I´m pretty new in all this.

I´m trying to make a moves generator in basic and now I´m trying to know how to debug it so I found this topic.

A question:
as far as I understand (poor english here) you talk about compare moves, not just the number of moves that are legal from any position.
You are talking about list of moves?
What about if differents engines makes moves in different order?

Sorry if my question is a nonsense :-(

Thanks.

User avatar
Luis Babboni
Posts: 422
Joined: Sat Feb 28, 2015 3:37 pm
Location: Argentina

Re: Best way to debug perft?

Post by Luis Babboni » Thu Feb 25, 2016 11:06 pm

Mmm, may be you could compare a list of FENs not necesary in the same order?

Aleks Peshkov
Posts: 870
Joined: Sun Nov 19, 2006 8:16 pm
Location: Russia

Re: Best way to debug perft?

Post by Aleks Peshkov » Fri Feb 26, 2016 6:38 am

Perft is recursive number of legal moves.

Perft for depth 1 is number of legal moves from the given position.
Perft for depth N is sum of legal moves for all positions of Perft N-1.

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

Re: Best way to debug perft?

Post by stegemma » Fri Feb 26, 2016 7:28 am

You must count and sum all the legal "leaves" nodes. It is not the same as counting the Nth node moves, because some variant could lead to a mate before of depth N.

You could use an algorithm like this one:

Code: Select all

int Perft(int depth)
{
  int legal_moves = MakeLegalMovesOnly();
  if(GetMated() || IsStale()) return 1;
  if(depth==0) return legal_moves;
  int n = 0;
  for&#40;i=0; i<legal_moves; i++)
  &#123;
     MakeMove&#40;i&#41;;
     n+= Perft&#40;depth - 1&#41;;
     UnMakeMove&#40;i&#41;;
  &#125;
  return n;
&#125;
Of course this an over-simplification; you can't return an int in 32 bit systems, because the number of moves could be larger than 32 bits signed, you need a legal move generator or just validate move after it has been executed and so on.
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com

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

Re: Best way to debug perft?

Post by hgm » Fri Feb 26, 2016 7:48 am

Note that with the conventional definition of 'depth' you would return the number of moves if depth==1 (not 0), which is known as bulk counting, or return 1 at depth==0.

Aleks Peshkov
Posts: 870
Joined: Sun Nov 19, 2006 8:16 pm
Location: Russia

Re: Best way to debug perft?

Post by Aleks Peshkov » Fri Feb 26, 2016 8:51 am

hgm wrote:or return 1 at depth==0.
I am not sure that '1' is correct sum of empty set.

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

Re: Best way to debug perft?

Post by stegemma » Fri Feb 26, 2016 9:17 am

hgm wrote:Note that with the conventional definition of 'depth' you would return the number of moves if depth==1 (not 0), which is known as bulk counting, or return 1 at depth==0.
Right, if you start calling Perft(depth) and depth 1 is the root then you must correct my simple code with depth==1 instead of depth==0.

For analogy with alphabeta I call Perft(depth-1), that's why my error.
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com

User avatar
Luis Babboni
Posts: 422
Joined: Sat Feb 28, 2015 3:37 pm
Location: Argentina

Re: Best way to debug perft?

Post by Luis Babboni » Fri Feb 26, 2016 3:19 pm

Thanks!

Now I think the numbers are too big to have "a list" of FENs to compare with. :oops:

I read something more and it seems not as easy as I thought, perft matter is a world in itself! :shock:
It seems I need to improve my program to make it more automatically in gives results. Even initial position is needed to be entered too manually. :?

BTW.
Look at this, where I´m wrong?
I tried perft 1 in Sharper, an engine recommended in other post to use for comparing, and gives me 20 where my generator and even by hand you could count 21 possible moves :
What other engine could I use to have perfts?

Image

Post Reply