The Simulator is an instance of a game configuration. You can call new_game on it to begin.
__init__(self, game_name, sim=None)
¶
Show source code in ctoybox/ffi.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | def __init__(self, game_name, sim=None): """ Construct a new instance. Parameters: game_name: one of "breakout", "amidar", etc. sim: optionally a Rust pointer to an existing simulator. """ if sim is None: sim = lib.simulator_alloc(game_name.encode('utf-8')) # sim should be a pointer self.game_name = game_name self.__sim = sim self.deleted = False |
Construct a new instance.
Parameters
Name | Type | Description | Default |
---|---|---|---|
game_name |
_empty |
one of "breakout", "amidar", etc. | required |
sim |
_empty |
optionally a Rust pointer to an existing simulator. | None |
from_json(self, config_js)
¶
Show source code in ctoybox/ffi.py
103 104 105 106 107 | def from_json(self, config_js: Union[Dict[str, Any], str]): """Mutably update this simulator/config with the replacement json.""" old_sim = self.__sim self.__sim = lib.simulator_from_json(self.get_simulator(), json_str(config_js).encode('utf-8')) del old_sim |
Mutably update this simulator/config with the replacement json.
get_frame_height(self)
¶
Show source code in ctoybox/ffi.py
77 78 79 | def get_frame_height(self) -> int: """Get the height in pixels of the frames this game renders.""" return lib.simulator_frame_height(self.__sim) |
Get the height in pixels of the frames this game renders.
get_frame_width(self)
¶
Show source code in ctoybox/ffi.py
73 74 75 | def get_frame_width(self) -> int: """Get the width in pixels of the frames this game renders.""" return lib.simulator_frame_width(self.__sim) |
Get the width in pixels of the frames this game renders.
get_simulator(self)
¶
Show source code in ctoybox/ffi.py
81 82 83 | def get_simulator(self): """Get access to the raw simulator pointer.""" return self.__sim |
Get access to the raw simulator pointer.
new_game(self)
¶
Show source code in ctoybox/ffi.py
85 86 87 | def new_game(self) -> 'State': """Start a new game.""" return State(self) |
Start a new game.
schema_for_config(self)
¶
Show source code in ctoybox/ffi.py
113 114 115 | def schema_for_config(self): """Get the JSON Schema for any config for this game.""" return json.loads(rust_str(lib.simulator_schema_for_config(self.__sim))) |
Get the JSON Schema for any config for this game.
schema_for_state(self)
¶
Show source code in ctoybox/ffi.py
109 110 111 | def schema_for_state(self) -> Dict[str, Any]: """Get the JSON Schema for any state for this game.""" return json.loads(rust_str(lib.simulator_schema_for_state(self.__sim))) |
Get the JSON Schema for any state for this game.
set_seed(self, seed)
¶
Show source code in ctoybox/ffi.py
65 66 67 68 69 70 71 | def set_seed(self, seed: int): """Configure the random number generator that spawns new game states. Parameters: seed: a parameter to reset the built-in random number generator. """ lib.simulator_seed(self.__sim, seed) |
Configure the random number generator that spawns new game states.
Parameters
Name | Type | Description | Default |
---|---|---|---|
seed |
int |
a parameter to reset the built-in random number generator. | required |
state_from_json(self, js)
¶
Show source code in ctoybox/ffi.py
89 90 91 92 93 94 95 96 | def state_from_json(self, js: Union[Dict[str, Any], str]) -> 'State': """Generate a State from the state json and this configuration. Parameters: js: a JSON object or string containing a serialized state. """ state = lib.state_from_json(self.get_simulator(), json_str(js).encode('utf-8')) return State(self, state=state) |
Generate a State from the state json and this configuration.
Parameters
Name | Type | Description | Default |
---|---|---|---|
js |
Union[Dict[str, Any], str] |
a JSON object or string containing a serialized state. | required |
to_json(self)
¶
Show source code in ctoybox/ffi.py
98 99 100 101 | def to_json(self) -> Dict[str, Any]: """Get the configuration of this simulator/config as JSON""" json_str = rust_str(lib.simulator_to_json(self.get_simulator())) return json.loads(str(json_str)) |
Get the configuration of this simulator/config as JSON