factoriax.engine.envs.rocket#
The Rocket scenario: an achievement reward with the rocket as the last step.
The scenario defines 38 achievements in tiers, in the Craftax style, worth 1, 3, 5, and 8 points. The highest score is 140. The order teaches the natural path of the game: gather raw ore, refine half-fabricates in a furnace and an assembler, build and place the rest of the factory, assemble the three rocket parts (the hull, the engine, and the avionics), then launch the rocket.
The setup:
A furnace and an assembler stand next to the spawn tile of the player. The agent therefore does not craft the first machines by hand, and every craft goes through those two machines. The
craft_furnaceandcraft_assemblerachievements unlock when the main assembler produces a second furnace or assembler.The environment masks every direct player-craft action, from
CRAFT_IRON_PLATEtoCRAFT_ROCKET, and replaces each one withNOOP. It reports nothing. Production must flow through the furnace and the assembler.factoriax.make("Rocket-v1"), which calls therocket()factory, builds the environment with the achievement conditions as a step hook and the hand-craft maskROCKET_BLOCKED_ACTIONSalready applied.
Module Attributes
10 Basic bits worth 1 point, 11 Intermediate bits worth 3 points, 13 Advanced bits worth 5 points, and 4 Very Advanced bits worth 8 points. |
|
The |
|
The |
- factoriax.engine.envs.rocket.ROCKET_ACHIEVEMENTS: tuple[Achievement, ...] = (Achievement(id='collect_iron', condition=functools.partial(<function holds_item>, item=2), name='Collect Iron', hint='Mine iron ore.', weight=1.0), Achievement(id='collect_copper', condition=functools.partial(<function holds_item>, item=3), name='Collect Copper', hint='Mine copper ore.', weight=1.0), Achievement(id='collect_tin', condition=functools.partial(<function holds_item>, item=4), name='Collect Tin', hint='Mine tin ore.', weight=1.0), Achievement(id='collect_coal', condition=functools.partial(<function holds_item>, item=1), name='Collect Coal', hint='Mine coal. Every smelt needs it.', weight=1.0), Achievement(id='collect_silicon', condition=functools.partial(<function holds_item>, item=5), name='Collect Silicon', hint='Mine silicon.', weight=1.0), Achievement(id='smelt_iron', condition=functools.partial(<function holds_item>, item=7), name='Smelt Iron', hint='Hold an iron plate.', weight=1.0), Achievement(id='smelt_copper', condition=functools.partial(<function holds_item>, item=8), name='Smelt Copper', hint='Hold a copper plate.', weight=1.0), Achievement(id='smelt_tin', condition=functools.partial(<function holds_item>, item=9), name='Smelt Tin', hint='Hold a tin plate.', weight=1.0), Achievement(id='smelt_wafer', condition=functools.partial(<function holds_item>, item=10), name='Smelt Wafer', hint='Hold a wafer.', weight=1.0), Achievement(id='craft_wire', condition=functools.partial(<function holds_item>, item=13), name='Craft Wire', hint='Combine iron and copper into wire.', weight=1.0), Achievement(id='craft_circuit', condition=functools.partial(<function holds_item>, item=12), name='Craft Circuit', hint='Combine copper and wafer.', weight=3.0), Achievement(id='craft_frame', condition=functools.partial(<function holds_item>, item=11), name='Craft Frame', hint='Combine iron and tin plates.', weight=3.0), Achievement(id='craft_motor', condition=functools.partial(<function holds_item>, item=14), name='Craft Motor', hint='Combine frame and wire.', weight=3.0), Achievement(id='craft_sensor', condition=functools.partial(<function holds_item>, item=15), name='Craft Sensor', hint='Combine circuit and wire.', weight=3.0), Achievement(id='craft_miner', condition=functools.partial(<function holds_item>, item=24), name='Craft Miner', hint='Hold a miner in inventory.', weight=3.0), Achievement(id='place_miner', condition=functools.partial(<function has_machines>, machine=1), name='Place Miner', hint='Place a miner on the map.', weight=3.0), Achievement(id='craft_furnace', condition=functools.partial(<function holds_item>, item=30), name='Craft Furnace', hint='Hold a furnace in inventory.', weight=3.0), Achievement(id='place_furnace', condition=functools.partial(<function has_machines>, machine=7), name='Place Furnace', hint='Place a furnace on the map.', weight=3.0), Achievement(id='automated_mining', condition=functools.partial(<function any_buffer_nonempty>, machine=1), name='Automated Mining', hint='Have a placed miner produce ore.', weight=3.0), Achievement(id='craft_belt', condition=functools.partial(<function holds_item>, item=26), name='Craft Belt', hint='Hold a conveyor belt in inventory.', weight=3.0), Achievement(id='place_belt', condition=functools.partial(<function has_machines>, machine=3), name='Place Belt', hint='Place a conveyor belt on the map.', weight=3.0), Achievement(id='craft_pallet', condition=functools.partial(<function holds_item>, item=25), name='Craft Pallet', hint='Hold a pallet in inventory.', weight=5.0), Achievement(id='place_pallet', condition=functools.partial(<function has_machines>, machine=2), name='Place Pallet', hint='Place a pallet on the map.', weight=5.0), Achievement(id='pallet_filled', condition=functools.partial(<function any_buffer_nonempty>, machine=2), name='Pallet Filled', hint='Put an item in a pallet.', weight=5.0), Achievement(id='craft_arm', condition=functools.partial(<function holds_item>, item=28), name='Craft Arm', hint='Hold an arm in inventory.', weight=5.0), Achievement(id='place_arm', condition=functools.partial(<function has_machines>, machine=5), name='Place Arm', hint='Place an arm on the map.', weight=5.0), Achievement(id='craft_assembler', condition=functools.partial(<function holds_item>, item=27), name='Craft Assembler', hint='Hold an assembler in inventory.', weight=5.0), Achievement(id='place_assembler', condition=functools.partial(<function has_machines>, machine=4), name='Place Assembler', hint='Place an assembler on the map.', weight=5.0), Achievement(id='first_assembly', condition=<function any_assembler_has_output>, name='First Assembly', hint='Have a placed assembler produce output.', weight=5.0), Achievement(id='belt_network', condition=functools.partial(<function has_machines>, machine=3, count=5), name='Belt Network', hint='Place five conveyor belts.', weight=5.0), Achievement(id='craft_hull', condition=functools.partial(<function holds_item>, item=19), name='Craft Hull', hint='Assemble a rocket hull (2 frame + 2 iron plate).', weight=5.0), Achievement(id='craft_engine_unit', condition=functools.partial(<function holds_item>, item=20), name='Craft Engine Unit', hint='Assemble a rocket engine (2 motor + 1 wire).', weight=5.0), Achievement(id='craft_avionics', condition=functools.partial(<function holds_item>, item=21), name='Craft Avionics', hint='Assemble an avionics package (2 circuit + 2 sensor).', weight=5.0), Achievement(id='craft_rocket_core', condition=functools.partial(<function holds_item>, item=22), name='Craft Rocket Core', hint='Assemble a rocket core (engine + avionics).', weight=5.0), Achievement(id='scaling_up', condition=functools.partial(<function has_machines>, machine=1, count=3), name='Scaling Up', hint='Place three miners at once.', weight=8.0), Achievement(id='industrialist', condition=<function _ten_machines_placed>, name='Industrialist', hint='Place ten machines in total.', weight=8.0), Achievement(id='craft_rocket', condition=functools.partial(<function holds_item>, item=29), name='Craft Rocket', hint='Assemble a rocket into inventory.', weight=8.0), Achievement(id='place_rocket', condition=functools.partial(<function has_machines>, machine=6), name='Place Rocket', hint='Place the rocket. This reaches the goal.', weight=8.0))#
10 Basic bits worth 1 point, 11 Intermediate bits worth 3 points, 13 Advanced bits worth 5 points, and 4 Very Advanced bits worth 8 points. The highest score is 140. The order teaches the natural path of the game.
- Type:
The 38 bits, in tiers in the Craftax style
- factoriax.engine.envs.rocket.ROCKET_RECIPE_BOOK: RecipeBook = RecipeBook(recipes=(Recipe(output=7, inputs=((2, 1), (1, 1)), ticks=2, output_count=1, name='Iron Plate'), Recipe(output=8, inputs=((3, 1), (1, 1)), ticks=2, output_count=1, name='Copper Plate'), Recipe(output=9, inputs=((4, 1), (1, 1)), ticks=2, output_count=1, name='Tin Plate'), Recipe(output=10, inputs=((5, 1), (1, 1)), ticks=2, output_count=1, name='Wafer'), Recipe(output=11, inputs=((7, 1), (9, 1)), ticks=4, output_count=1, name='Frame'), Recipe(output=12, inputs=((8, 1), (10, 1)), ticks=4, output_count=1, name='Circuit'), Recipe(output=13, inputs=((8, 1), (9, 1)), ticks=4, output_count=1, name='Wire'), Recipe(output=14, inputs=((11, 1), (13, 1)), ticks=6, output_count=1, name='Motor'), Recipe(output=15, inputs=((12, 1), (13, 1)), ticks=6, output_count=1, name='Sensor'), Recipe(output=26, inputs=((7, 1), (8, 1)), ticks=4, output_count=10, name='Conveyor Belt'), Recipe(output=24, inputs=((7, 1), (13, 1)), ticks=6, output_count=1, name='Miner'), Recipe(output=27, inputs=((11, 1), (12, 1)), ticks=8, output_count=1, name='Assembler'), Recipe(output=25, inputs=((9, 1), (13, 1)), ticks=4, output_count=1, name='Pallet'), Recipe(output=28, inputs=((8, 1), (13, 1)), ticks=4, output_count=1, name='Arm'), Recipe(output=30, inputs=((7, 1), (18, 1)), ticks=6, output_count=1, name='Furnace'), Recipe(output=16, inputs=((14, 1), (9, 1)), ticks=8, output_count=1, name='Tier 1 Science Pack'), Recipe(output=17, inputs=((15, 1), (10, 1)), ticks=8, output_count=1, name='Tier 2 Science Pack'), Recipe(output=23, inputs=((17, 1), (15, 1)), ticks=8, output_count=1, name='Tier 3 Science Pack'), Recipe(output=29, inputs=((19, 6), (22, 4)), ticks=300, output_count=1, name='Rocket'), Recipe(output=31, inputs=((12, 2), (14, 2)), ticks=8, output_count=1, name='Science Lab'), Recipe(output=32, inputs=((9, 1), (1, 1)), ticks=4, output_count=4, name='Splitter'), Recipe(output=33, inputs=((8, 1), (1, 1)), ticks=4, output_count=4, name='Crossing'), Recipe(output=18, inputs=((6, 1), (1, 1)), ticks=4, output_count=1, name='Refractory'), Recipe(output=19, inputs=((11, 2), (7, 2)), ticks=8, output_count=1, name='Hull'), Recipe(output=20, inputs=((14, 2), (13, 1)), ticks=8, output_count=1, name='Engine Unit'), Recipe(output=21, inputs=((12, 2), (15, 2)), ticks=10, output_count=1, name='Avionics'), Recipe(output=22, inputs=((20, 1), (21, 1)), ticks=10, output_count=1, name='Rocket Core')))#
The
RecipeBookof the rocket scenario. It appliesROCKET_RECIPE_BALANCEoverBASE_RECIPE_BOOK. Pass it to a scripted agent that reads recipes, so the material totals of that agent match the recipe table of the engine.
- factoriax.engine.envs.rocket.ROCKET_RECIPE_TABLE: RecipeTable = RecipeTable(outputs=Array([ 7, 8, 9, 10, 11, 12, 13, 14, 15, 26, 24, 27, 25, 28, 30, 16, 17, 23, 29, 31, 32, 33, 18, 19, 20, 21, 22], dtype=int32), output_counts=Array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 1], dtype=int32), input_items=Array([[ 2, 1], [ 3, 1], [ 4, 1], [ 5, 1], [ 7, 9], [ 8, 10], [ 8, 9], [11, 13], [12, 13], [ 7, 8], [ 7, 13], [11, 12], [ 9, 13], [ 8, 13], [ 7, 18], [14, 9], [15, 10], [17, 15], [19, 22], [12, 14], [ 9, 1], [ 8, 1], [ 6, 1], [11, 7], [14, 13], [12, 15], [20, 21]], dtype=int32), input_counts=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], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [6, 4], [2, 2], [1, 1], [1, 1], [1, 1], [2, 2], [2, 1], [2, 2], [1, 1]], dtype=int32), ticks=Array([ 2, 2, 2, 2, 4, 4, 4, 6, 6, 4, 6, 8, 4, 4, 6, 8, 8, 8, 300, 8, 4, 4, 4, 8, 8, 10, 10], dtype=int32), machine_type=Array([7, 7, 7, 7, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4], dtype=int32), output_to_recipe=Array([-1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, 22, 23, 24, 25, 26, 17, 10, 12, 9, 11, 13, 18, 14, 19, 20, 21], dtype=int32), names=('Iron Plate', 'Copper Plate', 'Tin Plate', 'Wafer', 'Frame', 'Circuit', 'Wire', 'Motor', 'Sensor', 'Conveyor Belt', 'Miner', 'Assembler', 'Pallet', 'Arm', 'Furnace', 'Tier 1 Science Pack', 'Tier 2 Science Pack', 'Tier 3 Science Pack', 'Rocket', 'Science Lab', 'Splitter', 'Crossing', 'Refractory', 'Hull', 'Engine Unit', 'Avionics', 'Rocket Core'))#
The
RecipeTableofROCKET_RECIPE_BOOK. Pass it as therecipe_tableofEnvParams, so the JIT-compiled engine produces the new output counts.
- factoriax.engine.envs.rocket.build_rocket_level() Level#
Build the 32x32 level of the rocket scenario.
The player spawns at
_SPAWN. Five 2x2 ore patches, of iron, copper, tin, silicon, and limestone, sit on columns 3 and 4. They stand one above the other with one-tile dirt gaps, at rows 9, 12, 15, 18, and 21. A coal column one tile wide fills the whole left edge, at x = 0. Each ore tile holds_ORE_RESOURCES_PER_TILEunits, and each coal tile holds_COAL_RESOURCES_PER_TILE. A furnace stands one tile west of the spawn, and an assembler stands one tile east of it.The function takes no arguments and no PRNG key. The layout is fixed, so every reset of this scenario gives the same world.
- Returns:
The level of the rocket scenario, ready for
factoriax.engine.levels.build_state().- Return type:
- factoriax.engine.envs.rocket.rocket(*, obs: str = 'x_ray_local', obs_radius: int = 5) tuple[Any, EnvParams]#
Build the Rocket-v1 environment, with its achievement hook and action mask.
- Parameters:
obs – Observation variant. The function passes it to
FactoriaxEnv.obs_radius – Radius for a local observation variant.
- Returns:
(env, params), ready for a gymnax-style rollout.- Return type:
- factoriax.engine.envs.rocket.rocket_reward(prev_state: EnvState, new_state: EnvState, params: EnvParams) Array#
Sparse reward for the rocket-scenario achievements that a step unlocked.
This function is a short wrapper around
factoriax.engine.rewards.achievement_reward(), bound toROCKET_ACHIEVEMENT_WEIGHTS. It expects twoEnvStateobjects whoseachievements_unlockedfield theachievement_fnof the environment already latched. That function is usuallyrocket_conditions().- Parameters:
prev_state – State just before the step.
new_state – State just after the step.
params – The function does not read this argument. It is present for the shared reward signature.
- Returns:
Scalar float32, the weighted sum of the achievements that this step unlocked. The value is zero on most steps.
- Return type: