1. Install


1.1 Install with Docker

  • We have provided the Dockerfile to install the GVGAI environment.
  • The Guidelines for using Docker to install GVGAI is detailed in this page.

1.2 Install on your Operate System

  1. Install Python Environment, Firstly. (Anaconda or Miniconda is recommended)
  2. Install Java Environment in your machine.
  3. Download the GVGAI from Github
  4.    git clone https://github.com/SUSTechGameAI/GVGAI_GYM.git      
  5. Install the GVGAI in your machine.
  6.    pip install -e GVGAI/      
  7. Test the Environment (In GVGAI_GYM folder)
  8.    pytest      

1.3 The video tutorial

  • If the video is not fluent, you can watch it in the YouTube. link
  • The scripts in video are available in github. link


2. Example (DQN RL baseline from OpenAI)


2.1 Install RL baseline (GPU/CPU)

If you use Dockerfile we provided, the RL baseline has been installed. pip install stable-baselines[mpi]

The RL-baseline requires Tensorflow (version \< 2.0). So, the Tensorflow is required to be installed before you use algorithm from RL baseline. pip install tensorflow==1.14 or install tensorflow-gpu==1.14

2.2 Test the RL baseline

In GVGAI_GYM folder, use following command

   pytest      

2.3 Use algorithm from RL baseline

Take DQN as an example (The code is in This)
  1. Implement your policy and train your agent on a given game level, shown in train.py
  2. Example: train.py , game -> gold digger, level0
  3. Save your agent
  4. Example: best_model_gold_digger_lvl0.pkl
  5. Use trained model in Agent class by loading trained model
  6. Example: Agent.py

3. Visualization for the GVGAI-GYM

3.1 Offline approach


Step 1: Save each step as an image

      def show_state(env, step, name, info):
          plt.figure(3)
          plt.clf()
          plt.imshow(env.render(mode='rgb_array'))
          plt.title("%s | Step: %d %s" % (name, step, info))
          plt.axis("off")
          path = 'imgs/' + name + str(step) +'.png'
          plt.savefig(path)

Step 2: Convert all images into .gif image

      import imageio

      def create_gif(image_list, gif_name): 
          frames = []
          for image_name in image_list:
              frames.append(imageio.imread(image_name))
          # Save them as frames into a gif 
          imageio.mimsave(gif_name, frames, 'GIF', duration = 0.1)
          return

      def main():
          image_list = []
          for i in range(186):
              name = "imgs/game" + str(i) + ".png"
              image_list.append(name)
          gif_name = 'created_gif.gif'
          create_gif(image_list, gif_name)
        
      if __name__ == "__main__":
          main()

3.2 Online approach: Use Jupyter Notebook

Demo:
    import gym
    import gym_gvgai
    import Agent as Agent
    from IPython import display
    import matplotlib.pyplot as plt

    def show_state(env, step, name, info):
        plt.figure(3)
        plt.clf()
        plt.imshow(env.render(mode='rgb_array'))
        plt.title("%s | Step: %d %s" % (name, step, info))
        plt.axis("off")
        
        display.clear_output(wait=True)
        display.display(plt.gcf())

    %matplotlib inline
    env = gym_gvgai.make('gvgai-aliens' + '-' + 'lvl0-v0')
    agent = Agent.Agent()
    stateObs = env.reset()
    actions = env.unwrapped.get_action_meanings()
    score = 0
    for  i in range(1000):
        show_state(env, i, 'Aliens', str(score))
        action_id = agent.act(stateObs, actions)
        stateObs, diffScore, done, debug = env.step(action_id)
        score += diffScore
        if done:
            break
    print("finished")

4. Problem Feedback


  1. Email to support@aingames.cn or htong6@outlook.com or liujl@sustech.edu.cn with the prefix [GVGAILearning] in the subject of the email.
  2. Submit issues in the Github repository. (Recommended) Go

Affiliations