TronGridClientEnvironment

class colosseumrl.envs.tron.TronGridClientEnvironment.TronGridClientEnvironment(*args, **kwargs)[source]

Bases: colosseumrl.ClientEnvironment.ClientEnvironment

board(x: int = None, y: int = None)[source]

Helper method to get a location on the board

Parameters
  • x (int) – The x coordinate of the board; or, if y is none, the absolute location

  • y (int) – The y coordinate of the board

Returns

  • If both parameters are None, returns the whole board

  • If x is given and y is not, then it gets an absolute location at the board

  • If both x and y are given, then it gets the location (x, y) on the board

check_connection() → None

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

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]

static direction_to_delta(direction: int) → Tuple[int, int][source]

Convert an integer direction into an x, y delta

Parameters

direction (int) – The base direction provided by the directions dictionary.

Returns

The offset required in the x and y direction.

Return type

Tuple[int, int]

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.

next_location()[source]

Get the location and object in front of your current head

Returns

  • location (int) – Location that you will be in the next move if you move forward

  • object (int) – Object located at that location

property observation

Get the current observation present for this agent.

Returns

The observation dictionary for this environment.

Return type

Dict[str, np.ndarray]

pull_dataframe() → None

Helper function to update all dataframes for this environment.

push_dataframe() → None

Helper function to push all dataframes for this environment.

property server_environment

Get the full server environment object if we have it available.

Returns

Server environment or None is not available.

Return type

BaseEnvironment

step(action: str) → Tuple[Dict[str, numpy.ndarray], float, bool, Optional[List[int]]]

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

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()

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)

Secondary name for to be clearer when starting game.

wait_for_turn(timeout: Optional[float] = None)

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.