#!/usr/bin/env node // verifyRoulette.js — headless checks for Roulette: both wheels, every legal // inside bet, felt hit-testing (sweep + round trip from each chip spot), // payouts and exact house edges, La Partage, call bets and the racetrack, // table limits, an AI + random-human chip-conservation soak, the ball planner // landing on every pocket, and screen layout sanity. import { WHEELS, BET, INSIDE, EVEN_MONEY, PAYOUT, TABLE_LIMITS, RED, colorOf, legalInsideBets, normalizeSpec, betKey, createInitialState, placeBet, removeBet, refundBets, setVariant, maxAddable, spotLimit, resolveSpin, betOutcome, houseEdge, totalAtRisk, callBetSpecs, callBetNumbers, CALL_BETS, neighbours, spinResult, dealerCall, numberWords, outsideNumbers, findBet, } from '../src/games/roulette/RouletteLogic.js'; import { chooseBets, chooseLateBets, noteResult, personalityOf, PERSONALITIES } from '../src/games/roulette/RouletteAI.js'; import { P, VIEW, hitBetUV, hitBet, spotFor, insideSpots, feltBoxes, ZERO_U0, GRID_U0, CELL_U, GRID_U1, COL_U1, GRID_V0, ROW_V, GRID_V1, DOZ_V1, EVEN_V1, RT, RT_GEOM, RT_STEP, racetrackPoint, hitRacetrackUV, racetrackSectionCenters, racetrackLines, SEATS, seatNames, seatPortrait, railPose, bankPose, BOARD, CAM, CALL, DOCK, WHEEL, wheelCenter, CABINET_U1, NEIGHBOUR_UI, tableOutline, numberCenter, } from '../src/games/roulette/RouletteTable.js'; import { planSpin, mulberry32, GEO, WHEEL_SPEED, wheelAngleAt } from '../src/games/roulette/RouletteBall.js'; let pass = 0, fail = 0; function ok(label, cond, detail = '') { if (cond) pass++; else { console.error(` ✗ ${label}${detail ? ` — ${detail}` : ''}`); fail++; } } const section = (n) => console.log(`\n${n}`); const near = (a, b, eps = 1e-9) => Math.abs(a - b) <= eps; const VARIANTS = ['us', 'eu']; // ── 1. Wheels ──────────────────────────────────────────────────────────────── section('1. Wheels'); { for (const v of VARIANTS) { const P_ = WHEELS[v].pockets; const expect = v === 'us' ? 38 : 37; ok(`${v}: ${expect} pockets`, P_.length === expect, String(P_.length)); ok(`${v}: every number once`, new Set(P_).size === P_.length); for (let n = 1; n <= 36; n++) ok(`${v}: has ${n}`, P_.includes(n)); ok(`${v}: zeros`, WHEELS[v].zeros.every((z) => P_.includes(z))); // red and black alternate round the wheel (zeros aside) let alt = true; for (let i = 0; i < P_.length; i++) { const a = P_[i], b = P_[(i + 1) % P_.length]; if (colorOf(a) !== 'green' && colorOf(b) !== 'green' && colorOf(a) === colorOf(b)) alt = false; } ok(`${v}: red/black alternate`, alt); } const EU = [0, 32, 15, 19, 4, 21, 2, 25, 17, 34, 6, 27, 13, 36, 11, 30, 8, 23, 10, 5, 24, 16, 33, 1, 20, 14, 31, 9, 22, 18, 29, 7, 28, 12, 35, 3, 26]; ok('eu: exact pocket order', JSON.stringify(WHEELS.eu.pockets) === JSON.stringify(EU)); ok('18 reds', RED.size === 18); ok('partage only on eu', WHEELS.eu.partage && !WHEELS.us.partage); } // ── 2. Legal bets & payouts ────────────────────────────────────────────────── section('2. Legal bets, payouts, house edges'); { const counts = (v) => legalInsideBets(v).reduce((m, b) => (m[b.type] = (m[b.type] ?? 0) + 1, m), {}); const us = counts('us'), eu = counts('eu'); ok('us counts', us.straight === 38 && us.split === 62 && us.street === 12 && us.corner === 22 && us.sixline === 11 && us.trio === 3 && us.basket === 1 && !us.firstfour, JSON.stringify(us)); ok('eu counts', eu.straight === 37 && eu.split === 60 && eu.street === 12 && eu.corner === 22 && eu.sixline === 11 && eu.trio === 2 && eu.firstfour === 1 && !eu.basket, JSON.stringify(eu)); for (const v of VARIANTS) { const keys = new Set(); for (const b of legalInsideBets(v)) { const k = betKey(b.type, b.numbers); ok(`${v}: unique ${k}`, !keys.has(k)); keys.add(k); const n = b.numbers.length; if (b.type === BET.BASKET) ok('basket pays 6', PAYOUT[b.type] === 6 && n === 5); else ok(`${v}: ${k} pays 36/n − 1`, PAYOUT[b.type] === 36 / n - 1, `${PAYOUT[b.type]} vs ${36 / n - 1}`); ok(`${v}: ${k} numbers on wheel`, b.numbers.every((x) => WHEELS[v].pockets.includes(x))); } } const outside = [ [BET.RED], [BET.BLACK], [BET.ODD], [BET.EVEN], [BET.LOW], [BET.HIGH], [BET.DOZEN, 1], [BET.DOZEN, 2], [BET.DOZEN, 3], [BET.COLUMN, 1], [BET.COLUMN, 2], [BET.COLUMN, 3], ]; for (const [type, number] of outside) { const nums = outsideNumbers(type, number ?? null); ok(`${type}${number ?? ''} pays 36/n − 1`, PAYOUT[type] === 36 / nums.length - 1); } ok('column 1 = 1,4,7…', JSON.stringify(outsideNumbers(BET.COLUMN, 1).slice(0, 3)) === '[1,4,7]'); ok('red set', outsideNumbers(BET.RED).length === 18 && outsideNumbers(BET.RED).every((n) => RED.has(n))); ok('illegal split rejected', normalizeSpec('us', { type: BET.SPLIT, numbers: [3, 4] }) === null); ok('eu has no 00', normalizeSpec('eu', { type: BET.STRAIGHT, numbers: ['00'] }) === null); ok('us basket ok', !!normalizeSpec('us', { type: BET.BASKET, numbers: [3, 2, 1, '00', 0] })); ok('eu first four ok', !!normalizeSpec('eu', { type: BET.FIRST_FOUR, numbers: [0, 1, 2, 3] })); ok('bad dozen rejected', normalizeSpec('us', { type: BET.DOZEN, number: 4 }) === null); // exact edges for (const b of legalInsideBets('us')) { const e = houseEdge(b, 'us'); ok(`us edge ${b.type}`, near(e, b.type === BET.BASKET ? 3 / 38 : 2 / 38, 1e-12), String(e)); } for (const b of legalInsideBets('eu')) ok(`eu edge ${b.type}`, near(houseEdge(b, 'eu'), 1 / 37, 1e-12)); for (const [type, number] of outside) { ok(`us edge ${type}`, near(houseEdge({ type, number }, 'us'), 2 / 38, 1e-12)); const eu = houseEdge({ type, number }, 'eu'); ok(`eu edge ${type}`, near(eu, EVEN_MONEY.has(type) ? 0.5 / 37 : 1 / 37, 1e-12), String(eu)); } console.log(` edges: US ${(2 / 38 * 100).toFixed(2)}%, basket ${(3 / 38 * 100).toFixed(2)}%, EU ${(1 / 37 * 100).toFixed(2)}%, EU even-money ${(0.5 / 37 * 100).toFixed(2)}%`); } // ── 3. Placement, limits, resolution ───────────────────────────────────────── section('3. Placement, limits, resolution'); { let s = createInitialState([], 5000, 'T', 'us'); s = placeBet(s, 0, { type: BET.STRAIGHT, numbers: [17], amount: 25 }); s = placeBet(s, 0, { type: BET.STRAIGHT, numbers: [17], amount: 25 }); ok('stacks merge', s.players[0].bets.length === 1 && s.players[0].bets[0].amount === 50); ok('stake leaves bankroll', s.players[0].chips === 4950); ok('maxAddable straight', maxAddable(s, 0, { type: BET.STRAIGHT, numbers: [17] }) === 50); const s2 = placeBet(s, 0, { type: BET.STRAIGHT, numbers: [17], amount: 60 }); ok('over limit rejected', s2 === s); ok('limits', spotLimit(BET.SPLIT) === 200 && spotLimit(BET.RED) === TABLE_LIMITS.outside); const s3 = placeBet(s, 0, { type: BET.RED, amount: 6000 }); ok('unaffordable rejected', s3 === s); ok('zero amount rejected', placeBet(s, 0, { type: BET.RED, amount: 0 }) === s); let r = removeBet(s, 0, s.players[0].bets[0].key, 20); ok('partial remove', findBet(r.players[0], 'straight:17').amount === 30 && r.players[0].chips === 4970); r = removeBet(r, 0, 'straight:17'); ok('remove all', r.players[0].bets.length === 0 && r.players[0].chips === 5000); // resolution let t = createInitialState([], 1000, 'T', 'eu'); t = placeBet(t, 0, { type: BET.RED, amount: 20 }); t = placeBet(t, 0, { type: BET.STRAIGHT, numbers: [0], amount: 10 }); t = placeBet(t, 0, { type: BET.DOZEN, number: 1, amount: 10 }); const z = resolveSpin(t, 0); const red = z.payouts.find((p) => p.type === BET.RED); ok('partage half back', red.result === 'partage' && red.credited === 10 && red.delta === -10); ok('zero straight pays 35', z.payouts.find((p) => p.type === BET.STRAIGHT).winnings === 350); ok('dozen loses on 0', z.payouts.find((p) => p.type === BET.DOZEN).result === 'lose'); ok('eu zero bankroll', z.state.players[0].chips === 960 + 10 + 360 && z.state.players[0].lastDelta === -10 + 350 - 10); ok('bets cleared', z.state.players[0].bets.length === 0); let u = createInitialState([], 1000, 'T', 'us'); u = placeBet(u, 0, { type: BET.RED, amount: 20 }); const uz = resolveSpin(u, 0); ok('no partage on us', uz.payouts[0].result === 'lose' && uz.state.players[0].chips === 980); const w = resolveSpin(u, 3); ok('red wins on 3 (stake back + 1:1)', w.state.players[0].chips === 1020 && w.payouts[0].credited === 40); let sv = setVariant(u, 'eu'); ok('setVariant refunds', sv.variant === 'eu' && sv.players[0].chips === 1000 && !sv.players[0].bets.length); ok('refundBets', refundBets(u, 0).players[0].chips === 1000); ok('betOutcome win credited', betOutcome({ type: BET.SPLIT, numbers: [1, 2], amount: 10 }, 2, 'us').credited === 180); // dealer calls for (const v of WHEELS.us.pockets) { const c = dealerCall(v); ok(`call ${v}`, typeof c === 'string' && !c.includes('undefined') && c.length > 3, c); } ok('numberWords 27', numberWords(27) === 'Twenty-seven'); } // ── 4. Call bets & racetrack ───────────────────────────────────────────────── section('4. Call bets & racetrack'); { const expect = { voisins: [9, 17], tiers: [6, 12], orphelins: [5, 8], zero: [4, 7] }; for (const [name, [chips, nums]] of Object.entries(expect)) { const specs = callBetSpecs('eu', name, 5); ok(`${name} chips`, specs.reduce((a, s) => a + s.amount, 0) === chips * 5); ok(`${name} numbers`, callBetNumbers('eu', name).length === nums, String(callBetNumbers('eu', name).length)); ok(`${name} all legal`, specs.every((s) => normalizeSpec('eu', s))); } const all = new Set([...callBetNumbers('eu', 'voisins'), ...callBetNumbers('eu', 'tiers'), ...callBetNumbers('eu', 'orphelins')]); ok('voisins + tiers + orphelins = whole wheel', all.size === 37); const zeroIn = callBetNumbers('eu', 'zero').every((n) => callBetNumbers('eu', 'voisins').includes(n)); ok('jeu zéro ⊂ voisins', zeroIn); // sections are contiguous runs on the wheel const contiguous = (nums) => { const P_ = WHEELS.eu.pockets; const idx = nums.map((n) => P_.indexOf(n)); let runs = 0; for (const i of idx) if (!idx.includes((i - 1 + 37) % 37)) runs++; return runs; }; ok('voisins one arc', contiguous(callBetNumbers('eu', 'voisins')) === 1); ok('tiers one arc', contiguous(callBetNumbers('eu', 'tiers')) === 1); ok('orphelins two arcs', contiguous(callBetNumbers('eu', 'orphelins')) === 2); ok('jeu zéro one arc', contiguous(callBetNumbers('eu', 'zero')) === 1); for (const v of VARIANTS) { for (const n of WHEELS[v].pockets) { const nb = neighbours(v, n, 2); ok(`${v} neighbours ${n}`, nb.length === 5 && nb[2] === n && contiguous.length >= 0); ok(`${v} neighbour specs legal ${n}`, callBetSpecs(v, 'neighbours', 1, { number: n, k: 3 }).every((s) => normalizeSpec(v, s))); } } // racetrack: every segment clicks as its own number; inside regions match their numbers const P_ = WHEELS.eu.pockets; for (let i = 0; i < P_.length; i++) { const m = racetrackPoint(i * RT_STEP); const h = hitRacetrackUV(m.u, m.v); ok(`racetrack segment ${P_[i]}`, h?.call === 'neighbours' && h.number === P_[i], JSON.stringify(h)); // just inside the band, the section region should include this number const inner = RT_GEOM.R - RT.band - RT_GEOM.RC - 0.012; const q = { u: m.u + m.nu * inner, v: m.v + m.nv * inner }; const s = hitRacetrackUV(q.u, q.v); ok(`inside the band beside ${P_[i]} is a section`, s && s.call !== 'neighbours'); // away from the (slanted) dividers, the section holds the number beside it const clear = racetrackLines().every(([t, b]) => Math.abs(q.u - (t.u + (b.u - t.u) * (q.v - t.v) / (b.v - t.v))) > 0.05); if (clear) ok(`section beside ${P_[i]}`, callBetNumbers('eu', s.call).includes(P_[i]), `${JSON.stringify(s)}`); } for (const c of racetrackSectionCenters()) { ok(`section label ${c.name} hits`, hitRacetrackUV(c.u, c.v)?.call === c.name); } ok('racetrack above grid', RT.v1 < GRID_V0); ok('no racetrack on us', !hitBetUV((RT.u0 + RT.u1) / 2, RT.v0 + 0.01, 'us')); } // ── 5. Felt hit-testing ────────────────────────────────────────────────────── section('5. Felt hit-testing'); { for (const v of VARIANTS) { // round trip: clicking exactly on each legal bet's chip spot gives that bet for (const b of insideSpots(v)) { const h = hitBetUV(b.spot.u, b.spot.v, v); ok(`${v} spot round-trip ${b.key}`, h?.key === b.key, `${h?.key}`); const sp = spotFor({ ...b }, v); ok(`${v} spotFor ${b.key}`, near(sp.u, b.spot.u) && near(sp.v, b.spot.v)); } // a fine sweep: every hit is legal, near its own chip spot; every bet is reachable const seen = new Set(); let bad = 0, far = 0; for (let u = ZERO_U0 - 0.01; u <= COL_U1 + 0.01; u += 0.0025) { for (let vv = GRID_V0 - 0.01; vv <= EVEN_V1 + 0.01; vv += 0.0025) { const h = hitBetUV(u, vv, v); if (!h) continue; if (h.kind !== 'bet') continue; const norm = normalizeSpec(v, h); if (!norm) { bad++; continue; } seen.add(norm.key); if (INSIDE.has(norm.type)) { const sp = spotFor(norm, v); const tolV = isZeroStraight(norm) ? (v === 'eu' ? 1.55 : 1.0) * ROW_V : 0.62 * ROW_V; if (Math.abs(sp.u - u) > 0.62 * CELL_U || Math.abs(sp.v - vv) > tolV) far++; } } } ok(`${v} sweep: all hits legal`, bad === 0, String(bad)); ok(`${v} sweep: chips land near the pointer`, far === 0, String(far)); const missing = legalInsideBets(v).filter((b) => !seen.has(betKey(b.type, b.numbers))); ok(`${v} sweep: every inside bet reachable`, missing.length === 0, missing.map((b) => betKey(b.type, b.numbers)).slice(0, 6).join(' ')); for (const k of ['red', 'black', 'odd', 'even', 'low', 'high', 'dozen:1', 'dozen:2', 'dozen:3', 'column:1', 'column:2', 'column:3']) { ok(`${v} sweep: reaches ${k}`, seen.has(k)); } // each outside box: its centre hits it, and the spot is inside the box for (const b of feltBoxes(v).filter((x) => x.kind === 'out')) { const h = hitBetUV((b.u0 + b.u1) / 2, (b.v0 + b.v1) / 2, v); ok(`${v} box ${b.type}${b.number ?? ''}`, h?.type === b.type && (h.number ?? null) === (b.number ?? null)); } // number boxes: centre is a straight-up of that number for (const b of feltBoxes(v).filter((x) => x.kind === 'num')) { const c = numberCenter(b.n, v); const h = hitBetUV(c.u, c.v, v); ok(`${v} number ${b.n}`, h?.type === BET.STRAIGHT && h.numbers[0] === b.n, JSON.stringify(h)); } } // screen round trip through the projection const s = P.project(GRID_U0 + CELL_U * 5.5, GRID_V0 + ROW_V * 1.5); ok('screen hit (5.5, 1.5) = 17', hitBet(s.x, s.y, 'us')?.numbers?.[0] === 17); ok('far off the felt = nothing', hitBet(5, 5, 'us') === null); } function isZeroStraight(norm) { return norm.type === BET.STRAIGHT && (norm.numbers[0] === 0 || norm.numbers[0] === '00'); } // ── 6. AI ──────────────────────────────────────────────────────────────────── section('6. AI'); { const names = Array.from({ length: 60 }, (_, i) => `Bot${i}`); const kinds = new Set(names.map((n) => personalityOf({ name: n }))); ok('every personality used', kinds.size === Object.keys(PERSONALITIES).length, [...kinds].join(',')); const rng = mulberry32(7); for (const v of VARIANTS) { for (const name of names) { for (const chips of [2000, 140, 12, 3]) { const p = { name, chips, bets: [] }; const mem = {}; const specs = chooseBets(p, { variant: v, history: [17, 17, 4, 0, 22], memory: mem, rng }); const total = specs.reduce((a, s) => a + s.amount, 0); ok(`${v} ${name} ${chips}: affordable`, total <= chips, `${total}`); ok(`${v} ${name}: legal`, specs.every((s) => normalizeSpec(v, s) && s.amount >= 1 && s.amount <= spotLimit(s.type)), JSON.stringify(specs)); const late = chooseLateBets(p, { variant: v, rng }); ok(`${v} ${name}: late legal`, late.every((s) => normalizeSpec(v, s) && s.amount <= chips)); } } } // martingale doubles after a loss and resets on a win const mName = names.find((n) => personalityOf({ name: n }) === 'martingale'); const mp = { name: mName, chips: 2000, bets: [] }; const mem = {}; chooseBets(mp, { variant: 'us', memory: mem, rng }); const base = mem.stake; noteResult(mp, mem, [{ type: mem.type, result: 'lose' }]); ok('martingale doubles', mem.stake === base * 2); noteResult(mp, mem, [{ type: mem.type, result: 'win' }]); ok('martingale resets', mem.stake === base); } // ── 7. Soak: chip conservation ─────────────────────────────────────────────── section('7. Soak (20k spins)'); { const rng = mulberry32(12345); const pickR = (a) => a[Math.floor(rng() * a.length)]; for (const v of VARIANTS) { const opps = Array.from({ length: 6 }, (_, i) => ({ name: `Soak${i}${v}` })); let s = createInitialState(opps, 5000, 'Human', v); const mem = s.players.map(() => ({})); const hist = []; let violations = 0, neg = 0, deltaMismatch = 0; const legal = legalInsideBets(v); for (let spin = 0; spin < 10000; spin++) { // refill busted players so the soak keeps exercising bets for (const p of s.players) if (p.chips < 50 && !p.bets.length) p.chips += 2000; for (let pi = 1; pi < s.players.length; pi++) { for (const spec of chooseBets(s.players[pi], { variant: v, history: hist, memory: mem[pi], rng })) s = placeBet(s, pi, spec); for (const spec of chooseLateBets(s.players[pi], { variant: v, rng })) s = placeBet(s, pi, spec); } // the human: random inside/outside/call bets, some removes const n = Math.floor(rng() * 5); for (let k = 0; k < n; k++) { const r = rng(); if (r < 0.5) { const b = pickR(legal); s = placeBet(s, 0, { ...b, amount: 1 + Math.floor(rng() * 30) }); } else if (r < 0.8) s = placeBet(s, 0, { type: pickR([BET.RED, BET.BLACK, BET.ODD, BET.EVEN, BET.LOW, BET.HIGH]), amount: 1 + Math.floor(rng() * 50) }); else if (v === 'eu') for (const spec of callBetSpecs(v, pickR(['voisins', 'tiers', 'orphelins', 'zero']), 1)) s = placeBet(s, 0, spec); else s = placeBet(s, 0, { type: BET.DOZEN, number: 1 + Math.floor(rng() * 3), amount: 5 }); } if (s.players[0].bets.length && rng() < 0.1) s = removeBet(s, 0, s.players[0].bets[0].key, 3); const before = s.players.map((p) => p.chips + totalAtRisk(p)); for (const p of s.players) for (const b of p.bets) if (b.amount > spotLimit(b.type)) violations++; const value = spinResult(v, rng); hist.push(value); const out = resolveSpin(s, value); s = out.state; s.players.forEach((p, pi) => { if (p.chips < 0) neg++; if (p.chips !== before[pi] + p.lastDelta) deltaMismatch++; const sum = out.payouts.filter((x) => x.playerIndex === pi).reduce((a, x) => a + x.delta, 0); if (sum !== p.lastDelta) deltaMismatch++; noteResult(p, mem[pi], out.payouts.filter((x) => x.playerIndex === pi)); }); } ok(`${v}: chips conserved (stake + delta)`, deltaMismatch === 0, String(deltaMismatch)); ok(`${v}: never negative`, neg === 0); ok(`${v}: table limits respected`, violations === 0); } // empirical edge on red, 200k spins for (const v of VARIANTS) { const r = mulberry32(99); let net = 0; const N = 200000; for (let i = 0; i < N; i++) { const val = spinResult(v, r); net += betOutcome({ type: BET.RED, numbers: outsideNumbers(BET.RED), amount: 2 }, val, v).credited - 2; } const edge = -net / (2 * N); const want = v === 'us' ? 2 / 38 : 0.5 / 37; ok(`${v}: empirical red edge ≈ ${(want * 100).toFixed(2)}%`, Math.abs(edge - want) < 0.006, (edge * 100).toFixed(2)); } } // ── 8. Ball planner ────────────────────────────────────────────────────────── section('8. Ball planner'); { let landed = 0, total = 0; const stats = { settle: [], nmb: [], w: [] }; for (const v of VARIANTS) { const pockets = WHEELS[v].pockets; for (const target of pockets) { for (let s = 1; s <= 25; s++) { const plan = planSpin({ variant: v, target, wheelAngle0: s * 0.77, seed: s * 7919 + pockets.indexOf(target) }); total++; const T = plan.T; const good = plan.pocketUnderBall(T.settle) === target && plan.pocketUnderBall(T.end) === target && plan.pocketUnderBall(T.end + 3) === target; if (good) landed++; else ok(`${v} ${target} seed ${s} lands`, false, String(plan.pocketUnderBall(T.end))); ok(`${v} ${target} ω₀ in range`, plan.omega0 >= WHEEL_SPEED.min - 1e-9 && plan.omega0 <= WHEEL_SPEED.max + 1e-9, plan.omega0.toFixed(3)); ok(`${v} ${target} timeline order`, T.noMoreBets < T.drop && T.drop < T.entry && T.entry < T.settle && T.settle < T.end); stats.settle.push(T.settle); stats.nmb.push(T.noMoreBets); stats.w.push(plan.omega0); if (s > 3) continue; // the per-frame sweep is slow; three seeds per pocket let prev = plan.sample(0), maxJump = 0, rOut = 0, bad = 0, maxWJump = 0; for (let t = 1 / 120; t <= T.end + 0.5; t += 1 / 120) { const q = plan.sample(t); const b = q.ball; if (![b.angle, b.r, b.h, q.wheel].every(Number.isFinite)) bad++; if (b.r < GEO.R_POCKET - 0.02 || b.r > GEO.R_TRACK + 0.02 || b.h < -0.01 || b.h > 0.3) rOut++; maxJump = Math.max(maxJump, Math.abs(b.angle - prev.ball.angle)); maxWJump = Math.max(maxWJump, Math.abs(q.wheel - prev.wheel)); prev = q; } ok(`${v} ${target} s${s}: finite`, bad === 0); ok(`${v} ${target} s${s}: ball inside the bowl`, rOut === 0, String(rOut)); ok(`${v} ${target} s${s}: smooth ball`, maxJump < 0.2, maxJump.toFixed(3)); ok(`${v} ${target} s${s}: smooth wheel`, maxWJump < 0.05, maxWJump.toFixed(3)); ok(`${v} ${target} s${s}: ≤ 2 diamond hits`, plan.diamondHits.length <= 2); } } } ok(`every spin lands on its number (${landed}/${total})`, landed === total); const mm = (a) => `${Math.min(...a).toFixed(2)}–${Math.max(...a).toFixed(2)}`; console.log(` settle ${mm(stats.settle)}s · no-more-bets ${mm(stats.nmb)}s · wheel push ${mm(stats.w)} rad/s`); ok('wheel starts at idle speed', near(planSpin({ variant: 'us', target: 5, seed: 3 }).wheelSpeed(0), WHEEL_SPEED.idle, 1e-9)); ok('wheelAngleAt(0) = W0', near(wheelAngleAt(1.23, 2.5, 0), 1.23)); // uniform landing is the RNG's job: spinResult covers the wheel evenly const r = mulberry32(4); const freq = new Map(); for (let i = 0; i < 38000; i++) { const x = spinResult('us', r); freq.set(x, (freq.get(x) ?? 0) + 1); } ok('spinResult hits every pocket', freq.size === 38); ok('spinResult roughly uniform', Math.max(...freq.values()) < 1250 && Math.min(...freq.values()) > 750); } // ── 9. Screen layout ───────────────────────────────────────────────────────── section('9. Screen layout'); { const inScreen = (p, m = 0) => p.x >= m && p.x <= 1920 - m && p.y >= m && p.y <= 1080 - m; for (const [u, v] of [[-1, 0], [1, 0], [-1, 1], [1, 1]]) ok(`table corner ${u},${v} on screen`, inScreen(P.project(u, v))); const layoutCorners = [[ZERO_U0, GRID_V0], [COL_U1, GRID_V0], [ZERO_U0, EVEN_V1], [COL_U1, EVEN_V1]]; for (const [u, v] of layoutCorners) { ok(`layout corner ${u.toFixed(2)},${v.toFixed(2)} on felt`, u > -1 && u < 1 && v > 0 && v < 1); } ok('layout right of the wheel cabinet', ZERO_U0 > CABINET_U1); const wc = wheelCenter(); const bowlRight = wc.x + WHEEL.R * 1.12; const zeroLeft = P.project(ZERO_U0, WHEEL.v).x; ok('wheel bowl clear of the layout', bowlRight < zeroLeft, `${bowlRight.toFixed(0)} vs ${zeroLeft.toFixed(0)}`); ok('wheel bowl on screen', wc.x - WHEEL.R * 1.12 > 150 && wc.y - WHEEL.R * WHEEL.tilt * 1.4 > 190); const ports = []; for (const name of Object.keys(SEATS)) { if (name === 'H') continue; const pt = seatPortrait(name); ok(`seat ${name} portrait on screen`, inScreen(pt, pt.r)); ok(`seat ${name} above the dock`, pt.y + pt.r < DOCK.y, `${pt.y + pt.r}`); ok(`seat ${name} clear of the marquee`, !(pt.x + pt.r > BOARD.x && pt.x - pt.r < BOARD.x + BOARD.w && pt.y - pt.r < BOARD.y + BOARD.h)); ports.push(pt); ok(`seat ${name} rail on screen`, inScreen(railPose(name, 0.05)) && inScreen(railPose(name, -0.05))); } for (let i = 0; i < ports.length; i++) for (let j = i + 1; j < ports.length; j++) { ok(`portraits ${i}/${j} apart`, Math.hypot(ports[i].x - ports[j].x, ports[i].y - ports[j].y) > ports[i].r * 2 + 60); } ok('seat names for 6', seatNames(6).length === 7 && new Set(seatNames(6)).size === 7); ok('bank on screen', inScreen(bankPose())); ok('marquee left of the music widget', BOARD.x + BOARD.w <= 1600 && BOARD.y >= 0); ok('marquee above the table', BOARD.y + BOARD.h < P.project(0, 0).y - 20); ok('cam panel above the dock', CAM.y + CAM.h < DOCK.y && CAM.x + CAM.w < 1920); ok('dealer call clear of the left buttons', CALL.x - 350 > 170); const nb = P.project(NEIGHBOUR_UI.u, NEIGHBOUR_UI.v); ok('neighbour stepper right of the racetrack', nb.x - 50 > P.project(RT.u1, NEIGHBOUR_UI.v).x, `${nb.x}`); ok('neighbour stepper on the felt', NEIGHBOUR_UI.u < 1 - 0.05); // cell size on screen is comfortable to click const a = P.project(GRID_U0, GRID_V0), b = P.project(GRID_U0 + CELL_U, GRID_V0); ok('far cells ≥ 60px wide', b.x - a.x >= 60, (b.x - a.x).toFixed(0)); } console.log(`\n${pass} passed, ${fail} failed`); process.exit(fail ? 1 : 0);