There exist three dependencies:
To install dependencies, run
pip3 install -r requirements.txt
git clone https://github.com/Chrispresso/SnakeAI.git
settings.py, which control the hyperparameters of the Neural Network and Genetic Algorithm and
snake_app.py, which is the graphics and GA.
settings.py. If you change the
board_sizedrastically you will probably want to change
snake_app.py. The current settings when you first clone are the settings I used for training a snake to solve 10x10 and the 50x50 grids. Play around with this stuff if you want, you can always create another population in a new command window that use different settings.
show=True, fps=200if you would like.
showcontrols whether or not to display the snakes learning. FPS in the case of show is capped at your monitor refresh. Definitely faster to train with
# Next generationand you can print out the fitness if you would like. This is also where you can
savethe snake. Well you can save anywhere I guess, but this is where I saved the best snake from each generation. This can be done with
save_snake('path/to/population/folder', 'snake_name (i.e. best_snake_gen0)', snake, self.settings). This saves the snake, the constructor params that were used to create the snake and the
settings.pyfile used for hyperparameters. If you load the same snake you saved, the snake will play exactly how it did before. The apple locations are based off an initially
apple seed. So if you load the same snake without modifying the contructor, then the snake will replay what it did. Very helpful for me since I trained without visualizations and needed to go back and record stuff for the video.
Let's say you have a 50 generations of snakes saved and you want to create a new population with the last 10 generations. You could start a new instance of
for _ in range(self.settings['num_parents']):portion to generate 10 less snakes. Then you can load your 10 best snakes and insert them into the population. This is where you can choose to either modify the constructor of your snake to have a different
apple_seedor allow the snake to run it's previous course. The choice is up to you and totally dependent on your goals!
If the ability to load snakes is something you want to have an easier time with let me know and I can work on that.