clone

a browser grid puzzle game where you push words around to rewrite the rules of each level

Draft rule precedence and reading OpenSpec change

Dami committed cce20af
commit
cce20af6bbfcbebcb4d4ac1f7d1bcc68a96de8f1
parent
f92b270685d13109ab1bc38f2360b03c50ee6aba
author
Dami <dami.etoile@gmail.com>
5 files changed, +163 -0
Aopenspec/changes/fix-rule-precedence-and-reading/.openspec.yaml2+
Aopenspec/changes/fix-rule-precedence-and-reading/design.md60++++++++++++++++++++++++++++++
Aopenspec/changes/fix-rule-precedence-and-reading/proposal.md28++++++++++++++
Aopenspec/changes/fix-rule-precedence-and-reading/specs/rule-precedence-and-reading/spec.md55++++++++++++++++++++++++++++
Aopenspec/changes/fix-rule-precedence-and-reading/tasks.md18+++++++++
A openspec/changes/fix-rule-precedence-and-reading/.openspec.yaml +2 -0
A openspec/changes/fix-rule-precedence-and-reading/design.md +60 -0
@@ -0,0 +1,60 @@
1+## Context2+3+The W6 audit compares current behavior with Baba-style author expectations. The engine already has stable movement and contact phases, but several outcomes depend on incidental occupant or authored object order. The worlds team also needs a decision on whether stacked cells select one token per grammar path or allow permissive alternatives; that choice is not settled and must not be hidden in this change.4+5+## Goals / Non-Goals6+7+**Goals:**8+9+- Make STOP/PUSH, DEFEAT/WIN, and singleton hazard outcomes explicit.10+- Make self-transform suppression and competing noun transformations deterministic.11+- Preserve one-link transformation semantics within a turn.12+- Add regression fixtures that expose event order and resulting nouns.13+- Keep the stacked-cell AND choice visible as an open question.14+15+**Non-Goals:**16+17+- Choosing or implementing the one-token-per-cell versus permissive stacked grammar.18+- Reworking Crossword levels before the worlds reply.19+- Adding new vocabulary, goals, automata, or contact timing modes.20+21+## Decisions22+23+### PUSH wins over STOP when carried by one object24+25+When the same destination object carries both STOP and PUSH, PUSH allows the object to be pushed rather than treating its STOP as a block. This matches the worlds audit's Baba-compatible semantics; treating STOP first prevents intended `ROCK IS STOP AND PUSH` behavior.26+27+### Resolve defeat before victory, including singleton entities28+29+Contact resolution evaluates DEFEAT before WIN. A singleton entity carrying both YOU and DEFEAT is removed and cannot win from its own WIN property. The same ordering applies when distinct entities overlap.30+31+### Self-transform rules suppress other transforms32+33+`X IS X` contributes no noun change, but its presence suppresses every other noun transformation for X in that turn. This makes `ROCK IS ROCK` plus `ROCK IS FLAG` stable regardless of parse order and avoids an incidental transform conflict.34+35+### Choose transformations by spatial rule-reading order and apply one link36+37+For one noun with multiple valid noun targets, select the first rule in the parser's documented spatial order: rule origin in row-major board order, then horizontal before vertical at the same origin, then sentence token order. Apply at most one noun transformation per object per turn; do not recursively apply the result to another noun rule until a later turn. This keeps `A IS B` and `B IS C` as a one-link chain.38+39+### Leave stacked-cell AND grammar unresolved40+41+The spec records the competing options: one selected token per cell/path with valid alternatives enumerated, or permissive stacked grammar. No parser implementation choice is made until worlds confirms the intended contract.42+43+## Risks / Trade-offs44+45+- [Risk] Existing levels rely on authored object order for transform conflicts. → Add fixtures and review affected worlds before enabling the new order broadly.46+- [Risk] Singleton YOU+DEFEAT changes a loss outcome. → Add explicit event/state assertions and rerun bundled solver checks.47+- [Risk] Spatial ordering differs from author expectations. → Expose source rule IDs and axis in settled state and document the ordering.48+- [Risk] Stacked grammar remains unresolved. → Keep Crossword changes deferred and require a follow-up spec decision.49+50+## Migration Plan51+52+1. Add focused engine tests for precedence and deterministic reading.53+2. Implement parser/contact changes behind the existing deterministic engine path.54+3. Run bundled solver and browser regression checks.55+4. Revisit stacked-cell grammar in a follow-up after worlds confirmation.56+57+## Open Questions58+59+- Should stacked-cell grammar select one token per cell/path and enumerate valid alternatives, or permit permissive stacked combinations?60+- Does the worlds team accept row-major, horizontal-before-vertical rule order for transformation conflicts?
A openspec/changes/fix-rule-precedence-and-reading/proposal.md +28 -0
@@ -0,0 +1,28 @@
1+## Why2+3+The W6 audit found several Baba-compatible edge cases where collision and rule-reading order can change the result: STOP/PUSH overlap, singleton YOU+DEFEAT, self-transform rules, competing transformations, and one-link chains. These cases need one deterministic contract before Crossword and other worlds are reworked; stacked-cell AND grammar remains an explicit design decision pending worlds confirmation.4+5+## What Changes6+7+- Define PUSH precedence over STOP when the same object carries both properties.8+- Resolve singleton YOU+DEFEAT and DEFEAT-before-WIN contacts deterministically.9+- Suppress `X IS X` as a no-op that masks other transformations for X.10+- Resolve competing noun transformations by spatial rule-reading order and apply only one link per turn.11+- Preserve deterministic one-link transformation chains.12+- Record the stacked-cell AND grammar as an open decision rather than silently settling permissive or one-token parsing.13+14+## Capabilities15+16+### New Capabilities17+18+- `rule-precedence-and-reading`: deterministic collision, contact, transformation, and rule-reading semantics for Baba-compatible levels.19+20+### Modified Capabilities21+22+None. This change is intentionally isolated until the worlds team confirms the stacked-cell grammar choice.23+24+## Impact25+26+- Affected engine contact resolution, transformation selection, and rule parser ordering.27+- Requires focused engine fixtures for the audited cases and follow-up world solver checks.28+- Crossword shove-the-danger and carry-the-pair content remains deferred until the grammar question is answered.
A openspec/changes/fix-rule-precedence-and-reading/specs/rule-precedence-and-reading/spec.md +55 -0
@@ -0,0 +1,55 @@
1+## ADDED Requirements2+3+### Requirement: PUSH SHALL take precedence over STOP on the same object4+When one object carries both STOP and PUSH, the PUSH property SHALL take precedence for movement into that object. The object SHALL be eligible for the push chain, while a distinct STOP object without PUSH SHALL still block movement.5+6+#### Scenario: ROCK IS STOP AND PUSH can be pushed7+- **WHEN** a YOU entity moves into a ROCK object governed by `ROCK IS STOP AND PUSH`8+- **THEN** the ROCK is pushed by the atomic chain and the move is not rejected by STOP9+10+#### Scenario: A distinct STOP still blocks11+- **WHEN** a YOU entity moves into a STOP object that does not carry PUSH12+- **THEN** the move is rejected with a STOP block and the destination occupant remains in place13+14+### Requirement: DEFEAT SHALL resolve before WIN, including singleton contacts15+Contact resolution SHALL evaluate DEFEAT before WIN. A surviving YOU entity that shares a cell with DEFEAT SHALL be removed before victory evaluation, and an entity carrying both YOU and DEFEAT SHALL be removed even when it is the only entity in its cell.16+17+#### Scenario: A singleton YOU and DEFEAT entity loses18+- **WHEN** one entity has both YOU and DEFEAT after movement or transformation19+- **THEN** the entity is destroyed, the settled state is not won, and the event reports control loss when no YOU remains20+21+#### Scenario: DEFEAT wins the precedence race22+- **WHEN** YOU and WIN overlap an entity carrying DEFEAT in one contact cell23+- **THEN** DEFEAT removes the controlled entity before WIN can mark the level won24+25+### Requirement: Self-transform rules SHALL suppress other transformations26+The engine SHALL treat `X IS X` as a no-op for the object's noun while its presence suppresses every other noun transformation for X in the same turn, regardless of parse order.27+28+#### Scenario: Self-transform is ignored29+- **WHEN** the board contains `BABA IS BABA` and no other noun transformation for BABA30+- **THEN** BABA objects retain their noun and no transformation event is emitted31+32+#### Scenario: Self-transform masks another target33+- **WHEN** the board contains both `ROCK IS ROCK` and `ROCK IS FLAG`34+- **THEN** ROCK objects retain ROCK and do not transform to FLAG regardless of which sentence is parsed first35+36+### Requirement: Competing noun transformations SHALL use spatial reading order37+When a noun has multiple valid noun transformation targets, the engine SHALL choose the first rule in deterministic spatial reading order: rule origin row-major, horizontal before vertical at the same origin, then sentence token order. The selected source rule SHALL remain observable in the settled transformation record.38+39+#### Scenario: Earlier spatial rule wins40+- **WHEN** BABA has valid transformations from two sentence origins and one origin is earlier in row-major reading order41+- **THEN** BABA transforms to the target from the earlier rule regardless of authored object array order42+43+### Requirement: Noun transformations SHALL apply one link per turn44+The engine SHALL apply at most one noun-to-noun transformation link to each object in a turn. A transformed noun SHALL not immediately transform again through a second rule until a later accepted turn.45+46+#### Scenario: A transformation chain stops after one link47+- **WHEN** the board contains `BABA IS ROCK` and `ROCK IS FLAG`48+- **THEN** a BABA object becomes ROCK for that turn and does not become FLAG until a later turn that still satisfies the second rule49+50+### Requirement: Rule reading SHALL keep stacked-cell grammar explicit51+The engine SHALL not silently broaden or narrow stacked-cell AND parsing as part of this change. The accepted grammar SHALL be chosen in a follow-up decision between one selected token per cell/path with valid alternatives enumerated and permissive stacked combinations.52+53+#### Scenario: The unresolved grammar is surfaced54+- **WHEN** a level uses stacked words around `AND` or `IS`55+- **THEN** validation or authoring review identifies the grammar decision as pending rather than treating one interpretation as a settled W6 contract
A openspec/changes/fix-rule-precedence-and-reading/tasks.md +18 -0