rename second perft function, perft_test()

This commit is contained in:
2024-04-17 18:43:09 +02:00
parent a13bdb04f1
commit 36e1d987f3
4 changed files with 16 additions and 25 deletions

View File

@@ -91,7 +91,7 @@ pos_t *pos_clear(pos_t *pos)
pos->castle = 0; pos->castle = 0;
pos->clock_50 = 0; pos->clock_50 = 0;
pos->plycount = 0; pos->plycount = 0;
//pos->captured = NO_PIECE; pos->captured = NO_PIECE;
for (square_t sq = A1; sq <= H8; ++sq) for (square_t sq = A1; sq <= H8; ++sq)
pos->board[sq] = EMPTY; pos->board[sq] = EMPTY;

View File

@@ -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 * @pos: &position to search
* @depth: Wanted depth. * @depth: Wanted depth.
* @ply: perft depth level. * @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 * 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 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. * @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; u64 nodes = 0;
movelist_t pseudo; movelist_t movelist;
move_t move; move_t *move, *last;
state_t state; state_t state;
pseudo.nmoves = 0; movelist.nmoves = 0;
pos_set_checkers_pinners_blockers(pos); pos_set_checkers_pinners_blockers(pos);
state = pos->state; state = pos->state;
pos_gen_pseudo(pos, &pseudo); pos_legal(pos, pos_gen_pseudo(pos, &movelist));
while ((move = pos_next_legal(pos, &pseudo, &movetmp)) != MOVE_NONE) { last = movelist.move + movelist.nmoves;
for (move = movelist.move; move < last; ++move) {
if (depth == 1) { if (depth == 1) {
nodes++; nodes++;
} else { } else {
move_do(pos, move); move_do(pos, *move);
subnodes = perft_new_pinners(pos, depth - 1, ply + 1); subnodes = perft(pos, depth - 1, ply + 1);
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);
} }
nodes += subnodes; nodes += subnodes;
move_undo(pos, move); move_undo(pos, *move);
pos->state = state; pos->state = state;
} }
} }

View File

@@ -20,7 +20,6 @@
//eval_t pvs(pos_t *pos, int depth, int alpha, int beta, int color); //eval_t pvs(pos_t *pos, int depth, int alpha, int beta, int color);
u64 perft(pos_t *pos, int depth, int ply); u64 perft(pos_t *pos, int depth, int ply);
u64 perft2(pos_t *pos, int depth, int ply); u64 perft_test(pos_t *pos, int depth, int ply);
u64 perft_new_pinners(pos_t *pos, int depth, int ply);
#endif /* SEARCH_H */ #endif /* SEARCH_H */

View File

@@ -306,7 +306,7 @@ int main(int __unused ac, __unused char**av)
if (run & 2) { if (run & 2) {
clock_start(&clock); clock_start(&clock);
my_count = perft_new_pinners(pos, depth, 1); my_count = perft_test(pos, depth, 1);
ms2 = clock_elapsed_ms(&clock); ms2 = clock_elapsed_ms(&clock);
ms2_total += ms2; ms2_total += ms2;