From 36e1d987f3db19bcbae80cf3cf1b3305703540b1 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Wed, 17 Apr 2024 18:43:09 +0200 Subject: [PATCH] rename second perft function, perft_test() --- src/position.c | 2 +- src/search.c | 34 +++++++++++++--------------------- src/search.h | 3 +-- test/perft-test.c | 2 +- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/position.c b/src/position.c index f861f90..580c3f2 100644 --- a/src/position.c +++ b/src/position.c @@ -91,7 +91,7 @@ pos_t *pos_clear(pos_t *pos) pos->castle = 0; pos->clock_50 = 0; pos->plycount = 0; - //pos->captured = NO_PIECE; + pos->captured = NO_PIECE; for (square_t sq = A1; sq <= H8; ++sq) pos->board[sq] = EMPTY; diff --git a/src/search.c b/src/search.c index b0579c4..d71a9fb 100644 --- a/src/search.c +++ b/src/search.c @@ -77,7 +77,7 @@ u64 perft(pos_t *pos, int depth, int ply) } /** - * perft_new_pinners() - Perform perft on position + * perft_test() - Perform perft on position, experiment version. * @pos: &position to search * @depth: Wanted depth. * @ply: perft depth level. @@ -85,42 +85,34 @@ u64 perft(pos_t *pos, int depth, int ply) * Run perft on a position. This function displays the available moves at @depth * level for each possible first move, and the total of moves. * - * This version uses the algorithm: - * if last depth - * return 1; - * gen pseudo-legal moves - * loop for each legal move in pseudo-legal list - * do-move - * perft (depth -1) - * undo-move - * * @return: total moves found at @depth level. */ -u64 perft_new_pinners(pos_t *pos, int depth, int ply) +u64 perft_test(pos_t *pos, int depth, int ply) { - int subnodes, movetmp = 0; + int subnodes; u64 nodes = 0; - movelist_t pseudo; - move_t move; + movelist_t movelist; + move_t *move, *last; state_t state; - pseudo.nmoves = 0; + movelist.nmoves = 0; pos_set_checkers_pinners_blockers(pos); state = pos->state; - pos_gen_pseudo(pos, &pseudo); - while ((move = pos_next_legal(pos, &pseudo, &movetmp)) != MOVE_NONE) { + pos_legal(pos, pos_gen_pseudo(pos, &movelist)); + last = movelist.move + movelist.nmoves; + for (move = movelist.move; move < last; ++move) { if (depth == 1) { nodes++; } else { - move_do(pos, move); - subnodes = perft_new_pinners(pos, depth - 1, ply + 1); + move_do(pos, *move); + subnodes = perft(pos, depth - 1, ply + 1); if (ply == 1) { char movestr[8]; - printf("%s: %d\n", move_str(movestr, move, 0), subnodes); + printf("%s: %d\n", move_str(movestr, *move, 0), subnodes); } nodes += subnodes; - move_undo(pos, move); + move_undo(pos, *move); pos->state = state; } } diff --git a/src/search.h b/src/search.h index 64b358e..c76ce2e 100644 --- a/src/search.h +++ b/src/search.h @@ -20,7 +20,6 @@ //eval_t pvs(pos_t *pos, int depth, int alpha, int beta, int color); u64 perft(pos_t *pos, int depth, int ply); -u64 perft2(pos_t *pos, int depth, int ply); -u64 perft_new_pinners(pos_t *pos, int depth, int ply); +u64 perft_test(pos_t *pos, int depth, int ply); #endif /* SEARCH_H */ diff --git a/test/perft-test.c b/test/perft-test.c index 92d862b..86f6033 100644 --- a/test/perft-test.c +++ b/test/perft-test.c @@ -306,7 +306,7 @@ int main(int __unused ac, __unused char**av) if (run & 2) { clock_start(&clock); - my_count = perft_new_pinners(pos, depth, 1); + my_count = perft_test(pos, depth, 1); ms2 = clock_elapsed_ms(&clock); ms2_total += ms2;