matrx.objects.agent_body.AgentBody

class AgentBody(location, possible_actions, sense_capability, class_callable, callback_agent_get_action, callback_agent_set_action_result, callback_agent_observe, callback_agent_get_messages, callback_agent_set_messages, callback_agent_initialize, callback_agent_log, callback_create_context_menu_for_other, callback_create_context_menu_for_self, visualize_size, visualize_shape, visualize_colour, visualize_depth, visualize_opacity, visualize_when_busy, is_traversable, team, name, is_movable, is_human_agent, customizable_properties, **custom_properties)

This class is a representation of an agent’s body in the GridWorld.

It is used as a measure to keep the AgentBrain code and Environment code separate. This AgentBody is used by the environment to update the GUI, perform actions, and update properties. It is kept in sync with the Agent’s brain every iteration.

It inherits from EnvObject which allows you set any custom properties you want. In addition it also has all the mandatory properties of an EnvObject plus a few extra. Which is the team name the agent is part of (if any) and what the Agent’s body is carrying.

In addition the Agent’s body keeps a set of callbacks to methods inside the Agent. This forms the connection between the GridWorld (that calls them) and the Agent (that defined them).

Parameters
locationList or tuple of length two.

The location of the Agent’s body in the grid world.

possible_actionslist

The list of Action class names this agent may be able to perform. This allows you to create agents that can only perform a couple of the available actions.

sense_capabilityThe SenseCapability object.
class_callableAgent class

The Agent class; in other words, the class of the agent’s brain. This is stored here so that the Visualizer (which visualizes an agent based on this Agent’s body object) and agents knows what kind of agent it is. Allows you to visualize certain agent types in a certain way.

callback_agent_get_actionfunction

The callback function as defined by the Agent instance of which this is an Agent’s body of. It is called each tick by the GridWorld. As such the GridWorld determines when the Agent can perform an action by calling this function which is stored in the Agent’s Agent’s body.

callback_agent_set_action_resultfunction

Same as the callback_get_action but is used by GridWorld to set the ActionResult object in the Agent after performing the action. This allows the Agent to know how its planned action went.

callback_agent_observefunction

Similar to callback_agent_get_action, is used by GridWorld to obtain the processed state dictionary of the Agent. As the GridWorld does not know exactly what the Agent is allowed to see or not, the ‘observe’ preprocesses the given state further. But to accurately visualize what the agent sees we have to obtain that pre-processed state, which is done through this callback.

callback_agent_initializefunction

Call the initialize function in an Agent’s Brain. Is done at the initialize of a GridWorld.

callback_agent_get_messagesfunction

A callback function that allows the GridWorld to obtain the agent’s messages that need to be send to different agents.

callback_agent_set_messagesfunction

A callback function that allows the GridWorld to set any message send by some agent to a list of received messages in an agent.

callback_create_context_menu_for_otherfunction

A callback function that allows the gridworld or API to call the subsequent agent function that generates the menu options of an agent for a context menu opened by a user not controlling that specific agent.

callback_create_context_menu_for_selffunction

A callback function that allows the gridworld or API to call the subsequent agent function that generates the menu options for a context menu opened by the user controlling the current human agent. If this is not a human agent, it is set to None.

namestring. Optional, default=”Agent”

Defaults to “Agent”. The name of the agent, does not need to be unique.

is_human_agentBoolean. Optional, default=False.

Boolean to signal that the agent represented by this Agent’s body is a human controlled agent.

customizable_propertiesList. Optional, default=obtained from defaults.py.

The list of attribute names that can be customized by other objects (including Agent’s body and as an extension any Agent).

is_traversableBoolean. Optional, default obtained from defaults.py.

Signals whether other objects can be placed on top of this object.

carried_byList. Optional, default obtained from defaults.py.

A list of who is carrying this object.

teamstring. Optional, default is ID of agent

The team name the agent is part of. Defaults to the team name similar to the Agent’s body unique ID, as such denoting that by default each Agent’s body belongs to its own team and as an extension so does its “brain” the Agent.

visualize_sizeFloat. Optional, default obtained from defaults.py.

A visualization property used by the Visualizer. Denotes the size of the object, its unit is a single grid square in the visualization (e.g. a value of 0.5 is half of a square, object is in the center, a value of 2 is twice the square’s size centered on its location.)

visualize_shapeInt. Optional, default obtained from defaults.py.

A visualization property used by the Visualizer. Denotes the shape of the object in the visualization.

visualize_colourHexcode string. Optional, default obtained from defaults.py.

A visualization property used by the Visualizer. Denotes the

visualize_depthInteger. Optional, default obtained from defaults.py.

A visualization property that s used by the Visualizer to draw objects in layers.

visualize_opacityInteger.

Opacity of object. Between 0.0 and 1.0.

visualize_when_busyBoolean.

Whether to show a loading icon when the agent is busy (performing an action).

**custom_propertiesdict, optional

Any other keyword arguments. All these are treated as custom attributes. For example the property ‘heat’=2.4 of an EnvObject representing a fire.

Attributes
current_action
current_action_args
current_action_duration_in_ticks
current_action_tick_started
is_blocked
location

We override the location.

properties

Returns the custom properties of this object, but also any mandatory properties such as location, name, is_traversable and all visualization properties (those are in their own dictionary under ‘visualization’).

Methods

add_property(self, property_name, property_value)

Adds a new(!) property with its value to the object.

change_property(self, property_name, …)

Changes the value of an existing (!) property.

update(self, grid_world)

Used to update some properties of this object if needed.

__init__(self, location, possible_actions, sense_capability, class_callable, callback_agent_get_action, callback_agent_set_action_result, callback_agent_observe, callback_agent_get_messages, callback_agent_set_messages, callback_agent_initialize, callback_agent_log, callback_create_context_menu_for_other, callback_create_context_menu_for_self, visualize_size, visualize_shape, visualize_colour, visualize_depth, visualize_opacity, visualize_when_busy, is_traversable, team, name, is_movable, is_human_agent, customizable_properties, **custom_properties)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, location, possible_actions, …)

Initialize self.

add_property(self, property_name, property_value)

Adds a new(!) property with its value to the object.

change_property(self, property_name, …)

Changes the value of an existing (!) property.

update(self, grid_world)

Used to update some properties of this object if needed.

Attributes

current_action

current_action_args

current_action_duration_in_ticks

current_action_tick_started

is_blocked

location

We override the location.

properties

Returns the custom properties of this object, but also any mandatory properties such as location, name, is_traversable and all visualization properties (those are in their own dictionary under ‘visualization’).