Components
The reusable "capability" mixins that navix.entities compose into
concrete entities.
Each Component subclass adds one field (or one abstract property) plus
its semantics: Positionable -> position, Directional ->
direction, Openable -> requires/open, and so on. An entity like
Door is just Positionable + Directional + Openable + HasColour + ....
Every field is a JAX array and the leading axis is the entity-instance
axis, so a whole batch of doors is one Door struct.
DISCARD_PILE_COORDS = jnp.asarray((0, -1), dtype=jnp.int32)
module-attribute
The off-grid (row, col) an entity's position is set to once it has
been picked up / consumed. Column -1 is outside every grid, so such an
entity renders nowhere and matches no real cell.
DISCARD_PILE_IDX = jnp.asarray(-1, dtype=jnp.int32)
module-attribute
The flat patch index that DISCARD_PILE_COORDS maps to; rendering
slices it off (patches[:DISCARD_PILE_IDX]).
EMPTY_POCKET_ID = jnp.asarray(-1, dtype=jnp.int32)
module-attribute
Holder.pocket / Player.pocket value meaning "carrying nothing".
UNSET_CONSUMED = jnp.asarray(-1, dtype=jnp.int32)
module-attribute
Sentinel for a "consumed key" slot that has not been used yet.
UNSET_DIRECTION = jnp.asarray(-1, dtype=jnp.int32)
module-attribute
Directional.direction sentinel for an entity whose facing is
irrelevant (it is never used as a rotation).
Component
Bases: PyTreeNode
Base of every capability mixin. A Component is a frozen
flax.struct pytree; concrete entities inherit from several at once.
Carries no data itself.
check_ndim(batched=False)
Hook for asserting each field has the expected rank (one extra
axis when batched). The base implementation does nothing;
subclasses may override. Not called on the hot path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batched
|
bool
|
whether an extra leading instance axis is expected. |
False
|
Directional
Bases: Component
Entity has a facing direction.
direction = field(shape=())
class-attribute
instance-attribute
i32[] in 0..3: 0 east, 1 south, 2 west, 3 north
(clockwise). Used directly by grid.translate / grid.rotate.
HasColour
Bases: Component
Entity is drawn/encoded in one of the palette colours.
colour = field(shape=())
class-attribute
instance-attribute
i32[] index into navix.rendering.registry.PALETTE (0 red,
1 green, 2 blue, 3 purple, 4 yellow, 5 grey). This is the
colour channel of a symbolic observation and picks the sprite
variant for rgb.
HasSprite
Bases: Component
Entity has an RGB sprite for rgb rendering.
sprite
property
u8[TILE_SIZE, TILE_SIZE, 3] (or with leading instance /
direction axes) - the tile drawn for this entity.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
on the base class. |
HasTag
Bases: Component
Entity has an integer tag identifying its type in observations.
tag
property
i32[] - the value this entity's cells take in a categorical
observation and the first channel of a symbolic one. Constant
per entity type (see entities.EntityIds).
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
on the base class. |
Holder
Bases: Component
Entity can carry one Pickable in a pocket (the Player).
pocket = field(shape=())
class-attribute
instance-attribute
i32[] - the Pickable.id currently carried, or EMPTY_POCKET_ID
(-1) when empty.
Openable
Bases: Component
Entity (a Door) can be opened, possibly after unlocking.
open = field(shape=())
class-attribute
instance-attribute
0 closed, 1 open. navix doors do not re-close, so this only
ever goes 0 -> 1.
requires = field(shape=())
class-attribute
instance-attribute
i32[] - the Pickable.id of the key that unlocks this door, or
-1 if it needs no key. Set to -1 once the door has been
unlocked.
Pickable
Bases: Component
Entity can be picked up into a pocket (Key, Ball, Box).
id = field(shape=())
class-attribute
instance-attribute
i32[] >= 1 - the identity written to player.pocket when this
entity is picked up, and matched against Openable.requires.
Positionable
Bases: Component
Entity has a location on the grid.
position = field(shape=(2,))
class-attribute
instance-attribute
(row, col) as i32[2] (or i32[n_instances, 2] batched).
DISCARD_PILE_COORDS ((0, -1)) once the entity has been picked up
or consumed.
Stochastic
Bases: Component
Entity's reward (e.g. a Goal) is granted only with some
probability when reached.
probability = field(shape=())
class-attribute
instance-attribute
f32[] in [0, 1] - the chance the reward fires on contact.
1.0 for a deterministic goal.
field(shape, **kwargs)
A dataclasses.field that also records the per-instance shape
of the array (excluding the leading instance axis) in its metadata,
so Component.check_ndim can validate batched vs unbatched structs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
the shape of one instance's value -
|
required |
**kwargs
|
forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
|
dataclasses.Field: the field descriptor. |