EnvObject(location, name, class_callable, is_traversable=None, is_movable=None, visualize_size=None, visualize_shape=None, visualize_colour=None, visualize_depth=None, visualize_opacity=None, visualize_from_center=None, **custom_properties)¶
The basic class for all objects in the world. This includes the AgentAvatar. All objects that are added to the GridWorld should inherit this class.
An EnvObject always needs a location and a name. Since we have no idea where you want to put the object or how you want to call it.
In addition agents may alter properties of objects.
A few properties are mandatory for the GridWorld, some Actions and the Visualizer to function. These are keyword arguments (e.g. is_traversable). If these are not set, they are obtained from the defaults.py file.
This class specific allows you to create any object you desire that only differs in the properties it holds. For example both a simple block or complex object such as a ‘fire’ can be modeled with this class. They only differ in their mandatory and custom properties (a block is simply a colored square, whereas a ‘fire’ has potentially many more properties). In such a case you simply provide more keyword arguments to the constructor, these are automatically added to the self.custom_attributes dictionary. Allowing you to intuitively extend the properties of any EnvObject.
If you want an object that can be altered by an action in a specific way, you can create it as long as it inherits from this class. For example the Door object is such an example which has a unique method that ‘opens’ or ‘closes’ the door. Which is called by the OpenDoor and CloseDoor actions.
If you want an object that needs to update some of its own properties during the simulation, you can again create your own object as long as it inherits from this class. Then you can implement the update_properties method. The Battery object is such an example, which simply decreases its energy level property each time step.
If you have a specific object you need to create a lot and you do not want to keep on setting every property every time for the custom_properties, you can make your own class again which must inherit from this class and only implement its constructor where these custom properties are set with your default value of choosing.
The name of object, does not need to be unique.
- locationList or tuple of length two
The location of the object in the grid world.
- 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.
- class_callableCallable class. Optional, defaults to EnvObject
This is required to make a distinction between what kind of object is actually seen or visualized. The last element is always the lowest level class, whereas the first element is always EnvObject and everything in between are potential other classes in the inheritance chain.
- 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. 0=Rectangle, 1=Triangle, 2=Circle
- visualize_colourHexcode string. Optional, default obtained from defaults.py
A visualization property used by the Visualizer. Denotes the colour of the object in visualization.
- visualize_depthInteger. Optional, default obtained from defaults.py
A visualization property that is used by the Visualizer to draw objects in layers.
- visualize_opacityInteger. Optional, default obtained from defaults.py
Opacity of the object. From 0.0 to 1.0.
- visualize_from_center: Boolean. Optional, by default True.
Whether an object should be visualized and scaled from its center point, or top left point.
- **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.
update(self, grid_world, state)¶
Used to update some properties of this object if needed. For example a ‘status’ property that changes over time. It can also be used to update something in the GridWorld. For example a Fire object that damages other objects in its location.
If you want this functionality, you should create a new object that inherits from this class EnvObject.
This method is called automatically in the game-loop inside a running GridWorld instance.
The GridWorld instance representing the entire grid world. Can be used to alter itself or others in the world in some way.
change_property(self, property_name, property_value)¶
Changes the value of an existing (!) property.
The name of the property.
The value of the property.
- The new properties.
add_property(self, property_name, property_value)¶
Adds a new(!) property with its value to the object.
The name of the property.
The value of the property.
The location of any object is a pythonic property, this allows us to do various checks on it. One of them is the setter that is overridden in AgentAvatar to also transfer all carried objects with it.
- Current Locationtuple
The current location as a tuple; (x, y)
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’).
In the case we return the properties of a class that inherits from EnvObject, we check if that class has
- All mandatory and custom properties in a dictionary.