clone

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

main
miau-is-true / openspec / changes / fix-rule-precedence-and-reading / specs / rule-precedence-and-reading / spec.md
spec.md 6.0K source

ADDED Requirements

Requirement: PUSH SHALL take precedence over STOP on the same object

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.

Scenario: ROCK IS STOP AND PUSH can be pushed

  • WHEN a YOU entity moves into a ROCK object governed by ROCK IS STOP AND PUSH
  • THEN the ROCK is pushed by the atomic chain and the move is not rejected by STOP

Scenario: A distinct STOP still blocks

  • WHEN a YOU entity moves into a STOP object that does not carry PUSH
  • THEN the move is rejected with a STOP block and the destination occupant remains in place

Requirement: DEFEAT SHALL resolve before WIN, including singleton contacts

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.

Scenario: A singleton YOU and DEFEAT entity loses

  • WHEN one entity has both YOU and DEFEAT after movement or transformation
  • THEN the entity is destroyed, the settled state is not won, and the event reports control loss when no YOU remains

Scenario: DEFEAT wins the precedence race

  • WHEN YOU and WIN overlap an entity carrying DEFEAT in one contact cell
  • THEN DEFEAT removes the controlled entity before WIN can mark the level won

Requirement: Self-transform rules SHALL suppress other transformations

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.

Scenario: Self-transform is ignored

  • WHEN the board contains BABA IS BABA and no other noun transformation for BABA
  • THEN BABA objects retain their noun and no transformation event is emitted

Scenario: Self-transform masks another target

  • WHEN the board contains both ROCK IS ROCK and ROCK IS FLAG
  • THEN ROCK objects retain ROCK and do not transform to FLAG regardless of which sentence is parsed first

Requirement: Competing noun transformations SHALL use spatial reading order

When a noun has multiple valid noun transformation targets, the engine SHALL choose the first rule by the first word's spatial reading order: first-word row top-to-bottom, then left-to-right, then sentence token order. The selected source rule SHALL remain observable in the settled transformation record.

Scenario: Earlier first word wins

  • WHEN BABA has valid transformations from two sentence origins and one first word is earlier top-to-bottom, then left-to-right
  • THEN BABA transforms to the target from the earlier rule regardless of authored object array order

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.

  • WHEN the board contains BABA IS ROCK and ROCK IS FLAG
  • THEN a BABA object becomes ROCK for that turn and does not become FLAG until a later turn that still satisfies the second rule

Scenario: Restoring a settled snapshot is not a turn

  • WHEN a snapshot contains ROCK after the first link of BABA IS ROCK, ROCK IS FLAG
  • THEN restoring that snapshot preserves ROCK and its automaton phase; only a later accepted turn may advance it to FLAG

Requirement: Rule reading SHALL select one stacked token per cell/path and enumerate alternatives

For each candidate sentence path, the parser SHALL select one word from each stacked cell, enumerate every valid alternative, and allow a sentence to start at a stacked cell. It SHALL not combine all stacked tokens as one permissive grammar. The resulting semantic rules SHALL remain deterministically ordered and physically sourced.

Scenario: A stacked operator cell yields one valid rule

  • WHEN the path is ROCK [AND+IS] FLAG
  • THEN the parser includes ROCK IS FLAG as a valid alternative

Scenario: A stacked noun before IS yields the valid alternative

  • WHEN the path is MIAU [AND+ROCK] IS YOU
  • THEN the parser includes ROCK IS YOU only and does not treat MIAU AND ROCK IS YOU as one malformed subject path

Scenario: A stacked predicate enumerates alternatives

  • WHEN the path is ROCK IS [WIN+PUSH]
  • THEN the parser includes both ROCK IS WIN and ROCK IS PUSH

Scenario: A stacked subject enumerates alternatives

  • WHEN the path is [ROCK+FLAG] IS WIN
  • THEN the parser includes both ROCK IS WIN and FLAG IS WIN

Scenario: A stacked AND path starts from each valid subject

  • WHEN the path is ROCK AND [FLAG+IS] IS WIN
  • THEN the parser includes ROCK IS WIN and FLAG IS WIN from the valid alternatives and excludes malformed combinations

Requirement: Stacked rule parsing SHALL have a deterministic complexity limit

The parser SHALL either return every valid rule and physical sentence span or fail with a typed complexity error before exposing partial results. A pack whose initial board exceeds the limit SHALL report an authored-level validation error. If a played turn would exceed the limit, the engine SHALL reject that turn atomically without advancing moves, history, or automata.

Scenario: An authored board exceeds the parser budget

  • WHEN a dense stack of words generates more sentence paths or spans than the supported budget
  • THEN parsing fails with a typed rule-complexity error and no partial rule set is returned

Scenario: A push would exceed the parser budget

  • WHEN an accepted push would create a word arrangement above the supported parsing budget
  • THEN the turn reports a rule-complexity block and restores the exact pre-turn board, move count, undo history, and automata phase