# -*- coding: utf-8 -*- """play_atari_breakout_v3_2_mai2025_short.ipynb Automatically generated by Colab. Original file is located at https://colab.research.google.com/drive/1378RHSQk3vXBp56jblCuVV1RdodKAHhp # Play Atari games with gymnasium This notebook implements a simple way to play Atari games (here Atari Breakout) by G. Turinici May 2025 """ # Step 1: Install required packages !pip install gymnasium[atari] autorom !mkdir -p ~/.gymnasium/roms !AutoROM --accept-license --install-dir ~/.gymnasium/roms #!ls ~/.gymnasium/roms # Step 2: Import packages import gymnasium as gym import matplotlib.pyplot as plt from IPython.display import clear_output import time # Step 3: Create environment import ale_py env = gym.make("ALE/Breakout-v5", render_mode="rgb_array") obs, info = env.reset() # Step 4: Play random moves and display frames for step in range(10): action = env.action_space.sample() obs, reward, terminated, truncated, info = env.step(action) # Show the frame plt.imshow(obs) plt.axis('off') plt.title(f"Step: {step+1}, Reward: {reward}") clear_output(wait=True) plt.show() time.sleep(0.3) # Pause briefly to simulate animation if terminated or truncated: obs, info = env.reset()