petomuro / Snake-GA

Snake GA - Genetic algorithm that solves the Snake game. GA was implemented by PyGAD library available for Python, neural networks was created in Keras and game was created in Pygame.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Snake-GA

Snake GA - Genetic algorithm that solves the Snake game. GA was implemented by PyGAD library available for Python, neural networks was created in Keras and game was created in Pygame.

You have to installed Python 3.7.9 and other requirements which are necessary for run the program (requirements.txt).

Example

Train neural network

If you want to train neural network, you need to:

  1. change OPTIMIZATION = True
  2. run main.py

Example

Test neural network

When the training of neural network is complete, a file will be created in the weights folder.

If you want to test trained neural network you need to:

  1. change OPTIMIZATION = False
  2. change in neural_network.py --> self.network.load_weights('weights/model_name.h5') --> e.g. self.network.load_weights('weights/model20210526044312.h5')
  3. run main.py

Create graph

When the training is complete, a file will be created in the results folder.

If you want to create graph you need to:

  1. change in helper.py --> with open('results/results_name.csv') as results_file: --> e.g. with open('results/results20210520223339.csv') as results_file:
  2. run helper.py

About

Snake GA - Genetic algorithm that solves the Snake game. GA was implemented by PyGAD library available for Python, neural networks was created in Keras and game was created in Pygame.

License:MIT License


Languages

Language:Python 100.0%