# -*- coding: utf-8 -*- """play_atari_breakout_v1.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1oInyDSY79BWivrxiFZ8TrNJj3IUmaB0u # Play Atari games with gym This notebook implements a simple way to play Atari games (here Atari Breakout) by G. Turinici june 2022 """ # Commented out IPython magic to ensure Python compatibility. #XVFB will be launched if you run on a server import sys, os if 'google.colab' in sys.modules: # %tensorflow_version 1.x if type(os.environ.get("DISPLAY")) is not str or len(os.environ.get("DISPLAY"))==0: !bash ../xvfb start # %env DISPLAY=:1 # Commented out IPython magic to ensure Python compatibility. import gym import numpy as np import pandas as pd import matplotlib.pyplot as plt # %matplotlib inline import urllib.request urllib.request.urlretrieve('http://turinici.com/wp-content/uploads/cours/reinforcement_learning/breakout_rom.zip', 'breakout_rom.zip') !mkdir -p romzip !mv breakout_rom.zip romzip !python -m atari_py.import_roms romzip #useful commands #!pip install atari_py #!pip install gym[atari] #!pip install gym[all] ##to list available envs #from gym import envs #print(envs.registry.all()) #play directly : env_test = gym.make("BreakoutDeterministic-v4") #To start a new game state0=env_test.reset() print("state0.shape=",state0.shape) plt.imshow(state0) print(env_test.observation_space) print(env_test.action_space) print(env_test.reward_range) print(env_test.spec) print(env_test.metadata) #test the game; action meaning : 0=NOOP; 1=FIRE; 2=RIGHT; 3=LEFT # use this cell as many times as necessary changing the action "1" with another env_test.step(1) plt.imshow(env_test.render(mode='rgb_array'))