Test Game

Example server environment primarily for testing.

class colosseumrl.envs.testgame.TestGame.TestGame(config: str = '')[source]

Bases: colosseumrl.BaseEnvironment.BaseEnvironment

is_valid_action(state: numpy.ndarray, 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.

Return type

bool

property max_players

Property holding the max number of players present for a game.

Currently, this should be the same as min_players. Future additions will allow for dynamic games.

Returns

Maximum number of players allowed in game.

Return type

int

property min_players

Property holding the number of players present required to play game.

Returns

Minimum number of players for game to start.

Return type

int

new_state(num_players: int = 1)[source]

Create a fresh state. This could return a fixed object or randomly initialized on, depending on the game.

Note that player numbers must be numbers in the set {0, 1, …, n-1} for an n player game.

Parameters

num_players (int) – Total number of players in this game.

Returns

  • new_state (object) – The initial state for the game. This can be any python object you wish.

  • new_players (List[int]) – List of players who’s turn it is now.

next_state(state: numpy.ndarray, players: [<class 'int'>], actions: [<class 'str'>]) → Tuple[numpy.ndarray, List[int], List[float], bool, Optional[List[int]]][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 (object) – 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.

This needs to be static to setup spacetime dataframes.

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]]

state_to_observation(state: numpy.ndarray, 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.

This can return different values for the different players. Default implementation is just the identity.

valid_actions(state: numpy.ndarray, 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.

Return type

List[str]