A 2048 game api for training supervised learning (imitation learning) or reinforcement learning agents
game2048/: the main package.game.py: the core 2048Gameclass.agents.py: 定义了MyAgent,用到Net.py和model/里的model.pth.displays.py: theDisplayclass with instances, to show theGamestate.expectimax/: a powerful ExpectiMax agent by here.
Net.py:定义了卷积神经网络。train.py:训练模型的函数,包括加载数据集,数据预处理,模型训练。运行此代码得到model.pth并保存在model文件夹里。model/:模型文件model.pth。DataSet/:运行training_data.py得到数据集。explore.ipynb: introduce how to use theAgent,DisplayandGame.static/: frontend assets (based on Vue.js) for web app.webapp.py: run the web app (backend) demo.evaluate.py: evaluate your self-defined agent.
- code only tested on linux system (ubuntu 16.04)
- Python 3 (Anaconda 3.6.3 specifically) with numpy and flask
from game2048.agents import Agent
class YourOwnAgent(Agent):
def step(self):
'''To define the agent's 1-step behavior given the `game`.
You can find more instance in [`agents.py`](game2048/agents.py).
:return direction: 0: left, 1: down, 2: right, 3: up
'''
direction = some_function(self.game)
return directioncd game2048/expectimax
bash configure
makepython webapp.pyThe code is under Apache-2.0 License.
Please read here.
