perft2: is_in_check() before recursion
This commit is contained in:
16
src/search.c
16
src/search.c
@@ -100,8 +100,6 @@ u64 perft2(pos_t *pos, int depth, int ply)
|
|||||||
move_t move;
|
move_t move;
|
||||||
state_t state;
|
state_t state;
|
||||||
|
|
||||||
if (is_in_check(pos, OPPONENT(pos->turn)))
|
|
||||||
return 0;
|
|
||||||
if (depth == 0)
|
if (depth == 0)
|
||||||
return 1;
|
return 1;
|
||||||
pos->checkers = pos_checkers(pos, pos->turn);
|
pos->checkers = pos_checkers(pos, pos->turn);
|
||||||
@@ -113,13 +111,13 @@ u64 perft2(pos_t *pos, int depth, int ply)
|
|||||||
for (nmove = 0; nmove < pseudo.nmoves; ++nmove ) {
|
for (nmove = 0; nmove < pseudo.nmoves; ++nmove ) {
|
||||||
move = pseudo.move[nmove];
|
move = pseudo.move[nmove];
|
||||||
move_do(pos, move);
|
move_do(pos, move);
|
||||||
|
if (!is_in_check(pos, OPPONENT(pos->turn))) {
|
||||||
subnodes = perft2(pos, depth - 1, ply + 1);
|
subnodes = perft2(pos, depth - 1, ply + 1);
|
||||||
|
nodes += subnodes;
|
||||||
nodes += subnodes;
|
if (ply == 1) {
|
||||||
if (ply == 1) {
|
char movestr[8];
|
||||||
char movestr[8];
|
printf("%s: %d\n", move_str(movestr, move, 0), subnodes);
|
||||||
printf("%s: %d\n", move_str(movestr, move, 0), subnodes);
|
}
|
||||||
}
|
}
|
||||||
move_undo(pos, move);
|
move_undo(pos, move);
|
||||||
pos->state = state;
|
pos->state = state;
|
||||||
|
Reference in New Issue
Block a user