ClientEnvironment¶
-
class
colosseumrl.ClientEnvironment.
ClientEnvironment
(dataframe: spacetime.dataframe.Dataframe, dimensions: List[str], observation_class: Type[colosseumrl.data_model.Observation], host: str, server_environment: Optional[Type[colosseumrl.BaseEnvironment.BaseEnvironment]] = None, auth_key: str = '')[source]¶ Basic client environment that will work with any server environment and handles most of the connection and playing capabilities.
-
check_connection
() → None[source]¶ Helper function to error out if we are not yet connected to a game server.
- Raises
ConnectionError – If connect() has not been called yet.
-
connect
(username: str, timeout: Optional[float] = None) → int[source]¶ Connect to the remote server and wait for the game to start.
- Parameters
username (str) – Your desired Player Name.
timeout (float) – Optional timout for how long to wait before abandoning connection
- Returns
player_number – The assigned player number in the global game.
- Return type
int
- Raises
ConnectionError – If we could not connect to the game server successfully.
Notes
This is your absolute player number that will be used for interpreting the full server state and the winners after the end of the game.
-
property
dimensions
¶ Get all of the observations that we recieve from the server.
- Returns
The keys in the observation dictionary.
- Return type
List[str]
-
property
full_state
¶ Full server state for the game if the environment and the server support it.
- Returns
Current server state
- Return type
object
- Raises
ConnectionError – If connect() has not been called yet.
ValueError – If we do not have access to the full state.
-
property
observation
¶ Get the current observation present for this agent.
- Returns
The observation dictionary for this environment.
- Return type
Dict[str, np.ndarray]
-
property
server_environment
¶ Get the full server environment object if we have it available.
- Returns
Server environment or None is not available.
- Return type
-
step
(action: str) → Tuple[Dict[str, numpy.ndarray], float, bool, Optional[List[int]]][source]¶ Perform an action and send it to the server. This wil block until it is your turn again.
- Parameters
action (str) – Your action string.
- Returns
observation (Dict[str, np.ndarray]) – The new observation dictionary for the new state.
reward (float) – The reward for the previous action.
terminal (bool) – Whether or not the game has ended.
winners (Optional[List[int]]) – If terminal is true, this will be a list of the player numbers that have won If terminal is false, this will be None
-
property
terminal
¶ Check if the game has ended for us or not.
- Returns
Whether or not the game has reached a terminal state.
- Return type
bool
- Raises
ConnectionError – If connect() has not been called yet.
-
tick
() → bool[source]¶ Helper function to wait for a tick of the framerate.
- Returns
Whether or not the framerate keeper has raised a timeout.
- Return type
bool
-
valid_actions
()[source]¶ Get a list of all valid moves for the current state.
- Raises
NotImplementedError – If the client environment does not have access to all of your available moves.
- Returns
moves
- Return type
list[str]
-
wait_for_start
(timeout: Optional[float] = None)[source]¶ Secondary name for to be clearer when starting game.
-
wait_for_turn
(timeout: Optional[float] = None)[source]¶ Block until it is your turn. This is usually only used in the beginning of the game.
- Parameters
timeout (float) – An optional hard timeout on waiting for the game to start.
- Returns
The player’s observation once its turn has arrived.
- Return type
observation
-
property
winners
¶ Get the current list of winners for the game.
- Returns
The list of player numbers of the winners.
- Return type
List[int]
- Raises
ConnectionError – If connect() has not been called yet.
ValueError – If the game is not over yet.
-