Game mechanics integration¶
Layer 3 connects tangl.mechanics.games to the story VM so blocks can host
stateful games with automatic setup, move provisioning, journaling, and predicate
evaluation.
Quick start¶
from tangl.mechanics.games import RpsGame, RpsGameHandler
from tangl.mechanics.games import HasGame
from tangl.story.episode import Block
class RpsBlock(HasGame, Block):
"""Rock–Paper–Scissors block with a game facet."""
pass
block = RpsBlock.create_game_block(
graph=story_graph,
game_class=RpsGame,
handler_class=RpsGameHandler,
victory_dest=victory_scene,
defeat_dest=defeat_scene,
)
VM pipeline¶
HasGame nodes participate in the standard resolution phases:
PREREQS –
setup_game_on_first_visitprepares the game when the cursor enters for the first time.PLANNING –
provision_game_movesemits self-loopActioninstances for each available move reported by the handler.UPDATE –
process_game_moveroutes the selected move into the handler and records round results incursor.locals.JOURNAL –
generate_game_journalconverts the round state intoContentFragmentrecords for downstream renderers.CONTEXT –
inject_game_contextexposes predicate-friendly flags such asgame_wonandgame_lostfor POSTREQS exit edges.
Creating new games¶
Implement a
tangl.mechanics.games.Gamesubclass with scoring fields and history tracking.Implement a
tangl.mechanics.games.GameHandlerthat returns available moves and resolves rounds by mutating the game instance.Subclass
tangl.mechanics.games.HasGameon your story block and configure_game_classand_game_handler_class(or override viacreate_game_block).Wire exit destinations through the factory to route victory/defeat/draw states.
Add integration tests under
engine/tests/mechanics/gamesto validate move flows and predicate-driven exits.
See also¶
For the broader family taxonomy and future-shape note, see the code-adjacent
design doc at engine/src/tangl/mechanics/games/GAME_MECHANICS_DESIGN.md.