matrx.grid_world.GridWorld

class GridWorld(shape, tick_duration, simulation_goal, rnd_seed=1, visualization_bg_clr='#C2C2C2', visualization_bg_img=None, verbose=False, world_id=0)

The Gridworld is the representation of the world and the core of MATRX

Attributes
current_nr_ticks

Int: Current tick at which the gridworld is.

environment_objects

Dict: Dictionary of all non-agent environment objects, keys are the IDs, values are the registered objects.

grid

Numpy 2D array: Numpy array of shape x by y.

is_done

Bool: Boolean that indicates whether the GridWorld is done: either stopped by the user or due to the goal having been achieved.

registered_agents

Dict: Dictionary of all registered agents, keys are the IDs, values are the registered objects.

shape

list: [x,y] shape of the grid

simulation_goal

WorldGoal: The world goal of type WorldGoal, or a class that extends WorldGoal

tick_duration

float: the desired duration of one tick. The real tick_duration might be longer due to a large amount of

Methods

get_env_object(self, requested_id[, obj_type])

Fetch an object or agent from the GridWorld using its ID, optionally checking for its object type.

get_objects_in_range(self, agent_loc, …)

Get all objects of a specific obj type (normal objects or agent) within a certain range around an agent’s location.

initialize(self, api_info)

Initializes the gridworld instance and any connected visualizations via the API, then pauses the GridWorld.

remove_from_grid(self, object_id[, …])

Remove an object from the grid.

run(self, api_info)

Runs the gridworld instance until stopped via the visualization or the goal has been achieved.

Create a GridWorld instance.

With the constructor you can set a number of general properties and from the resulting instance you can call numerous methods to add new objects and/or agents.

Parameters
shapetuple or list

Denotes the width and height of the world you create.

tick_durationfloat

The duration of a single ‘tick’ or loop in the game-loop of the world you create.

simulation_goalWorldGoal, int, list or tuple

The goal or goals of the world, either a single WorldGoal, a list of such or a positive non-zero integer to denote the maximum number of ‘ticks’ the world(s) has to run.

rnd_seedbool (optional, default, 1)

The master random seed set by the WorldBuilder on which all objects, agents and worlds are seeded. Should be a positive non-zero integer.

visualization_bg_clrstring (optional, “C2C2C2”)

The color of the world when visualized using MATRX’ own visualisation server. A string representation of hexadecimal color.

visualization_bg_imgstring (optional, None)

An optional background image of the world when visualized using MATRX’ own visualisation server. A string of the path to the image file. When None, no background image is used.

verbosebool (optional, False)

Whether the GridWorld should be verbose and print development logs to the console.

world_idint (optional, 0)

The ID of this world. Every new GridWorld instance should have a unique ID, such that the frontend knows when it has to reinitialize the visualization.

Examples

Create a world builder and generate 10 worlds and run them: >>> from matrx.world_builder import WorldBuilder >>> builder = WorldBuilder(shape=(10, 10)) >>> for gridworld in builder.worlds(): >>> gridworld.run()

Every gridworld received from builder.worlds() is a GridWorld instance.

Attributes
current_nr_ticks

Int: Current tick at which the gridworld is.

environment_objects

Dict: Dictionary of all non-agent environment objects, keys are the IDs, values are the registered objects.

grid

Numpy 2D array: Numpy array of shape x by y.

is_done

Bool: Boolean that indicates whether the GridWorld is done: either stopped by the user or due to the goal having been achieved.

registered_agents

Dict: Dictionary of all registered agents, keys are the IDs, values are the registered objects.

shape

list: [x,y] shape of the grid

simulation_goal

WorldGoal: The world goal of type WorldGoal, or a class that extends WorldGoal

tick_duration

float: the desired duration of one tick. The real tick_duration might be longer due to a large amount of

Methods

get_env_object(self, requested_id[, obj_type])

Fetch an object or agent from the GridWorld using its ID, optionally checking for its object type.

get_objects_in_range(self, agent_loc, …)

Get all objects of a specific obj type (normal objects or agent) within a certain range around an agent’s location.

initialize(self, api_info)

Initializes the gridworld instance and any connected visualizations via the API, then pauses the GridWorld.

remove_from_grid(self, object_id[, …])

Remove an object from the grid.

run(self, api_info)

Runs the gridworld instance until stopped via the visualization or the goal has been achieved.

__init__(self, shape, tick_duration, simulation_goal, rnd_seed=1, visualization_bg_clr='#C2C2C2', visualization_bg_img=None, verbose=False, world_id=0)

Create a GridWorld instance.

With the constructor you can set a number of general properties and from the resulting instance you can call numerous methods to add new objects and/or agents.

Parameters
shapetuple or list

Denotes the width and height of the world you create.

tick_durationfloat

The duration of a single ‘tick’ or loop in the game-loop of the world you create.

simulation_goalWorldGoal, int, list or tuple

The goal or goals of the world, either a single WorldGoal, a list of such or a positive non-zero integer to denote the maximum number of ‘ticks’ the world(s) has to run.

rnd_seedbool (optional, default, 1)

The master random seed set by the WorldBuilder on which all objects, agents and worlds are seeded. Should be a positive non-zero integer.

visualization_bg_clrstring (optional, “C2C2C2”)

The color of the world when visualized using MATRX’ own visualisation server. A string representation of hexadecimal color.

visualization_bg_imgstring (optional, None)

An optional background image of the world when visualized using MATRX’ own visualisation server. A string of the path to the image file. When None, no background image is used.

verbosebool (optional, False)

Whether the GridWorld should be verbose and print development logs to the console.

world_idint (optional, 0)

The ID of this world. Every new GridWorld instance should have a unique ID, such that the frontend knows when it has to reinitialize the visualization.

Examples

Create a world builder and generate 10 worlds and run them: >>> from matrx.world_builder import WorldBuilder >>> builder = WorldBuilder(shape=(10, 10)) >>> for gridworld in builder.worlds(): >>> gridworld.run()

Every gridworld received from builder.worlds() is a GridWorld instance.

Methods

__init__(self, shape, tick_duration, …[, …])

Create a GridWorld instance.

get_env_object(self, requested_id[, obj_type])

Fetch an object or agent from the GridWorld using its ID, optionally checking for its object type.

get_objects_in_range(self, agent_loc, …)

Get all objects of a specific obj type (normal objects or agent) within a certain range around an agent’s location.

initialize(self, api_info)

Initializes the gridworld instance and any connected visualizations via the API, then pauses the GridWorld.

remove_from_grid(self, object_id[, …])

Remove an object from the grid.

run(self, api_info)

Runs the gridworld instance until stopped via the visualization or the goal has been achieved.

Attributes

current_nr_ticks

Int: Current tick at which the gridworld is.

environment_objects

Dict: Dictionary of all non-agent environment objects, keys are the IDs, values are the registered objects.

grid

Numpy 2D array: Numpy array of shape x by y.

is_done

Bool: Boolean that indicates whether the GridWorld is done: either stopped by the user or due to the goal having been achieved.

registered_agents

Dict: Dictionary of all registered agents, keys are the IDs, values are the registered objects.

shape

list: [x,y] shape of the grid

simulation_goal

WorldGoal: The world goal of type WorldGoal, or a class that extends WorldGoal

tick_duration

float: the desired duration of one tick.