Entities
The concrete things that live on a grid: Player, Goal, Wall,
Key, Door, Lava, Ball, Box.
Each is a frozen flax.struct pytree built by composing the mixins in
navix.components (Positionable, Directional, Openable, ...). All
fields are batched: state.entities["key"] is a single Key struct
holding every key in the environment, with the instance count as the
leading axis (key.position is i32[n_keys, 2]). Index into a batch
with entity[i].
Entities also expose derived, per-instance properties the engine reads:
walkable, transparent, tag, sprite, symbolic_state.
Ball
Bases: Entity, Pickable, HasColour, Stochastic
A blocking obstacle that is also pickable. Not walkable,
transparent. Colliding with the player fires a (BALL, HIT) event
(terminations.on_ball_hit).
Under the default transitions.stochastic_transition, every ball
moves one random step each timestep (transitions.update_balls), so
it acts as a wandering hazard. An environment that wants a static
ball - a pickup target or decoy - must use
transitions_fn=transitions.deterministic_transition instead (as
GoToObject / Fetch / PutNear / BlockedUnlockPickup do).
id (from Pickable) is the pickup identity, matched against
player.pocket; probability (from Stochastic) is unused by
Ball.
create(position, colour, probability, id)
classmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Array
|
|
required |
colour
|
Array
|
palette index (see |
required |
probability
|
Array
|
unused by |
required |
id
|
Array
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Ball |
Ball
|
the entity. |
Box
Bases: Entity, Pickable, HasColour, Holder
A pickable container. Not walkable, transparent. open (the
toggle action) while facing it removes the box and, if its pocket
holds a Key's id, reveals that key at the box's former cell
(matching MiniGrid's Box.toggle). Used by ObstructedMaze to hide
keys.
Two separate id fields: id (from Pickable) is the box's own
pickup identity, matched against player.pocket; pocket (from
Holder) is the id of the item hidden inside.
create(position, colour, id, pocket)
classmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Array
|
|
required |
colour
|
Array
|
palette index (see |
required |
id
|
Array
|
|
required |
pocket
|
Array
|
id of the contained item, or
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Box |
Box
|
the entity. |
Directions
Named values for Directional.direction: EAST=0, SOUTH=1,
WEST=2, NORTH=3 (clockwise). rotate_cw adds 1 (mod 4).
Door
Bases: Entity, Openable, HasColour
A door in a wall. While closed it is not walkable and not
transparent; once open it is both. Opening needs the open action
while facing it and, if requires != -1, the matching Key in the
pocket (which is then consumed and requires set to -1). navix
doors do not re-close.
locked
property
bool[*shape] - True while the door still needs a key
(requires != -1). Becomes False once unlocked.
symbolic_state
property
Returns an integer array encoding the symbolic state of the door:
- 0: Door is open
- 1: Door is closed but not locked
- 2: Door is closed and locked (requires a key or tool)
Examples:
- If open = 1 and locked = 0: symbolic_state = 0 (open)
- If open = 0 and locked = 0: symbolic_state = 1 (closed, not locked)
- If open = 0 and locked = 1: symbolic_state = 2 (closed and locked)
create(position, requires, colour, open)
classmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Array
|
|
required |
requires
|
Array
|
|
required |
colour
|
Array
|
palette index (see |
required |
open
|
Array
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Door |
Door
|
the entity. |
Entities
Bases: PyTreeNode
The string keys used in state.entities (a dict[str, Entity]).
Use Entities.KEY etc. rather than the bare literal "key" so a
rename is caught statically.
Entity
Bases: Positionable, HasTag, HasSprite
Base of every concrete entity: has a position, a tag and a
sprite. Subclasses add more mixins and fill in the derived
properties below. Build one with the subclass's create.
name
property
The class name ("Key", "Door", ...).
ndim
property
Number of batch dimensions (len(self.shape)) - 0 for a
single instance, 1 for a flat batch.
shape
property
The batch shape - the entity's axes excluding each field's
own trailing axes. () for a single instance, (n,) for a batch
of n (position is then (n, 2)).
symbolic_state
property
i32[*shape] - the third channel of a symbolic observation
for this entity (e.g. a door's open/closed/locked; 0 for
entities with no internal state).
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
on the base class. |
transparent
property
bool[*shape] - does line of sight pass through this cell?
Feeds the first-person view cone (False blocks vision).
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
on the base class. |
walkable
property
bool[*shape] - can the player step onto this entity's cell?
(False for walls and closed doors, True for goal/lava/floor.)
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
on the base class. |
__getitem__(idx)
Selects instance(s) from the batch - key[0] is the first key,
key[mask] the masked subset - by indexing every field's leading
axis.
EntityIds
The integer tag each entity type takes in a categorical
observation and in the first channel of a symbolic one. uint8
scalars. The values are not contiguous (there is no 3) - treat them
as opaque ids, and MAX_CATEGORICAL_VALUE (in
environments.environment) as the count the observation Space uses.
UNKNOWN (0) is also the value of a cell that has not been seen in
a first-person observation.
Goal
Bases: Entity, HasColour, Stochastic
The target cell. Walkable and transparent. Reaching it fires a
(GOAL, REACH) event with probability probability (1.0 in the
standard tasks) - rewards.on_goal_reached /
terminations.on_goal_reached react to it.
create(position, probability)
classmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Array
|
|
required |
probability
|
Array
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Goal |
Goal
|
the entity. |
Key
Bases: Entity, Pickable, HasColour
A pickable key. Not walkable, transparent. pickup puts its id
in the player's pocket; a Door whose requires equals that id
can then be opened, consuming the key. Its colour matches the door
it opens.
create(position, colour, id)
classmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Array
|
|
required |
colour
|
Array
|
palette index (see |
required |
id
|
Array
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Key |
Key
|
the entity. |
Lava
Bases: Entity
A hazard cell. Walkable and transparent (the player can step
onto it), but doing so fires a (LAVA, FALL) event that
terminations.on_lava_fall turns into a TERMINATION - stepping in
ends the episode with no reward.
create(position)
classmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Array
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Lava |
Lava
|
the entity. |
Player
Bases: Entity, Directional, Holder
The agent. Has a direction it faces and a pocket holding at
most one Pickable. navix is single-agent, so state.entities["player"]
is a batch of one.
create(position, direction, pocket)
classmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Array
|
|
required |
direction
|
Array
|
facing, |
required |
pocket
|
Array
|
carried item id, or |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Player |
Player
|
the entity. |
Wall
An impassable, opaque cell. Not walkable, not transparent. The grid border is walls; interior walls form rooms and corridors.
create(position)
classmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Array
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Wall |
Wall
|
the batch of walls. |