Computer Chess Club Archives




Subject: Perft revisited

Author: Normand M. Blais

Date: 09:50:43 01/05/03


After seeing how others do "perft", I thought I'd share the way I do it. It is
less sophisticated but I think it is easy for "everybody" to understand.

int chess::perft_nodes[8];

void chess::perft(int d)
	if (d == 0) return;


	for (int i=g->list_idx[p->ply]; i<g->list_idx[p->ply+1]; i++) {
		if (p->make(g->move_list[i].m)) {

void chess::perft_report()
	for (int i=0; i<perft_depth; i++) {
		printf("perft(%d): %d\n", i+1, perft_nodes[i+1]);

I have a class "chess" with "p" (board) and "g" (movegenerator) as members. If
you do abstraction of the C++ stuff, you can see that the code is simple to
understand. It is not sophisticated because it compute the numbers with minimal
side effect. I'm ready to accept critisism at this point. Am I doing something
wrong? I do perft to a maximum of 7 plies thinking that if there is a problem
with my move generator (make/unmake included) it will show up after 4 or 5
plies. I have already found a problem that was not showing at 4 plies but was at
5 plies in a specific position. I do captures and non-captures separately but I
was not doing under-promotion in my capture generation function. perft was
giving me the correct number (I used movei to test; thanks Uri!) until a pawn
was promoted by capturing a piece. Again, if anyone find something wrong with
the code above, please let me know.

Thank you,


This page took 0.03 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.