bug fix in perft() - stupid initialization !
This commit is contained in:
51
src/search.c
51
src/search.c
@@ -45,12 +45,13 @@ u64 perft(pos_t *pos, int depth, int ply)
|
|||||||
{
|
{
|
||||||
int subnodes, movetmp = 0;
|
int subnodes, movetmp = 0;
|
||||||
u64 nodes = 0;
|
u64 nodes = 0;
|
||||||
movelist_t pseudo = { .nmoves = 0 };
|
movelist_t pseudo;
|
||||||
move_t move;
|
move_t move;
|
||||||
state_t state;
|
state_t state;
|
||||||
|
|
||||||
if (depth == 0)
|
if (depth == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
pseudo.nmoves = 0;
|
||||||
pos->checkers = pos_checkers(pos, pos->turn);
|
pos->checkers = pos_checkers(pos, pos->turn);
|
||||||
pos_set_pinners_blockers(pos);
|
pos_set_pinners_blockers(pos);
|
||||||
state = pos->state;
|
state = pos->state;
|
||||||
@@ -74,7 +75,7 @@ u64 perft(pos_t *pos, int depth, int ply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* perft2() - Perform perft on position
|
* perft_new_pinners() - Perform perft on position
|
||||||
* @pos: &position to search
|
* @pos: &position to search
|
||||||
* @depth: Wanted depth.
|
* @depth: Wanted depth.
|
||||||
* @ply: perft depth level.
|
* @ply: perft depth level.
|
||||||
@@ -82,61 +83,19 @@ u64 perft(pos_t *pos, int depth, int ply)
|
|||||||
* Run perft on a position. This function displays the available moves at @depth
|
* Run perft on a position. This function displays the available moves at @depth
|
||||||
* level for each possible first move, and the total of moves.
|
* level for each possible first move, and the total of moves.
|
||||||
*
|
*
|
||||||
* This version uses the algorithm:
|
|
||||||
* if (king in check)
|
|
||||||
* finish;
|
|
||||||
* if last depth
|
|
||||||
* return 1;
|
|
||||||
* gen pseudo-legal moves
|
|
||||||
* foreach pseudo-legal move...
|
|
||||||
*
|
|
||||||
* @return: total moves found at @depth level.
|
* @return: total moves found at @depth level.
|
||||||
*/
|
*/
|
||||||
u64 perft2(pos_t *pos, int depth, int ply)
|
|
||||||
{
|
|
||||||
int subnodes, nmove = 0;
|
|
||||||
u64 nodes = 0;
|
|
||||||
movelist_t pseudo = { .nmoves = 0 };
|
|
||||||
move_t move;
|
|
||||||
state_t state;
|
|
||||||
|
|
||||||
if (depth == 0)
|
|
||||||
return 1;
|
|
||||||
pos->checkers = pos_checkers(pos, pos->turn);
|
|
||||||
pos_set_pinners_blockers(pos);
|
|
||||||
state = pos->state;
|
|
||||||
|
|
||||||
pos_gen_pseudomoves(pos, &pseudo);
|
|
||||||
|
|
||||||
for (nmove = 0; nmove < pseudo.nmoves; ++nmove ) {
|
|
||||||
move = pseudo.move[nmove];
|
|
||||||
move_do(pos, move);
|
|
||||||
if (!is_in_check(pos, OPPONENT(pos->turn))) {
|
|
||||||
subnodes = perft2(pos, depth - 1, ply + 1);
|
|
||||||
nodes += subnodes;
|
|
||||||
if (ply == 1) {
|
|
||||||
char movestr[8];
|
|
||||||
printf("%s: %d\n", move_str(movestr, move, 0), subnodes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
move_undo(pos, move);
|
|
||||||
pos->state = state;
|
|
||||||
}
|
|
||||||
if (ply == 1)
|
|
||||||
printf("Total: %lu\n", nodes);
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 perft_new_pinners(pos_t *pos, int depth, int ply)
|
u64 perft_new_pinners(pos_t *pos, int depth, int ply)
|
||||||
{
|
{
|
||||||
int subnodes, movetmp = 0;
|
int subnodes, movetmp = 0;
|
||||||
u64 nodes = 0;
|
u64 nodes = 0;
|
||||||
movelist_t pseudo = { .nmoves = 0 };
|
movelist_t pseudo;
|
||||||
move_t move;
|
move_t move;
|
||||||
state_t state;
|
state_t state;
|
||||||
|
|
||||||
if (depth == 0)
|
if (depth == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
pseudo.nmoves = 0;
|
||||||
pos_set_checkers_pinners_blockers(pos);
|
pos_set_checkers_pinners_blockers(pos);
|
||||||
state = pos->state;
|
state = pos->state;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user