Prompt specification
Build or customize the Three.js 3D scene "Move Then Collect Versus Collect Then Move" 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: Move Then Collect Versus Collect Then Move
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/move-then-collect-versus-collect-then-move-x3590
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts turn order and competing simultaneous moves. Create a tiny strategy board where action order changes which resource is reachable. Execute each legal sequence from the same initial state and compare outcomes. Low-poly.
Working Three.js Starter (move-then-collect-versus-collect-then-move-x3590):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Crosscut — Simultaneous Turn Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(12, 23, 34, 0.92);
--panel-strong: #0d1a27;
--line: rgba(159, 190, 211, 0.15);
--text: #edf6fb;
--muted: #8298a8;
--cyan: #56d9f5;
--cyan-soft: rgba(86, 217, 245, 0.14);
--orange: #ff9a55;
--orange-soft: rgba(255, 154, 85, 0.14);
--gold: #ffd479;
--green: #80e6ad;
--danger: #ff6e73;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
grid-template-rows: 66px minmax(0, 1fr);
width: 100%;
height: 100%;
}
header {
grid-column: 1 / -1;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(6, 14, 22, 0.96);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 34px;
height: 34px;
flex: 0 0 auto;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 3px;
border: 1px solid var(--cyan);
transform: rotate(45deg);
}
.brand-mark::after {
inset: 9px;
border-color: var(--orange);
background: rgba(255, 154, 85, 0.15);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.brand h1 {
margin: 1px 0 0;
font-size: 18px;
line-height: 1;
letter-spacing: 0.035em;
font-weight: 760;
}
.header-note {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 18px;
color: var(--muted);
font-size: 11px;
}
.header-note strong {
color: var(--text);
font-weight: 650;
}
.live-dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 14px var(--green);
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 45% 35%, #142837 0, #091722 43%, #060d14 100%);
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.brief {
position: absolute;
top: 20px;
left: 20px;
width: 272px;
padding: 17px 18px;
border: 1px solid var(--line);
border-radius: 14px;
background: linear-gradient(145deg, rgba(15, 29, 42, 0.92), rgba(8, 17, 26, 0.84));
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
pointer-events: none;
}
.brief-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.brief-title span:last-child {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
}
.brief p {
margin: 0;
color: #b5c5cf;
font-size: 12px;
line-height: 1.58;
}
.rule-row {
display: flex;
gap: 9px;
align-items: flex-start;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #9eb2bf;
font-size: 11px;
line-height: 1.45;
}
.rule-row b {
color: var(--text);
font-weight: 700;
}
.mini-icon {
display: grid;
place-items: center;
width: 21px;
height: 21px;
flex: 0 0 auto;
border-radius: 6px;
background: var(--cyan-soft);
color: var(--cyan);
font-size: 10px;
font-weight: 900;
}
.mini-icon.orange {
background: var(--orange-soft);
color: var(--orange);
}
.stage-status {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
min-width: 310px;
max-width: calc(100% - 610px);
padding: 11px 18px;
border: 1px solid rgba(86, 217, 245, 0.2);
border-radius: 999px;
background: rgba(8, 18, 28, 0.86);
text-align: center;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(10px);
pointer-events: none;
}
.stage-status .status-kicker {
display: block;
margin-bottom: 3px;
color: var(--cyan);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.stage-status strong {
display: block;
overflow: hidden;
color: #dcebf2;
font-size: 11px;
font-weight: 650;
text-overflow: ellipsis;
white-space: nowrap;
}
.stage-status.running {
border-color: rgba(255, 212, 121, 0.36);
}
.stage-status.running .status-kicker {
color: var(--gold);
}
.legend {
position: absolute;
right: 20px;
top: 20px;
display: flex;
gap: 8px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(8, 17, 26, 0.78);
color: #a7bac6;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 2px;
transform: rotate(45deg);
}
.legend-dot.a {
background: var(--cyan);
box-shadow: 0 0 9px rgba(86, 217, 245, 0.65);
}
.legend-dot.e {
background: var(--orange);
box-shadow: 0 0 9px rgba(255, 154, 85, 0.65);
}
.view-hint {
position: absolute;
left: 20px;
bottom: 104px;
color: rgba(177, 197, 209, 0.65);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.timeline-shell {
position: absolute;
left: 20px;
right: 20px;
bottom: 18px;
display: grid;
grid-template-columns: minmax(170px, 0.9fr) minmax(320px, 1.4fr) minmax(170px, 0.9fr);
gap: 12px;
align-items: stretch;
pointer-events: none;
}
.timeline-card {
min-height: 66px;
padding: 11px 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(8, 18, 28, 0.87);
box-shadow: 0 14px 38px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(10px);
}
.timeline-card h3 {
margin: 0 0 8px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#event-text {
color: #c9d7df;
font-size: 11px;
line-height: 1.45;
}
#beats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.beat {
position: relative;
padding: 9px 8px;
border: 1px solid rgba(145, 172, 190, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.025);
transition: 180ms ease;
}
.beat.active {
border-color: rgba(255, 212, 121, 0.65);
background: rgba(255, 212, 121, 0.08);
box-shadow: inset 0 0 18px rgba(255, 212, 121, 0.035);
}
.beat.complete {
border-color: rgba(128, 230, 173, 0.25);
}
.beat-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 7px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.beat-order {
display: flex;
align-items: center;
justify-content: center;
gap: 5px;
font-size: 9px;
font-weight: 800;
}
.beat-order .a {
color: var(--cyan);
}
.beat-order .e {
color: var(--orange);
}
.beat-order .arrow {
color: #4f6473;
font-size: 9px;
}
.timeline-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.same-state {
display: flex;
align-items: center;
gap: 7px;
color: #9fb3bf;
font-size: 9px;
line-height: 1.3;
}
.same-state i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 10px rgba(128, 230, 173, 0.7);
}
.score-mini {
text-align: right;
white-space: nowrap;
}
.score-mini strong {
display: block;
font-size: 12px;
}
.score-mini span {
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
aside {
min-height: 0;
overflow-y: auto;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(14, 27, 40, 0.98), rgba(8, 17, 26, 0.98));
scrollbar-width: thin;
scrollbar-color: #263b4a transparent;
}
.side-section {
padding: 20px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.section-heading h2 {
margin: 0;
font-size: 13px;
font-weight: 780;
letter-spacing: 0.015em;
}
.section-heading p {
margin: 3px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.counter {
padding: 4px 7px;
border: 1px solid rgba(86, 217, 245, 0.2);
border-radius: 6px;
background: var(--cyan-soft);
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.plan-note {
margin: 0 0 13px;
padding: 10px 11px;
border: 1px solid rgba(145, 172, 190, 0.11);
border-radius: 8px;
background: rgba(255, 255, 255, 0.025);
color: #8fa5b3;
font-size: 10px;
line-height: 1.5;
}
.plan-note strong {
color: #c5d4dd;
}
#sequence-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.sequence-button {
position: relative;
min-height: 55px;
padding: 9px 10px;
border: 1px solid rgba(145, 172, 190, 0.13);
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
color: var(--text);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.sequence-button:hover {
border-color: rgba(86, 217, 245, 0.38);
background: rgba(86, 217, 245, 0.055);
transform: translateY(-1px);
}
.sequence-button.selected {
border-color: rgba(86, 217, 245, 0.7);
background: linear-gradient(135deg, rgba(86, 217, 245, 0.12), rgba(86, 217, 245, 0.035));
box-shadow: inset 3px 0 0 var(--cyan);
}
.sequence-button .seq-code {
display: block;
margin-bottom: 5px;
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.11em;
}
.sequence-button .seq-name {
display: block;
color: #8fa5b3;
font-size: 8px;
line-height: 1.25;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.action-button {
min-height: 39px;
padding: 9px 10px;
border: 1px solid rgba(145, 172, 190, 0.18);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: #c7d6df;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
.action-button:hover {
border-color: rgba(255, 255, 255, 0.32);
background: rgba(255, 255, 255, 0.075);
}
.action-button.primary {
border-color: rgba(86, 217, 245, 0.6);
background: var(--cyan);
color: #06131b;
}
.action-button.primary:hover {
background: #79e5fb;
}
.action-button.stop {
border-color: rgba(255, 110, 115, 0.65);
background: rgba(255, 110, 115, 0.12);
color: #ff9da1;
}
.result-card {
padding: 14px;
border: 1px solid rgba(145, 172, 190, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.result-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.result-code {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.12em;
}
.result-winner {
padding: 4px 7px;
border-radius: 5px;
background: rgba(128, 230, 173, 0.1);
color: var(--green);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.result-description {
color: #a7bac6;
font-size: 11px;
line-height: 1.48;
}
.resource-readout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.resource-chip {
padding: 8px 9px;
border: 1px solid rgba(145, 172, 190, 0.11);
border-radius: 7px;
background: rgba(0, 0, 0, 0.12);
}
.resource-chip span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 7px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.resource-chip strong {
color: #d7e5ec;
font-size: 10px;
font-weight: 720;
}
.resource-chip.frost strong {
color: var(--cyan);
}
.resource-chip.ore strong {
color: var(--orange);
}
.comparison-wrap {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 9px;
}
th {
padding: 7px 6px;
border-bottom: 1px solid var(--line);
color: #667e8e;
font-size: 7px;
font-weight: 850;
letter-spacing: 0.11em;
text-align: left;
text-transform: uppercase;
}
td {
padding: 8px 6px;
border-bottom: 1px solid rgba(145, 172, 190, 0.08);
color: #91a6b3;
white-space: nowrap;
}
td.code {
color: #c9d8df;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 800;
}
td.owner-a {
color: var(--cyan);
}
td.owner-e {
color: var(--orange);
}
td.winner {
color: var(--green);
font-weight: 800;
}
tr.selected-row td {
background: rgba(86, 217, 245, 0.045);
}
.table-foot {
margin: 10px 0 0;
color: #617987;
font-size: 9px;
line-height: 1.45;
}
@media (max-width: 1050px) {
#app {
grid-template-columns: minmax(0, 1fr) 340px;
}
.brief {
width: 235px;
}
.legend {
display: none;
}
.stage-status {
left: auto;
right: 18px;
transform: none;
max-width: 340px;
}
}
@media (max-width: 780px) {
html,
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100%;
grid-template-columns: 1fr;
grid-template-rows: 66px 62vh auto;
}
header {
padding: 0 15px;
}
.header-note {
display: none;
}
#stage {
min-height: 500px;
}
aside {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.brief {
display: none;
}
.stage-status {
top: 14px;
left: 14px;
right: 14px;
min-width: 0;
max-width: none;
}
.timeline-shell {
left: 12px;
right: 12px;
bottom: 12px;
grid-template-columns: 1fr;
}
.timeline-card:first-child,
.timeline-card:last-child {
display: none;
}
.view-hint {
bottom: 96px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="eyebrow">Simultaneous-turn laboratory</div>
<h1>CROSSCUT / 01</h1>
</div>
</div>
<div class="header-note">
<span><span class="live-dot"></span>Deterministic replay</span>
<span><strong>8</strong> legal priority schedules</span>
<span><strong>1</strong> shared initial state</span>
</div>
</header>
<main id="stage">
<canvas id="scene" aria-label="Interactive low-poly strategy board"></canvas>
<section class="brief">
<div class="brief-title">
<span>Scenario</span>
<span>Two couriers · one relay</span>
</div>
<p>
AXIOM and EMBER submit the same three-beat route. Both moves are
simultaneous; only the priority order changes.
</p>
<div class="rule-row">
<span class="mini-icon">A</span>
<span><b>First mover</b> occupies the central relay before the other courier.</span>
</div>
<div class="rule-row">
<span class="mini-icon orange">E</span>
<span><b>FROST is worth 5.</b> If it is occupied, the second courier may be diverted to ORE.</span>
</div>
</section>
<div class="stage-status" id="stage-status">
<span class="status-kicker" id="status-kicker">Ready for execution</span>
<strong id="status-main">Choose a priority schedule, then replay it.</strong>
</div>
<div class="legend">
<div class="legend-item"><i class="legend-dot a"></i>Axiom</div>
<div class="legend-item"><i class="legend-dot e"></i>Ember</div>
</div>
<div class="view-hint">Drag to orbit · wheel to zoom</div>
<div class="timeline-shell">
<div class="timeline-card">
<h3>Resolution event</h3>
<div id="event-text">No events yet. Both couriers submit simultaneously.</div>
</div>
<div class="timeline-card">
<h3>Priority schedule</h3>
<div id="beats"></div>
</div>
<div class="timeline-card">
<div class="timeline-meta">
<div class="same-state">
<i></i>
<span>Every run resets<br />to the same state</span>
</div>
<div class="score-mini">
<strong id="score-main">0 — 0</strong>
<span>Axiom — Ember</span>
</div>
</div>
</div>
</div>
</main>
<aside>
<section class="side-section">
<div class="section-heading">
<div>
<h2>Legal sequences</h2>
<p>Priority order for each of the three simultaneous beats.</p>
</div>
<span class="counter">8 total</span>
</div>
<p class="plan-note">
<strong>Fixed action plan:</strong> advance toward RELAY, advance again,
then advance again. A courier blocked at RELAY must spend the next
beat catching up.
</p>
<div id="sequence-list"></div>
<div class="button-row">
<button class="action-button" id="replay-selected">Replay selected</button>
<button class="action-button primary" id="run-all">Run all 8</button>
</div>
</section>
<section class="side-section">
<div class="section-heading">
<div>
<h2>Selected outcome</h2>
<p>Computed from the replayed state.</p>
</div>
</div>
<div class="result-card">
<div class="result-top">
<span class="result-code" id="result-code">AAA</span>
<span class="result-winner" id="result-winner">Not run</span>
</div>
<div class="result-description" id="result-description">
Execute this schedule to resolve the contested relay.
</div>
<div class="resource-readout">
<div class="resource-chip frost">
<span>Frost · 5 points</span>
<strong id="frost-owner">Unclaimed</strong>
</div>
<div class="resource-chip ore">
<span>Ore · 3 points</span>
<strong id="ore-owner">Unclaimed</strong>
</div>
</div>
</div>
</section>
<section class="side-section">
<div class="section-heading">
<div>
<h2>Outcome comparison</h2>
<p>Results are recorded only after execution.</p>
</div>
<span class="counter" id="executed-count">0 / 8</span>
</div>
<div class="comparison-wrap">
<table>
<thead>
<tr>
<th>Seq.</th>
<th>Frost</th>
<th>Ore</th>
<th>Winner</th>
</tr>
</thead>
<tbody id="comparison-body"></tbody>
</table>
</div>
<p class="table-foot">
A priority change can decide who reaches FROST and whether ORE is
reachable before the three-beat cutoff.
</p>
</section>
</aside>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM references
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const stage = document.querySelector("#stage");
const sequenceList = document.querySelector("#sequence-list");
const beatsElement = document.querySelector("#beats");
const comparisonBody = document.querySelector("#comparison-body");
const executedCount = document.querySelector("#executed-count");
const statusElement = document.querySelector("#stage-status");
const statusKicker = document.querySelector("#status-kicker");
const statusMain = document.querySelector("#status-main");
const eventText = document.querySelector("#event-text");
const scoreMain = document.querySelector("#score-main");
const resultCode = document.querySelector("#result-code");
const resultWinner = document.querySelector("#result-winner");
const resultDescription = document.querySelector("#result-description");
const frostOwner = document.querySelector("#frost-owner");
const oreOwner = document.querySelector("#ore-owner");
const replayButton = document.querySelector("#replay-selected");
const runAllButton = document.querySelector("#run-all");
const ACTOR_NAMES = {
A: "AXIOM",
E: "EMBER"
};
const ACTOR_COLORS = {
A: 0x56d9f5,
E: 0xff9a55
};
const CSS_ACTOR_COLORS = {
A: "#56d9f5",
E: "#ff9a55"
};
const POSITIONS = {
startA: { c: 1, r: 2 },
startB: { c: 3, r: 2 },
relay: { c: 2, r: 2 },
frost: { c: 2, r: 1 },
ore: { c: 2, r: 3 }
};
const SEQUENCE_NAMES = {
AAA: "Axiom keeps priority",
AAE: "Axiom opens, Ember closes",
AEA: "Axiom opens, Ember interrupts",
AEE: "Ember closes with priority",
EAA: "Ember keeps priority",
EAE: "Ember opens, Axiom interrupts",
EEA: "Ember opens, Axiom closes",
EEE: "Ember keeps priority"
};
const sequences = [];
for (const beat0 of ["A", "E"]) {
for (const beat1 of ["A", "E"]) {
for (const beat2 of ["A", "E"]) {
const code = beat0 + beat1 + beat2;
sequences.push({
code,
name: SEQUENCE_NAMES[code],
order: [
[beat0, beat0 === "A" ? "E" : "A"],
[beat1, beat1 === "A" ? "E" : "A"],
[beat2, beat2 === "A" ? "E" : "A"]
]
});
}
}
}
let selectedSequence = sequences[0];
const comparisonResults = new Map();
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x071018, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x071018, 12, 24);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xbfeaff, 0x18212b, 1.45);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xd9f3ff, 2.1);
keyLight.position.set(-4, 9, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x56d9f5, 18, 7, 2);
cyanLight.position.set(-3.5, 2.6, -1.8);
scene.add(cyanLight);
const orangeLight = new THREE.PointLight(0xff9a55, 17, 7, 2);
orangeLight.position.set(3.5, 2.4, 1.7);
scene.add(orangeLight);
const world = new THREE.Group();
scene.add(world);
const boardBase = new THREE.Mesh(
new THREE.BoxGeometry(5.55, 0.34, 5.55),
new THREE.MeshStandardMaterial({
color: 0x0b1721,
roughness: 0.94,
metalness: 0.05
})
);
boardBase.position.y = -0.24;
boardBase.receiveShadow = true;
world.add(boardBase);
const underglow = new THREE.Mesh(
new THREE.BoxGeometry(5.76, 0.07, 5.76),
new THREE.MeshBasicMaterial({
color: 0x1b4d62,
transparent: true,
opacity: 0.18
})
);
underglow.position.y = -0.43;
world.add(underglow);
const tileGeometry = new THREE.BoxGeometry(0.94, 0.18, 0.94);
const tileMaterials = [];
for (let i = 0; i < 5; i++) {
tileMaterials.push(
new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(
0.55,
0.18,
0.105 + ((i % 3) * 0.009)
),
roughness: 0.96,
metalness: 0.02,
flatShading: true
})
);
}
function worldPosition(positionKey, y = 0.13) {
const p = POSITIONS[positionKey];
return new THREE.Vector3((p.c - 2) * 1.05, y, (p.r - 2) * 1.05);
}
const routeTiles = new Set(["startA", "startB", "relay", "frost", "ore"]);
for (let r = 0; r < 5; r++) {
for (let c = 0; c < 5; c++) {
const key = Object.keys(POSITIONS).find(
(name) => POSITIONS[name].c === c && POSITIONS[name].r === r
);
const material = tileMaterials[(c + r * 2) % tileMaterials.length].clone();
if (routeTiles.has(key)) {
material.color.set(0x182b37);
material.emissive.set(0x10232d);
material.emissiveIntensity = 0.25;
}
const tile = new THREE.Mesh(tileGeometry, material);
tile.position.set((c - 2) * 1.05, 0, (r - 2) * 1.05);
tile.receiveShadow = true;
world.add(tile);
if (routeTiles.has(key)) {
const inset = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.86, 0.012, 0.86)),
new THREE.LineBasicMaterial({
color: key === "relay" ? 0x7595a7 : 0x365160,
transparent: true,
opacity: key === "relay" ? 0.5 : 0.24
})
);
inset.position.set(tile.position.x, 0.097, tile.position.z);
world.add(inset);
}
}
}
function makeRoute(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => worldPosition(point, 0.125))
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.28
})
);
world.add(line);
}
makeRoute(["startA", "relay", "frost"], ACTOR_COLORS.A);
makeRoute(["startB", "relay", "frost"], ACTOR_COLORS.E);
// Relay platform.
const relayPedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.48, 0.12, 8),
new THREE.MeshStandardMaterial({
color: 0x2c4351,
emissive: 0x173443,
emissiveIntensity: 0.55,
roughness: 0.72,
metalness: 0.16,
flatShading: true
})
);
relayPedestal.position.copy(worldPosition("relay", 0.15));
relayPedestal.receiveShadow = true;
world.add(relayPedestal);
const relayRing = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.035, 5, 18),
new THREE.MeshBasicMaterial({
color: 0xb9d7e5,
transparent: true,
opacity: 0.72
})
);
relayRing.position.copy(worldPosition("relay", 0.235));
relayRing.rotation.x = Math.PI / 2;
world.add(relayRing);
const relayCore = new THREE.Mesh(
new THREE.OctahedronGeometry(0.105, 0),
new THREE.MeshBasicMaterial({ color: 0xd5ecf6 })
);
relayCore.position.copy(worldPosition("relay", 0.38));
world.add(relayCore);
// Resource objects.
function createResource(key, color, geometry) {
const group = new THREE.Group();
group.position.copy(worldPosition(key, 0.13));
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.35, 0.43, 0.15, 6),
new THREE.MeshStandardMaterial({
color: 0x233441,
roughness: 0.8,
metalness: 0.1,
flatShading: true
})
);
pedestal.position.y = 0.08;
pedestal.receiveShadow = true;
group.add(pedestal);
const crystalMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.52,
roughness: 0.28,
metalness: 0.18,
flatShading: true
});
const crystal = new THREE.Mesh(geometry, crystalMaterial);
crystal.position.y = 0.52;
crystal.scale.y = 1.25;
crystal.castShadow = true;
group.add(crystal);
const claimRing = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.027, 4, 14),
new THREE.MeshBasicMaterial({
color: 0x3d5360,
transparent: true,
opacity: 0.65
})
);
claimRing.position.y = 0.18;
claimRing.rotation.x = Math.PI / 2;
group.add(claimRing);
const ownerDot = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.075, 0),
new THREE.MeshBasicMaterial({ color })
);
ownerDot.position.set(0.25, 0.28, 0);
ownerDot.visible = false;
group.add(ownerDot);
world.add(group);
return {
group,
crystal,
crystalMaterial,
claimRing,
ownerDot
};
}
const frostResource = createResource(
"frost",
0x72eaff,
new THREE.IcosahedronGeometry(0.26, 0)
);
const oreResource = createResource(
"ore",
0xffa85e,
new THREE.OctahedronGeometry(0.29, 0)
);
function makeTextSprite(text, color = "#d8eaf2", scale = 1.45) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
context.fillStyle = "rgba(5, 13, 20, 0.72)";
context.beginPath();
context.roundRect(8, 12, 496, 100, 18);
context.fill();
context.strokeStyle = "rgba(150, 190, 210, 0.22)";
context.lineWidth = 3;
context.stroke();
context.font = "700 38px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = color;
context.fillText(text, 256, 63);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
})
);
sprite.scale.set(scale, scale * 0.25, 1);
return sprite;
}
const frostLabel = makeTextSprite("FROST · 5", "#72eaff", 1.3);
frostLabel.position.copy(worldPosition("frost", 1.35));
world.add(frostLabel);
const oreLabel = makeTextSprite("ORE · 3", "#ffb376", 1.15);
oreLabel.position.copy(worldPosition("ore", 1.35));
world.add(oreLabel);
const relayLabel = makeTextSprite("RELAY", "#b9ced8", 0.95);
relayLabel.position.copy(worldPosition("relay", 0.72));
world.add(relayLabel);
// Courier actors.
function createActor(id) {
const color = ACTOR_COLORS[id];
const root = new THREE.Group();
const visual = new THREE.Group();
root.add(visual);
const actorMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.17,
roughness: 0.56,
metalness: 0.14,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.28, 0.43, 5),
actorMaterial
);
body.position.y = 0.32;
body.castShadow = true;
visual.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 0),
actorMaterial
);
head.position.y = 0.68;
head.castShadow = true;
visual.add(head);
const crest = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.24, 3),
new THREE.MeshStandardMaterial({
color: 0xf0fbff,
emissive: color,
emissiveIntensity: 0.28,
roughness: 0.55,
flatShading: true
})
);
crest.position.y = 0.88;
crest.rotation.z = id === "A" ? -0.18 : 0.18;
visual.add(crest);
const badge = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.13, 0.04),
new THREE.MeshBasicMaterial({ color: 0x071018 })
);
badge.position.set(0, 0.34, 0.24);
visual.add(badge);
const shadow = new THREE.Mesh(
new THREE.CircleGeometry(0.28, 12),
new THREE.MeshBasicMaterial({
color: 0x02070b,
transparent: true,
opacity: 0.36,
depthWrite: false
})
);
shadow.rotation.x = -Math.PI / 2;
shadow.position.y = 0.015;
visual.add(shadow);
const label = makeTextSprite(
id === "A" ? "AXIOM" : "EMBER",
CSS_ACTOR_COLORS[id],
0.95
);
label.position.y = 1.25;
visual.add(label);
world.add(root);
return {
id,
root,
visual,
material: actorMaterial,
flashUntil: 0
};
}
const actors = {
A: createActor("A"),
E: createActor("E")
};
// The marker hovers above the actor whose simultaneous move resolves first.
const priorityMarker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.13, 0),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
priorityMarker.visible = false;
world.add(priorityMarker);
// Small low-poly scenery accents.
const accentGeometry = new THREE.ConeGeometry(0.09, 0.28, 4);
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0x294150,
roughness: 0.95,
flatShading: true
});
[
[0, 0],
[4, 0],
[0, 4],
[4, 4],
[1, 0],
[3, 4]
].forEach(([c, r], index) => {
const accent = new THREE.Mesh(accentGeometry, accentMaterial);
accent.position.set(
(c - 2) * 1.05 + (index % 2 ? 0.27 : -0.27),
0.22,
(r - 2) * 1.05 + (index % 2 ? -0.22 : 0.22)
);
accent.rotation.y = index * 0.61;
accent.castShadow = true;
world.add(accent);
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x061019,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.47;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Custom camera controls: no addon imports
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.68,
pitch: 0.78,
radius: 9.6,
target: new THREE.Vector3(0, 0.15, 0)
};
let dragging = false;
let previousPointer = { x: 0, y: 0 };
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.35,
1.35
);
previousPointer = { x: event.clientX, y: event.clientY };
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.007,
6.8,
13.5
);
},
{ passive: false }
);
function updateCamera() {
const { yaw, pitch, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
}
const resizeObserver = new ResizeObserver(() => {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
resizeObserver.observe(stage);
// -------------------------------------------------------------------------
// Simulation
// -------------------------------------------------------------------------
function createInitialState() {
return {
pos: {
A: "startA",
E: "startB"
},
claims: {
frost: null,
ore: null
}
};
}
let state = createInitialState();
function targetFor(actorId, currentState) {
const position = currentState.pos[actorId];
if (position === "startA" || position === "startB") {
return "relay";
}
if (position === "relay") {
return "frost";
}
return position;
}
function otherActor(actorId) {
return actorId === "A" ? "E" : "A";
}
function isPositionOccupied(position, actorId, currentState) {
return (
currentState.pos[otherActor(actorId)] === position ||
(currentState.claims[position] &&
currentState.claims[position] !== actorId)
);
}
function moveActor(actorId, position) {
state.pos[actorId] = position;
if (position === "frost" || position === "ore") {
state.claims[position] = actorId;
}
}
function calculateScores(currentState) {
return {
A:
(currentState.claims.frost === "A" ? 5 : 0) +
(currentState.claims.ore === "A" ? 3 : 0),
E:
(currentState.claims.frost === "E" ? 5 : 0) +
(currentState.claims.ore === "E" ? 3 : 0)
};
}
function describeOutcome(currentState) {
const scores = calculateScores(currentState);
const winner =
scores.A === scores.E
? "Tie"
: scores.A > scores.E
? "Axiom"
: "Ember";
const bothReachable =
currentState.claims.frost !== null &&
currentState.claims.ore !== null;
let description;
if (bothReachable) {
description =
currentState.claims.frost === "A"
? "Axiom secures FROST and Ember reaches the ORE fallback. Both resources are reachable."
: "Ember secures FROST and Axiom reaches the ORE fallback. Both resources are reachable.";
} else if (currentState.claims.frost === "A") {
description =
"Axiom secures FROST. Ember is still one beat from the ORE fallback at the cutoff.";
} else if (currentState.claims.frost === "E") {
description =
"Ember secures FROST. Axiom is still one beat from the ORE fallback at the cutoff.";
} else {
description = "Neither courier reaches a resource before the cutoff.";
}
return {
scores,
winner,
description,
frost: currentState.claims.frost,
ore: currentState.claims.ore
};
}
// -------------------------------------------------------------------------
// Tweening
// -------------------------------------------------------------------------
const tweens = [];
function tweenPosition(object, destination, duration = 340) {
return new Promise((resolve) => {
tweens.push({
object,
from: object.position.clone(),
to: destination.clone(),
start: performance.now(),
duration,
resolve
});
});
}
function updateTweens(now) {
for (let i = tweens.length - 1; i >= 0; i--) {
const tween = tweens[i];
const progress = THREE.MathUtils.clamp(
(now - tween.start) / tween.duration,
0,
1
);
const eased =
progress < 0.5
? 4 * progress * progress * progress
: 1 - Math.pow(-2 * progress + 2, 3) / 2;
tween.object.position.lerpVectors(tween.from, tween.to, eased);
if (progress >= 1) {
tween.object.position.copy(tween.to);
tweens.splice(i, 1);
tween.resolve();
}
}
}
function sleep(duration) {
return new Promise((resolve) => setTimeout(resolve, duration));
}
// -------------------------------------------------------------------------
// Visual state
// -------------------------------------------------------------------------
function updateResourceVisuals() {
const resources = {
frost: frostResource,
ore: oreResource
};
for (const [resourceName, resource] of Object.entries(resources)) {
const owner = state.claims[resourceName];
resource.crystalMaterial.emissiveIntensity = owner ? 1.05 : 0.52;
resource.crystal.scale.setScalar(owner ? 1.13 : 1);
resource.ownerDot.visible = Boolean(owner);
if (owner) {
resource.claimRing.material.color.set(ACTOR_COLORS[owner]);
resource.claimRing.material.opacity = 0.95;
resource.ownerDot.material.color.set(ACTOR_COLORS[owner]);
} else {
resource.claimRing.material.color.set(0x3d5360);
resource.claimRing.material.opacity = 0.65;
}
}
}
function resetScene() {
state = createInitialState();
for (const actorId of ["A", "E"]) {
actors[actorId].root.position.copy(
worldPosition(state.pos[actorId], 0.13)
);
actors[actorId].flashUntil = 0;
}
priorityMarker.visible = false;
updateResourceVisuals();
updateScoreDisplay();
}
function flashActor(actorId) {
actors[actorId].flashUntil = performance.now() + 430;
}
function setPriorityMarker(actorId) {
if (!actorId) {
priorityMarker.visible = false;
return;
}
priorityMarker.visible = true;
priorityMarker.material.color.set(ACTOR_COLORS[actorId]);
priorityMarker.position.copy(actors[actorId].root.position);
priorityMarker.position.y += 1.48;
}
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
function renderSequenceButtons() {
sequenceList.innerHTML = "";
for (const sequence of sequences) {
const button = document.createElement("button");
button.className = "sequence-button";
button.dataset.code = sequence.code;
button.innerHTML = `
<span class="seq-code">${sequence.code}</span>
<span class="seq-name">${sequence.name}</span>
`;
button.addEventListener("click", () => {
if (running) return;
selectedSequence = sequence;
renderSequenceButtons();
renderTimeline();
showSelectedPreRun();
});
sequenceList.appendChild(button);
}
markSelectedSequence();
}
function markSelectedSequence() {
for (const button of sequenceList.querySelectorAll(".sequence-button")) {
button.classList.toggle(
"selected",
button.dataset.code === selectedSequence.code
);
}
}
function renderTimeline() {
beatsElement.innerHTML = "";
selectedSequence.order.forEach((order, index) => {
const beat = document.createElement("div");
beat.className = "beat";
beat.dataset.beat = index;
beat.innerHTML = `
<span class="beat-label">Beat ${index + 1}</span>
<span class="beat-order">
<span class="${order[0].toLowerCase()}">${order[0]}</span>
<span class="arrow">→</span>
<span class="${order[1].toLowerCase()}">${order[1]}</span>
</span>
`;
beatsElement.appendChild(beat);
});
}
function setActiveBeat(index) {
for (const beat of beatsElement.querySelectorAll(".beat")) {
const beatIndex = Number(beat.dataset.beat);
beat.classList.toggle("active", beatIndex === index);
beat.classList.toggle("complete", beatIndex < index);
}
}
function clearBeatStates() {
for (const beat of beatsElement.querySelectorAll(".beat")) {
beat.classList.remove("active", "complete");
}
}
function renderComparison() {
comparisonBody.innerHTML = "";
for (const sequence of sequences) {
const result = comparisonResults.get(sequence.code);
const row = document.createElement("tr");
if (sequence.code === selectedSequence.code) {
row.className = "selected-row";
}
const ownerCell = (owner) =>
owner
? `<td class="owner-${owner.toLowerCase()}">${
owner === "A" ? "Axiom" : "Ember"
}</td>`
: "<td>—</td>";
row.innerHTML = `
<td class="code">${sequence.code}</td>
${ownerCell(result?.frost)}
${ownerCell(result?.ore)}
<td class="winner">${result?.winner ?? "—"}</td>
`;
comparisonBody.appendChild(row);
}
executedCount.textContent = `${comparisonResults.size} / ${sequences.length}`;
}
function updateScoreDisplay() {
const scores = calculateScores(state);
scoreMain.textContent = `${scores.A} — ${scores.E}`;
}
function showSelectedPreRun() {
resultCode.textContent = selectedSequence.code;
resultWinner.textContent = "Not run";
resultWinner.style.color = "#8298a8";
resultWinner.style.background = "rgba(130,152,168,0.1)";
resultDescription.textContent =
"Execute this schedule to resolve the contested relay.";
frostOwner.textContent = "Unclaimed";
oreOwner.textContent = "Unclaimed";
markSelectedSequence();
renderComparison();
}
function showOutcome(result) {
resultCode.textContent = selectedSequence.code;
resultWinner.textContent = result.winner;
resultWinner.style.color = "#80e6ad";
resultWinner.style.background = "rgba(128,230,173,0.1)";
resultDescription.textContent = result.description;
frostOwner.textContent = result.frost
? ACTOR_NAMES[result.frost]
: "Unclaimed";
oreOwner.textContent = result.ore
? ACTOR_NAMES[result.ore]
: "Unreachable";
}
function setStatus(kicker, main, running = false) {
statusKicker.textContent = kicker;
statusMain.textContent = main;
statusElement.classList.toggle("running", running);
}
// -------------------------------------------------------------------------
// Replay engine
// -------------------------------------------------------------------------
let running = false;
let runToken = 0;
async function resolveActorMove(actorId, target, token) {
const actor = actors[actorId];
if (target === state.pos[actorId]) {
eventText.textContent = `${ACTOR_NAMES[actorId]} holds its position.`;
await sleep(150);
return;
}
const occupied = isPositionOccupied(target, actorId, state);
if (occupied) {
if (target === "frost" && !state.claims.ore) {
moveActor(actorId, "ore");
updateResourceVisuals();
updateScoreDisplay();
flashActor(actorId);
await tweenPosition(
actor.root,
worldPosition("ore", 0.13),
330
);
eventText.textContent =
`${ACTOR_NAMES[actorId]} finds FROST occupied and is diverted to ORE.`;
} else {
flashActor(actorId);
eventText.textContent =
`${ACTOR_NAMES[actorId]} is blocked at ${
target === "relay" ? "RELAY" : target.toUpperCase()
}.`;
await sleep(190);
}
return;
}
moveActor(actorId, target);
updateResourceVisuals();
updateScoreDisplay();
if (target === "frost" || target === "ore") {
flashActor(actorId);
eventText.textContent = `${ACTOR_NAMES[actorId]} claims ${target.toUpperCase()}.`;
} else {
eventText.textContent = `${ACTOR_NAMES[actorId]} enters RELAY.`;
}
await tweenPosition(actor.root, worldPosition(target, 0.13), 340);
}
async function playSequence(sequence, token) {
running = true;
selectedSequence = sequence;
markSelectedSequence();
renderTimeline();
clearBeatStates();
resetScene();
replayButton.disabled = true;
runAllButton.disabled = false;
runAllButton.textContent = "Stop";
runAllButton.classList.add("stop");
runAllButton.classList.remove("primary");
setStatus(
"Resetting identical state",
`${sequence.code} · both couriers submit simultaneously`,
true
);
await sleep(280);
for (let beatIndex = 0; beatIndex < sequence.order.length; beatIndex++) {
if (token !== runToken) return;
setActiveBeat(beatIndex);
setStatus(
`Beat ${beatIndex + 1} of 3 · simultaneous submission`,
`${ACTOR_NAMES[sequence.order[beatIndex][0]]} resolves first`,
true
);
eventText.textContent =
"Both actions are locked. Priority determines the contested destination.";
await sleep(280);
// Snapshot both intended targets before either move is resolved.
const targets = {
A: targetFor("A", state),
E: targetFor("E", state)
};
for (const actorId of sequence.order[beatIndex]) {
if (token !== runToken) return;
setPriorityMarker(actorId);
setStatus(
`Beat ${beatIndex + 1} · resolving ${ACTOR_NAMES[actorId]}`,
`${ACTOR_NAMES[actorId]} resolves first this beat`,
true
);
await resolveActorMove(actorId, targets[actorId], token);
if (token !== runToken) return;
}
priorityMarker.visible = false;
await sleep(180);
}
if (token !== runToken) return;
const result = describeOutcome(state);
comparisonResults.set(sequence.code, result);
showOutcome(result);
renderComparison();
setStatus(
"Execution complete",
`${sequence.code} · ${result.winner} wins · ${result.scores.A}—${result.scores.E}`,
false
);
running = false;
replayButton.disabled = false;
runAllButton.disabled = false;
runAllButton.textContent = "Run all 8";
runAllButton.classList.remove("stop");
runAllButton.classList.add("primary");
}
async function runSelected() {
if (running) return;
const token = ++runToken;
await playSequence(selectedSequence, token);
}
async function runAll() {
if (running) {
runToken++;
running = false;
replayButton.disabled = false;
runAllButton.disabled = false;
runAllButton.textContent = "Run all 8";
runAllButton.classList.remove("stop");
runAllButton.classList.add("primary");
priorityMarker.visible = false;
setStatus("Execution stopped", "Completed results remain in the comparison table.");
return;
}
const token = ++runToken;
for (const sequence of sequences) {
if (token !== runToken) break;
await playSequence(sequence, token);
if (token !== runToken) break;
await sleep(320);
}
if (token === runToken) {
setStatus(
"Comparison complete",
`${comparisonResults.size} legal sequences executed from the same initial state`,
false
);
}
}
replayButton.addEventListener("click", runSelected);
runAllButton.addEventListener("click", runAll);
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function render() {
const now = performance.now();
const elapsed = clock.getElapsedTime();
updateTweens(now);
updateCamera();
frostResource.crystal.rotation.y = elapsed * 0.9;
frostResource.crystal.rotation.z = Math.sin(elapsed * 0.8) * 0.08;
oreResource.crystal.rotation.y = -elapsed * 1.05;
oreResource.crystal.rotation.x = Math.sin(elapsed * 0.7) * 0.06;
relayRing.rotation.z = elapsed * 0.32;
relayCore.position.y =
worldPosition("relay", 0.38).y + Math.sin(elapsed * 2.2) * 0.055;
relayCore.rotation.y = elapsed * 1.4;
priorityMarker.rotation.y = elapsed * 2.3;
priorityMarker.position.y =
actors[priorityMarker.userData.actorId === "E" ? "E" : "A"]
.root.position.y + 1.48 + Math.sin(elapsed * 4.2) * 0.07;
for (const actor of Object.values(actors)) {
actor.visual.position.y = Math.sin(elapsed * 2.5 + (actor.id === "A" ? 0 : 1.5)) * 0.018;
const flash = Math.max(0, actor.flashUntil - now) / 430;
actor.material.emissiveIntensity = 0.17 + flash * 1.05;
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(render);
// -------------------------------------------------------------------------
// Initialize
// -------------------------------------------------------------------------
renderSequenceButtons();
renderTimeline();
renderComparison();
resetScene();
setStatus(
"Ready for execution",
"Choose a priority schedule, then replay it.",
false
);
// Expose a tiny inspection API for optional console use.
window.crosscut = {
sequences,
getState: () => structuredClone(state),
getResults: () => Object.fromEntries(comparisonResults),
runAll
};
</script>
</body>
</html>
```