47:51Ranking major U.S. Open-Weights Models. (Where does Ripple 65B fit in?)
Nov 6, 2026 · YouTube
10:57"Crouton Alpha": the latest super-efficient coding model by Meta?
Nov 3, 2026 · YouTube
38:58Testing Particle-1: a post-trained DeepSeek V4.1 Flash specializing in coding and efficiency
Oct 28, 2026 · YouTube
29:55Kimi K3.1 Pro Looked Incredible. Then I Kept Testing.
Oct 26, 2026 · YouTube
22:47Mistral Large 4 Is Cheap. But Is It Good Enough to Compete?
Oct 6, 2026 · YouTube
16:54Stealth Union Alpha: Is this another cheap GPT model? (better than Luna, cheaper than Terra?)
Sep 16, 2026 · YouTube
16:45DeepSeek V4.1 Flash Is Shockingly Good for the Price
Sep 10, 2026 · YouTube
17:37Tencent Hy4 Preview Tested: Is It Really Better Than Kimi K3 and GLM 5.3?
Aug 28, 2026 · YouTube
23:58Qwen 3.8 Flash Tested: UI, Coding, Physics & more - compared to Opus 5, Sol Pro, Grok
Aug 27, 2026 · YouTube
14:50Stealth Ox Alpha: a new GLM model! Full test (coding & writing) against Grok, Gemini, GPT & others
Aug 21, 2026 · YouTube
My buddy runs a bar. I told him I'd build him something for Thursdays. He's the one talking here — I just write down what he says and hand it to you.
It's not real pool. Three balls on the table, you shoot until all three are down, and we count how many shots it took you. Low is good. Everybody takes a turn, then we go around again — that's a round.
Twenty bucks to play. You start with five chips. Take more than four shots to clear the table and it costs you a chip. Out of chips and you're out, go back to drinking. Last one with chips left takes the pot.
There's a clock on your turn — a minute, minute and a half, we've never really settled it. Clock runs out and you're not at the table, that's a chip.
It's a Thursday. Nine o'clock, everybody's had a few, the jukebox is loud and half the room is outside smoking. Twelve, sixteen people usually, however many show up. It runs two, three hours and nobody's in a hurry.
Last year I ran the whole thing on a legal pad and it got away from me around round four. Two guys arguing with me about what they shot, me trying to remember whose turn it was, somebody's beer on the pad. Never again.
I'm running this off my phone, one-handed, standing at the table with a beer in the other. There's a TV over the bar and that's the only screen anybody in the room can see — from across the room, in the dark, so it's got to be big. People want to know where they stand without walking over and asking me.
My phone's on 15% by ten. The bar's wifi is the bar's wifi.
Twenty a head, all of it in the pot. Winner takes it — mostly. We kick a little to second. And there's a side thing we do for whoever's shooting best early on, I never wrote that part down properly.
The app doesn't hold the money. I do. But at the end of the night it has to tell me what I owe who, and I'm reading that off my phone with sixteen people standing around the table.
Two pages.
The console — the thing I run it from, and the thing that goes up on the TV. Open it and there's already a game going. I'm not typing in twelve names to find out whether it works.
The playback — a separate page that plays a whole night through, start to finish, so I can watch it work before Thursday. One step at a time, a step being one thing happening, with the scorecard filling in as it goes and a slider for how fast it runs. I want to slow it down, back it up, and read what just happened. Show me the way a night actually goes.
The playback runs the same rules the console runs. If the two of them drift apart, the playback is a cartoon and it's no use to me.
data: URIs are fine.localStorage, sessionStorage, cookies or indexedDB — these run in a sandboxed frame where those throw.html blocks: the console first, the playback second. Leave yourself room for the second one.I know I wasn't clear about everything. Everything you had to decide for me, one line each — what you decided and why. Short.
The first fenced html block.
The second fenced html block.
It's Thursday, it's nine o'clock, and I'm running this for real. What comes up that this doesn't handle? Be straight with me. I'd much rather hear it now than find out with sixteen people around a pool table and three hundred dollars sitting on the bar.
TO.<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Thursday Three-Ball Console</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#0b0f14;color:#f1f5f9;font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif}
header{display:flex;justify-content:space-between;align-items:center;padding:10px 14px;background:#111827;border-bottom:2px solid #334155;position:sticky;top:0;z-index:10}
.brand{font-weight:900;letter-spacing:1px;font-size:clamp(18px,2.5vw,28px)}
.stats{display:flex;gap:12px;font-size:clamp(14px,1.6vw,20px);flex-wrap:wrap}
.stats b{color:#fbbf24}
main{padding:12px;max-width:1400px;margin:0 auto}
.current{text-align:center;margin:8px 0 14px}
.label{font-size:clamp(14px,1.5vw,20px);color:#94a3b8;text-transform:uppercase;letter-spacing:2px}
.huge{font-size:clamp(42px,9vw,110px);font-weight:900;line-height:1;color:#fff;text-shadow:0 0 20px #3b82f6}
.chips{font-size:clamp(20px,3vw,36px);color:#fbbf24;margin-top:6px}
.controls{margin:12px 0}
.shots{display:grid;grid-template-columns:repeat(5,1fr);gap:8px}
.shots button{font-size:clamp(20px,4vw,40px);font-weight:900;padding:12px 0;border:none;border-radius:14px;background:#1e293b;color:#fff;box-shadow:0 2px 0 #0f172a}
.shots button:active{background:#334155;transform:translateY(2px)}
.danger{width:100%;margin-top:10px;padding:14px;font-size:clamp(18px,2.5vw,28px);font-weight:900;border:none;border-radius:14px;background:#7f1d1d;color:#fff}
.util{display:flex;gap:8px;margin-top:10px}
.util button{flex:1;padding:12px;font-size:clamp(14px,2vw,20px);border:none;border-radius:12px;background:#334155;color:#fff}
.scorecard{margin-top:20px}
h2{font-size:clamp(20px,2.5vw,32px);margin:10px 0;color:#93c5fd}
.tableWrap{overflow:auto;max-height:50vh;border:1px solid #334155;border-radius:12px}
table{border-collapse:collapse;width:100%;font-size:clamp(14px,1.8vw,22px)}
th,td{padding:6px 8px;text-align:center;border-bottom:1px solid #1e293b;white-space:nowrap}
th{background:#1e293b;position:sticky;top:0;z-index:2}
.sticky{position:sticky;left:0;background:#0b0f14;z-index:3;text-align:left;min-width:120px}
th.sticky{background:#1e293b;z-index:4}
tr.cur{background:#1e3a8a}
tr.win{background:#14532d}
tr.out{opacity:0.45}
.name{font-weight:700}
.payouts{margin-top:20px;background:#111827;padding:16px;border-radius:12px;border:1px solid #334155;font-size:clamp(16px,2vw,24px)}
.payouts ul{margin:8px 0 0 20px}
.overlay{position:fixed;inset:0;background:rgba(0,0,0,0.8);display:flex;align-items:center;justify-content:center;z-index:100;padding:16px}
.overlay.hidden{display:none}
.modal{background:#111827;padding:20px;border-radius:16px;width:min(500px,100%);border:1px solid #334155}
.modal textarea{width:100%;font-size:18px;padding:10px;border-radius:8px;border:1px solid #334155;background:#0b0f14;color:#fff}
.modalActions{display:flex;gap:10px;margin-top:12px}
.modalActions button{flex:1;padding:12px;font-size:18px;border:none;border-radius:10px;background:#2563eb;color:#fff}
.customShot{display:flex;gap:8px;margin-top:8px;align-items:center}
#customShots{width:80px;padding:10px;font-size:20px;border-radius:10px;border:1px solid #334155;background:#0b0f14;color:#fff}
.customShot button{padding:10px 16px;font-size:18px;border:none;border-radius:10px;background:#2563eb;color:#fff}
</style>
</head>
<body>
<header>
<div class="brand">THURSDAY THREE-BALL</div>
<div class="stats">
<span>Round <b id="round">1</b></span>
<span>Pot <b id="pot">$240</b></span>
<span>Active <b id="active">12</b></span>
<span>Clock <b id="clock">1:15</b></span>
</div>
</header>
<main>
<section class="current">
<div class="label">Now shooting</div>
<div id="curName" class="huge">Al</div>
<div id="curChips" class="chips">5 chips</div>
</section>
<section class="controls">
<div class="shots" id="shotButtons"></div>
<div class="customShot">
<input id="customShots" type="number" min="1" inputmode="numeric" placeholder="shots">
<button id="customLog">Log</button>
</div>
<button id="timeoutBtn" class="danger">Clock out — chip</button>
<div class="util">
<button id="undoBtn">Undo</button>
<button id="setupBtn">Names</button>
<button id="resetBtn">Reset demo</button>
</div>
</section>
<section class="scorecard">
<h2>Scorecard</h2>
<div class="tableWrap"><table id="scoreTable"></table></div>
</section>
<section id="payouts" class="payouts hidden"></section>
</main>
<div id="setupOverlay" class="overlay hidden">
<div class="modal">
<h2>Players</h2>
<p>One name per line. Applying resets the night.</p>
<textarea id="namesInput" rows="12"></textarea>
<div class="modalActions">
<button id="applyNames">Apply & reset</button>
<button id="closeSetup">Cancel</button>
</div>
</div>
</div>
<script>
const RULES = {
buyIn: 20,
startChips: 5,
chipThreshold: 4,
clockSeconds: 75,
earlyPct: 0.10,
secondPct: 0.10
};
function makeGame(names) {
const players = names.map((name, i) => ({
id: i,
name: name.trim() || ('Player ' + (i + 1)),
chips: RULES.startChips,
shots: [],
eliminated: false
}));
return {
players,
round: 1,
turnIndex: 0,
finished: false,
winnerId: null,
earlyWinnerId: null,
earlyAwarded: false,
lastEliminatedId: null,
pot: players.length * RULES.buyIn,
payouts: null
};
}
function isActive(p) { return p.chips > 0 && !p.eliminated; }
function activeCount(g) { return g.players.filter(isActive).length; }
function currentPlayer(g) { return g.players[g.turnIndex]; }
function nextActiveIndex(g, from) {
for (let i = 1; i <= g.players.length; i++) {
const idx = (from + i) % g.players.length;
if (isActive(g.players[idx])) return idx;
}
return -1;
}
function awardEarly(g) {
if (g.earlyAwarded) return;
g.earlyAwarded = true;
const candidates = g.players.filter(p => p.shots && p.shots.slice(0, 2).some(s => typeof s === 'number'));
if (!candidates.length) return;
function score(p) {
let total = 0, timeouts = 0;
for (let r = 0; r < 2; r++) {
const s = p.shots[r];
if (typeof s === 'number') total += s;
else if (s === 'TO') timeouts++;
}
return { total, timeouts };
}
candidates.sort((a, b) => {
const sa = score(a), sb = score(b);
if (sa.total !== sb.total) return sa.total - sb.total;
if (sa.timeouts !== sb.timeouts) return sa.timeouts - sb.timeouts;
return a.id - b.id;
});
g.earlyWinnerId = candidates[0].id;
}
function finish(g) {
if (g.finished) return;
const active = g.players.filter(isActive);
if (active.length === 1) {
g.finished = true;
g.winnerId = active[0].id;
if (!g.earlyAwarded) awardEarly(g);
computePayouts(g);
} else if (active.length === 0) {
g.finished = true;
let best = g.players.slice().sort((a, b) => {
const ta = a.shots.reduce((s, x) => s + (typeof x === 'number' ? x : 99), 0);
const tb = b.shots.reduce((s, x) => s + (typeof x === 'number' ? x : 99), 0);
return ta - tb;
})[0];
g.winnerId = best.id;
if (!g.earlyAwarded) awardEarly(g);
computePayouts(g);
}
}
function computePayouts(g) {
const pot = g.pot;
let early = 0, second = 0, first = pot;
if (g.earlyWinnerId != null) early = Math.floor(pot * RULES.earlyPct);
if (g.lastEliminatedId != null && g.lastEliminatedId !== g.winnerId) second = Math.floor(pot * RULES.secondPct);
first = pot - early - second;
const byPlayer = {};
function add(id, amt) {
if (id == null || amt <= 0) return;
byPlayer[id] = (byPlayer[id] || 0) + amt;
}
add(g.winnerId, first);
add(g.lastEliminatedId, second);
add(g.earlyWinnerId, early);
g.payouts = { first, second, early, byPlayer };
}
function applyTurn(g, value) {
const p = currentPlayer(g);
if (!p || !isActive(p)) return null;
const ev = {
type: value === 'TO' ? 'timeout' : 'shot',
playerId: p.id,
player: p.name,
round: g.round,
shots: value,
text: ''
};
p.shots[g.round - 1] = value;
if (value === 'TO') {
p.chips--;
ev.chipDelta = -1;
if (p.chips <= 0) {
p.chips = 0;
p.eliminated = true;
g.lastEliminatedId = p.id;
ev.eliminated = true;
}
ev.text = `${p.name} clocked out — loses a chip (${p.chips} left)`;
} else {
if (value > RULES.chipThreshold) {
p.chips--;
ev.chipDelta = -1;
if (p.chips <= 0) {
p.chips = 0;
p.eliminated = true;
g.lastEliminatedId = p.id;
ev.eliminated = true;
}
ev.text = `${p.name} shot ${value} — over 4, loses a chip (${p.chips} left)`;
} else {
ev.text = `${p.name} shot ${value} — clean`;
}
}
if (activeCount(g) === 1) {
finish(g);
ev.gameOver = true;
if (g.winnerId != null) {
const w = g.players[g.winnerId];
ev.text += ` · GAME OVER: ${w.name} wins`;
}
return ev;
}
const next = nextActiveIndex(g, g.turnIndex);
if (next === -1) {
finish(g);
ev.gameOver = true;
return ev;
}
if (next <= g.turnIndex) {
g.round++;
if (g.round === 3 && !g.earlyAwarded) {
awardEarly(g);
const e = g.players[g.earlyWinnerId];
ev.early = true;
ev.text += ` · Early side: ${e.name}`;
}
}
g.turnIndex = next;
return ev;
}
function clone(g) { return JSON.parse(JSON.stringify(g)); }
function escapeHtml(s) { return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); }
const DEFAULT_NAMES = ['Al','Bev','Cal','Dana','Ed','Flo','Gus','Hal','Ike','Jo','Kim','Lou'];
let game = makeGame(DEFAULT_NAMES);
let history = [];
let timerKey = '', timerSec = RULES.clockSeconds;
const shotVals = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
const shotButtons = document.getElementById('shotButtons');
shotButtons.innerHTML = shotVals.map(n => `<button data-shots="${n}">${n}</button>`).join('');
shotButtons.addEventListener('click', e => {
const btn = e.target.closest('button[data-shots]');
if (!btn) return;
doShot(parseInt(btn.dataset.shots, 10));
});
function doShot(n) {
if (game.finished) return;
history.push(clone(game));
applyTurn(game, n);
render();
}
function doTimeout() {
if (game.finished) return;
history.push(clone(game));
applyTurn(game, 'TO');
render();
}
document.getElementById('timeoutBtn').onclick = doTimeout;
document.getElementById('customLog').onclick = () => {
const v = parseInt(document.getElementById('customShots').value, 10);
if (v > 0) {
doShot(v);
document.getElementById('customShots').value = '';
}
};
document.getElementById('undoBtn').onclick = () => {
if (history.length) {
game = history.pop();
timerKey = '';
render();
}
};
document.getElementById('resetBtn').onclick = () => {
game = makeGame(DEFAULT_NAMES);
history = [];
timerKey = '';
render();
};
document.getElementById('setupBtn').onclick = () => {
document.getElementById('namesInput').value = game.players.map(p => p.name).join('\n');
document.getElementById('setupOverlay').classList.remove('hidden');
};
document.getElementById('closeSetup').onclick = () => document.getElementById('setupOverlay').classList.add('hidden');
document.getElementById('applyNames').onclick = () => {
const names = document.getElementById('namesInput').value.split('\n').map(s => s.trim()).filter(Boolean);
if (names.length < 2) names.push('Player 2');
game = makeGame(names);
history = [];
timerKey = '';
document.getElementById('setupOverlay').classList.add('hidden');
render();
};
function resetTimer() {
timerSec = RULES.clockSeconds;
renderClock();
}
function renderClock() {
const el = document.getElementById('clock');
if (game.finished) { el.textContent = '—'; return; }
const m = Math.floor(timerSec / 60);
const s = timerSec % 60;
el.textContent = m + ':' + String(s).padStart(2, '0');
}
setInterval(() => {
if (game.finished) return;
if (timerSec > 0) timerSec--;
renderClock();
}, 1000);
function render() {
const g = game;
document.getElementById('round').textContent = g.round;
document.getElementById('pot').textContent = '$' + g.pot;
document.getElementById('active').textContent = activeCount(g);
const p = currentPlayer(g);
if (g.finished) {
const w = g.players[g.winnerId];
document.getElementById('curName').textContent = w ? w.name + ' wins' : 'Game over';
document.getElementById('curChips').textContent = '';
} else if (p) {
document.getElementById('curName').textContent = p.name;
document.getElementById('curChips').textContent = p.chips + ' chips';
}
renderScore(g);
renderPayouts(g);
const key = g.finished ? 'done' : g.round + '-' + g.turnIndex;
if (key !== timerKey) {
timerKey = key;
resetTimer();
}
renderClock();
}
function renderScore(g) {
const maxRound = Math.max(g.round, ...g.players.map(p => p.shots.length), 1);
let html = '<thead><tr><th class="sticky">Player</th><th>Chips</th><th>Total</th>';
for (let r = 1; r <= maxRound; r++) html += `<th>R${r}</th>`;
html += '</tr></thead><tbody>';
g.players.forEach(p => {
const total = p.shots.reduce((s, x) => s + (typeof x === 'number' ? x : 0), 0);
const isCur = p.id === g.turnIndex && !g.finished && isActive(p);
const isWin = g.finished && p.id === g.winnerId;
html += `<tr class="${isCur ? 'cur' : ''} ${isWin ? 'win' : ''} ${!isActive(p) ? 'out' : ''}">`;
html += `<td class="sticky name">${escapeHtml(p.name)}</td>`;
html += `<td>${p.chips}</td>`;
html += `<td>${total}</td>`;
for (let r = 1; r <= maxRound; r++) {
const s = p.shots[r - 1];
let cell = '';
if (typeof s === 'number') cell = s;
else if (s === 'TO') cell = 'TO';
html += `<td>${cell}</td>`;
}
html += '</tr>';
});
html += '</tbody>';
document.getElementById('scoreTable').innerHTML = html;
}
function renderPayouts(g) {
const el = document.getElementById('payouts');
if (!g.finished || !g.payouts) {
el.classList.add('hidden');
el.innerHTML = '';
return;
}
el.classList.remove('hidden');
const w = g.players[g.winnerId];
const e = g.players[g.earlyWinnerId];
const s = g.players[g.lastEliminatedId];
let html = `<h2>Payouts</h2><div class="payGrid">`;
html += `<div>Winner: <b>${w ? escapeHtml(w.name) : '—'}</b> $${g.payouts.first}</div>`;
if (g.payouts.second) html += `<div>Second: <b>${s ? escapeHtml(s.name) : '—'}</b> $${g.payouts.second}</div>`;
if (g.payouts.early) html += `<div>Early: <b>${e ? escapeHtml(e.name) : '—'}</b> $${g.payouts.early}</div>`;
html += `</div><h3>Owe each</h3><ul>`;
for (const id in g.payouts.byPlayer) {
const p = g.players[id];
html += `<li>${escapeHtml(p.name)} — $${g.payouts.byPlayer[id]}</li>`;
}
html += `</ul>`;
el.innerHTML = html;
}
render();
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Thursday Three-Ball Playback</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#0b0f14;color:#f1f5f9;font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif}
header{display:flex;justify-content:space-between;align-items:center;padding:10px 14px;background:#111827;border-bottom:2px solid #334155;position:sticky;top:0;z-index:10}
.brand{font-weight:900;letter-spacing:1px;font-size:clamp(18px,2.5vw,28px)}
.stats{display:flex;gap:12px;font-size:clamp(14px,1.6vw,20px);flex-wrap:wrap}
.stats b{color:#fbbf24}
main{padding:12px;max-width:1400px;margin:0 auto}
.controls{margin:12px 0}
.playRow{display:flex;gap:8px}
.playRow button{flex:1;padding:14px;font-size:clamp(18px,2.5vw,28px);font-weight:900;border:none;border-radius:12px;background:#2563eb;color:#fff}
.speedRow{margin:10px 0;font-size:clamp(16px,2vw,22px);display:flex;align-items:center;gap:10px}
.speedRow input{flex:1}
.eventText{background:#111827;border:1px solid #334155;border-radius:12px;padding:12px;font-size:clamp(18px,2.5vw,30px);font-weight:700;min-height:60px}
.scorecard{margin-top:20px}
h2{font-size:clamp(20px,2.5vw,32px);margin:10px 0;color:#93c5fd}
.tableWrap{overflow:auto;max-height:50vh;border:1px solid #334155;border-radius:12px}
table{border-collapse:collapse;width:100%;font-size:clamp(14px,1.8vw,22px)}
th,td{padding:6px 8px;text-align:center;border-bottom:1px solid #1e293b;white-space:nowrap}
th{background:#1e293b;position:sticky;top:0;z-index:2}
.sticky{position:sticky;left:0;background:#0b0f14;z-index:3;text-align:left;min-width:120px}
th.sticky{background:#1e293b;z-index:4}
tr.cur{background:#1e3a8a}
tr.win{background:#14532d}
tr.out{opacity:0.45}
.name{font-weight:700}
.payouts{margin-top:20px;background:#111827;padding:16px;border-radius:12px;border:1px solid #334155;font-size:clamp(16px,2vw,24px)}
.payouts ul{margin:8px 0 0 20px}
.eventLog{margin-top:20px}
.eventList{max-height:300px;overflow:auto;border:1px solid #334155;border-radius:12px}
.eventItem{padding:8px 10px;border-bottom:1px solid #1e293b;font-size:clamp(14px,1.8vw,20px);cursor:pointer}
.eventItem.cur{background:#1e3a8a}
</style>
</head>
<body>
<header>
<div class="brand">THURSDAY THREE-BALL · PLAYBACK</div>
<div class="stats"><span id="stepLabel">Step 0 / 0</span></div>
</header>
<main>
<section class="controls">
<div class="playRow">
<button id="playBtn">Play</button>
<button id="backBtn">◀ Back</button>
<button id="fwdBtn">Forward ▶</button>
</div>
<div class="speedRow">
<label>Speed <input id="speed" type="range" min="0.25" max="8" step="0.25" value="1"> <span id="speedLabel">1x</span></label>
</div>
<div id="eventText" class="eventText">Start of night</div>
</section>
<section class="scorecard">
<h2>Scorecard</h2>
<div class="tableWrap"><table id="scoreTable"></table></div>
</section>
<section id="payouts" class="payouts hidden"></section>
<section class="eventLog">
<h2>Events</h2>
<div id="eventList" class="eventList"></div>
</section>
</main>
<script>
const RULES = {
buyIn: 20,
startChips: 5,
chipThreshold: 4,
clockSeconds: 75,
earlyPct: 0.10,
secondPct: 0.10
};
function makeGame(names) {
const players = names.map((name, i) => ({
id: i,
name: name.trim() || ('Player ' + (i + 1)),
chips: RULES.startChips,
shots: [],
eliminated: false
}));
return {
players,
round: 1,
turnIndex: 0,
finished: false,
winnerId: null,
earlyWinnerId: null,
earlyAwarded: false,
lastEliminatedId: null,
pot: players.length * RULES.buyIn,
payouts: null
};
}
function isActive(p) { return p.chips > 0 && !p.eliminated; }
function activeCount(g) { return g.players.filter(isActive).length; }
function currentPlayer(g) { return g.players[g.turnIndex]; }
function nextActiveIndex(g, from) {
for (let i = 1; i <= g.players.length; i++) {
const idx = (from + i) % g.players.length;
if (isActive(g.players[idx])) return idx;
}
return -1;
}
function awardEarly(g) {
if (g.earlyAwarded) return;
g.earlyAwarded = true;
const candidates = g.players.filter(p => p.shots && p.shots.slice(0, 2).some(s => typeof s === 'number'));
if (!candidates.length) return;
function score(p) {
let total = 0, timeouts = 0;
for (let r = 0; r < 2; r++) {
const s = p.shots[r];
if (typeof s === 'number') total += s;
else if (s === 'TO') timeouts++;
}
return { total, timeouts };
}
candidates.sort((a, b) => {
const sa = score(a), sb = score(b);
if (sa.total !== sb.total) return sa.total - sb.total;
if (sa.timeouts !== sb.timeouts) return sa.timeouts - sb.timeouts;
return a.id - b.id;
});
g.earlyWinnerId = candidates[0].id;
}
function finish(g) {
if (g.finished) return;
const active = g.players.filter(isActive);
if (active.length === 1) {
g.finished = true;
g.winnerId = active[0].id;
if (!g.earlyAwarded) awardEarly(g);
computePayouts(g);
} else if (active.length === 0) {
g.finished = true;
let best = g.players.slice().sort((a, b) => {
const ta = a.shots.reduce((s, x) => s + (typeof x === 'number' ? x : 99), 0);
const tb = b.shots.reduce((s, x) => s + (typeof x === 'number' ? x : 99), 0);
return ta - tb;
})[0];
g.winnerId = best.id;
if (!g.earlyAwarded) awardEarly(g);
computePayouts(g);
}
}
function computePayouts(g) {
const pot = g.pot;
let early = 0, second = 0, first = pot;
if (g.earlyWinnerId != null) early = Math.floor(pot * RULES.earlyPct);
if (g.lastEliminatedId != null && g.lastEliminatedId !== g.winnerId) second = Math.floor(pot * RULES.secondPct);
first = pot - early - second;
const byPlayer = {};
function add(id, amt) {
if (id == null || amt <= 0) return;
byPlayer[id] = (byPlayer[id] || 0) + amt;
}
add(g.winnerId, first);
add(g.lastEliminatedId, second);
add(g.earlyWinnerId, early);
g.payouts = { first, second, early, byPlayer };
}
function applyTurn(g, value) {
const p = currentPlayer(g);
if (!p || !isActive(p)) return null;
const ev = {
type: value === 'TO' ? 'timeout' : 'shot',
playerId: p.id,
player: p.name,
round: g.round,
shots: value,
text: ''
};
p.shots[g.round - 1] = value;
if (value === 'TO') {
p.chips--;
ev.chipDelta = -1;
if (p.chips <= 0) {
p.chips = 0;
p.eliminated = true;
g.lastEliminatedId = p.id;
ev.eliminated = true;
}
ev.text = `${p.name} clocked out — loses a chip (${p.chips} left)`;
} else {
if (value > RULES.chipThreshold) {
p.chips--;
ev.chipDelta = -1;
if (p.chips <= 0) {
p.chips = 0;
p.eliminated = true;
g.lastEliminatedId = p.id;
ev.eliminated = true;
}
ev.text = `${p.name} shot ${value} — over 4, loses a chip (${p.chips} left)`;
} else {
ev.text = `${p.name} shot ${value} — clean`;
}
}
if (activeCount(g) === 1) {
finish(g);
ev.gameOver = true;
if (g.winnerId != null) {
const w = g.players[g.winnerId];
ev.text += ` · GAME OVER: ${w.name} wins`;
}
return ev;
}
const next = nextActiveIndex(g, g.turnIndex);
if (next === -1) {
finish(g);
ev.gameOver = true;
return ev;
}
if (next <= g.turnIndex) {
g.round++;
if (g.round === 3 && !g.earlyAwarded) {
awardEarly(g);
const e = g.players[g.earlyWinnerId];
ev.early = true;
ev.text += ` · Early side: ${e.name}`;
}
}
g.turnIndex = next;
return ev;
}
function clone(g) { return JSON.parse(JSON.stringify(g)); }
function escapeHtml(s) { return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); }
const DEFAULT_NAMES = ['Al','Bev','Cal','Dana','Ed','Flo','Gus','Hal','Ike','Jo','Kim','Lou'];
function generateNight() {
let g = makeGame(DEFAULT_NAMES);
const initial = clone(g);
const steps = [];
let seed = 987654321;
function rnd() {
seed = (seed * 1664525 + 1013904223) % 4294967296;
return seed / 4294967296;
}
let guard = 0;
while (!g.finished && guard < 800) {
guard++;
const p = currentPlayer(g);
if (!p) break;
let val;
if (rnd() < 0.035) {
val = 'TO';
} else {
const r = rnd();
if (r < 0.15) val = 1;
else if (r < 0.40) val = 2;
else if (r < 0.65) val = 3;
else if (r < 0.80) val = 4;
else if (r < 0.90) val = 5;
else if (r < 0.96) val = 6;
else val = 7 + Math.floor(rnd() * 5);
}
const beforeEarly = g.earlyAwarded;
const ev = applyTurn(g, val);
if (!beforeEarly && g.earlyAwarded) {
ev.early = true;
const e = g.players[g.earlyWinnerId];
if (e) ev.text += ` · Early side: ${e.name}`;
}
if (g.finished && !ev.gameOver) {
ev.gameOver = true;
const w = g.players[g.winnerId];
if (w) ev.text += ` · GAME OVER: ${w.name} wins`;
}
steps.push({ event: ev, state: clone(g) });
}
if (g.finished && g.payouts) {
const w = g.players[g.winnerId];
const s = g.players[g.lastEliminatedId];
const e = g.players[g.earlyWinnerId];
let text = `Payouts — Winner: ${w ? w.name : '—'} $${g.payouts.first}`;
if (g.payouts.second) text += `, Second: ${s ? s.name : '—'} $${g.payouts.second}`;
if (g.payouts.early) text += `, Early: ${e ? e.name : '—'} $${g.payouts.early}`;
steps.push({ event: { type: 'payout', text, gameOver: true }, state: clone(g) });
}
return { initial, steps };
}
const sim = generateNight();
let stepIndex = -1;
let playing = false;
let speed = 1;
let playTimer = null;
function render() {
const state = stepIndex < 0 ? sim.initial : sim.steps[stepIndex].state;
const ev = stepIndex < 0 ? { text: 'Start of night' } : sim.steps[stepIndex].event;
document.getElementById('stepLabel').textContent = `Step ${stepIndex + 1} / ${sim.steps.length}`;
document.getElementById('eventText').textContent = ev.text;
renderScore(state);
renderPayouts(state);
renderEventList();
}
function renderScore(g) {
const maxRound = Math.max(g.round, ...g.players.map(p => p.shots.length), 1);
let html = '<thead><tr><th class="sticky">Player</th><th>Chips</th><th>Total</th>';
for (let r = 1; r <= maxRound; r++) html += `<th>R${r}</th>`;
html += '</tr></thead><tbody>';
g.players.forEach(p => {
const total = p.shots.reduce((s, x) => s + (typeof x === 'number' ? x : 0), 0);
const isCur = p.id === g.turnIndex && !g.finished && isActive(p);
const isWin = g.finished && p.id === g.winnerId;
html += `<tr class="${isCur ? 'cur' : ''} ${isWin ? 'win' : ''} ${!isActive(p) ? 'out' : ''}">`;
html += `<td class="sticky name">${escapeHtml(p.name)}</td>`;
html += `<td>${p.chips}</td>`;
html += `<td>${total}</td>`;
for (let r = 1; r <= maxRound; r++) {
const s = p.shots[r - 1];
let cell = '';
if (typeof s === 'number') cell = s;
else if (s === 'TO') cell = 'TO';
html += `<td>${cell}</td>`;
}
html += '</tr>';
});
html += '</tbody>';
document.getElementById('scoreTable').innerHTML = html;
}
function renderPayouts(g) {
const el = document.getElementById('payouts');
if (!g.finished || !g.payouts) {
el.classList.add('hidden');
el.innerHTML = '';
return;
}
el.classList.remove('hidden');
const w = g.players[g.winnerId];
const e = g.players[g.earlyWinnerId];
const s = g.players[g.lastEliminatedId];
let html = `<h2>Payouts</h2><div class="payGrid">`;
html += `<div>Winner: <b>${w ? escapeHtml(w.name) : '—'}</b> $${g.payouts.first}</div>`;
if (g.payouts.second) html += `<div>Second: <b>${s ? escapeHtml(s.name) : '—'}</b> $${g.payouts.second}</div>`;
if (g.payouts.early) html += `<div>Early: <b>${e ? escapeHtml(e.name) : '—'}</b> $${g.payouts.early}</div>`;
html += `</div><h3>Owe each</h3><ul>`;
for (const id in g.payouts.byPlayer) {
const p = g.players[id];
html += `<li>${escapeHtml(p.name)} — $${g.payouts.byPlayer[id]}</li>`;
}
html += `</ul>`;
el.innerHTML = html;
}
function renderEventList() {
const list = document.getElementById('eventList');
list.innerHTML = sim.steps.map((s, i) => `<div class="eventItem ${i === stepIndex ? 'cur' : ''}" data-i="${i}">${i + 1}. ${escapeHtml(s.event.text)}</div>`).join('');
list.querySelectorAll('.eventItem').forEach(el => {
el.onclick = () => {
setPlaying(false);
stepIndex = parseInt(el.dataset.i, 10);
render();
};
});
}
function setPlaying(val) {
playing = val;
document.getElementById('playBtn').textContent = playing ? 'Pause' : 'Play';
if (playTimer) { clearTimeout(playTimer); playTimer = null; }
if (playing) scheduleNext();
}
function scheduleNext() {
if (!playing) return;
const ms = Math.max(50, 1200 / speed);
playTimer = setTimeout(() => {
if (stepIndex < sim.steps.length - 1) {
stepIndex++;
render();
scheduleNext();
} else {
setPlaying(false);
}
}, ms);
}
document.getElementById('playBtn').onclick = () => setPlaying(!playing);
document.getElementById('backBtn').onclick = () => {
setPlaying(false);
stepIndex = Math.max(-1, stepIndex - 1);
render();
};
document.getElementById('fwdBtn').onclick = () => {
setPlaying(false);
stepIndex = Math.min(sim.steps.length - 1, stepIndex + 1);
render();
};
document.getElementById('speed').oninput = (e) => {
speed = parseFloat(e.target.value);
document.getElementById('speedLabel').textContent = speed + 'x';
if (playing) {
if (playTimer) clearTimeout(playTimer);
scheduleNext();
}
};
render();
</script>
</body>
</html>