Chrispresso / SnakeAI

MIT License
246 stars 75 forks source link

Need help replaying saved snakes #8

Open guillebot opened 4 years ago

guillebot commented 4 years ago

Hi! I have 1000+ generations of snakes saved. Buy I'm having difficulties trying to replay them.

Any help would be appreciated.

Thanks

Chrispresso commented 4 years ago

Hi. What exactly is the problem with replaying it? The code should save the best individual from each generation. If you're just curious how to replay, unfortunately I did a poor job adding functionality to this (I did much better in Mario and can add the same here). To replay, go to snake_app.py and right after the empty initialization of individuals: List[Individual] = [], you will see a for loop.

Let's say you have 1012 generations you want to replay/tinker with. Change num_parents under the settings to be 1012. Next, change the loop to look like this:

for i in range(self.settings['num_parents']):
    individual_name = f'best_snake_gen{i}'
    individual = load_snake(population_folder, individual_name, None)
    individuals.append(individual)

As long as you set population_folder to a folder containing the generations, individual_name to represent the individual. You can use the i from the loop for each generation, etc. and the settings can be None unless you want to override them here.

This should successfully load the snakes for you. If you want to terminate afterwards, you can go under next_generation and put sys.exit(0) at the top of the function to prevent anything more from happening.

arch-user-france1 commented 3 years ago

What do I have to do to save the population? I want let it run with 100000 FPS and no window and then continue later with only 15 FPS and Window