I made a perft function to test the speed of my chess engine, and the function takes 205 seconds (>2 minutes) to go 3 ply deep and evaluate all the leaves (~42,000 leaves, because 35^3 = 42,000). Is this slowness supposed to happen? It's only 42,000 nodes, which is very few. I hope that some people with chess engine experience can help me figure out what's wrong. Perf results in chess: https://www.chessprogramming.org/Perft_Results#Perft_10
The running of the perft function doesn't involve using minimax or alpha-beta pruning at all, so it can't be those that is causing the slowness.
My perft function:
a = GameState()
def perft(game_state, nodes, counter):
if nodes == 0:
return 1
internal_count = 0
if game_state.player_turn == 'w':
for piece in game_state.w_pieces:
# I call .copy() after game_state because I don't want the set holding the pieces in
# game_state to change when I call all_possible_moves() on it. .copy() in GameState
# calls deepcopy on the internal sets and dicts in game_state. Every piece in the
# game_state set has a method called .all_possible_moves(GameState) that
# generates all the possible moves for that piece.
for move in piece.all_possible_moves(game_state.copy()):
counter += perft(game_state.copy().make_move(piece.coor, move), nodes - 1, 0)
else:
for piece in game_state.b_pieces:
for move in piece.all_possible_moves(game_state.copy()):
counter += perft(game_state.copy().make_move(piece.coor, move), nodes - 1, 0)
return counter
counter = perft(a, 3, 0)
print(counter)
There shouldn't be anything overtly wrong with my perft function, right? I have no idea why it would run so long. I expected finding 42,000 nodes to take under a second, but it took more than 2 minutes as you can see here: https://i.stack.imgur.com/NzUB7.jpg
For those who want to look at my full code, here it is: https://repl.it/@kasparov/WarmHightechKeygen-1