Arcade Learning EnvironmentΒΆ

The Arcade Learning Environment (ALE), commonly referred to as Atari, is a framework that allows researchers and hobbyists to develop AI agents for Atari 2600 roms. Its built on top of the Atari 2600 emulator Stella and separates the details of emulation from agent design. Users can interact with the games through the Gymnasium API, Python interface and C++ interface. For an overview of our goals for the ALE read The Arcade Learning Environment: An Evaluation Platform for General Agents and if you use ALE in your research, we ask that you please cite the appropriate paper(s) in reference to the environment.

import gymnasium as gym
import ale_py

gym.register_envs(ale_py)

# Initialise the environment
env = gym.make("ALE/Breakout-v5", render_mode="human")

# Reset the environment to generate the first observation
observation, info = env.reset(seed=42)
for _ in range(1000):
    # this is where you would insert your policy
    action = env.action_space.sample()

    # step (transition) through the environment with the action
    # receiving the next observation, reward and if the episode has terminated or truncated
    observation, reward, terminated, truncated, info = env.step(action)

    # If the episode has ended then we can reset to start a new episode
    if terminated or truncated:
        observation, info = env.reset()

env.close()