A 2048 game api for training supervised learning (imitation learning) or reinforcement learning agents
- if you want to evaluate the model, run blow command in the path of
/2048-api
python evaluate.py
note: the models should be in the path of /2048-api/model
- if you want to test train the model
- first modify the import part of myAgent2.py as below
# test use
#from game2048.agents import Agent, ExpectiMaxAgent
#from game2048.game import Game
# train use
from agents import Agent, ExpectiMaxAgent
from game import Game
note: if there exists models in the path /2048-api/model
, set firstTime to False in instantiation myOwnAgent in the last part of myAgent2.py, or set to True
myAgent = myOwnAgent(
game=tmpGame,
maxPower=16,
modelLevel=[256, 512, 900],
firstTime=False)
- then run blow command in the path of
/2048-api
python game2048/myAgent2.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.myAgent2.py
: my weak agent.
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.