Formal Mathematical & Algorithmic Specification
Web-native, deep-linkable edition of Phalanx Duel Classic v3.0 (Engine v1.6.0). Every formula below is bound to @phalanxduel/engine, verified across 2,355,388 finite combat transitions, and proved unbounded over all integers ℤ by Z3 SMT-LIB2.
1. State Space, Geometry & Deck Axioms
A Phalanx Duel match is a finite-state, zero-RNG-after-deal deterministic transition system ℳ = (𝒮, 𝒜, δ, s₀, ℰ) on a rectangular r × c battlefield (Classic: r = 2, c = 4, LP₀ = 20).
In Classic v3.0 (r = 2, c = 4): 8 battlefield slots, max hand 4, opening draw D₀ = 12, leaving a 40-card reserve (40 ≥ 4). Deck values: A = 1, 2–10 = face value, J = Q = K = 11.
2. Deterministic 8-Phase Turn Lifecycle
The authoritative transition function δ : 𝒮 × 𝒜 → 𝒮 × ℰ* advances through eight phases enforced by engine/src/state-machine.ts and verified deadlock-free:
View Single-Source Turn Lifecycle & Cascade Diagram (SVG) D2 · Build-Time SVG
Open full-resolution SVG in new tab · Open live TypeScript STATE_MACHINE Graphviz SVG
3. Combat Cascade & Suit Boundary Algebra
For ordinary contact with incoming damage d ≥ 0 and target card HP h ≥ 1:
Fired between opposing Front and Back cards. Diamond shield (♦) resolves before Club weapon (♣):
Fired into Opponent LP. Last-destroyed Heart ward (♥) resolves before Spade finisher (♠):
- Face-Card Eligibility (
isFaceCardEligible): On face-card defenders{J, Q, K},Jackcan destroy{J},Queencan destroy{J, Q}, andKingcan destroy{J, Q, K}(non-face attackers are unrestricted). Ineligible targets survive withcarryover = 0. - Ace Duality (
modeClassicAces): Only a front-rank Ace can destroy another Ace. Any non-Ace attacker deals at most 1 absorbed damage; the Ace remains athp′ = 1(undestroyed) and passesd − 1carryover through.
4. Theorem 1 — Non-Commutativity of Shield & Weapon Operators
Let S_δ(x) = max(0, x − δ) be a boundary shield and W(x) = 2x be a weapon multiplier. For all integers x ≥ 0, δ ≥ 0:
Strict inequality (W ∘ S_δ)(x) < (S_δ ∘ W)(x) holds if and only if 0 < δ < 2x.
Design consequence: Classic v3.0 applies Shield-before-Weapon (W ∘ S_δ), strictly capping burst variance vs. legacy v1.0 (S_δ ∘ W) and guaranteeing that any shield with δ ≥ x zeroes out the weapon doubling trigger completely.
5. Theorem 2 — Guaranteed Finite Termination (Liveness)
At every v3.0 AttackPhase turn boundary, engine/src/liveness.ts evaluates a collision-free canonical position witness σ(s) and a four-coordinate progress vector:
No infinite loop is reachable in v3.0. Every match terminates in at most 200 completed turns.
6. Authority Ledger, Fog-of-War & Cryptographic Replay
Every match is an immutable fold from its initial seed over the server-authoritative action log, with per-turn canonical SHA-256 hashes:
Each player receives only the redacted projection π_p(s_t) stripping opponent hidden hands and drawpile order; spectators receive delayed frames via replayGameAtOrBeforeTurn.
View Authority Ledger & Fog-of-War Diagram (SVG) D2 · Build-Time SVG
7. Unbounded Mathematical Proofs (Z3 SMT-LIB2 · 8/8 Q.E.D.)
Each theorem below is proved over all unbounded mathematical integers ℤ in docs/formal/phalanx_duel_proofs.smt2 by asserting its negation and verifying Z3 returns unsat (re-verify locally with pnpm verify:proofs):
Proof 1 — Shield-Zeroes-Weapon Theorem Z3 · Q.E.D. (unsat)
Proves that whenever a Diamond or Heart shield meets or exceeds incoming carryover, the Club or Spade ×2 multiplier can never fire.
Proof 2 — v3.0 Burst-Dominance Theorem Z3 · Q.E.D. (unsat)
Proves Shield-before-Weapon never produces higher burst damage than legacy Weapon-before-Shield.
Proof 3 — Exact Non-Commutativity Closed-Form Identity Z3 · Q.E.D. (unsat)
Proves the exact integer delta between v1.0 and v3.0 across all non-negative integers.
Proof 4 — Strict Non-Commutativity Biconditional (iff) Z3 · Q.E.D. (unsat)
Establishes the exact necessary and sufficient boundary where operator order changes combat output.
Proof 5 — Damage Conservation & Surviving-Card Stop Z3 · Q.E.D. (unsat)
Proves zero damage is created or lost during standard contact, and any surviving card halts carryover.
Proof 6 — Ace Invulnerability Conservation Z3 · Q.E.D. (unsat)
Proves non-Ace strikes against an Ace conserve total damage while keeping the Ace at 1 HP.
Proof 7 — Liveness Bounded Termination (≤ 200 Turns) Z3 · Q.E.D. (unsat)
Proves no active v3.0 match can ever exceed the 200-turn hard termination bound.
Proof 8 — Fog-of-War Projection Non-Interference Z3 · Q.E.D. (unsat)
Proves perturbing opponent hidden hands or drawpile order cannot alter Player 0's projected view.
8. Machine-Checked Worked Cascade Examples
Every example below is executed against the live TypeScript engine on every pnpm verify:formal run:
| Attacker | Defending Column | Step-by-Step Resolution (v3.0) | LP Loss |
|---|---|---|---|
| 9♣ | Front 4♦, Back 5♠ | 9 hits 4♦ → destroyed, carryover 5. ♦ Shield: 5 − 4 = 1. ♣ Weapon: 1 × 2 = 2. Hits 5♠ → survives at 3 HP. | 0 LP |
| 10♠ | Front 6♣, Back 2♥ | 10 hits 6♣ → destroyed, carryover 4. Hits 2♥ → destroyed, carryover 2. ♥ Ward: 2 − 2 = 0. ♠ Weapon: 0 × 2 = 0. | 0 LP |
| 10♠ | Front 5♣, Back 2♦ | 10 hits 5♣ → destroyed, carryover 5. Hits 2♦ → destroyed, carryover 3. No Heart at LP boundary. ♠ Weapon: 3 × 2 = 6. | 6 LP |
| 8♥ | Front A♦, Back 3♣ | Non-Ace vs Ace: A♦ absorbs 1, survives (1 HP, no Diamond shield), carryover 7 destroys 3♣ → carryover 4 hits LP. | 4 LP |
9. Companion Print Editions & Source Artifacts
Prefer a printable sheet for tabletop play or offline archival review? Every artifact below compiles from the same canonical source:
Canonical sources: Z3 SMT-LIB2 Proofs · TLA+ Specification · Executable Engine Verifier