Snake game controlled by an artificial neural network
Once you have cloned the repository,
- In command line from project root, run:
cd SnakeBrain
python server.py
-
Import ./Snake/ into IntelliJ IDEA
Make sureIS_TRAINING = false
inConfig.java
. -
Run
Snake.java
and watch the snake eat apples by itself.
To train the snake (assuming you have completed quickstart):
-
Change
IS_TRAINING
totrue
inConfig.java
. -
Run
Snake.java
. Use the arrow keys to move the snake.
When training is complete, press 'E' to export the training data. -
Look in ./TrainingData/ and find the .csv file you want to use to train the snake. Copy this file into ./TrainingData/active/. Make note of the vision type. You are only generating parameters for this vision type. Parameters for other vision types will be unaffected.
-
Open config.py and change
import config_visionX as cfg
to the correct vision type. For example, if you wanted to generate parameters for vision1, you would change it toimport config_vision1 as cfg
. -
Run
snakecharmer.py
(assuming you are already in ./SnakeBrain/):
python snakecharmer.py
-
Look in ./Parameters/ for the newly generated .csv file. Copy that to ./Parameters/active/ and rename to
weights_visionX.csv
, where visionX corresponds to the vision type. -
Restart the Python server (
server.py
) -
Make sure
VISION_TYPE
inConfig.java
is set to the correct vision type. For example, if you trained for vision1, then set it toExample.VISION_1
. -
Change
IS_TRAINING
inConfig.java
back tofalse
-
Run
Snake.java
and watch your newly trained snake eat apples by itself.
-
There are total 3 vision types, creatively named vision1, vision2, vision3.
-
Different vision types determine what the snake sees. Play around with them until you find one that works the best. Then let me know (please?)
-
You should know that vision1 sucks. A lot. Unless your board is less than 10x10, don't use it.
-
I'm have not yet determined which is better, vision2 or vision3. They both work pretty well.
-
I'm not a snake master. Thus snakes that learn from me are not masters themselves. The included trained parameters will get your snake to a score of around 30, 40 if you're lucky, and 50 if you're really lucky.
-
If you have trained this snake to do better, please submit a pull request :)
-
The snake's name is Ann. Ann A. Conda. Not Anne. Not Annie. Don't ask why. Just remember what it uses for a brain.
Special thanks to wollip for creating the snake game this project is based off of.