Skip to content

Commit

Permalink
Bug fix: avoid reliance on uninitialized pyspiel.Game objects.
Browse files Browse the repository at this point in the history
Backward compatible change preparing for pybind11 update.

Relevant pybind11 change:
* pybind/pybind11#2152
* Throw TypeError when subclasses forget to call __init__

PiperOrigin-RevId: 328182655
Change-Id: I8dc8cd69ee328f95bdca58b0f9045d65d11307a8
  • Loading branch information
DeepMind Technologies Ltd authored and [email protected] committed Aug 27, 2020
1 parent 196b0cc commit 3bfe548
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions open_spiel/python/rl_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,19 @@ def __init__(self,
self._chance_event_sampler = chance_event_sampler or ChanceEventSampler()
self._include_full_state = include_full_state

if isinstance(game, pyspiel.Game):
if isinstance(game, str):
if kwargs:
game_settings = {
key: pyspiel.GameParameter(val) for (key, val) in kwargs.items()
}
logging.info("Using game settings: %s", game_settings)
self._game = pyspiel.load_game(game, game_settings)
else:
logging.info("Using game string: %s", game)
self._game = pyspiel.load_game(game)
else: # pyspiel.Game or API-compatible object.
logging.info("Using game instance: %s", game.get_type().short_name)
self._game = game
elif kwargs:
game_settings = {
key: pyspiel.GameParameter(val) for (key, val) in kwargs.items()
}
logging.info("Using game settings: %s", game_settings)
self._game = pyspiel.load_game(game, game_settings)
else:
logging.info("Using game string: %s", game)
self._game = pyspiel.load_game(game)

self._num_players = self._game.num_players()
self._state = None
Expand Down

0 comments on commit 3bfe548

Please sign in to comment.