A 2048 game api for training supervised learning (imitation learning) or reinforcement learning agents
It is a course project and TA provides us with an expectimax agent which can get scores above 2048. Therefore, we can collect board and the agent’s corresponding solution (direction: up, down, left, right). It’s just like an image classification task where boards are parallel to images, solutions are parallel to labels. Our aim is to make our own agent's score reach 900+.
Deep learning part. My net: game2048/Model.py, training: game2048/train_CNN.py.
game2048/: the main package.game.py: the core 2048Gameclass.agents.py: theAgentclass with instances. AddedLXYAgentdisplays.py: theDisplayclass with instances, to show theGamestate.expectimax/: a powerful ExpectiMax agent by here.mergedata.py: preprocess the data obtained from ExpectiMaxModel.py: My Nettrain_CNN.py: train my Netpara.pkl: the best parameters for my net
explore.ipynb: introduce how to use theAgent,DisplayandGame.static/: frontend assets (based on Vue.js) for web app.get_layer_boards/:agents.py: get data from Expectimax Agentgetboards.py: get data from Expectimax Agent
webapp.py: run the web app (backend) demo.evaluate.py: evaluateLXYAgent.generate_fingerprint.py: getLXYAgent's fingerprint.past_train_log.out: part of my past train log.
- code only tested on linux system (ubuntu 16.04)
- Python 3 (Anaconda 3.6.3 specifically) with numpy and flask
- Pytorch
Before train the net, you should create the dir ./game2048/saved
then:
python3 train_CNN.pypython3 evaluate.py >>evaluation.logpython3 generate_fingerprint.pycd game2048/expectimax
bash configure
makepython webapp.pyThe code is under Apache-2.0 License.
