factoriax.engine.actions#

Lookup tables between an item and the action that addresses it.

The name of a PLACE_, CRAFT_, or DEPOSIT_ action contains the name of the item that the action addresses. An action and an item therefore determine each other. This module holds both directions as jnp gather arrays. The item tuples in factoriax.engine.constants supply the contents.

The two directions answer different questions. *_ACTION_TO_ITEM maps an action offset to the item that the action addresses. execute_action in factoriax.engine.step reads this table once it holds an action, and indexes it with a traced value inside jax.jit. ITEM_TO_*_ACTION maps an item back to an absolute action. The play UI reads this table to turn a click on an item into an action, and indexes it on the host with a Python int.

An import of this module runs _validate(). If two tables disagree, _validate() raises ValueError. The module then fails to import, and the engine cannot dispatch an action to the wrong item.

Module Attributes

NO_ACTION

Backward-table entry for an item with no action in that list.

PLACE_ACTION_TO_ITEM

Item placed by each PLACE_ action, indexed by action - PLACE_BASE.

CRAFT_ACTION_TO_ITEM

Item crafted by each CRAFT_ action, indexed by action - CRAFT_BASE.

DEPOSIT_ACTION_TO_ITEM

Item deposited by each DEPOSIT_ action, indexed by action - DEPOSIT_BASE.

ITEM_TO_PLACE_ACTION

PLACE_ action for each item, indexed by ItemType.

ITEM_TO_CRAFT_ACTION

CRAFT_ action for each item, indexed by ItemType.

ITEM_TO_DEPOSIT_ACTION

DEPOSIT_ action for each item, indexed by ItemType.

factoriax.engine.actions.CRAFT_ACTION_TO_ITEM = Array([ 7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,        24, 25, 26, 27, 28, 29, 30, 31, 32, 33], dtype=int32)#

Item crafted by each CRAFT_ action, indexed by action - CRAFT_BASE.

factoriax.engine.actions.DEPOSIT_ACTION_TO_ITEM = Array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,        18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33],      dtype=int32)#

Item deposited by each DEPOSIT_ action, indexed by action - DEPOSIT_BASE.

factoriax.engine.actions.ITEM_TO_CRAFT_ACTION = Array([-1, -1, -1, -1, -1, -1, -1, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,        37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53],      dtype=int32)#

CRAFT_ action for each item, indexed by ItemType. NO_ACTION for the raw resources, which are mined rather than crafted, and for EMPTY.

factoriax.engine.actions.ITEM_TO_DEPOSIT_ACTION = Array([-1, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,        70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86],      dtype=int32)#

DEPOSIT_ action for each item, indexed by ItemType. NO_ACTION at EMPTY and nowhere else: every real item can be deposited.

factoriax.engine.actions.ITEM_TO_PLACE_ACTION = Array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,        -1, -1, -1, -1, -1, -1, -1, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],      dtype=int32)#

PLACE_ action for each item, indexed by ItemType. NO_ACTION for every item that is not a machine, EMPTY included.

factoriax.engine.actions.NO_ACTION: int = -1#

Backward-table entry for an item with no action in that list. The value is negative because 0 is itself an action (MoveAction.NOOP). A caller must compare against this value, and must not test truthiness.

factoriax.engine.actions.PLACE_ACTION_TO_ITEM = Array([24, 25, 26, 27, 28, 29, 30, 31, 32, 33], dtype=int32)#

Item placed by each PLACE_ action, indexed by action - PLACE_BASE.