Ever played the classic helicopter game during your childhood?
If you haven't, here's the flash game: helicoptergame.net
So, this repo contains the source for training a clone of that game using reinforcement learning. That is, the helicopter (agent) learns to play the game by itself by avoiding the obstacles and traveling maximum possible distance.
- Tested on
Python 3.6
withTensorflow 1.12
andKeras 2.1.6-tf
pip3 install numpy pygame pillow pynput matplotlib tensorflow keras tensorflow-gpu
- I trained on Google Colab, but the
.ipynb
notebook should work on Jupyter, etc.
To play the game by yourself, enter in Terminal:
python3 pixelCopterHumanPlay.py
Press Up
arrow key to make the helicopter move up.
Press Esc
key to quit the play.
Use the Train_Helicopter_DQN_RL.ipynb notebook to train the model (without gameplay render)
Note: You have to execute each cells step by step from bottom to top as directed in the .ipynb
file.
To visualize the reward plot and loss plot, use the plotRewards.py
and plotLoss.py
files respectively. (You can set the filename inside the code)
Inference has to be done on computer with graphics display for rendering.
python3 inferenceHelicopter.py
This will load the saved model weights and show the gameplay inference. I have included a sample weights file in this repo that works well, but it's not fully trained.
(If you change the model architecture in the notebook, don't forget to alter the same in this code as well)
This game was modified by me from the PyGame Learning Environment (PLE)'s PixelCopter game.
The instructions to use the environment can be found in their docs. The training code was inspired from this post.
- Add support for this environment to OpenAI Gym ;)
- Include the graph plotting code as part of the training code instead of separate files.
- Train using this official example.
Feel free to clone/contribute to the repo :)