Files
JoshHeaps.Net/tests/holdem/load.js
T
jheapsandClaude Opus 5 2d80edd513 Say how many ways once, in the one control that owns it
"Split between" on Quick Split was two controls for one value stacked on
each other: chips 2 3 4 5, and under them a bar reading "2 ways" with a −
and a +. The count was written down three times at once — the lit chip,
the bar, and "Each of 2 players gets" in the panel above — and two of the
three were controls. 134px with its label, against 74px for "Smallest
chip in play" right below it, which offers five choices in one row.

The bar was never meant to be a bar. `.waysStepper` asked for a 150px
min-width inside a wrapping flex row, so on a phone it always wrapped to a
line of its own, and `flex: 1 1 auto` then gave it all 358px of that line:
252px of empty readout with the − and + pushed 304px apart, on a screen
390px wide. Now it is 136px with its ends 121px apart, and it only exists
once you are through the door — a fifth chip reading "6+", behind which
the stepper is where the count is written. Under six ways, which is every
chop a home game will run, the field is one row and 74px.

Two more things went with it:

Neither stepper ever disabled an end, so − at the floor and + at the
ceiling looked live and swallowed the tap. NN/G's stepper guidance asks
for the opposite. Both ends of both steppers now grey out.

The per-pot chop capped its + with `Math.max(contenderCount, MAX_WAYS)`,
which is always 12 — a side pot only P1 and P2 were eligible for would
happily chop ten ways at $12 each. It is `chopCeiling()` now, and a
two-contender pot is offered no stepper at all, that being the common
shape.

The sweep went straight to the all-in mode and audited only that, so the
mode the screen opens in had never been looked at in fourteen rounds,
which is how a 358px bar lasted this long. It audits both now — 428
audits, clean — and the first run of it found the step buttons had been
40px wide rather than 44 since they were written.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015bnp7xKUPFFSpwkYNFaPgb
2026-09-11 22:24:49 -06:00

124 lines
4.6 KiB
JavaScript

// Loads the dealer's browser modules into Node so they can be tested directly.
//
// The modules are plain script-tag files: each one declares a `const` namespace and
// ends with a `module.exports` guard. In the browser they find each other as globals,
// so the same names have to exist on `globalThis` here or `Betting` can't reach
// `HoldemState`. Load order matches the <script> order in TexasHoldem.cshtml.
const path = require("path");
const SRC = path.join(__dirname, "..", "..", "JoshHeaps.Net", "wwwroot", "js", "casino", "holdem");
function load(name) {
const mod = require(path.join(SRC, `${name}.js`));
globalThis[name.charAt(0).toUpperCase() + name.slice(1)] = mod;
return mod;
}
const Money = load("money");
const HandRank = load("handRank");
const PotCalculator = load("potCalculator");
const SplitCalculator = load("splitCalculator");
const Betting = load("betting");
const SettleUp = load("settleUp");
const HandHistoryExport = load("handHistoryExport");
// render.js exports { Render } rather than the namespace directly.
const Render = require(path.join(SRC, "render.js")).Render;
globalThis.Render = Render;
// state.js exports `HoldemState`, which doesn't match its filename.
const HoldemState = require(path.join(SRC, "state.js"));
globalThis.HoldemState = HoldemState;
// actionBar.js after state, since its own module-level code reaches for neither but
// its methods reach for both. Loaded last so nothing it touches is still undefined.
const ActionBar = load("actionBar");
// The picker's slot bookkeeping — which slots it is filling, what is already dealt —
// is plain state work and testable here. Only render() and open() touch the DOM.
const CardPicker = load("cardPicker");
// The wake lock's rule about when a table needs the screen is plain state work too.
// Its acquire/release bookkeeping is testable here as well, against a stand-in for
// navigator.wakeLock — see wakeLock.test.js.
const WakeLock = load("wakeLock");
// Modal is DOM behaviour through and through, but two pieces of it answer here: the
// list of what counts as a Tab stop, which is a string, and preservingFocus, which asks
// so little of a document that a stand-in can answer it. See theKeyboardInASheet.
const Modal = load("modal");
// Quick Split draws itself entirely from the DOM, but the arithmetic that decides what
// its two steppers are allowed to reach — and how many ways a pot may be chopped — is
// plain and answers here. See theWaysControl.
const QuickSplit = load("quickSplit");
// The seat menu's list — which actions a seat is offered and which group each one
// lands in — is decided before anything is drawn, so actionsFor() answers here. Only
// render() and open() touch the DOM.
const SeatMenu = load("seatMenu");
// ---- Table builders ----------------------------------------------------------
// A table with `seatCount` chairs where `seated` (a list of seat indexes) are dealt
// in with `stack` chips each. Everything else is the app's own defaults, so a test
// that forgets to set a field gets whatever a real dealer would get.
function makeTable({ seatCount = 6, seated = null, stack = 100, smallBlind = 1, bigBlind = 2, dealerSeatIndex = 0 } = {}) {
const state = HoldemState.createDefault();
HoldemState.resizeSeats(state, seatCount);
state.smallBlind = smallBlind;
state.bigBlind = bigBlind;
state.dealerSeatIndex = dealerSeatIndex;
const sitting = seated || state.seats.map((_, i) => i);
state.seats.forEach((player, index) => {
player.inHand = sitting.includes(index);
player.stack = sitting.includes(index) ? stack : null;
player.name = `P${index + 1}`;
});
return state;
}
// Total chips the table is accountable for: what's in front of everyone, plus what
// they've pushed in this street, plus what's already banked into the pot.
function chipsOnTable(state) {
return Money.round(
state.seats.reduce(
(sum, p) => sum + (Number(p.stack) || 0) + (Number(p.committed) || 0) + (Number(p.amountOverride) || 0),
0
)
);
}
// Contributions in the shape PotCalculator wants them.
function contributions(state) {
return state.seats
.filter(p => p.inHand)
.map(p => ({
id: p.id,
contribution: Betting.handTotal(p),
folded: p.folded,
}));
}
module.exports = {
Money,
HandRank,
Render,
HandHistoryExport,
PotCalculator,
SplitCalculator,
SettleUp,
Betting,
HoldemState,
ActionBar,
CardPicker,
WakeLock,
SeatMenu,
Modal,
QuickSplit,
makeTable,
chipsOnTable,
contributions,
};