Actions
The action primitives an integer action indexes into.
Each function here is a pure State -> State transformation of the
world. An Environment holds an ordered action_set (a tuple of these),
and transitions_fn applies action_set[a] for an integer action a;
the environment's action_space is Discrete(len(action_set)). So the
meaning of action 2 depends on which set the environment uses - see
MINIGRID_ACTION_SET (the default) and COMPLETE_ACTION_SET.
Conventions shared by all of them:
- "the player" is
state.get_player(idx=0)(navix is single-agent for now); "in front" is the cell one step alongplayer.direction(0east,1south,2west,3north). - Movement that would enter a wall or a non-walkable entity is a no-op: the player stays put (and a wall/entity-hit event is recorded).
- Every action is total - it always returns a
Stateof the same structure, so the set can go throughjax.lax.switch.
COMPLETE_ACTION_SET = (noop, rotate_cw, rotate_ccw, forward, right, backward, left, pickup, open, done)
module-attribute
Every action navix defines, in index order:
0 noop, 1 rotate_cw, 2 rotate_ccw, 3 forward, 4 right,
5 backward, 6 left, 7 pickup, 8 open, 9 done. Wider than
MiniGrid's set (adds strafing and noop); use it for environments that
need lateral movement.
DEFAULT_ACTION_SET = MINIGRID_ACTION_SET
module-attribute
The action_set an Environment uses unless overridden -
MINIGRID_ACTION_SET.
MINIGRID_ACTION_SET = (rotate_ccw, rotate_cw, forward, pickup, drop, toggle, done)
module-attribute
MiniGrid's seven actions, in the same index order MiniGrid uses:
0 rotate_ccw (MiniGrid "left"), 1 rotate_cw ("right"), 2 forward,
3 pickup, 4 drop, 5 toggle, 6 done. See
https://github.com/Farama-Foundation/Minigrid/blob/master/minigrid/core/actions.py
backward(state)
Steps the player one cell backwards (opposite to where it faces)
without turning. Blocked-move rules as for forward. Not in the
MiniGrid action set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
the current state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
the state with the player's |
State
|
blocked). |
done(state)
The agent's "I'm finished" signal. Returns the state unchanged - it
does not end the episode by itself. Only environments whose
termination_fn inspects for it (e.g. GoToObject, via
events.on_target_done) react to it; under the default termination
it is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
the current state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
|
drop(state)
Places the item currently in player.pocket on the cell in front
of the player and empties the pocket. No-op if the pocket is empty or
the cell in front is not walkable (occupied or a wall).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
the current state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
the state with the pocketed item back on the grid in front |
State
|
of the player and |
forward(state)
Moves the player one cell in the direction it faces. No-op if that
cell is a wall or a non-walkable entity (a hit event is recorded);
direction never changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
the current state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
the state with the player's |
State
|
blocked). |
left(state)
Strafes the player one cell to its left (90 degrees
counter-clockwise of where it faces) without turning. Blocked-move
rules as for forward. Not in the MiniGrid action set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
the current state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
the state with the player's |
State
|
blocked). |
noop(state)
open(state)
Opens whatever openable thing is directly in front of the player:
- a
Box-> removed, and its contents (aKey) revealed at that cell (seeopen_box); - a
Door-> opened iff it is closed and either unlocked (requires == -1) or the player is carrying the required key (player.pocket == door.requires), in which case that key is consumed from the pocket. Opening records a door-opening event.
A Door that is already open, and any other cell, are left
untouched. toggle is an alias for this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
the current state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
the state with the door/box in front opened if the |
State
|
conditions held. |
open_box(state, position_in_front)
Opens the Box in front of the player, if any (verified against
MiniGrid's actual Box.toggle: env.grid.set(pos, self.contains)
- the box is removed and, if it held something, that object takes
its place at the same position). Currently only Key boxes are
supported (Box.pocket stores the id of a Key instance, the same
way player.pocket does) - ObstructedMaze's only real user of
this, keys hidden inside boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
The current state. |
required |
position_in_front
|
Array
|
The position directly in front of the player. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
The new state, with any opened box removed and its |
State
|
contents (if any) revealed at its former position. |
pickup(state)
Picks up the pickable entity (Key, Box, or Ball) directly in
front of the player: the entity is moved off the grid and its id is
written to player.pocket, overwriting whatever was there. No-op if
the cell in front holds nothing pickable. Records a pickup event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
the current state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
the state with the item removed from the grid and its |
State
|
|
right(state)
Strafes the player one cell to its right (90 degrees clockwise of
where it faces) without turning. Blocked-move rules as for
forward. Not in the MiniGrid action set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
the current state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
the state with the player's |
State
|
blocked). |