Skip to content

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 along player.direction (0 east, 1 south, 2 west, 3 north).
  • 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 State of the same structure, so the set can go through jax.lax.switch.

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.

The action_set an Environment uses unless overridden - MINIGRID_ACTION_SET.

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

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 position updated (or not, if

State

blocked).

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

state, unchanged.

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 player.pocket cleared.

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 position updated (or not, if

State

blocked).

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 position updated (or not, if

State

blocked).

Does nothing - the world is returned unchanged. Present so an action set can include an explicit "wait".

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
State State

state, unchanged.

Opens whatever openable thing is directly in front of the player:

  • a Box -> removed, and its contents (a Key) revealed at that cell (see open_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.

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.

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

id in player.pocket.

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 position updated (or not, if

State

blocked).

Turns the player 90 degrees counter-clockwise (direction -> direction - 1 mod 4). Position is unchanged.

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
State State

the state with the player's direction updated.

Turns the player 90 degrees clockwise (direction -> direction + 1 mod 4). Position is unchanged.

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
State State

the state with the player's direction updated.

MiniGrid's toggle action. An alias for open: in navix a door, once opened, stays open (there is no close), so "toggle" and "open" are the same operation.

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
State State

see open.