----
I've added a perft command to help ensure that my other edits haven't disrupted the original mechanics.
Code: Select all
static unsigned int count_legal_moves()
{
unsigned int count = 0;
unsigned int base = first_move[ply];
unsigned int limit = first_move[ply + 1] - base;
unsigned int index;
for (index = 0; index < limit; index++)
{
if (makemove(gen_dat[base + index].m.b))
{
count++;
takeback();
};
};
return count;
}
static unsigned long int perft_aux(unsigned int draft)
{
unsigned long sum;
if (draft == 0)
sum = 1;
else
{
if (ply > 0)
gen();
if (draft == 1)
sum = (unsigned long int) count_legal_moves();
else
{
unsigned int newdraft = draft - 1;
unsigned int base = first_move[ply];
unsigned int limit = first_move[ply + 1] - base;
unsigned int index;
sum = 0;
for (index = 0; index < limit; index++)
{
if (makemove(gen_dat[base + index].m.b))
{
sum += perft_aux(newdraft);
takeback();
};
};
};
};
return sum;
}
void perft(unsigned int draft)
{
unsigned long int sum;
int t0 = get_ms(), t1;
double freq;
sum = perft_aux(draft);
t1 = get_ms();
freq = (double) sum / (double) (t1 - t0) * 1.0e3;
printf("perft(%d): %lu %.3lf MHz\n", draft, sum, (freq / 1.0e6));
}
Code: Select all
tscp> perft 0
perft(0): 1 0.001 MHz
tscp> perft 1
perft(1): 20 inf MHz
tscp> perft 2
perft(2): 400 inf MHz
tscp> perft 3
perft(3): 8902 0.742 MHz
tscp> perft 4
perft(4): 197281 1.273 MHz
tscp> perft 5
perft(5): 4865609 1.132 MHz
tscp> perft 6
perft(6): 119060324 1.237 MHz
tscp> e2e4
tscp> e7e5
tscp> perft 4
perft(4): 728887 1.225 MHz
tscp> perft 5
perft(5): 22273312 1.092 MHz
tscp> perft 6
perft(6): 673070116 1.195 MHz