OpenSpiel

Getting started

  • What is OpenSpiel?
  • Installation
    • Python-only installation via pip
      • Python-only installation via pip (from source).
    • Installation from Source
    • Summary
    • Installing via Docker
    • Running the first examples
    • Detailed steps
      • Configuring conditional dependencies
      • Installing system-wide dependencies
      • Installing Python dependencies
        • Required dependencies
        • Optional dependencies
      • Building and running tests
      • Setting Your PYTHONPATH environment variable

Core OpenSpiel

  • First examples
  • Concepts
    • The tree representation
  • Loading a game
    • Creating sequential games from simultaneous games
  • Playing a trajectory
  • OpenSpiel Core API Reference
    • Core Functions
    • State methods
    • Game methods
  • Available algorithms
  • Available games

Evaluation

  • Alpha-Rank
    • Importing the Alpha-Rank module
    • Running Alpha-Rank on various games
      • Example: symmetric 2-player game rankings
      • Example: multi-population game rankings
    • Visualizing and reporting results
      • Basic Ranking Outputs
      • Markov Chain Visualization
      • Alpha-sweep plots

Julia OpenSpiel

  • OpenSpiel on Julia
    • Install
    • Known Problems
    • Example
    • Q&A

AlphaZero

  • AlphaZero
    • Background
    • Overview:
      • Model
      • MCTS
      • MCTS Evaluator
      • Actors
      • Learner
      • Evaluators
      • Output
    • Usage:
      • Python
      • Analysis
      • Playing vs checkpoints

Developer guide

  • The code structure
  • C++ and Python implementations.
  • Adding a game
  • Conditional dependencies
  • Debugging tools
  • Adding Game-Specific Functionality
  • Language APIs
  • Guidelines
  • Support expectations
    • Bugs
    • Pull requests
  • OpenSpiel visual Graph
  • Roadmap and Call for Contributions

Using OpenSpiel as a C++ Library

  • Using OpenSpiel as a C++ Library
    • Install Dependencies
    • Compiling OpenSpiel as a Shared Library
    • Compiling and Running the Example

Extra information

  • Authors
    • OpenSpiel contributors
    • OpenSpiel with Swift for Tensorflow (now removed)
    • External contributors
OpenSpiel
  • OpenSpiel state methods: legal_actions_mask
  • View page source

OpenSpiel state methods: legal_actions_mask

Back to Core API reference

  1. legal_actions_mask(player: int)

  2. legal_actions_mask()

Returns a binary vector where 1 indicates a legal action and 0 indicates an illegal action. The length is game.num_distinct_actions() for player nodes, or game.max_chance_outcomes() for chance nodes. The parameterless version uses the current player.

This is useful for masking illegal actions in neural network policy outputs.

Examples:

import pyspiel

game = pyspiel.load_game("tic_tac_toe")
state = game.new_initial_state()
print(state.legal_actions_mask())
# Output: [1, 1, 1, 1, 1, 1, 1, 1, 1]  (all 9 squares available)

state.apply_action(4)   # Player 0 takes center
print(state.legal_actions_mask())
# Output: [1, 1, 1, 1, 0, 1, 1, 1, 1]  (center no longer available)

# Also works with explicit player argument
print(state.legal_actions_mask(1))
# Output: [1, 1, 1, 1, 0, 1, 1, 1, 1]

© Copyright 2019, DeepMind Technologies Ltd.

Built with Sphinx using a theme provided by Read the Docs.