git clone https://github.com/SUSTechGameAI/GVGAI_GYM.git
pip install -e GVGAI/
pytest
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
In GVGAI_GYM folder, use following command
pytest
train.py
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()
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")