OpenSpiel: A Framework for Reinforcement Learning in Games

1.6.12 · active · verified Fri Apr 17

OpenSpiel is a collection of environments and algorithms for research in reinforcement learning and search in games. It provides implementations of numerous games (e.g., Chess, Go, Poker, Tic-Tac-Toe) and common algorithms (e.g., MCTS, AlphaZero, CFR). The library is currently at version 1.6.12, with frequent staging releases in preparation for a major 2.0 release. It's developed and maintained by Google DeepMind.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a game, create an initial state, apply an action, and check the game's status using the core `pyspiel` module.

import pyspiel

# Load a game by its string identifier
game = pyspiel.load_game("tic_tac_toe")

# Create a new initial state for the game
state = game.new_initial_state()

# Print the initial state
print("Initial state:\n", state)

# Apply a move (e.g., player 0 places 'X' in the center)
# Actions are integer indices, you can get valid actions via state.legal_actions()
state.apply_action(4) # Assuming 4 is a valid action in Tic-Tac-Toe
print("\nState after move:\n", state)

# Check if the game is terminal
if state.is_terminal():
    print("\nGame is over. Returns:", state.returns())

view raw JSON →