open_spiel icon indicating copy to clipboard operation
open_spiel copied to clipboard

Document undocumented methods that are common across games

Open carlosgmartin opened this issue 10 months ago • 1 comments

The following methods are common across games but undocumented at the OpenSpiel Core API Reference:

Undocumented common game methods:

  • [ ] get_parameters
  • [ ] get_type
  • [ ] information_state_tensor_layout
  • [ ] make_observer
  • [ ] max_chance_nodes_in_history
  • [ ] max_history_length
  • [ ] max_move_number
  • [ ] new_initial_state_for_population
  • [ ] new_initial_states
  • [ ] num_players
  • [ ] observation_tensor_layout
  • [ ] policy_tensor_shape
  • [ ] utility_sum

Undocumented common state methods:

  • [ ] apply_action_with_legality_check
  • [ ] apply_actions_with_legality_checks
  • [ ] child
  • [ ] clone
  • [ ] distribution_support
  • [ ] full_history
  • [ ] get_game
  • [ ] get_type
  • [ ] history_str
  • [ ] is_initial_state
  • [ ] is_mean_field_node
  • [ ] is_player_node
  • [ ] legal_actions_mask
  • [ ] mean_field_population
  • [ ] move_number
  • [ ] num_distinct_actions
  • [ ] num_players
  • [ ] player_return
  • [ ] player_reward
  • [ ] resample_from_infostate
  • [ ] string_to_action
  • [ ] to_string
  • [ ] undo_action
  • [ ] update_distribution

I'd be happy to help with some of these, if desired.

Here's a quick script I used to generate these lists:
import pyspiel
import requests
from lxml import html
import re

game_methods = []
state_methods = []

for game_string in pyspiel.registered_names():
    try:
        game = pyspiel.load_game(game_string)
    except Exception as e:
        # print(f"Error creating {game_string}: {e}")
        continue
    state = game.new_initial_state()

    game_methods.append(set(method for method in dir(game) if not method.startswith("_")))
    state_methods.append(set(method for method in dir(state) if not method.startswith("_")))

common_game_methods = set.intersection(*game_methods)
common_state_methods = set.intersection(*state_methods)

URL = "https://openspiel.readthedocs.io/en/latest/api_reference.html"

response = requests.get(URL)
response.raise_for_status()
tree = html.fromstring(response.content)

documented_state_methods = set(
    re.match(r"([a-zA-Z0-9_]*)", element.text).group(0)
    for element in tree.xpath('//section[2]//tr/td[1]/code')
)

documented_game_methods = set(
    re.match(r"([a-zA-Z0-9_]*)", element.text).group(0)
    for element in tree.xpath('//section[3]//tr/td[1]/code')
)

undocumented_common_game_methods = common_game_methods - documented_game_methods
undocumented_common_state_methods = common_state_methods - documented_state_methods

print()
print(f"The following methods are common across games but undocumented at the [OpenSpiel Core API Reference]({URL}):")
print()
print("Undocumented common game methods:")
print("\n".join("- [ ] " + name for name in sorted(undocumented_common_game_methods)))
print()
print("Undocumented common state methods:")
print("\n".join("- [ ] " + name for name in sorted(undocumented_common_state_methods)))

carlosgmartin avatar Feb 04 '26 05:02 carlosgmartin

Is anyone working on it?

abhaygoudannavar avatar Feb 06 '26 10:02 abhaygoudannavar