Code: Select all
void perft_per_ply(unsigned short depth, unsigned short white_to_move)
{
unsigned short number_of_legal_moves, i;
unsigned long long total_nodes = 0;
unsigned long long nodes_per_ply[MAX_LEGAL_MOVES_POSSIBLE_PER_POSITION];
CHECKERS_POSITION array_of_legal_moves[MAX_LEGAL_MOVES_POSSIBLE_PER_POSITION];
char message[80];
clock_t start, end;
sprintf(message, "\n\nPERFORMING perft(%d) ....\n\n", depth);
add_comment_to_board_position(message);
printf("\n\nPERFORMING perft(%d) ....\n\n", depth);
if(white_to_move)
sprintf(message, "PARENT POSITION WITH WHITE TO MOVE\n");
else
sprintf(message, "PARENT POSITION WITH RED TO MOVE\n");
add_comment_to_board_position(message);
fprintf_little_board_position_from_bits(g_white_pieces, g_red_pieces, g_all_kings);
sprintf(message, "=================================================================\n");
add_comment_to_board_position(message);
start = clock();
if(white_to_move)
number_of_legal_moves = white_64_bit_move_generator(g_white_pieces, g_red_pieces, g_all_kings, array_of_legal_moves);
else
number_of_legal_moves = red_64_bit_move_generator(g_white_pieces, g_red_pieces, g_all_kings, array_of_legal_moves);
sprintf(message, "number of legal moves = %d\n", number_of_legal_moves);
add_comment_to_board_position(message);
for(i = 0; i < number_of_legal_moves; i++)
{
nodes_per_ply[i] = my_64_bit_perft(array_of_legal_moves[i].white_pieces, array_of_legal_moves[i].red_pieces, array_of_legal_moves[i].all_kings, 1-white_to_move, depth - 1);
total_nodes += nodes_per_ply[i];
printf("Move %d of %d, nodes = %llu\n", i+1, number_of_legal_moves, nodes_per_ply[i]);
if(1 - white_to_move)
sprintf(message, "move %d of %d from parent position, white to move nodes below after %d plies = %llu\n", i+1, number_of_legal_moves, depth - 1, nodes_per_ply[i]);
else
sprintf(message, "move %d of %d from parent position, red to move nodes below after %d plies= %llu\n", i+1, number_of_legal_moves, depth - 1, nodes_per_ply[i]);
add_comment_to_board_position(message);
fprintf_little_board_position_from_bits(array_of_legal_moves[i].white_pieces, array_of_legal_moves[i].red_pieces, array_of_legal_moves[i].all_kings);
}
end = clock();
printf("\n TOTAL NODES = %llu\n", total_nodes);
sprintf(message, "\n TOTAL NODES = %llu", total_nodes);
add_comment_to_board_position(message);
printf("\n TOTAL TIME = %.4lf seconds\n", (end - start)/(double)CLOCKS_PER_SEC);
sprintf(message, "\n TOTAL TIME = %.4lf seconds",(end - start)/(double)CLOCKS_PER_SEC);
add_comment_to_board_position(message);
printf("\n TOTAL SPEED = %.4lf nodes/second.\n\n", (total_nodes * (double)CLOCKS_PER_SEC)/(end - start));
sprintf(message, "\n TOTAL SPEED = %.4lf nodes/second.", (total_nodes * (double)CLOCKS_PER_SEC)/(end - start));
add_comment_to_board_position(message);
}