Prompt specification
Build or customize the Three.js 3D scene "Simultaneous Plans With Collision Resolution" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Simultaneous Plans With Collision Resolution
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/simultaneous-plans-with-collision-resolution-x3592
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: simultaneous plans with collision resolution. Create a planning game where two players choose actions before execution. Apply a published conflict-resolution rule consistently and show how it differs from sequential turns.
Working Three.js Starter (simultaneous-plans-with-collision-resolution-x3592):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LOCKSTEP — Voxel Simultaneous Tactics</title>
<style>
:root {
--bg: #07101c;
--bg-soft: #0b1727;
--panel: rgba(13, 27, 44, 0.88);
--panel-solid: #0e1c2e;
--line: rgba(151, 185, 215, 0.16);
--text: #edf7ff;
--muted: #8ea5ba;
--amber: #ffb547;
--cyan: #42d8ff;
--green: #9dff73;
--red: #ff6f7d;
--shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background:
radial-gradient(circle at 48% -20%, #183451 0, transparent 42%),
var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
summary {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
summary:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
.app-header {
height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(5, 13, 24, 0.82);
backdrop-filter: blur(18px);
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
transform: rotate(30deg) skewY(-8deg);
border: 2px solid var(--cyan);
border-radius: 8px;
box-shadow:
inset 0 0 20px rgba(66, 216, 255, 0.12),
0 0 24px rgba(66, 216, 255, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--cyan);
opacity: 0.85;
}
.brand-mark::before {
width: 14px;
height: 2px;
left: 10px;
top: 17px;
}
.brand-mark::after {
width: 2px;
height: 14px;
left: 16px;
top: 11px;
}
.brand h1 {
margin: 0;
font-size: 19px;
letter-spacing: 0.18em;
line-height: 1;
}
.brand p {
margin: 6px 0 0;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
}
.round-pill {
min-width: 130px;
padding: 9px 14px;
border: 1px solid var(--line);
border-radius: 9px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.12em;
text-align: center;
text-transform: uppercase;
}
.round-pill strong {
color: var(--text);
}
.ghost-button,
.small-button {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.035);
border-radius: 9px;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.ghost-button {
padding: 10px 13px;
color: #cfe0ee;
font-size: 12px;
font-weight: 700;
}
.ghost-button:hover,
.small-button:hover {
border-color: rgba(66, 216, 255, 0.45);
background: rgba(66, 216, 255, 0.07);
}
.ghost-button:active,
.small-button:active {
transform: translateY(1px);
}
.app {
height: calc(100vh - 76px);
display: grid;
grid-template-columns: 292px minmax(420px, 1fr) 326px;
gap: 14px;
padding: 14px;
}
.panel {
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
overflow: hidden;
}
.console {
display: flex;
flex-direction: column;
min-height: 0;
}
.panel-heading {
padding: 18px 18px 15px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel-heading h2,
.section-title {
margin: 0;
font-size: 15px;
letter-spacing: 0.02em;
}
.panel-heading p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.console-scroll {
min-height: 0;
overflow-y: auto;
padding: 16px;
scrollbar-width: thin;
scrollbar-color: #294158 transparent;
}
.plan-stack {
display: grid;
gap: 9px;
margin-bottom: 16px;
}
.plan-card {
position: relative;
display: grid;
grid-template-columns: 37px 1fr auto;
align-items: center;
gap: 11px;
min-height: 62px;
padding: 10px 11px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
transition:
border-color 180ms ease,
background 180ms ease;
}
.plan-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--player-color);
opacity: 0.9;
}
.plan-card.amber {
--player-color: var(--amber);
}
.plan-card.cyan {
--player-color: var(--cyan);
}
.plan-card.active {
border-color: color-mix(in srgb, var(--player-color) 55%, transparent);
background: color-mix(in srgb, var(--player-color) 7%, transparent);
}
.player-token {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border: 1px solid color-mix(in srgb, var(--player-color) 45%, transparent);
border-radius: 9px;
color: var(--player-color);
background: color-mix(in srgb, var(--player-color) 9%, transparent);
font-size: 13px;
font-weight: 900;
}
.plan-name {
color: var(--player-color);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.plan-value {
margin-top: 4px;
color: var(--text);
font-size: 13px;
font-weight: 700;
}
.plan-state {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-line {
display: flex;
align-items: center;
gap: 9px;
min-height: 44px;
margin-bottom: 13px;
padding: 10px 12px;
border: 1px solid rgba(66, 216, 255, 0.15);
border-radius: 11px;
background: rgba(66, 216, 255, 0.045);
color: #cde8f8;
font-size: 12px;
line-height: 1.4;
}
.status-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 13px var(--cyan);
}
.action-label {
margin: 17px 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.dpad {
display: grid;
grid-template-columns: repeat(3, 52px);
grid-template-rows: repeat(3, 45px);
justify-content: center;
gap: 6px;
margin: 0 auto 14px;
}
.action-button {
position: relative;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition:
transform 120ms ease,
border-color 120ms ease,
background 120ms ease,
color 120ms ease;
}
.action-button:hover:not(:disabled) {
border-color: rgba(66, 216, 255, 0.45);
background: rgba(66, 216, 255, 0.07);
transform: translateY(-1px);
}
.action-button.selected {
color: #07101c;
border-color: var(--active-color, var(--cyan));
background: var(--active-color, var(--cyan));
box-shadow: 0 0 24px color-mix(in srgb, var(--active-color, var(--cyan)) 20%, transparent);
}
.action-button:disabled {
cursor: not-allowed;
opacity: 0.34;
}
.dpad .action-button {
font-size: 22px;
font-weight: 900;
}
.dpad .north {
grid-column: 2;
grid-row: 1;
}
.dpad .west {
grid-column: 1;
grid-row: 2;
}
.dpad .east {
grid-column: 3;
grid-row: 2;
}
.dpad .south {
grid-column: 2;
grid-row: 3;
}
.utility-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 13px;
}
.utility-actions .action-button {
min-height: 48px;
padding: 7px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.04em;
}
.utility-actions .wide {
grid-column: 1 / -1;
}
.initiative-box {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 4px 0 13px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.initiative-box span {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.initiative-box strong {
color: var(--cyan);
font-size: 12px;
}
.primary-button {
width: 100%;
min-height: 50px;
border: 0;
border-radius: 11px;
background: linear-gradient(135deg, #42d8ff, #69e5ff);
color: #06101b;
cursor: pointer;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
box-shadow: 0 10px 26px rgba(66, 216, 255, 0.16);
transition:
transform 140ms ease,
opacity 140ms ease;
}
.primary-button:hover:not(:disabled) {
transform: translateY(-1px);
}
.primary-button:disabled {
cursor: not-allowed;
opacity: 0.35;
box-shadow: none;
}
.demo-button {
width: 100%;
margin-top: 9px;
padding: 10px;
border: 1px dashed rgba(157, 255, 115, 0.32);
border-radius: 10px;
background: rgba(157, 255, 115, 0.045);
color: var(--green);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.demo-button:hover {
background: rgba(157, 255, 115, 0.09);
}
.keyboard-note {
margin: 10px 0 0;
color: #61798e;
font-size: 10px;
line-height: 1.5;
text-align: center;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 17px;
background:
radial-gradient(circle at 50% 40%, rgba(35, 73, 103, 0.34), transparent 55%),
#081321;
box-shadow: var(--shadow);
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.viewport-hud {
position: absolute;
z-index: 2;
inset: 15px 15px auto;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.hud-block {
padding: 10px 12px;
border: 1px solid rgba(158, 194, 222, 0.13);
border-radius: 11px;
background: rgba(6, 16, 29, 0.68);
backdrop-filter: blur(12px);
}
.hud-block span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.hud-block strong {
display: block;
margin-top: 4px;
font-size: 12px;
}
.objective-hud {
max-width: 230px;
text-align: right;
}
.objective-hud strong {
color: var(--green);
}
.outcome-banner {
position: absolute;
z-index: 2;
top: 86px;
left: 50%;
width: min(420px, calc(100% - 40px));
padding: 12px 16px;
border: 1px solid rgba(66, 216, 255, 0.18);
border-radius: 12px;
background: rgba(7, 18, 32, 0.8);
backdrop-filter: blur(12px);
transform: translateX(-50%);
text-align: center;
pointer-events: none;
}
.outcome-banner .banner-kicker {
color: var(--cyan);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.outcome-banner strong {
display: block;
margin-top: 5px;
font-size: 14px;
}
.outcome-banner p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
}
.lens {
position: absolute;
z-index: 3;
left: 50%;
bottom: 17px;
display: flex;
align-items: center;
gap: 8px;
padding: 6px;
border: 1px solid rgba(158, 194, 222, 0.16);
border-radius: 12px;
background: rgba(6, 16, 29, 0.78);
backdrop-filter: blur(14px);
transform: translateX(-50%);
}
.lens-label {
padding: 0 7px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.lens-button {
padding: 8px 10px;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.lens-button.active {
border-color: rgba(66, 216, 255, 0.27);
background: rgba(66, 216, 255, 0.09);
color: var(--cyan);
}
.camera-note {
position: absolute;
z-index: 2;
right: 15px;
bottom: 18px;
color: rgba(181, 207, 225, 0.55);
font-size: 9px;
pointer-events: none;
}
.intel {
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #294158 transparent;
}
.intel-section {
padding: 17px;
border-bottom: 1px solid var(--line);
}
.intel-section:last-child {
border-bottom: 0;
}
.score-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 12px;
}
.score-card {
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.score-card.amber {
border-top: 2px solid var(--amber);
}
.score-card.cyan {
border-top: 2px solid var(--cyan);
}
.score-name {
color: var(--player-color);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.score-value {
margin-top: 8px;
font-size: 19px;
font-weight: 850;
}
.score-value small {
color: var(--muted);
font-size: 11px;
font-weight: 600;
}
.progress-track {
height: 4px;
margin-top: 10px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
.progress-fill {
height: 100%;
border-radius: inherit;
background: var(--player-color);
transition: width 300ms ease;
}
.rulebook {
margin-top: 12px;
}
.rulebook summary {
cursor: pointer;
color: #dcebf7;
font-size: 12px;
font-weight: 800;
}
.rulebook ol {
margin: 13px 0 0;
padding-left: 18px;
color: #a8bbcb;
font-size: 11px;
line-height: 1.55;
}
.rulebook li + li {
margin-top: 7px;
}
.rulebook strong {
color: #e7f4ff;
}
.priority-table {
display: grid;
gap: 5px;
margin: 12px 0;
}
.priority-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 7px 9px;
border-radius: 7px;
background: rgba(255, 255, 255, 0.035);
color: #aec2d2;
font-size: 10px;
}
.priority-row strong {
color: var(--green);
font-size: 10px;
}
.compare-wrap {
display: grid;
gap: 8px;
margin-top: 12px;
}
.compare-card {
padding: 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
transition:
border-color 180ms ease,
background 180ms ease;
}
.compare-card.active {
border-color: rgba(66, 216, 255, 0.35);
background: rgba(66, 216, 255, 0.055);
}
.compare-card header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.compare-card h3 {
margin: 0;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.official-badge {
padding: 3px 5px;
border-radius: 4px;
background: rgba(157, 255, 115, 0.11);
color: var(--green);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.compare-summary {
margin-top: 8px;
color: #dce9f4;
font-size: 11px;
line-height: 1.45;
}
.difference-box {
padding: 10px;
border-left: 2px solid var(--green);
border-radius: 0 8px 8px 0;
background: rgba(157, 255, 115, 0.055);
color: #b9cbd8;
font-size: 10px;
line-height: 1.5;
}
.difference-box.same {
border-left-color: #6d8499;
background: rgba(109, 132, 153, 0.06);
}
.log-list {
display: grid;
gap: 7px;
margin-top: 11px;
}
.log-entry {
padding: 9px 10px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.028);
color: #9eb3c5;
font-size: 10px;
line-height: 1.45;
}
.log-entry strong {
color: #e1eef8;
}
.log-entry.clash {
border-left: 2px solid var(--amber);
}
.log-entry.action {
border-left: 2px solid var(--cyan);
}
.empty-note {
padding: 14px;
border: 1px dashed var(--line);
border-radius: 10px;
color: #6f879b;
font-size: 11px;
line-height: 1.55;
text-align: center;
}
@media (max-width: 1120px) {
.app {
grid-template-columns: 270px minmax(380px, 1fr) 292px;
}
.app-header {
padding: 0 16px;
}
.round-pill {
display: none;
}
}
@media (max-width: 900px) {
body {
overflow: auto;
}
.app-header {
height: 68px;
}
.brand p {
display: none;
}
.app {
height: auto;
grid-template-columns: 1fr;
grid-template-areas:
"view"
"console"
"intel";
}
.viewport {
grid-area: view;
min-height: 590px;
}
.console {
grid-area: console;
}
.intel {
grid-area: intel;
overflow: visible;
}
.console-scroll {
overflow: visible;
}
.camera-note {
display: none;
}
}
@media (max-width: 520px) {
.app {
padding: 8px;
gap: 8px;
}
.app-header {
padding: 0 10px;
}
.brand h1 {
font-size: 15px;
}
.header-actions .ghost-button:first-of-type {
display: none;
}
.viewport {
min-height: 520px;
}
.viewport-hud {
inset: 9px 9px auto;
}
.objective-hud {
display: none;
}
.outcome-banner {
top: 73px;
}
.lens {
bottom: 10px;
}
.lens-label {
display: none;
}
.camera-note {
display: none;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>LOCKSTEP</h1>
<p>Voxel simultaneous tactics</p>
</div>
</div>
<div class="header-actions">
<div class="round-pill">Round <strong id="roundPill">01</strong></div>
<button class="ghost-button" id="resetBtn" type="button">New game</button>
<button class="ghost-button" id="rulesBtn" type="button">Rulebook</button>
</div>
</header>
<main class="app">
<section class="panel console" aria-label="Action console">
<div class="panel-heading">
<p class="eyebrow">Planning console</p>
<h2>Commit both orders</h2>
<p>Each player chooses one order. Nothing happens until both are sealed.</p>
</div>
<div class="console-scroll">
<div class="plan-stack">
<div class="plan-card amber" id="amberPlanCard">
<div class="player-token">A</div>
<div>
<div class="plan-name">Amber</div>
<div class="plan-value" id="amberPlan">Choose an order</div>
</div>
<div class="plan-state" id="amberState">Planning</div>
</div>
<div class="plan-card cyan" id="cyanPlanCard">
<div class="player-token">C</div>
<div>
<div class="plan-name">Cyan</div>
<div class="plan-value" id="cyanPlan">Choose an order</div>
</div>
<div class="plan-state" id="cyanState">Waiting</div>
</div>
</div>
<div class="status-line">
<span class="status-dot" id="statusDot"></span>
<span id="statusText">Amber is planning.</span>
</div>
<div class="action-label">Movement</div>
<div class="dpad" aria-label="Movement controls">
<button class="action-button north" data-action="north" type="button" aria-label="Move north">↑</button>
<button class="action-button west" data-action="west" type="button" aria-label="Move west">←</button>
<button class="action-button east" data-action="east" type="button" aria-label="Move east">→</button>
<button class="action-button south" data-action="south" type="button" aria-label="Move south">↓</button>
</div>
<div class="action-label">Special orders</div>
<div class="utility-actions">
<button class="action-button" data-action="collect" type="button">◆ Collect</button>
<button class="action-button" data-action="exit" type="button">▣ Extract</button>
<button class="action-button wide" data-action="wait" type="button">● Hold position</button>
</div>
<div class="initiative-box">
<span>Initiative tie-break</span>
<strong id="initiativeText">Amber · odd rounds</strong>
</div>
<button class="primary-button" id="primaryBtn" type="button">Choose an order</button>
<button class="demo-button" id="demoBtn" type="button">Load collision drill</button>
<p class="keyboard-note">
Keyboard: arrows move · C collects · X extracts · Space holds
</p>
</div>
</section>
<section class="panel viewport" id="viewport" aria-label="Three-dimensional voxel board">
<div id="scene"></div>
<div class="viewport-hud">
<div class="hud-block">
<span>Hot-seat planning</span>
<strong id="hudRound">Round 01</strong>
</div>
<div class="hud-block objective-hud">
<span>Shared objective</span>
<strong>Collect 2 shards, then extract</strong>
</div>
</div>
<div class="outcome-banner" id="outcomeBanner">
<div class="banner-kicker" id="bannerKicker">Planning phase</div>
<strong id="bannerTitle">Amber chooses first</strong>
<p id="bannerText">Both orders will resolve from the same board snapshot.</p>
</div>
<div class="lens" aria-label="Outcome comparison lens">
<span class="lens-label">Outcome lens</span>
<button class="lens-button active" data-lens="sim" type="button">Simultaneous</button>
<button class="lens-button" data-lens="seq" type="button">Sequential A→B</button>
</div>
<div class="camera-note">Drag to orbit · Wheel to zoom · Click a tile to move</div>
</section>
<aside class="panel intel" aria-label="Game status and official rules">
<section class="intel-section">
<p class="eyebrow">Live status</p>
<h2 class="section-title">Shard inventory</h2>
<div class="score-grid">
<div class="score-card amber">
<div class="score-name">Amber</div>
<div class="score-value" id="amberScore">0 <small>/ 2</small></div>
<div class="progress-track">
<div class="progress-fill" id="amberProgress" style="width: 0%"></div>
</div>
</div>
<div class="score-card cyan">
<div class="score-name">Cyan</div>
<div class="score-value" id="cyanScore">0 <small>/ 2</small></div>
<div class="progress-track">
<div class="progress-fill" id="cyanProgress" style="width: 0%"></div>
</div>
</div>
</div>
</section>
<section class="intel-section" id="rulebookSection">
<p class="eyebrow">Official rulebook v1.0</p>
<h2 class="section-title">Published conflict rule</h2>
<details class="rulebook" open>
<summary>Read the resolution order</summary>
<div class="priority-table" aria-label="Action priority table">
<div class="priority-row"><span>Extract</span><strong>100</strong></div>
<div class="priority-row"><span>Collect</span><strong>90</strong></div>
<div class="priority-row"><span>Hold</span><strong>60</strong></div>
<div class="priority-row"><span>Move</span><strong>40</strong></div>
</div>
<ol>
<li>Both orders resolve from the <strong>same snapshot</strong>.</li>
<li>If orders target one cell, the <strong>higher priority</strong> wins.</li>
<li>Equal priorities go to the round's <strong>initiative player</strong>: Amber on odd rounds, Cyan on even rounds.</li>
<li>A <strong>head-on swap is vetoed</strong>; both players hold position.</li>
<li>Invalid Collect or Extract orders become Hold. Holding also beats a Move into the same cell.</li>
</ol>
</details>
</section>
<section class="intel-section">
<p class="eyebrow">Timeline comparison</p>
<h2 class="section-title">Official vs. sequential</h2>
<div id="compareEmpty" class="empty-note">
Seal both orders and execute the round to compare the official simultaneous outcome with an Amber-first sequential reference.
</div>
<div class="compare-wrap" id="compareWrap" hidden>
<div class="compare-card active" id="simCard">
<header>
<h3>Simultaneous</h3>
<span class="official-badge">Official</span>
</header>
<div class="compare-summary" id="simSummary"></div>
</div>
<div class="compare-card" id="seqCard">
<header>
<h3>Sequential A→B</h3>
<span class="plan-state">Reference</span>
</header>
<div class="compare-summary" id="seqSummary"></div>
</div>
<div class="difference-box" id="differenceBox"></div>
</div>
</section>
<section class="intel-section">
<p class="eyebrow">Resolution feed</p>
<h2 class="section-title">Round events</h2>
<div class="log-list" id="logList">
<div class="log-entry">The board is ready. Build two orders, then execute.</div>
</div>
</section>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and game state
// -------------------------------------------------------------------------
const BOARD_SIZE = 7;
const CELL = 1.08;
const REQUIRED_SHARDS = 2;
const PLAYER_NAMES = ["Amber", "Cyan"];
const ACTIONS = {
north: { type: "move", dx: 0, dz: -1, label: "Move north", glyph: "↑" },
west: { type: "move", dx: -1, dz: 0, label: "Move west", glyph: "←" },
east: { type: "move", dx: 1, dz: 0, label: "Move east", glyph: "→" },
south: { type: "move", dx: 0, dz: 1, label: "Move south", glyph: "↓" },
collect: { type: "collect", label: "Collect shard", glyph: "◆" },
exit: { type: "exit", label: "Extract", glyph: "▣" },
wait: { type: "wait", label: "Hold position", glyph: "●" }
};
const PRIORITY = {
exit: 100,
collect: 90,
hold: 60,
move: 40
};
const PLAYER_COLORS = [0xffb547, 0x42d8ff];
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
function clone(value) {
return JSON.parse(JSON.stringify(value));
}
function sameCell(a, b) {
return a.x === b.x && a.z === b.z;
}
function cellKey(cell) {
return `${cell.x},${cell.z}`;
}
function insideBoard(x, z) {
return x >= 0 && x < BOARD_SIZE && z >= 0 && z < BOARD_SIZE;
}
function actionKey(action) {
if (!action) return "";
if (action.type === "move") {
return `move:${action.dx},${action.dz}`;
}
return action.type;
}
function actionLabel(action) {
if (!action) return "Choose an order";
return `${action.glyph} ${action.label}`;
}
function initialGame() {
return {
players: [
{
id: "amber",
name: "Amber",
color: PLAYER_COLORS[0],
pos: { x: 2, z: 3 },
shards: 0,
won: false
},
{
id: "cyan",
name: "Cyan",
color: PLAYER_COLORS[1],
pos: { x: 4, z: 3 },
shards: 0,
won: false
}
],
crystals: [
{ x: 1, z: 1, active: true },
{ x: 5, z: 1, active: true },
{ x: 1, z: 5, active: true },
{ x: 5, z: 5, active: true },
{ x: 3, z: 1, active: true },
{ x: 3, z: 5, active: true }
],
exit: { x: 3, z: 3 },
winner: null
};
}
const state = {
round: 1,
stage: "amber",
plans: { amber: null, cyan: null },
locked: { amber: false, cyan: false },
game: initialGame(),
result: null,
displayMode: "sim",
history: [],
demo: false
};
function initiativePlayer() {
return state.round % 2 === 1 ? 0 : 1;
}
function activePlayerId() {
return state.stage === "amber" || state.stage === "cyan"
? state.stage
: null;
}
// -------------------------------------------------------------------------
// Official simultaneous resolver
// -------------------------------------------------------------------------
function normalizeAction(action, player, game) {
const pos = { ...player.pos };
if (!action) {
return {
kind: "hold",
target: pos,
source: "wait",
reason: "No order",
label: "Hold"
};
}
if (action.type === "move") {
const target = {
x: pos.x + action.dx,
z: pos.z + action.dz
};
if (!insideBoard(target.x, target.z)) {
return {
kind: "hold",
target: pos,
source: "move",
reason: "Move would leave the board",
label: "Hold"
};
}
return {
kind: "move",
target,
source: "move",
label: action.label
};
}
if (action.type === "collect") {
const hasCrystal = game.crystals.some(
(crystal) =>
crystal.active &&
crystal.x === pos.x &&
crystal.z === pos.z
);
if (!hasCrystal) {
return {
kind: "hold",
target: pos,
source: "collect",
reason: "No shard on this tile",
label: "Hold"
};
}
return {
kind: "collect",
target: pos,
source: "collect",
label: "Collect shard"
};
}
if (action.type === "exit") {
const onExit = sameCell(pos, game.exit);
const enough = player.shards >= REQUIRED_SHARDS;
if (!onExit || !enough) {
return {
kind: "hold",
target: pos,
source: "exit",
reason: !onExit
? "Extract requires the glowing pad"
: `Extract requires ${REQUIRED_SHARDS} shards`,
label: "Hold"
};
}
return {
kind: "exit",
target: pos,
source: "exit",
label: "Extract"
};
}
return {
kind: "hold",
target: pos,
source: "wait",
reason: null,
label: "Hold"
};
}
function resolveSimultaneous(sourceGame, plans, initiative) {
const game = clone(sourceGame);
const actors = [
normalizeAction(plans[0], game.players[0], game),
normalizeAction(plans[1], game.players[1], game)
];
const blocked = [false, false];
const logs = [];
let contest = null;
const isSwap =
actors[0].kind === "move" &&
actors[1].kind === "move" &&
sameCell(actors[0].target, game.players[1].pos) &&
sameCell(actors[1].target, game.players[0].pos);
if (isSwap) {
blocked[0] = true;
blocked[1] = true;
logs.push({
tone: "clash",
title: "Head-on swap vetoed",
detail: "Both Move orders would exchange cells. The published rule blocks both players."
});
} else if (sameCell(actors[0].target, actors[1].target)) {
const priorityDifference =
PRIORITY[actors[0].kind] - PRIORITY[actors[1].kind];
const winner =
priorityDifference > 0
? 0
: priorityDifference < 0
? 1
: initiative;
const loser = winner === 0 ? 1 : 0;
blocked[loser] = true;
const winnerName = game.players[winner].name;
const loserName = game.players[loser].name;
const winnerKind = actors[winner].kind;
const loserKind = actors[loser].kind;
const tieText =
priorityDifference === 0
? `${winnerName} wins the initiative tie-break`
: `${winnerName} wins on priority ${PRIORITY[winnerKind]} vs ${PRIORITY[loserKind]}`;
contest = {
cell: { ...actors[winner].target },
winner,
loser,
reason: tieText
};
logs.push({
tone: "clash",
title: `Target contested at ${cellKey(actors[winner].target)}`,
detail: `${tieText}. ${loserName}'s order is blocked.`
});
}
for (let index = 0; index < 2; index += 1) {
if (blocked[index]) continue;
const actor = actors[index];
const player = game.players[index];
if (actor.kind === "move") {
player.pos = { ...actor.target };
logs.push({
tone: "action",
title: `${player.name} moved`,
detail: `${player.name} advanced to ${cellKey(player.pos)}.`
});
} else if (actor.kind === "collect") {
const crystal = game.crystals.find(
(item) =>
item.active &&
item.x === actor.target.x &&
item.z === actor.target.z
);
if (crystal) {
crystal.active = false;
player.shards += 1;
logs.push({
tone: "action",
title: `${player.name} collected a shard`,
detail: `${player.name} now carries ${player.shards} of ${REQUIRED_SHARDS} shards.`
});
}
} else if (actor.kind === "exit") {
player.won = true;
game.winner = player.id;
logs.push({
tone: "action",
title: `${player.name} extracted`,
detail: `${player.name} reached the pad with the required shards.`
});
} else if (actor.reason) {
logs.push({
tone: "action",
title: `${player.name} held position`,
detail: `${player.name}'s order was invalid: ${actor.reason.toLowerCase()}.`
});
}
}
if (!game.winner) {
logs.push({
tone: "action",
title: "Round complete",
detail: "Both players remain active. The initiative token changes next round."
});
}
return {
state: game,
logs,
contest,
actors
};
}
// -------------------------------------------------------------------------
// Sequential reference: Amber acts, then Cyan, using current occupancy
// -------------------------------------------------------------------------
function applySequentialAction(game, index, action, logs) {
if (game.winner) return;
const player = game.players[index];
const other = game.players[1 - index];
const actor = normalizeAction(action, player, game);
if (actor.kind === "move") {
if (sameCell(actor.target, other.pos)) {
logs.push({
tone: "clash",
title: `${player.name} was blocked`,
detail: `${other.name}'s unit occupied ${cellKey(actor.target)} when ${player.name}'s turn began.`
});
return;
}
player.pos = { ...actor.target };
logs.push({
tone: "action",
title: `${player.name} moved first`,
detail: `${player.name} reached ${cellKey(player.pos)}.`
});
} else if (actor.kind === "collect") {
const crystal = game.crystals.find(
(item) =>
item.active &&
item.x === actor.target.x &&
item.z === actor.target.z
);
if (crystal) {
crystal.active = false;
player.shards += 1;
logs.push({
tone: "action",
title: `${player.name} collected a shard`,
detail: `${player.name} now carries ${player.shards} of ${REQUIRED_SHARDS} shards.`
});
}
} else if (actor.kind === "exit") {
player.won = true;
game.winner = player.id;
logs.push({
tone: "action",
title: `${player.name} extracted`,
detail: `${player.name} completed the objective during their sequential turn.`
});
} else if (actor.reason) {
logs.push({
tone: "action",
title: `${player.name} held position`,
detail: `${player.name}'s order was invalid: ${actor.reason.toLowerCase()}.`
});
}
}
function resolveSequential(sourceGame, plans) {
const game = clone(sourceGame);
const logs = [];
applySequentialAction(game, 0, plans[0], logs);
applySequentialAction(game, 1, plans[1], logs);
logs.push({
tone: "action",
title: "Reference timeline complete",
detail: "This lens is comparison-only. The official game always uses simultaneous resolution."
});
return {
state: game,
logs
};
}
function gameFingerprint(game) {
return JSON.stringify({
winner: game.winner,
players: game.players.map((player) => ({
pos: player.pos,
shards: player.shards,
won: player.won
})),
crystals: game.crystals.map((crystal) => crystal.active)
});
}
function stateSummary(game) {
if (game.winner) {
const winner = game.players.find((player) => player.id === game.winner);
return `${winner.name} extracts and wins the run.`;
}
const amber = game.players[0];
const cyan = game.players[1];
return (
`Amber ${amber.shards}/${REQUIRED_SHARDS} at ${cellKey(amber.pos)} · ` +
`Cyan ${cyan.shards}/${REQUIRED_SHARDS} at ${cellKey(cyan.pos)}`
);
}
function explainDifference(sim, seq) {
const diverged =
gameFingerprint(sim.state) !== gameFingerprint(seq.state);
if (!diverged) {
return {
same: true,
text:
"Both timelines agree. The contested order did not change the final board or winner."
};
}
if (sim.contest) {
const cell = cellKey(sim.contest.cell);
const winner = sim.state.players[sim.contest.winner].name;
return {
same: false,
text:
`Divergence at ${cell}: the official simultaneous rule awards the cell to ${winner}. ` +
`In the sequential reference, Amber acts first, so occupancy changes before Cyan resolves.`
};
}
return {
same: false,
text:
"The timelines diverge. Simultaneous orders use one shared snapshot and the published priority rule; sequential turns update occupancy after every action."
};
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const viewport = $("#viewport");
const sceneHost = $("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x081321);
scene.fog = new THREE.Fog(0x081321, 17, 30);
const camera = new THREE.PerspectiveCamera(
43,
1,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const ambient = new THREE.AmbientLight(0x8ab9d8, 1.25);
scene.add(ambient);
const hemisphere = new THREE.HemisphereLight(
0xb9eaff,
0x162033,
2.0
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(6, 12, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x42d8ff, 18, 16, 2);
rimLight.position.set(-6, 5, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb547, 13, 13, 2);
warmLight.position.set(6, 4, 4);
scene.add(warmLight);
function cellToWorld(x, z, y = 0) {
return new THREE.Vector3(
(x - (BOARD_SIZE - 1) / 2) * CELL,
y,
(z - (BOARD_SIZE - 1) / 2) * CELL
);
}
const boardGroup = new THREE.Group();
scene.add(boardGroup);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x0c1b2a,
roughness: 0.8,
metalness: 0.18
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(
BOARD_SIZE * CELL + 0.64,
0.5,
BOARD_SIZE * CELL + 0.64
),
baseMaterial
);
base.position.y = -0.29;
base.receiveShadow = true;
boardGroup.add(base);
const underglow = new THREE.Mesh(
new THREE.BoxGeometry(
BOARD_SIZE * CELL + 0.76,
0.08,
BOARD_SIZE * CELL + 0.76
),
new THREE.MeshBasicMaterial({
color: 0x1a89a6,
transparent: true,
opacity: 0.1
})
);
underglow.position.y = -0.56;
boardGroup.add(underglow);
const tileMeshes = [];
const tileGeometry = new THREE.BoxGeometry(CELL - 0.09, 0.14, CELL - 0.09);
for (let z = 0; z < BOARD_SIZE; z += 1) {
for (let x = 0; x < BOARD_SIZE; x += 1) {
const isCenter = x === 3 && z === 3;
const isCheck = (x + z) % 2 === 0;
const material = new THREE.MeshStandardMaterial({
color: isCenter
? 0x213a50
: isCheck
? 0x14283b
: 0x102237,
roughness: 0.72,
metalness: 0.16,
emissive: isCenter ? 0x0a2730 : 0x000000,
emissiveIntensity: isCenter ? 0.5 : 0
});
const tile = new THREE.Mesh(tileGeometry, material);
tile.position.copy(cellToWorld(x, z, 0));
tile.receiveShadow = true;
tile.userData.cell = { x, z };
tile.userData.baseMaterial = material;
tileMeshes.push(tile);
boardGroup.add(tile);
}
}
// Decorative perimeter voxels.
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0x1d3a50,
roughness: 0.55,
metalness: 0.35
});
const edgeGeometry = new THREE.BoxGeometry(0.28, 0.42, 0.28);
for (let i = 0; i < BOARD_SIZE; i += 1) {
const offset = (i - 3) * CELL;
const half = (BOARD_SIZE * CELL) / 2 + 0.28;
const positions = [
[offset, -0.15, -half],
[offset, -0.15, half],
[-half, -0.15, offset],
[half, -0.15, offset]
];
positions.forEach(([x, y, z], index) => {
const post = new THREE.Mesh(edgeGeometry, edgeMaterial);
post.position.set(x, y + (index % 2 ? 0.05 : 0), z);
post.castShadow = true;
boardGroup.add(post);
});
}
// Extraction pad.
const exitGroup = new THREE.Group();
exitGroup.position.copy(cellToWorld(3, 3, 0.1));
scene.add(exitGroup);
const padMaterial = new THREE.MeshBasicMaterial({
color: 0x9dff73,
transparent: true,
opacity: 0.18,
depthWrite: false
});
const pad = new THREE.Mesh(
new THREE.BoxGeometry(0.88, 0.035, 0.88),
padMaterial
);
exitGroup.add(pad);
const padEdgeMaterial = new THREE.MeshBasicMaterial({
color: 0x9dff73,
transparent: true,
opacity: 0.75
});
[
[-0.4, -0.4],
[0.4, -0.4],
[-0.4, 0.4],
[0.4, 0.4]
].forEach(([x, z]) => {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.18, 0.18),
padEdgeMaterial
);
marker.position.set(x, 0.11, z);
exitGroup.add(marker);
});
const exitBeam = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 1.35, 0.48),
new THREE.MeshBasicMaterial({
color: 0x9dff73,
transparent: true,
opacity: 0.055,
depthWrite: false
})
);
exitBeam.position.y = 0.68;
exitGroup.add(exitBeam);
// Shards.
const crystalGroups = [];
gameShards: {
for (const crystal of state.game.crystals) {
const group = new THREE.Group();
group.position.copy(cellToWorld(crystal.x, crystal.z, 0.13));
const coreMaterial = new THREE.MeshStandardMaterial({
color: 0xa8ff7c,
emissive: 0x59d94f,
emissiveIntensity: 1.8,
roughness: 0.25,
metalness: 0.1
});
const core = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.28, 0.28),
coreMaterial
);
core.position.y = 0.48;
core.castShadow = true;
group.add(core);
const satelliteGeometry = new THREE.BoxGeometry(0.11, 0.11, 0.11);
[
[-0.24, 0.31, 0],
[0.24, 0.31, 0],
[0, 0.31, -0.24],
[0, 0.31, 0.24]
].forEach((position) => {
const satellite = new THREE.Mesh(
satelliteGeometry,
coreMaterial
);
satellite.position.set(...position);
group.add(satellite);
});
const glow = new THREE.Mesh(
new THREE.BoxGeometry(0.65, 0.08, 0.65),
new THREE.MeshBasicMaterial({
color: 0x73ff62,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
glow.position.y = 0.05;
group.add(glow);
scene.add(group);
crystalGroups.push({ group, crystal });
}
break gameShards;
}
function createLabelSprite(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, 128, 128);
context.fillStyle = color;
context.beginPath();
context.roundRect(18, 18, 92, 92, 18);
context.fill();
context.strokeStyle = "rgba(255,255,255,0.65)";
context.lineWidth = 7;
context.stroke();
context.fillStyle = "#07101c";
context.font = "900 62px system-ui";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 64, 68);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.52, 0.52, 0.52);
return sprite;
}
function createRobot(index) {
const color = PLAYER_COLORS[index];
const group = new THREE.Group();
const model = new THREE.Group();
group.add(model);
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.42,
metalness: 0.18,
emissive: color,
emissiveIntensity: 0.08
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x142131,
roughness: 0.65,
metalness: 0.25
});
const glowMaterial = new THREE.MeshBasicMaterial({
color: index === 0 ? 0xffe2a8 : 0xc4f7ff
});
const body = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.5, 0.48),
bodyMaterial
);
body.position.y = 0.36;
body.castShadow = true;
model.add(body);
const head = new THREE.Mesh(
new THREE.BoxGeometry(0.37, 0.31, 0.37),
darkMaterial
);
head.position.y = 0.79;
head.castShadow = true;
model.add(head);
const visor = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.09, 0.025),
glowMaterial
);
visor.position.set(0, 0.8, -0.19);
model.add(visor);
const antenna = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.2, 0.055),
bodyMaterial
);
antenna.position.y = 1.03;
model.add(antenna);
const antennaTip = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.09, 0.09),
glowMaterial
);
antennaTip.position.y = 1.15;
model.add(antennaTip);
const leftFoot = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.12, 0.27),
darkMaterial
);
leftFoot.position.set(-0.14, 0.08, 0);
leftFoot.castShadow = true;
model.add(leftFoot);
const rightFoot = leftFoot.clone();
rightFoot.position.x = 0.14;
model.add(rightFoot);
const label = createLabelSprite(index === 0 ? "A" : "C", index === 0 ? "#ffb547" : "#42d8ff");
label.position.y = 1.48;
group.add(label);
group.userData.model = model;
group.userData.target = new THREE.Vector3();
scene.add(group);
return group;
}
const robots = [createRobot(0), createRobot(1)];
// Selection ghost and directional order arrow.
const ghost = new THREE.Mesh(
new THREE.BoxGeometry(0.78, 0.13, 0.78),
new THREE.MeshBasicMaterial({
color: 0x42d8ff,
transparent: true,
opacity: 0.25,
depthWrite: false
})
);
ghost.visible = false;
scene.add(ghost);
const selectionWire = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(0.79, 0.14, 0.79)
),
new THREE.LineBasicMaterial({
color: 0x42d8ff,
transparent: true,
opacity: 0.9
})
);
ghost.add(selectionWire);
const orderArrow = new THREE.Group();
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x42d8ff,
transparent: true,
opacity: 0.9
});
const arrowShaft = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.09, 0.42),
arrowMaterial
);
arrowShaft.position.z = 0.25;
orderArrow.add(arrowShaft);
const arrowLeft = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.09, 0.19),
arrowMaterial
);
arrowLeft.position.set(-0.12, 0, 0.49);
arrowLeft.rotation.y = -0.55;
orderArrow.add(arrowLeft);
const arrowRight = arrowLeft.clone();
arrowRight.position.x = 0.12;
arrowRight.rotation.y = 0.55;
orderArrow.add(arrowRight);
orderArrow.visible = false;
scene.add(orderArrow);
const hoverTile = new THREE.Mesh(
new THREE.BoxGeometry(0.99, 0.16, 0.99),
new THREE.MeshBasicMaterial({
color: 0x9bdcff,
transparent: true,
opacity: 0.08,
depthWrite: false
})
);
hoverTile.visible = false;
scene.add(hoverTile);
// Custom orbit controls; no addon modules are used.
const cameraState = {
theta: 0.72,
phi: 0.77,
radius: 12.5
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
camera.position.set(
radius * Math.sin(phi) * Math.sin(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(0, 0.1, 0);
}
updateCamera();
const pointer = {
down: false,
moved: false,
x: 0,
y: 0,
startX: 0,
startY: 0
};
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
function raycastTile(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
return raycaster.intersectObjects(tileMeshes, false)[0];
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointer.down = true;
pointer.moved = false;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointer.down) {
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
if (
Math.abs(event.clientX - pointer.startX) +
Math.abs(event.clientY - pointer.startY) >
5
) {
pointer.moved = true;
}
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.16
);
updateCamera();
pointer.x = event.clientX;
pointer.y = event.clientY;
} else {
const hit = raycastTile(event);
hoverTile.visible = Boolean(hit);
if (hit) {
hoverTile.position.copy(
cellToWorld(hit.object.userData.cell.x, hit.object.userData.cell.z, 0.01)
);
}
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointer.down) return;
pointer.down = false;
if (!pointer.moved && activePlayerId()) {
const hit = raycastTile(event);
if (hit) {
const target = hit.object.userData.cell;
const player = state.game.players.find(
(playerItem) => playerItem.id === activePlayerId()
);
const dx = target.x - player.pos.x;
const dz = target.z - player.pos.z;
if (Math.abs(dx) + Math.abs(dz) === 1) {
const key =
dx === 1
? "east"
: dx === -1
? "west"
: dz === 1
? "south"
: "north";
chooseAction(key);
}
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointerleave", () => {
hoverTile.visible = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
8.5,
18
);
updateCamera();
},
{ passive: false }
);
function resizeRenderer() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
new ResizeObserver(resizeRenderer).observe(viewport);
resizeRenderer();
function setDisplayedState(game) {
game.players.forEach((player, index) => {
const robot = robots[index];
robot.userData.target.copy(
cellToWorld(player.pos.x, player.pos.z, 0.08)
);
});
game.crystals.forEach((crystal, index) => {
crystalGroups[index].group.visible = crystal.active;
});
}
function snapRobotsToDisplayedState(game) {
game.players.forEach((player, index) => {
robots[index].position.copy(
cellToWorld(player.pos.x, player.pos.z, 0.08)
);
});
}
function updateSelectionPreview() {
const activeId = activePlayerId();
ghost.visible = false;
orderArrow.visible = false;
if (!activeId) return;
const action = state.plans[activeId];
if (!action) return;
const player = state.game.players.find(
(playerItem) => playerItem.id === activeId
);
const color = player.color;
ghost.material.color.setHex(color);
selectionWire.material.color.setHex(color);
arrowMaterial.color.setHex(color);
let target = null;
if (action.type === "move") {
target = {
x: player.pos.x + action.dx,
z: player.pos.z + action.dz
};
if (!insideBoard(target.x, target.z)) {
target = null;
}
} else if (action.type === "collect") {
const hasCrystal = state.game.crystals.some(
(crystal) =>
crystal.active &&
crystal.x === player.pos.x &&
crystal.z === player.pos.z
);
if (hasCrystal) target = { ...player.pos };
} else if (action.type === "exit") {
if (
sameCell(player.pos, state.game.exit) &&
player.shards >= REQUIRED_SHARDS
) {
target = { ...state.game.exit };
}
}
if (target) {
ghost.position.copy(cellToWorld(target.x, target.z, 0.1));
ghost.visible = true;
}
if (action.type === "move" && target) {
orderArrow.position.copy(
cellToWorld(player.pos.x, player.pos.z, 0.18)
);
orderArrow.rotation.y = Math.atan2(action.dx, action.dz);
orderArrow.visible = true;
}
}
// -------------------------------------------------------------------------
// UI and interaction
// -------------------------------------------------------------------------
function chooseAction(key) {
const activeId = activePlayerId();
if (!activeId) return;
state.plans[activeId] = { ...ACTIONS[key] };
updateSelectionPreview();
renderUI();
}
function sealCurrentPlan() {
if (state.stage === "amber") {
state.locked.amber = true;
state.stage = "cyan";
} else if (state.stage === "cyan") {
state.locked.cyan = true;
state.stage = "ready";
}
renderUI();
}
function executeRound() {
if (state.stage !== "ready") return;
const sim = resolveSimultaneous(
state.game,
[state.plans.amber, state.plans.cyan],
initiativePlayer()
);
const seq = resolveSequential(
state.game,
[state.plans.amber, state.plans.cyan]
);
const difference = explainDifference(sim, seq);
state.result = { sim, seq, difference };
state.game = clone(sim.state);
state.stage = "result";
state.displayMode = "sim";
setDisplayedState(state.game);
state.history.unshift({
round: state.round,
title: difference.same
? "Timelines agreed"
: "Timelines diverged",
detail: difference.text
});
state.history = state.history.slice(0, 8);
renderUI();
}
function nextRound() {
if (state.game.winner) {
resetGame();
return;
}
state.round += 1;
state.stage = "amber";
state.plans = { amber: null, cyan: null };
state.locked = { amber: false, cyan: false };
state.result = null;
state.displayMode = "sim";
state.demo = false;
setDisplayedState(state.game);
updateSelectionPreview();
renderUI();
}
function resetGame() {
state.round = 1;
state.stage = "amber";
state.plans = { amber: null, cyan: null };
state.locked = { amber: false, cyan: false };
state.game = initialGame();
state.result = null;
state.displayMode = "sim";
state.history = [];
state.demo = false;
snapRobotsToDisplayedState(state.game);
updateSelectionPreview();
renderUI();
}
function loadCollisionDrill() {
state.round = 2;
state.stage = "ready";
state.plans = {
amber: { ...ACTIONS.east },
cyan: { ...ACTIONS.west }
};
state.locked = { amber: true, cyan: true };
state.game = initialGame();
state.result = null;
state.displayMode = "sim";
state.demo = true;
state.history = [
{
round: 2,
title: "Collision drill loaded",
detail:
"Amber and Cyan both target the center. Cyan has even-round initiative; the sequential reference gives Amber first occupancy."
}
];
snapRobotsToDisplayedState(state.game);
updateSelectionPreview();
renderUI();
}
function setLens(mode) {
if (!state.result) return;
state.displayMode = mode;
const game =
mode === "sim" ? state.result.sim.state : state.result.seq.state;
setDisplayedState(game);
renderUI();
}
$$("[data-action]").forEach((button) => {
button.addEventListener("click", () => {
chooseAction(button.dataset.action);
});
});
$("#primaryBtn").addEventListener("click", () => {
if (state.stage === "amber" || state.stage === "cyan") {
sealCurrentPlan();
} else if (state.stage === "ready") {
executeRound();
} else if (state.stage === "result") {
nextRound();
}
});
$("#resetBtn").addEventListener("click", resetGame);
$("#demoBtn").addEventListener("click", loadCollisionDrill);
$("#rulesBtn").addEventListener("click", () => {
$("#rulebookSection").scrollIntoView({
behavior: "smooth",
block: "center"
});
});
$$("[data-lens]").forEach((button) => {
button.addEventListener("click", () => {
setLens(button.dataset.lens);
});
});
window.addEventListener("keydown", (event) => {
const activeId = activePlayerId();
if (!activeId) return;
const keyMap = {
ArrowUp: "north",
ArrowLeft: "west",
ArrowRight: "east",
ArrowDown: "south"
};
if (keyMap[event.key]) {
event.preventDefault();
chooseAction(keyMap[event.key]);
} else if (event.key.toLowerCase() === "c") {
chooseAction("collect");
} else if (event.key.toLowerCase() === "x") {
chooseAction("exit");
} else if (event.code === "Space") {
event.preventDefault();
chooseAction("wait");
}
});
function renderPlanCard(id) {
const action = state.plans[id];
const locked = state.locked[id];
const active = activePlayerId() === id;
$(`#${id}Plan`).textContent = actionLabel(action);
$(`#${id}State`).textContent = locked
? "Sealed"
: active
? "Planning"
: "Waiting";
$(`#${id}PlanCard`).classList.toggle("active", active);
}
function renderComparison() {
const hasResult = Boolean(state.result);
$("#compareEmpty").hidden = hasResult;
$("#compareWrap").hidden = !hasResult;
if (!hasResult) return;
const { sim, seq, difference } = state.result;
$("#simSummary").textContent = stateSummary(sim.state);
$("#seqSummary").textContent = stateSummary(seq.state);
$("#simCard").classList.toggle(
"active",
state.displayMode === "sim"
);
$("#seqCard").classList.toggle(
"active",
state.displayMode === "seq"
);
$("#differenceBox").textContent = difference.text;
$("#differenceBox").classList.toggle("same", difference.same);
}
function renderLogs() {
const container = $("#logList");
container.innerHTML = "";
const entries = [];
if (state.result) {
state.result.sim.logs.forEach((log) => {
entries.push({
tone: log.tone,
title: `R${state.round} · ${log.title}`,
detail: log.detail
});
});
}
state.history.slice(0, 4).forEach((entry) => {
entries.push({
tone: entry.title === "Timelines diverged" ? "clash" : "action",
title: entry.title,
detail: entry.detail
});
});
if (!entries.length) {
entries.push({
tone: "action",
title: "The board is ready",
detail: "Build two orders, then execute the simultaneous round."
});
}
entries.slice(0, 9).forEach((entry) => {
const item = document.createElement("div");
item.className = `log-entry ${entry.tone}`;
item.innerHTML = `<strong>${entry.title}</strong><br>${entry.detail}`;
container.appendChild(item);
});
}
function renderUI() {
const activeId = activePlayerId();
const planning = Boolean(activeId);
$("#roundPill").textContent = String(state.round).padStart(2, "0");
$("#hudRound").textContent = `Round ${String(state.round).padStart(2, "0")}`;
renderPlanCard("amber");
renderPlanCard("cyan");
const initiative = initiativePlayer();
$("#initiativeText").textContent =
`${PLAYER_NAMES[initiative]} · ${state.round % 2 ? "odd" : "even"} rounds`;
const activeColor =
activeId === "amber" ? "#ffb547" : "#42d8ff";
$("#statusDot").style.background = activeColor;
$("#statusDot").style.boxShadow = `0 0 13px ${activeColor}`;
if (state.stage === "amber") {
$("#statusText").textContent = "Amber is choosing an order.";
$("#bannerKicker").textContent = "Planning phase";
$("#bannerTitle").textContent = "Amber chooses first";
$("#bannerText").textContent =
"Both orders will resolve from the same board snapshot.";
} else if (state.stage === "cyan") {
$("#statusText").textContent = "Amber is sealed. Cyan is choosing an order.";
$("#bannerKicker").textContent = "Planning phase";
$("#bannerTitle").textContent = "Cyan chooses second";
$("#bannerText").textContent =
"Cyan can plan without changing Amber's committed order.";
} else if (state.stage === "ready") {
$("#statusText").textContent = "Both orders are sealed and ready.";
$("#bannerKicker").textContent = "Ready to execute";
$("#bannerTitle").textContent = "Both plans are committed";
$("#bannerText").textContent =
"The official simultaneous resolver will now apply priority, initiative and swap vetoes.";
} else {
$("#statusText").textContent =
state.game.winner
? "The run is complete."
: "Round resolved. Inspect either timeline before continuing.";
$("#bannerKicker").textContent = state.game.winner
? "Run complete"
: "Round resolved";
const winner = state.game.players.find(
(player) => player.id === state.game.winner
);
$("#bannerTitle").textContent = winner
? `${winner.name} extracts with the core`
: state.demo
? "Collision resolved — compare the lenses"
: "Both timelines are available";
$("#bannerText").textContent = winner
? "The simultaneous outcome is official. Inspect the sequential reference for comparison."
: "Use the outcome lens to switch between the official result and Amber-first reference.";
}
const primary = $("#primaryBtn");
primary.disabled = false;
if (state.stage === "amber") {
primary.textContent = state.plans.amber
? "Seal Amber order →"
: "Choose Amber's order";
primary.disabled = !state.plans.amber;
} else if (state.stage === "cyan") {
primary.textContent = state.plans.cyan
? "Seal Cyan order →"
: "Choose Cyan's order";
primary.disabled = !state.plans.cyan;
} else if (state.stage === "ready") {
primary.textContent = "Execute simultaneous round";
} else {
primary.textContent = state.game.winner
? "Start a new run"
: "Plan the next round";
}
$$("[data-action]").forEach((button) => {
const selected =
planning &&
actionKey(state.plans[activeId]) === button.dataset.action;
button.disabled = !planning;
button.classList.toggle("selected", selected);
button.style.setProperty(
"--active-color",
activeId === "amber" ? "#ffb547" : "#42d8ff"
);
});
const amber = state.game.players[0];
const cyan = state.game.players[1];
$("#amberScore").innerHTML =
`${amber.shards} <small>/ ${REQUIRED_SHARDS}</small>`;
$("#cyanScore").innerHTML =
`${cyan.shards} <small>/ ${REQUIRED_SHARDS}</small>`;
$("#amberProgress").style.width =
`${Math.min(100, (amber.shards / REQUIRED_SHARDS) * 100)}%`;
$("#cyanProgress").style.width =
`${Math.min(100, (cyan.shards / REQUIRED_SHARDS) * 100)}%`;
$$("[data-lens]").forEach((button) => {
button.classList.toggle(
"active",
button.dataset.lens === state.displayMode
);
button.disabled = !state.result;
});
renderComparison();
renderLogs();
}
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
robots.forEach((robot, index) => {
robot.position.lerp(
robot.userData.target,
1 - Math.exp(-delta * 8)
);
robot.userData.model.position.y =
Math.sin(elapsed * 2.8 + index * 1.7) * 0.035;
robot.userData.model.rotation.y =
Math.sin(elapsed * 0.8 + index) * 0.025;
});
crystalGroups.forEach(({ group }, index) => {
group.rotation.y = elapsed * 0.65 + index * 0.6;
group.position.y =
0.13 + Math.sin(elapsed * 2.2 + index * 0.8) * 0.045;
});
exitBeam.material.opacity =
0.045 + Math.sin(elapsed * 2.5) * 0.018;
padMaterial.opacity =
0.15 + Math.sin(elapsed * 2.5) * 0.045;
if (ghost.visible) {
ghost.material.opacity =
0.18 + Math.sin(elapsed * 4) * 0.055;
}
if (orderArrow.visible) {
orderArrow.position.y =
0.18 + Math.sin(elapsed * 4) * 0.025;
}
renderer.render(scene, camera);
}
snapRobotsToDisplayedState(state.game);
updateSelectionPreview();
renderUI();
animate();
</script>
</body>
</html>
```