1## ADDED Requirements23### Requirement: The engine SHALL represent a deterministic stacked grid state4The engine SHALL represent a level as a bounded rectangular grid containing uniquely identified object and word entities. Multiple entities, including words, SHALL be allowed in one cell, and a turn snapshot SHALL include positions, entity kinds, word text, active rules, move count, win state, and the complete history needed for undo.56#### Scenario: Multiple words share a cell7- **WHEN** two word entities occupy the same coordinate8- **THEN** both remain addressable and rule scanning considers both word texts at that coordinate910#### Scenario: Invalid movement is rejected11- **WHEN** a caller requests a diagonal move, an out-of-bounds move, or a move after the level is won12- **THEN** the engine leaves state and undo history unchanged1314### Requirement: The engine SHALL derive the MVP rule vocabulary from movable words15The engine SHALL scan horizontal and vertical straight lines for `NOUN IS VALUE` sentences, with adjacent `AND` terms expanding the noun side or value side. The initial semantic properties SHALL be exactly `YOU`, `PUSH`, `STOP`, `WIN`, `SINK`, and `DEFEAT`; a noun-to-noun value SHALL be treated as a transformation. Rules SHALL be recomputed from the current word positions after a turn that changes board state.1617#### Scenario: An AND sentence expands to multiple properties18- **WHEN** the board contains `BABA IS YOU AND PUSH` in one straight line19- **THEN** the active rule table contains `BABA IS YOU` and `BABA IS PUSH`2021#### Scenario: A moved word changes the active rules22- **WHEN** a legal move changes the position of a word entity23- **THEN** the engine replaces the active rule table with rules parsed from the new word positions before the next player intent2425#### Scenario: A malformed line is ignored26- **WHEN** a word line lacks `IS` or has no noun and value on both sides27- **THEN** the line produces no active rule and does not make the turn fail2829### Requirement: The engine SHALL resolve controlled movement and pushes atomically30Entities whose noun has `YOU` SHALL receive the requested cardinal intent. A moving entity SHALL push a contiguous chain of `PUSH` entities when every destination is in bounds and free of `STOP` entities; a blocked chain SHALL not move any member. Word entities SHALL be pushable by default so that players can edit rules.3132#### Scenario: A legal push moves the complete chain33- **WHEN** a `YOU` entity moves toward one or more adjacent `PUSH` entities with an empty in-bounds destination34- **THEN** the chain moves one cell in the requested direction and the move count increases by one3536#### Scenario: STOP blocks a push37- **WHEN** a requested movement would push an entity into a `STOP` entity or outside the grid38- **THEN** no entity moves and the move count does not increase3940#### Scenario: Several YOU entities use stable ordering41- **WHEN** more than one `YOU` entity receives the same intent42- **THEN** the engine resolves them in a documented stable order and produces the same state for the same initial state and intent4344### Requirement: The engine SHALL apply transformations and contact effects deterministically45After movement, the engine SHALL apply active noun-to-noun transformations, then resolve contact effects using the MVP properties. `SINK` SHALL remove all occupants of a contact cell, `DEFEAT` SHALL remove controlled entities sharing its cell, and `WIN` SHALL mark the level won when a controlled entity shares a cell with a winning entity. The engine SHALL expose the settled state only after these effects complete.4647#### Scenario: A noun transforms48- **WHEN** the active rule `BABA IS KEKE` is present after a successful turn49- **THEN** every object with noun `BABA` becomes noun `KEKE` before the next rule scan5051#### Scenario: Sink removes contact occupants52- **WHEN** an entity with `SINK` shares a cell with another entity after movement53- **THEN** every entity in that cell is removed before the turn is committed5455#### Scenario: Defeat removes YOU56- **WHEN** a `YOU` entity shares a cell with an entity having `DEFEAT`57- **THEN** the controlled entity is removed and the level is not marked won by that contact5859#### Scenario: Win marks the level complete60- **WHEN** a `YOU` entity shares a cell with an entity having `WIN`61- **THEN** the engine marks the level won and rejects later movement until reset or progression6263### Requirement: The engine SHALL support complete turn undo and reset64The engine SHALL save the complete pre-turn state before each successful movement and SHALL restore it with `undo`. `reset` SHALL restore the original level, clear history, clear the win state, and rebuild rules and derived effects.6566#### Scenario: Undo restores a rule edit67- **WHEN** a successful push moves a word and the caller invokes `undo`68- **THEN** the word positions, active rules, objects, move count, and win state match the state before that push6970#### Scenario: Undo with no history is harmless71- **WHEN** the caller invokes `undo` before any successful move72- **THEN** the engine returns a false or equivalent no-op result and leaves the state unchanged7374#### Scenario: Reset returns to the level start75- **WHEN** the caller invokes `reset` after any sequence of moves and effects76- **THEN** the initial entities and rules are restored, move count is zero, win is false, and undo history is empty7778### Requirement: Active rules SHALL identify their source words79Each active rule SHALL expose the word entity IDs that formed it in reading order and whether the sentence runs horizontally or vertically. Duplicate sentences at different locations SHALL retain deterministic source information.8081#### Scenario: A horizontal sentence reports its source82- **WHEN** adjacent word entities form `MIAU IS YOU` from left to right83- **THEN** the resulting rule identifies those word IDs in order and reports horizontal axis8485#### Scenario: A vertical sentence reports its source86- **WHEN** adjacent word entities form `ROCK IS PUSH` from top to bottom87- **THEN** the resulting rule identifies those word IDs in order and reports vertical axis8889### Requirement: Engine actions SHALL return settled turn events90`step`, `undo`, and `reset` SHALL return an event record after resolving state. Every record SHALL have `kind: 'step' | 'undo' | 'reset'`, `accepted`, ordered `moved`, full-record `rulesAdded` and `rulesRemoved`, ordered `transformed`, ordered `destroyed`, `controlLost`, and final `won` fields. A blocked or invalid step SHALL retain `kind: 'step'`, report `accepted: false`, and leave state unchanged.9192For movement, each entry SHALL be `{ id, from, to, pushedBy }`, where `pushedBy` is the immediate pusher's entity id or `null` for a directly controlled mover. A physical block SHALL be `{ id, dir, blockerId, reason }`, where `blockerId` is the blocking entity id or `null` at the board edge and `reason` is `stop` or `bounds`. Rule delta entries SHALL be complete rule records with `subject`, `predicate`, `sourceIds`, and `axis`. Destroyed entries SHALL be `{ id, noun|text, at, cause }` with `cause` `sink` or `defeat`. Arrays SHALL preserve engine resolution order: movement, transformation, destruction, then win evaluation. `controlLost` SHALL be true when the settled state has no `YOU` entity.9394#### Scenario: Breaking a rule produces a rule delta95- **WHEN** a successful push moves a word out of a sentence96- **THEN** the step result lists the word movement with `from`, `to`, and `pushedBy`, and lists the removed rule as a full record retaining its former `sourceIds` and `axis`9798#### Scenario: A blocked push produces no state change99- **WHEN** a push chain is blocked by `STOP` or the board edge100- **THEN** the step result has `kind: 'step'`, reports `accepted: false`, identifies `id`, `dir`, `blockerId`, and `reason`, and leaves move count and history unchanged101102#### Scenario: Undo reports a restored state103- **WHEN** a successful move is undone104- **THEN** the undo result has `kind: 'undo'`, reports `accepted: true`, the reverse movement with `pushedBy: null`, the rule changes, `controlLost`, and the restored win state105106#### Scenario: Contact destruction includes presentation details107- **WHEN** a `SINK` or `DEFEAT` interaction removes an entity108- **THEN** the step result lists its id, noun or text, cell coordinate, and `cause` in the destruction order109110#### Scenario: Control loss is explicit111- **WHEN** a settled step removes the last entity with the `YOU` property112- **THEN** the step result reports `controlLost: true` even though the state remains inspectable for the loss feedback113114#### Scenario: Event arrays preserve resolution order115- **WHEN** one accepted step moves entities, transforms an object, destroys contacts, and evaluates a win116- **THEN** the event arrays retain movement order first, transformation order second, destruction order third, and the final win result after those phases