multigrid.core.world_object module#

class multigrid.core.world_object.WorldObj[source]#

Bases: ndarray

Base class for grid world objects.

Attributes:
typeType

The object type

colorColor

Return the object color.

stateState

Return the name of the object state.

containsWorldObj or None

The object contained by this object, if any

init_postuple[int, int] or None

The initial position of the object

cur_postuple[int, int] or None

The current position of the object

TYPE = 0#
COLOR = 1#
STATE = 2#
dim = 3#
static __new__(cls, type: str | None = None, color: str = Color.red)[source]#
Parameters:
typestr or None

Object type

colorstr

Object color

static empty() WorldObj[source]#

Return an empty WorldObj instance.

static from_array(arr: ArrayLike[int]) 'WorldObj' | None[source]#

Convert an array to a WorldObj instance.

Parameters:
arrArrayLike[int]

Array encoding the object type, color, and state

property type: Type#

Return the object type.

property color: Color#

Return the object color.

property state: str#

Return the name of the object state.

can_overlap() bool[source]#

Can an agent overlap with this?

can_pickup() bool[source]#

Can an agent pick this up?

can_contain() bool[source]#

Can this contain another object?

toggle(env: MultiGridEnv, agent: Agent, pos: tuple[int, int]) bool[source]#

Toggle the state of this object or trigger an action this object performs.

Parameters:
envMultiGridEnv

The environment this object is contained in

agentAgent

The agent performing the toggle action

postuple[int, int]

The (x, y) position of this object in the environment grid

Returns:
successbool

Whether the toggle action was successful

encode() tuple[int, int, int][source]#

Encode a 3-tuple description of this object.

Returns:
type_idxint

The index of the object type

color_idxint

The index of the object color

state_idxint

The index of the object state

static decode(type_idx: int, color_idx: int, state_idx: int) 'WorldObj' | None[source]#

Create an object from a 3-tuple description.

Parameters:
type_idxint

The index of the object type

color_idxint

The index of the object color

state_idxint

The index of the object state

render(img: ndarray[Any, dtype[uint8]])[source]#

Draw the world object.

Parameters:
imgndarray[int] of shape (width, height, 3)

RGB image array to render object on

class multigrid.core.world_object.Goal[source]#

Bases: WorldObj

Goal object an agent may be searching for.

static __new__(cls, color: str = Color.green)[source]#
Parameters:
typestr or None

Object type

colorstr

Object color

class multigrid.core.world_object.Floor[source]#

Bases: WorldObj

Colored floor tile an agent can walk over.

static __new__(cls, color: str = Color.blue)[source]#
Parameters:
colorstr

Object color

class multigrid.core.world_object.Lava[source]#

Bases: WorldObj

Lava object an agent can fall onto.

static __new__(cls)[source]#
class multigrid.core.world_object.Wall[source]#

Bases: WorldObj

Wall object that agents cannot move through.

__new__(color: str = Color.grey)[source]#
Parameters:
colorstr

Object color

class multigrid.core.world_object.Door[source]#

Bases: WorldObj

Door object that may be opened or closed. Locked doors require a key to open.

Attributes:
is_open: bool

Whether the door is open

is_locked: bool

Whether the door is locked

static __new__(cls, color: str = Color.blue, is_open: bool = False, is_locked: bool = False)[source]#
Parameters:
colorstr

Object color

is_openbool

Whether the door is open

is_lockedbool

Whether the door is locked

property is_open: bool#

Whether the door is open.

property is_locked: bool#

Whether the door is locked.

class multigrid.core.world_object.Key[source]#

Bases: WorldObj

Key object that can be picked up and used to unlock doors.

static __new__(cls, color: str = Color.blue)[source]#
Parameters:
colorstr

Object color

class multigrid.core.world_object.Ball[source]#

Bases: WorldObj

Ball object that can be picked up by agents.

static __new__(cls, color: str = Color.blue)[source]#
Parameters:
colorstr

Object color

class multigrid.core.world_object.Box[source]#

Bases: WorldObj

Box object that may contain other objects.

static __new__(cls, color: str = Color.yellow, contains: WorldObj | None = None)[source]#
Parameters:
colorstr

Object color

containsWorldObj or None

Object contents