Prompt specification
Build or customize the Three.js 3D scene "Ancient-style race board with marked squares" 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: Ancient-style race board with marked squares
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ancient-style-race-board-with-marked-squares-x2241
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing ancient board games and reconstructed rules. Build a small referenced ancient race-game board with distinct squares and two sets of counters. Label any uncertain rule interpretation separately from the physical evidence. Stylized solid forms.
Working Three.js Starter (ancient-style-race-board-with-marked-squares-x2241):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Senet — Physical Evidence and Reconstructed Rules</title>
<style>
:root {
--ink: #171713;
--paper: #eee5d1;
--paper-dim: #cfc3aa;
--gold: #d5a64a;
--red: #c96643;
--blue: #58a0b5;
--panel: rgba(24, 24, 20, 0.93);
--line: rgba(238, 229, 209, 0.17);
--uncertain: #d8a349;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #171713;
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.title-block {
position: fixed;
top: 28px;
left: 32px;
z-index: 3;
max-width: 460px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.65);
}
.eyebrow {
margin-bottom: 9px;
color: var(--gold);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5vw, 68px);
font-weight: 400;
line-height: 0.95;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 400px;
margin: 14px 0 0;
color: var(--paper-dim);
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
top: 22px;
right: 22px;
bottom: 22px;
z-index: 4;
display: flex;
width: min(390px, calc(100vw - 44px));
flex-direction: column;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(18px);
}
.panel-header {
padding: 20px 22px 0;
}
.panel-kicker {
margin-bottom: 6px;
color: var(--gold);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.panel-title {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 400;
}
.tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
margin: 18px 0 0;
padding: 4px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(0, 0, 0, 0.16);
}
.tab {
padding: 9px 5px;
border: 0;
border-radius: 7px;
background: transparent;
color: var(--paper-dim);
cursor: pointer;
font-size: 12px;
font-weight: 700;
}
.tab:hover {
color: var(--paper);
}
.tab.active {
background: rgba(238, 229, 209, 0.11);
color: var(--paper);
}
.panel-body {
flex: 1;
overflow-y: auto;
padding: 21px 22px 26px;
scrollbar-color: #5d584b transparent;
scrollbar-width: thin;
}
.tab-page {
display: none;
animation: fade-in 180ms ease-out;
}
.tab-page.active {
display: block;
}
@keyframes fade-in {
from { opacity: 0; transform: translateY(4px); }
to { opacity: 1; transform: translateY(0); }
}
.section-label {
margin: 0 0 9px;
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h2 {
margin: 0 0 10px;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 400;
line-height: 1.15;
}
h3 {
margin: 23px 0 8px;
font-size: 13px;
letter-spacing: 0.02em;
}
p,
li {
color: var(--paper-dim);
font-size: 13px;
line-height: 1.62;
}
p {
margin: 0 0 12px;
}
ul,
ol {
margin: 9px 0 17px;
padding-left: 20px;
}
li {
margin-bottom: 8px;
padding-left: 3px;
}
strong {
color: var(--paper);
font-weight: 700;
}
.evidence-note,
.uncertain-box,
.source-note {
margin-top: 18px;
padding: 14px 15px;
border-radius: 10px;
font-size: 12px;
line-height: 1.55;
}
.evidence-note {
border: 1px solid rgba(88, 160, 181, 0.34);
background: rgba(88, 160, 181, 0.08);
color: #b8dbe4;
}
.uncertain-box {
border: 1px solid rgba(216, 163, 73, 0.48);
background: rgba(216, 163, 73, 0.09);
color: #e5c990;
}
.source-note {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.025);
color: var(--paper-dim);
}
.references {
margin: 0;
padding: 0;
list-style: none;
}
.references li {
margin: 0 0 15px;
padding: 0;
}
a {
color: #e0bb72;
text-decoration-color: rgba(224, 187, 114, 0.45);
text-underline-offset: 3px;
}
a:hover {
color: #f3d491;
}
.citation {
display: block;
margin-bottom: 4px;
color: var(--paper);
font-size: 13px;
font-weight: 700;
line-height: 1.4;
}
.toolbar {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 5;
display: flex;
width: min(720px, calc(100vw - 48px));
align-items: center;
gap: 14px;
transform: translateX(-50%);
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(24, 24, 20, 0.91);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(16px);
}
.turn-info {
min-width: 170px;
flex: 1;
}
.turn-label {
margin-bottom: 3px;
color: var(--paper-dim);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#status {
color: var(--paper);
font-size: 12px;
line-height: 1.35;
}
.sticks-wrap {
display: grid;
grid-template-columns: repeat(4, 9px);
gap: 4px;
min-width: 52px;
}
.stick {
width: 9px;
height: 28px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 4px;
background: #ded3b9;
transform: rotate(-7deg);
}
.stick:nth-child(even) {
transform: rotate(7deg);
}
.stick.marked::after {
content: "";
display: block;
width: 5px;
height: 5px;
margin: 4px auto 0;
border-radius: 50%;
background: #26231d;
}
.action {
min-height: 40px;
padding: 0 16px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
background: rgba(255, 255, 255, 0.06);
color: var(--paper);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: background 150ms, transform 150ms;
}
.action:hover {
background: rgba(255, 255, 255, 0.12);
}
.action:active {
transform: translateY(1px);
}
.action.primary {
border-color: rgba(213, 166, 74, 0.55);
background: var(--gold);
color: #1c1b16;
}
.action.primary:hover {
background: #e2b65e;
}
.action:disabled {
cursor: not-allowed;
opacity: 0.42;
}
.camera-help {
position: fixed;
left: 30px;
bottom: 29px;
z-index: 3;
max-width: 270px;
color: rgba(238, 229, 209, 0.62);
font-size: 11px;
line-height: 1.55;
pointer-events: none;
}
.camera-help strong {
color: rgba(238, 229, 209, 0.9);
}
.legend {
position: fixed;
top: 31px;
right: 432px;
z-index: 3;
display: flex;
flex-direction: column;
gap: 8px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(24, 24, 20, 0.72);
color: var(--paper-dim);
font-size: 10px;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
}
.swatch.red { background: var(--red); }
.swatch.blue { background: var(--blue); }
.swatch.route {
height: 3px;
border-radius: 0;
background: linear-gradient(90deg, var(--red), var(--blue));
}
.overlay-toggle {
position: fixed;
right: 432px;
bottom: 30px;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
color: var(--paper-dim);
font-size: 11px;
cursor: pointer;
user-select: none;
}
.overlay-toggle input {
accent-color: var(--gold);
}
@media (max-width: 1050px) {
.legend {
display: none;
}
.overlay-toggle {
right: 432px;
}
}
@media (max-width: 760px) {
.title-block {
top: 18px;
left: 18px;
}
h1 {
font-size: 42px;
}
.subtitle {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 92px;
left: 12px;
width: auto;
height: 34vh;
}
.panel-header {
padding: 13px 16px 0;
}
.panel-title {
font-size: 19px;
}
.tabs {
margin-top: 10px;
}
.panel-body {
padding: 15px 16px 20px;
}
.toolbar {
bottom: 10px;
width: calc(100vw - 24px);
gap: 8px;
}
.turn-info {
min-width: 0;
}
.sticks-wrap {
display: none;
}
.action {
padding: 0 11px;
}
.camera-help,
.overlay-toggle {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D reconstruction of a Senet board"></canvas>
<header class="title-block">
<div class="eyebrow">Ancient race games / Evidence & reconstruction</div>
<h1>Senet</h1>
<p class="subtitle">
An evidence-led reconstruction of an Egyptian race game.
Explore the board, inspect the play model, and compare what is physical
evidence with what remains conjectural.
</p>
</header>
<aside class="panel" aria-label="Evidence and reconstruction notes">
<div class="panel-header">
<div class="panel-kicker">Museum interpretation desk</div>
<h2 class="panel-title">Board, evidence, uncertainty</h2>
<nav class="tabs" aria-label="Information sections">
<button class="tab active" data-tab="evidence">Evidence</button>
<button class="tab" data-tab="rules">Rules</button>
<button class="tab" data-tab="sources">Sources</button>
</nav>
</div>
<div class="panel-body">
<section class="tab-page active" id="tab-evidence">
<p class="section-label">Physical evidence</p>
<h2>What the surviving objects show</h2>
<p>
Surviving Egyptian <strong>senet</strong> boards commonly contain
<strong>30 distinct playing spaces</strong>, arranged as three rows
of ten within a rectangular box. The board shown here follows that
recognizable form and exaggerates the gaps so every space remains
legible.
</p>
<p>
Decorative motifs—including rosette-like forms—appear on some
boards. Gaming counters were made from many materials, including
wood, clay, stone, and faience. The appearance and number of
counters varied between finds.
</p>
<div class="evidence-note">
<strong>Evidence boundary:</strong> the board geometry and surviving
objects do not reveal a complete rule set. No ancient Senet rule
manual is known to survive.
</div>
<h3>The modern labels in this model</h3>
<p>
Squares are numbered for reference only:
<strong>1–10 across the rear row</strong>,
<strong>11–20 across the middle</strong>, and
<strong>21–30 across the front row</strong>. These numbers were not
ancient labels.
</p>
<h3>How to read the scene</h3>
<p>
The two sets of five counters represent a modern teaching
reconstruction. Colored route lines, highlighted destination
squares, and the extra-turn rosettes are interactive overlays—not
original inscriptions or proven gameplay features.
</p>
</section>
<section class="tab-page" id="tab-rules">
<p class="section-label">Reconstructed rule set used here</p>
<h2>A playable modern variant</h2>
<ol>
<li>Each player has five counters and begins on alternating spaces near their entry.</li>
<li>Four binary throwing sticks produce a value from one to four.</li>
<li>The active player selects one counter, throws, and chooses a highlighted destination.</li>
<li>The two players follow opposite directions around the same serpentine course.</li>
<li>Landing on an opponent returns that counter to its owner’s entry space.</li>
<li>Landing on a rosette grants another throw in this model.</li>
<li>A player wins by bearing off all five counters.</li>
</ol>
<div class="uncertain-box">
<strong>Uncertain interpretations — not settled ancient rules:</strong>
the route direction, starting arrangement, capture rule, rosette
function, number of counters, values of spaces, and bearing-off
procedure vary among modern reconstructions. The implementation here
is explicitly labeled as one operational hypothesis.
</div>
<h3>Controls</h3>
<p>
Select an active counter, throw the sticks, then select a glowing
destination. Drag the scene to orbit; use right-drag or Shift-drag to
pan; scroll to zoom; double-click the scene to reset the view.
</p>
</section>
<section class="tab-page" id="tab-sources">
<p class="section-label">References</p>
<h2>Objects and published reconstructions</h2>
<ul class="references">
<li>
<a
class="citation"
href="https://www.metmuseum.org/art/collection/search?q=senet"
target="_blank"
rel="noopener noreferrer"
>The Metropolitan Museum of Art — Senet boards</a>
Museum collection records for Egyptian game boards with thirty
playing spaces, including New Kingdom examples.
</li>
<li>
<a
class="citation"
href="https://www.britishmuseum.org/collection/search?keyword=senet"
target="_blank"
rel="noopener noreferrer"
>The British Museum — Senet collection search</a>
Objects, boards, gaming pieces, and comparative material from
ancient Egypt.
</li>
<li>
<a
class="citation"
href="https://www.ucl.ac.uk/museums-static/digitalegypt/games/senet.html"
target="_blank"
rel="noopener noreferrer"
>UCL Digital Egypt — Senet</a>
A concise scholarly overview of the board’s archaeological
context and the uncertainty surrounding its rules.
</li>
<li>
<a
class="citation"
href="https://search.worldcat.org/search?q=ti%3A%22The+Ancient+Egyptian+Board+Game+of+Senet%22"
target="_blank"
rel="noopener noreferrer"
>R. C. Bell — The Ancient Egyptian Board Game of Senet</a>
A major published attempt to reconstruct movement and gameplay.
Bibliographic search via WorldCat.
</li>
</ul>
<div class="source-note">
<strong>Method note:</strong> the visible board is a stylized solid-form
interpretation rather than a measured drawing of one specific object.
References support the general archaeological context; they do not
certify the particular rules implemented in the interactive model.
</div>
</section>
</div>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-row"><span class="swatch red"></span> Carmine player</div>
<div class="legend-row"><span class="swatch blue"></span> Lapis player</div>
<div class="legend-row"><span class="swatch route"></span> Modern route overlay</div>
</div>
<label class="overlay-toggle">
<input type="checkbox" id="show-routes" checked>
Show reconstructed routes
</label>
<div class="camera-help">
<strong>Drag</strong> orbit · <strong>Shift/right-drag</strong> pan ·
<strong>Scroll</strong> zoom · <strong>Double-click</strong> reset
</div>
<footer class="toolbar">
<div class="turn-info">
<div class="turn-label" id="turn-label">Carmine's turn</div>
<div id="status">Select a Carmine counter, then throw.</div>
</div>
<div class="sticks-wrap" id="sticks" aria-label="Throwing sticks">
<span class="stick"></span>
<span class="stick"></span>
<span class="stick"></span>
<span class="stick"></span>
</div>
<button class="action" id="reset-game">Reset game</button>
<button class="action" id="reset-view">Reset view</button>
<button class="action primary" id="throw-button">Throw sticks</button>
</footer>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* -----------------------------------------------------------
Scene setup
----------------------------------------------------------- */
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x171713);
scene.fog = new THREE.Fog(0x171713, 19, 35);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff1d6, 0x263027, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe4b3, 4.4);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8ec6d6, 2.2);
rimLight.position.set(7, 5, -8);
scene.add(rimLight);
const warmPoint = new THREE.PointLight(0xd88755, 18, 14, 2);
warmPoint.position.set(-7, 4, -2);
scene.add(warmPoint);
const board = new THREE.Group();
board.position.set(-0.8, 0, 0.15);
scene.add(board);
const materials = {
plinth: new THREE.MeshStandardMaterial({
color: 0x3a2a1d,
roughness: 0.75,
metalness: 0.05
}),
base: new THREE.MeshStandardMaterial({
color: 0x241c16,
roughness: 0.86
}),
tile: new THREE.MeshStandardMaterial({
color: 0xd7c6a4,
roughness: 0.76,
metalness: 0.02
}),
tileAlternate: new THREE.MeshStandardMaterial({
color: 0xcbb995,
roughness: 0.8,
metalness: 0.02
}),
trim: new THREE.MeshStandardMaterial({
color: 0x775238,
roughness: 0.58,
metalness: 0.08
}),
red: new THREE.MeshStandardMaterial({
color: 0xc65f3e,
roughness: 0.48,
metalness: 0.05
}),
blue: new THREE.MeshStandardMaterial({
color: 0x39869e,
roughness: 0.48,
metalness: 0.05
}),
redTop: new THREE.MeshStandardMaterial({
color: 0xe08a61,
roughness: 0.35
}),
blueTop: new THREE.MeshStandardMaterial({
color: 0x69b8ca,
roughness: 0.35
}),
gold: new THREE.MeshStandardMaterial({
color: 0xd6a54e,
roughness: 0.4,
metalness: 0.28
}),
highlight: new THREE.MeshBasicMaterial({
color: 0xf1c766,
transparent: true,
opacity: 0.44,
depthWrite: false,
side: THREE.DoubleSide
}),
selection: new THREE.MeshBasicMaterial({
color: 0xfff1b8,
transparent: true,
opacity: 0.9,
depthWrite: false
})
};
const ground = new THREE.Mesh(
new THREE.CircleGeometry(26, 72),
new THREE.MeshStandardMaterial({
color: 0x1b1c18,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.92;
ground.receiveShadow = true;
scene.add(ground);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(11.35, 0.48, 4.25),
materials.plinth
);
plinth.position.y = -0.58;
plinth.castShadow = true;
plinth.receiveShadow = true;
board.add(plinth);
const base = new THREE.Mesh(
new THREE.BoxGeometry(10.75, 0.22, 3.68),
materials.base
);
base.position.y = -0.23;
base.castShadow = true;
base.receiveShadow = true;
board.add(base);
const trimGeometry = new THREE.BoxGeometry(0.15, 0.28, 3.66);
for (const x of [-5.36, 5.36]) {
const trim = new THREE.Mesh(trimGeometry, materials.trim);
trim.position.set(x, -0.08, 0);
trim.castShadow = true;
board.add(trim);
}
const endTrimGeometry = new THREE.BoxGeometry(10.85, 0.28, 0.15);
for (const z of [-1.84, 1.84]) {
const trim = new THREE.Mesh(endTrimGeometry, materials.trim);
trim.position.set(0, -0.08, z);
trim.castShadow = true;
board.add(trim);
}
/* -----------------------------------------------------------
Board geometry and physical numbering
Squares 1–10: rear row
Squares 11–20: middle row
Squares 21–30: front row
----------------------------------------------------------- */
const COLS = 10;
const ROWS = 3;
const X_GAP = 0.98;
const Z_GAP = 1.03;
const TILE_SIZE = 0.82;
const TOP_Y = 0.02;
const squarePositions = new Map();
const tileMeshes = [];
const highlightMeshes = new Map();
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS; col++) {
const square = row * 10 + col + 1;
const x = (col - 4.5) * X_GAP;
const z = (row - 1) * Z_GAP;
squarePositions.set(square, new THREE.Vector3(x, TOP_Y, z));
const tile = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE, 0.14, TILE_SIZE),
(row + col) % 2 === 0 ? materials.tile : materials.tileAlternate
);
tile.position.set(x, -0.01, z);
tile.castShadow = true;
tile.receiveShadow = true;
tile.userData.square = square;
board.add(tile);
tileMeshes.push(tile);
const highlight = new THREE.Mesh(
new THREE.PlaneGeometry(TILE_SIZE * 0.96, TILE_SIZE * 0.96),
materials.highlight.clone()
);
highlight.rotation.x = -Math.PI / 2;
highlight.position.set(x, TOP_Y + 0.075, z);
highlight.visible = false;
board.add(highlight);
highlightMeshes.set(square, highlight);
}
}
// Decorative rosette markers on squares 16 and 26.
// Their gameplay effect is explicitly treated as conjectural.
function makeRosette(square) {
const group = new THREE.Group();
const pos = squarePositions.get(square);
group.position.set(pos.x, TOP_Y + 0.081, pos.z);
const center = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.09, 0.022, 16),
materials.gold
);
group.add(center);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const petal = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 10, 8),
materials.gold
);
petal.position.set(
Math.cos(angle) * 0.145,
0.012,
Math.sin(angle) * 0.145
);
petal.scale.y = 0.55;
group.add(petal);
}
board.add(group);
}
makeRosette(16);
makeRosette(26);
/* -----------------------------------------------------------
Two opposing route hypotheses used by the playable model
----------------------------------------------------------- */
const routeA = [
...Array.from({ length: 10 }, (_, i) => i + 1),
...Array.from({ length: 10 }, (_, i) => 20 - i),
...Array.from({ length: 10 }, (_, i) => 21 + i)
];
const routeB = [
...Array.from({ length: 10 }, (_, i) => 30 - i),
...Array.from({ length: 10 }, (_, i) => 11 + i),
...Array.from({ length: 10 }, (_, i) => 10 - i)
];
const routes = [routeA, routeB];
const routeGroup = new THREE.Group();
board.add(routeGroup);
function addRouteLine(route, color) {
const points = route.map(square => {
const p = squarePositions.get(square);
return new THREE.Vector3(p.x, TOP_Y + 0.086, p.z);
});
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.72,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.renderOrder = 2;
routeGroup.add(line);
}
addRouteLine(routeA, 0xe48254);
addRouteLine(routeB, 0x67c0d8);
function addRouteEnd(square, color) {
const p = squarePositions.get(square);
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.19, 0.27, 28),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.85,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(p.x, TOP_Y + 0.09, p.z);
routeGroup.add(ring);
}
addRouteEnd(routeA[0], 0xe48254);
addRouteEnd(routeB[0], 0x67c0d8);
/* -----------------------------------------------------------
Counters
----------------------------------------------------------- */
const pieces = [];
const counterMeshes = [];
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.37, 0.026, 8, 40),
materials.selection
);
selectionRing.rotation.x = -Math.PI / 2;
selectionRing.visible = false;
selectionRing.renderOrder = 4;
board.add(selectionRing);
function makeCounter(player, id) {
const group = new THREE.Group();
const isRed = player === 0;
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.30, 0.22, 20),
isRed ? materials.red : materials.blue
);
body.position.y = 0.20;
body.castShadow = true;
body.receiveShadow = true;
body.userData.pieceId = id;
group.add(body);
counterMeshes.push(body);
const top = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 16, 10),
isRed ? materials.redTop : materials.blueTop
);
top.scale.y = 0.63;
top.position.y = 0.37;
top.castShadow = true;
top.userData.pieceId = id;
group.add(top);
counterMeshes.push(top);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.285, 0.025, 8, 24),
materials.gold
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.115;
ring.userData.pieceId = id;
group.add(ring);
counterMeshes.push(ring);
board.add(group);
return {
id,
player,
group,
routeIndex: 0,
exited: false,
animation: null
};
}
let pieceId = 0;
for (let player = 0; player < 2; player++) {
for (let i = 0; i < 5; i++) {
pieces.push(makeCounter(player, pieceId++));
}
}
/* -----------------------------------------------------------
Game state
----------------------------------------------------------- */
const playerNames = ["Carmine", "Lapis"];
const playerColors = ["#e48254", "#67c0d8"];
const ROSETTES = new Set([16, 26]);
let activePlayer = 0;
let selectedPiece = null;
let thrownValue = null;
let hasThrown = false;
let gameOver = false;
let legalMove = null;
const throwButton = document.querySelector("#throw-button");
const resetGameButton = document.querySelector("#reset-game");
const resetViewButton = document.querySelector("#reset-view");
const showRoutesCheckbox = document.querySelector("#show-routes");
const statusElement = document.querySelector("#status");
const turnLabel = document.querySelector("#turn-label");
const stickElements = [...document.querySelectorAll(".stick")];
function getRouteFor(player) {
return routes[player];
}
function positionForPiece(piece) {
if (piece.exited) return null;
const square = getRouteFor(piece.player)[piece.routeIndex];
return squarePositions.get(square);
}
function placePiece(piece, square, animate = false) {
const target = squarePositions.get(square);
if (!animate) {
piece.group.position.set(target.x, TOP_Y, target.z);
return;
}
piece.animation = {
start: performance.now(),
duration: 440,
from: piece.group.position.clone(),
to: new THREE.Vector3(target.x, TOP_Y, target.z)
};
}
function resetGame() {
activePlayer = 0;
selectedPiece = null;
thrownValue = null;
hasThrown = false;
gameOver = false;
legalMove = null;
for (const piece of pieces) {
piece.exited = false;
piece.animation = null;
// Alternate route positions 0, 2, 4, 6, and 8.
piece.routeIndex = pieces
.filter(p => p.player === piece.player)
.indexOf(piece) * 2;
const square = getRouteFor(piece.player)[piece.routeIndex];
placePiece(piece, square, false);
piece.group.visible = true;
}
clearHighlights();
updateTurnLabel();
updateStatus("Select a Carmine counter, then throw.");
throwButton.disabled = false;
throwButton.textContent = "Throw sticks";
}
function updateTurnLabel() {
turnLabel.textContent = gameOver
? "Game complete"
: `${playerNames[activePlayer]}'s turn`;
turnLabel.style.color = gameOver
? "#f1d188"
: playerColors[activePlayer];
}
function updateStatus(message) {
statusElement.textContent = message;
}
function clearHighlights() {
for (const mesh of highlightMeshes.values()) {
mesh.visible = false;
}
selectionRing.visible = false;
}
function selectPiece(piece) {
if (gameOver || piece.exited) return;
if (piece.player !== activePlayer) {
updateStatus(
`It is ${playerNames[activePlayer]}'s turn. Select a ${playerNames[activePlayer]} counter.`
);
return;
}
selectedPiece = piece;
legalMove = null;
const position = positionForPiece(piece);
selectionRing.position.set(position.x, TOP_Y + 0.1, position.z);
selectionRing.visible = true;
if (hasThrown) {
calculateLegalMove();
} else {
updateStatus(
`${playerNames[activePlayer]} selected square ${getRouteFor(piece.player)[piece.routeIndex]}. Throw the sticks.`
);
}
}
function calculateLegalMove() {
clearHighlights();
if (!selectedPiece || !hasThrown) return;
const position = positionForPiece(selectedPiece);
selectionRing.position.set(position.x, TOP_Y + 0.1, position.z);
selectionRing.visible = true;
const nextIndex = selectedPiece.routeIndex + thrownValue;
if (nextIndex >= routes[selectedPiece.player].length) {
legalMove = null;
updateStatus(
`${playerNames[activePlayer]} rolled ${thrownValue}. This counter can be borne off; click its counter to confirm.`
);
return;
}
const destination = routes[selectedPiece.player][nextIndex];
legalMove = { piece: selectedPiece, destination, nextIndex };
const highlight = highlightMeshes.get(destination);
highlight.visible = true;
highlight.material.opacity = 0.66;
updateStatus(
`${playerNames[activePlayer]} rolled ${thrownValue}. Choose glowing square ${destination}.`
);
}
function findOccupant(player, square, exceptPiece = null) {
return pieces.find(piece =>
!piece.exited &&
piece !== exceptPiece &&
piece.player === player &&
getRouteFor(piece.player)[piece.routeIndex] === square
);
}
function commitMove() {
if (!legalMove || gameOver) return;
const { piece, destination, nextIndex } = legalMove;
const captured = findOccupant(
1 - piece.player,
destination,
piece
);
piece.routeIndex = nextIndex;
placePiece(piece, destination, true);
let extraTurn = ROSETTES.has(destination);
if (captured) {
captured.routeIndex = 0;
placePiece(captured, getRouteFor(captured.player)[0], true);
extraTurn = false;
updateStatus(
`${playerNames[piece.player]} captured a ${playerNames[captured.player]} counter.`
);
}
if (nextIndex >= routes[piece.player].length) {
piece.exited = true;
piece.group.visible = false;
extraTurn = false;
}
selectedPiece = null;
legalMove = null;
thrownValue = null;
hasThrown = false;
clearHighlights();
const remaining = pieces.filter(p =>
p.player === piece.player && !p.exited
).length;
if (remaining === 0) {
gameOver = true;
updateTurnLabel();
updateStatus(`${playerNames[piece.player]} bears off all five counters and wins.`);
throwButton.disabled = true;
return;
}
if (!extraTurn) {
activePlayer = 1 - activePlayer;
}
updateTurnLabel();
throwButton.disabled = false;
throwButton.textContent = "Throw sticks";
if (captured) {
updateStatus(
`${playerNames[piece.player]} captured a ${playerNames[captured.player]} counter. ` +
(extraTurn ? "Rosette: another turn." : `Now ${playerNames[activePlayer]}'s turn.`)
);
} else if (extraTurn) {
updateStatus(
`${playerNames[piece.player]} reached a rosette and receives another turn.`
);
} else {
updateStatus(
`${playerNames[piece.player]} moved to square ${destination}. ` +
`Now ${playerNames[activePlayer]}'s turn.`
);
}
}
function chooseMovablePiece() {
const candidates = pieces.filter(piece =>
!piece.exited &&
piece.player === activePlayer &&
piece.routeIndex < routes[piece.player].length - 1
);
if (candidates.length) {
selectedPiece = candidates[0];
const position = positionForPiece(selectedPiece);
selectionRing.position.set(position.x, TOP_Y + 0.1, position.z);
selectionRing.visible = true;
}
}
function throwSticks() {
if (gameOver || hasThrown) return;
if (!selectedPiece) {
chooseMovablePiece();
}
const marks = stickElements.map(() => Math.random() < 0.5 ? 1 : 0);
thrownValue = Math.max(1, marks.reduce((sum, value) => sum + value, 0));
hasThrown = true;
stickElements.forEach((element, index) => {
element.classList.toggle("marked", marks[index] === 1);
element.animate(
[
{ transform: "translateY(-8px) rotate(-16deg)" },
{ transform: "translateY(2px) rotate(8deg)" },
{ transform: "translateY(0) rotate(-7deg)" }
],
{ duration: 420, delay: index * 45, easing: "ease-out" }
);
});
calculateLegalMove();
}
/* -----------------------------------------------------------
Manual camera controls — no external controls addon
----------------------------------------------------------- */
const cameraState = {
target: new THREE.Vector3(-0.8, 0, 0.1),
radius: 15.4,
theta: 0.72,
phi: 0.92
};
const defaultCamera = {
target: cameraState.target.clone(),
radius: cameraState.radius,
theta: cameraState.theta,
phi: cameraState.phi
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
updateCamera();
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: false,
button: 0,
lastX: 0,
lastY: 0
};
function boardWorldPosition(square) {
const local = squarePositions.get(square);
return board.localToWorld(local.clone());
}
function pickAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const counterHits = raycaster.intersectObjects(counterMeshes, false);
if (counterHits.length) {
const piece = pieces.find(p => p.id === counterHits[0].object.userData.pieceId);
if (piece) return { type: "piece", piece };
}
const tileHits = raycaster.intersectObjects(tileMeshes, false);
if (tileHits.length) {
return {
type: "square",
square: tileHits[0].object.userData.square
};
}
return null;
}
canvas.addEventListener("pointerdown", event => {
pointerState.down = true;
pointerState.moved = false;
pointerState.button = event.button;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", event => {
if (!pointerState.down) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
if (Math.abs(dx) + Math.abs(dy) > 3) {
pointerState.moved = true;
}
const panning =
pointerState.button === 2 ||
pointerState.button === 1 ||
event.shiftKey;
if (panning) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const scale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-5,
5
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-4,
4
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.006,
0.28,
1.42
);
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", event => {
const wasClick = !pointerState.moved;
pointerState.down = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (!wasClick || gameOver) return;
const hit = pickAt(event.clientX, event.clientY);
if (!hit) return;
if (hit.type === "piece") {
selectPiece(hit.piece);
} else if (hit.type === "square") {
if (legalMove && legalMove.destination === hit.square) {
commitMove();
} else {
updateStatus(
`Square ${hit.square}. Select one of your counters, then throw the sticks.`
);
}
}
});
canvas.addEventListener("pointercancel", () => {
pointerState.down = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.2,
24
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
/* -----------------------------------------------------------
Interface controls
----------------------------------------------------------- */
document.querySelectorAll(".tab").forEach(button => {
button.addEventListener("click", () => {
document.querySelectorAll(".tab").forEach(tab => {
tab.classList.toggle("active", tab === button);
});
document.querySelectorAll(".tab-page").forEach(page => {
page.classList.toggle("active", page.id === `tab-${button.dataset.tab}`);
});
});
});
throwButton.addEventListener("click", throwSticks);
resetGameButton.addEventListener("click", resetGame);
resetViewButton.addEventListener("click", resetCamera);
showRoutesCheckbox.addEventListener("change", event => {
routeGroup.visible = event.target.checked;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
/* -----------------------------------------------------------
Animation
----------------------------------------------------------- */
function animatePiece(piece, time) {
if (!piece.animation) return;
const animation = piece.animation;
const raw = Math.min(1, (time - animation.start) / animation.duration);
const eased = 1 - Math.pow(1 - raw, 3);
piece.group.position.lerpVectors(animation.from, animation.to, eased);
piece.group.position.y = TOP_Y + Math.sin(raw * Math.PI) * 0.28;
if (raw >= 1) {
piece.group.position.copy(animation.to);
piece.animation = null;
}
}
function animate() {
requestAnimationFrame(animate);
const time = performance.now();
for (const piece of pieces) {
animatePiece(piece, time);
}
if (selectionRing.visible) {
const pulse = 1 + Math.sin(time * 0.004) * 0.07;
selectionRing.scale.setScalar(pulse);
selectionRing.material.opacity = 0.72 + Math.sin(time * 0.004) * 0.18;
}
for (const mesh of highlightMeshes.values()) {
if (mesh.visible) {
mesh.material.opacity =
0.43 + Math.sin(time * 0.005 + mesh.position.x) * 0.17;
}
}
renderer.render(scene, camera);
}
resetGame();
animate();
</script>
</body>
</html>
```