Skip to content

Instantly share code, notes, and snippets.

@sbodenstein
Created May 25, 2020 15:30
Show Gist options
  • Save sbodenstein/c0f4d5ad227331bc3d92ac580e10008e to your computer and use it in GitHub Desktop.
Save sbodenstein/c0f4d5ad227331bc3d92ac580e10008e to your computer and use it in GitHub Desktop.
Python OpenSpiel Random Game Benchmark
import numpy as np
import pyspiel
import time
def play_random_game(game):
game_state = game.new_initial_state()
while not game_state.is_terminal():
random_action = np.random.choice(game_state.legal_actions())
game_state.apply_action(random_action)
game = pyspiel.load_game("breakthrough")
n = 1000
start = time.time()
for _ in range(n):
play_random_game(game)
time_diff = (time.time() - start) / n
print("Mean Random Game Time (μs): ", 1e6 * time_diff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment