TronGridEnvironment¶
-
class
colosseumrl.envs.tron.TronGridEnvironment.
TronGridEnvironment
(config: str = '')[source]¶ -
STRING_TO_ACTION
= {'': 0, 'forward': 0, 'left': -1, 'right': 1}¶
-
static
create
(board_size: int = 20, num_players: int = 4, observation_window: int = -1, remove_on_death: bool = False) → colosseumrl.envs.tron.TronGridEnvironment.TronGridEnvironment[source]¶ Secondary constructor with explicit options for creating the environment
- Parameters
board_size (int) – This will specify the square size of the playing grid.
num_players (int) – Number of active players in the game.
observation_window (-1) – Current not used
remove_on_death (bool) – Whether or not to remove the player and their associated walls when they are eliminated.
-
static
deserialize_state
(serialized_state: bytearray) → object[source]¶ Convert a serialized bytearray back into a game state.
- Parameters
serialized_state (bytearray) – Serialized byte-string for the state.
- Returns
The current game state.
- Return type
object
-
is_valid_action
(state: object, player: int, action: str) → bool[source]¶ Whether or not an action is valid for a specific state.
- Parameters
state (object) – The current state of the game.
player (int) – The player who is executing this action.
action (str) – The action the player is executing.
- Returns
Whether or not this is a valid action in the current state. This is always true for tron as every action is valid.
- Return type
bool
-
property
max_players
¶ Property holding the number of players present required to play game.
- Returns
The specified number of players in this game.
- Return type
int
-
property
min_players
¶ Property holding the number of players present required to play game.
- Returns
The specified number of players in this game.
- Return type
int
-
new_state
(num_players: int = None) → Tuple[object, List[int]][source]¶ Create an initial tron state.
- Parameters
num_players (int, optional.) – The number of players for the game. Note, this option gets ignored here in favor of the global player configuration when creating the environment.
- Returns
State (Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]) – The full state of the new tron environment.
player_list (List[int]) – Which players are currently acting.
-
next_state
(state: object, players: [<class 'int'>], actions: [<class 'str'>])[source]¶ Compute a single step in the game.
Notes
Player numbers must be numbers in the set {0, 1, …, n-1} for an n player game.
- Parameters
state (Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]) – The current state of the game.
players ([int]) – The players which are taking the given actions.
actions ([str]) – The actions of each player.
- Returns
new_state (object) – The new state of the game.
new_players (List[int]) – List of players who’s turn it is in the new state now.
rewards (List[float]) – The reward for each player that acted.
terminal (bool) – Whether or not the game has ended.
winners (List[int]) – If the game has ended, who are the winners.
-
static
observation_names
() → List[str][source]¶ Static method for returning the names of the observation objects.
- Returns
The keys of the observation dictionary.
- Return type
List[str]
-
property
observation_shape
¶ Describe the fixed numpy shapes of each observation.
- Returns
The shape, as a tuple, of each numpy array by their name.
- Return type
Dict[str, Tuple[int]]
-
static
serializable
() → bool[source]¶ Whether or not this class supports serialization of the state.
- Returns
False, Tron doesnt need to be serializable as the state is current fully observable.
- Return type
bool
-
static
serialize_state
(state: object) → bytearray[source]¶ Serialize a game state and convert it to a bytearray to be saved or sent over a network.
- Parameters
state (object) – The current game state.
- Returns
Serialized byte-string for the state.
- Return type
bytearray
-
state_to_observation
(state: object, player: int) → Dict[str, numpy.ndarray][source]¶ Convert the raw game state to the observation for the agent. Maps each observation name into an observation.
- Parameters
state (object) – The full server state of the game.
player (int) – Which player is getting the observation.
- Returns
The observation dictionary with keys equal to the observation_names above.
- Return type
Dict[str, np.ndarray]
See also
colosseumrl.envs.tron.TronGridEnvironment.observation_names()
The list of observatio keys.
colosseumrl.envs.tron.TronGridEnvironment.observation_shapes()
The sizes of each observation.
-
valid_actions
(state: object, player: int) → [<class 'str'>][source]¶ Valid actions for a specific state.
- Parameters
state (object) – The current state of the game.
player (int) – The player who is executing this action.
- Returns
All possible actions for the game. For tron, this will always be [‘forward’, ‘left’, ‘right’]
- Return type
List[str]
-