Page 2 of 3

Re: Best way to debug perft?

Posted: Tue Jan 26, 2016 8:58 am
by stegemma
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.

Re: Best way to debug perft?

Posted: Wed Jan 27, 2016 6:34 pm
by Meni Rosenfeld

Re: Best way to debug perft?

Posted: Thu Feb 25, 2016 11:40 pm
by Luis Babboni
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.

Re: Best way to debug perft?

Posted: Fri Feb 26, 2016 12:06 am
by Luis Babboni
Mmm, may be you could compare a list of FENs not necesary in the same order?

Re: Best way to debug perft?

Posted: Fri Feb 26, 2016 7:38 am
by Aleks Peshkov
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.

Re: Best way to debug perft?

Posted: Fri Feb 26, 2016 8:28 am
by stegemma
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.

Re: Best way to debug perft?

Posted: Fri Feb 26, 2016 8:48 am
by hgm
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.

Re: Best way to debug perft?

Posted: Fri Feb 26, 2016 9:51 am
by Aleks Peshkov
hgm wrote:or return 1 at depth==0.
I am not sure that '1' is correct sum of empty set.

Re: Best way to debug perft?

Posted: Fri Feb 26, 2016 10:17 am
by stegemma
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.

Re: Best way to debug perft?

Posted: Fri Feb 26, 2016 4:19 pm
by Luis Babboni
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