FJJLeon / 2048-api

A 2048 api for training supervised learning (imitation learning) or reinforcement learning agents

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2048-api

A 2048 game api for training supervised learning (imitation learning) or reinforcement learning agents

For TA

  • 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
  1. 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)
  1. then run blow command in the path of /2048-api
    python game2048/myAgent2.py

Code structure

Requirements

  • code only tested on linux system (ubuntu 16.04)
  • Python 3 (Anaconda 3.6.3 specifically) with numpy and flask

To define your own agents

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

To compile the pre-defined ExpectiMax agent

cd game2048/expectimax
bash configure
make

To run the web app

python webapp.py

demo

LICENSE

The code is under Apache-2.0 License.

For EE369 students from SJTU only

Please read here.

About

A 2048 api for training supervised learning (imitation learning) or reinforcement learning agents

License:Apache License 2.0


Languages

Language:JavaScript 58.1%Language:Jupyter Notebook 27.3%Language:Python 5.7%Language:C++ 3.5%Language:Shell 3.1%Language:C 1.1%Language:HTML 0.5%Language:CSS 0.4%Language:Makefile 0.1%