A 2048 game api for training supervised learning (imitation learning) or reinforcement learning agents
best/
文件夹存放了模型的权重文件model.h5
.game2048/
文件夹中的agents.py
文件进行了修改.Agent.py
文件为自己的Agent程序,继承了agents.py
.EE369_fingerprint.json
为Agent指纹.Train.py
为训练程序.evaluate.py
为修改后的运行程序.generate_fingerprint.py
为修改后的指纹程序.model.py
为模型程序.
运行model.py,在best文件夹里生成初始的权重文件model.h5
python3 model.py
运行Train.py,训练并更新model.h5权重文件
python3 Train.py
运行evaluate.py,得到50次游戏结果并将棋盘保存在日志文件中
python3 evaluate.py >> EE369_evaluation.log
运行generate_fingerprint.py,得到Agent指纹
python3 generate_fingerprint.py
game2048/
: the main package.game.py
: the core 2048Game
class.agents.py
: theAgent
class with instances.displays.py
: theDisplay
class with instances, to show theGame
state.expectimax/
: a powerful ExpectiMax agent by here.
explore.ipynb
: introduce how to use theAgent
,Display
andGame
.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 direction
cd game2048/expectimax
bash configure
make
python webapp.py
The code is under Apache-2.0 License.
Please read here.