nagisa-eevee / 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

Code structure

  • game2048/: the main package.
  • data/: the main package.
    • data_eval.csv: the evaset to evaluate model generalization ability.
    • dataprocess.py: the Data class, to generate training data. Other functions or classes relate to data procession is also included.
    • dataprocess_old.py: the Data class, discarded.
    • test.py: several instances of IO function.
  • model_related/: the main package.
    • eval.py: the eval function with instances.
    • logger.py: the Logger class, to launch tensorboard.
    • model.py: the ConvNet class, the DNN used to complete the 2048 game.
    • train.py: the program used to train the model.
    • train_test.py: used to evaluate the ability of the initial model.
  • explore.ipynb: introduce how to use the Agent, Display and Game.
  • 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.

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 course project requirements and description.

About

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

License:Apache License 2.0


Languages

Language:Jupyter Notebook 89.0%Language:JavaScript 8.4%Language:Python 1.4%Language:C++ 0.5%Language:Shell 0.5%Language:C 0.2%Language:HTML 0.1%Language:CSS 0.1%Language:Makefile 0.0%