So, right now I'm working on a chess game. I've finished all the basic stuff, and now I'm trying to add the functionality of importing a PGN and viewing the moves as they're being played slowly.
Here's the part responsible for this:
def main2():
PGN = """
1.e4 e6 2.d4 d5 3.Nc3 Nf6 4.e5 Nfd7 5.Nce2 c5 6.c3 Nc6 7.f4 cxd4 8.cxd4 Qb6
9.Nf3 Be7 10.Ng3 Bb4+ 11.Kf2 f6 12.Be3 fxe5 13.fxe5 O-O 14.Ne2 Be7 15.b3 Nd8
16.Kg3 Nf7 17.Qd3 Nh8 18.h4 Rf5 19.Kf2 Qd8 20.g4 Rf7 21.Kg2 Nf8 22.Ng3 Nhg6
23.g5 Nf4+ 24.Bxf4 Rxf4 25.Ne2 Ng6 26.Kg3 Rf5 27.Bh3 Rf8 28.Rhf1 Nh8 29.Kh2 Bd7
30.Rg1 Rc8 31.h5 g6 32.Rg2 Rf7 33.Nh4 Kg7 34.h6+ Kg8 35.Rag1 Qf8 36.Qe3 Rc2
37.Ng3 Rff2 38.Rf1 Rxg2+ 39.Nxg2 Nf7 0-1
"""
game_gen = logic.state_from_PGN(PGN, wrapper_dict=LETTER_TO_PIECE)
game = game_gen.__next__()
screen, background, clock, pieces, buttons, moving_piece, game = initialize(game)
for game in game_gen:
update_screen(screen, background, pieces, buttons, moving_piece)
pygame.display.update()
clock.tick(10)
return game
So, this function, imports a PGN file and keeps updating the game, until it reaches the final state and returns it. Then, the main() function takes over and allows user input to the game if the game has not ended in a checkmate yet.
The problem occurs when I adjust the fps in the clock.tick(10)
.
With 10 fps, it works fine, but as I decrease the fps. the pygame window stops responding earlier and earlier. It then snaps out of the "not responding" once the PGN is fully finished (and after it has returned the final state of the game)