Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f3d0dce4b | ||
|
|
01f5139740 |
@@ -141,7 +141,13 @@
|
||||
</div>
|
||||
|
||||
<h3 class="panelSubhead">Hands</h3>
|
||||
<div class="handHistoryFilterRow">
|
||||
<input id="handHistoryFilter" type="search" class="handHistoryFilter"
|
||||
placeholder="Find a hand — name, amount or #" aria-label="Filter the hand log by player, amount or hand number" />
|
||||
<span id="handHistoryCount" class="handHistoryCount" hidden></span>
|
||||
</div>
|
||||
<div id="handHistoryList"></div>
|
||||
<p id="handHistoryNoMatch" class="fieldHint" hidden></p>
|
||||
<p id="handHistoryEmptyHint" class="fieldHint">Resolved pots are logged here, in case a chip count is disputed later.</p>
|
||||
|
||||
<div class="handHistoryActions">
|
||||
@@ -393,6 +399,22 @@
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="ruling" data-short="Who shows first">
|
||||
<h3>Who turns their hand over first</h3>
|
||||
<p>
|
||||
If there was a bet on the river, the last player to bet or raise shows
|
||||
first. If the river was checked all the way round, it's the first live
|
||||
player left of the button. Nobody has to be asked twice — a player may
|
||||
always turn their hand over early if they want to.
|
||||
</p>
|
||||
<p>
|
||||
When everyone is all-in before the river there was no final round to
|
||||
lead, so it falls to whoever last put money in, on whichever street that
|
||||
was. The action bar names the seat and the reason at every showdown, so
|
||||
the call is already made before anyone asks.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="ruling" data-short="Odd chip">
|
||||
<h3>The odd chip in a split pot</h3>
|
||||
<p>
|
||||
|
||||
@@ -1957,11 +1957,62 @@ button,
|
||||
color: #e07b7b;
|
||||
}
|
||||
|
||||
/* The showdown call, sat above the resolve button. Loud enough to be read across a
|
||||
table at a glance — this is something the dealer says out loud — but not so loud it
|
||||
competes with the button underneath it. */
|
||||
.showdownCall {
|
||||
margin: 0 0 0.45rem;
|
||||
text-align: center;
|
||||
font-size: 0.82rem;
|
||||
color: #f0d98c;
|
||||
}
|
||||
|
||||
.handHistoryFilterRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.45rem;
|
||||
}
|
||||
|
||||
.handHistoryFilter {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
/* 16px or iOS zooms the whole page on focus, which on a phone at the table throws
|
||||
the felt off screen mid-hand. Every other field in this panel is held at 16px
|
||||
for the same reason. */
|
||||
font-size: 16px;
|
||||
padding: 0.35rem 0.5rem;
|
||||
background: #141414;
|
||||
border: 1px solid #2c2c2c;
|
||||
border-radius: 6px;
|
||||
color: #e6e6e6;
|
||||
}
|
||||
|
||||
.handHistoryFilter::placeholder {
|
||||
color: #8a8a8a;
|
||||
}
|
||||
|
||||
.handHistoryFilter:focus-visible {
|
||||
outline: 2px solid #d8b46a;
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
.handHistoryCount {
|
||||
flex: 0 0 auto;
|
||||
font-size: 0.72rem;
|
||||
color: #8a8a8a;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
#handHistoryList {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
max-height: 260px;
|
||||
/* Was a flat 260px, which is about four and a half rows — the same four and a half
|
||||
whether the dealer is on a phone or a 27" screen with room for twenty. The floor
|
||||
keeps it honest on a short window; the ceiling stops the panel from running away
|
||||
on a tall one and pushing everything below it out of reach. */
|
||||
max-height: clamp(200px, 42vh, 560px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
|
||||
@@ -691,13 +691,41 @@ const ActionBar = {
|
||||
return wrap;
|
||||
},
|
||||
|
||||
// "Dee shows first — last to raise." The call the dealer has to make at every
|
||||
// showdown and that nobody at the table volunteers for, said out loud with the
|
||||
// reason attached so it can be repeated to whoever argues with it.
|
||||
showdownCall() {
|
||||
const call = Betting.showdownOrder(this.state);
|
||||
if (!call) return null;
|
||||
|
||||
const who = HoldemState.displayName(this.state.seats[call.index], call.index);
|
||||
const because = {
|
||||
aggressor: "last to bet or raise",
|
||||
// Semicolon, not a second dash: the sentence already spends its dash on
|
||||
// "shows first —", and two of them in one line reads as a stutter.
|
||||
allInAggressor: "last to put money in; nobody could bet the river",
|
||||
leftOfButton: "checked round, first left of the button",
|
||||
}[call.reason];
|
||||
|
||||
const line = document.createElement("p");
|
||||
line.className = "showdownCall";
|
||||
line.textContent = `${who} shows first — ${because}.`;
|
||||
return line;
|
||||
},
|
||||
|
||||
renderStreetDone() {
|
||||
const row = document.createElement("div");
|
||||
row.className = "actionButtons";
|
||||
const wrap = document.createElement("div");
|
||||
|
||||
const isRiver = this.state.street === "river";
|
||||
const label = isRiver ? "Showdown — resolve pot" : `Deal ${Betting.streetLabel(Betting.STREETS[Betting.STREETS.indexOf(this.state.street) + 1])}`;
|
||||
|
||||
if (isRiver) {
|
||||
const call = this.showdownCall();
|
||||
if (call) wrap.appendChild(call);
|
||||
}
|
||||
|
||||
const row = document.createElement("div");
|
||||
row.className = "actionButtons";
|
||||
row.appendChild(this.button(label, "actionAdvance", () => {
|
||||
if (isRiver) {
|
||||
this.hooks.resolvePot();
|
||||
@@ -705,22 +733,33 @@ const ActionBar = {
|
||||
}
|
||||
this.commit(`dealing the ${Betting.streetLabel(Betting.STREETS[Betting.STREETS.indexOf(this.state.street) + 1]).toLowerCase()}`, () => Betting.closeStreet(this.state));
|
||||
}));
|
||||
wrap.appendChild(row);
|
||||
|
||||
return row;
|
||||
return wrap;
|
||||
},
|
||||
|
||||
renderHandOver() {
|
||||
const row = document.createElement("div");
|
||||
row.className = "actionButtons";
|
||||
const wrap = document.createElement("div");
|
||||
const live = Betting.liveSeats(this.state);
|
||||
const winner = live.length === 1 ? HoldemState.displayName(live[0].player, live[0].index) : null;
|
||||
|
||||
// Two or more still in with the betting finished is a showdown however it was
|
||||
// arrived at — including everyone all-in on the flop, where the cards go on
|
||||
// their backs and the order still decides who turns over first.
|
||||
if (!winner) {
|
||||
const call = this.showdownCall();
|
||||
if (call) wrap.appendChild(call);
|
||||
}
|
||||
|
||||
const row = document.createElement("div");
|
||||
row.className = "actionButtons";
|
||||
row.appendChild(this.button(
|
||||
winner ? `Award pot to ${winner}` : "Resolve pot",
|
||||
"actionAdvance",
|
||||
() => this.hooks.resolvePot()
|
||||
));
|
||||
return row;
|
||||
wrap.appendChild(row);
|
||||
return wrap;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -276,6 +276,11 @@ const Betting = {
|
||||
|
||||
if (newBet > previousBet) {
|
||||
const increase = this.round(newBet - previousBet);
|
||||
// Aggression, whether or not it was a full raise — a short all-in doesn't
|
||||
// reopen the betting, but the player who made it is still the last one who
|
||||
// put money in, and at the showdown they are still the one who shows first.
|
||||
state.streetAggressorIndex = index;
|
||||
state.handAggressorIndex = index;
|
||||
// What a full raise would have had to be: at least as much again as the
|
||||
// last one, or the big blind if there hasn't been a raise yet.
|
||||
const fullRaise = this.round(state.lastRaiseSize || state.bigBlind || 0);
|
||||
@@ -337,6 +342,10 @@ const Betting = {
|
||||
|
||||
state.currentBet = 0;
|
||||
state.lastRaiseSize = 0;
|
||||
// Whoever led this street stops being the answer the moment the next one opens.
|
||||
// The hand's aggressor is deliberately left alone: it's the fallback for a
|
||||
// river nobody could bet on.
|
||||
state.streetAggressorIndex = null;
|
||||
|
||||
const nextStreetIndex = this.STREETS.indexOf(state.street || "preflop") + 1;
|
||||
state.street = this.STREETS[nextStreetIndex] || "river";
|
||||
@@ -424,6 +433,11 @@ const Betting = {
|
||||
state.street = "preflop";
|
||||
state.currentBet = 0;
|
||||
state.lastRaiseSize = 0;
|
||||
// Posting a blind isn't aggression — a hand limped and checked all the way
|
||||
// down has no aggressor at all, which is exactly the case the showdown rule
|
||||
// sends to the seat left of the button.
|
||||
state.streetAggressorIndex = null;
|
||||
state.handAggressorIndex = null;
|
||||
|
||||
// Deal around anyone with no chips, before anything else reads the table.
|
||||
//
|
||||
@@ -504,6 +518,45 @@ const Betting = {
|
||||
: this.nextToAct(state, bbIndex);
|
||||
},
|
||||
|
||||
// Who turns their hand over first.
|
||||
//
|
||||
// A call the dealer makes at every showdown that isn't a fold, and one nobody at
|
||||
// the table volunteers for — everyone would rather see a hand than show one. The
|
||||
// tool knew who last raised and who sits left of the button and said neither, so
|
||||
// the dealer was working it out from memory while five people waited.
|
||||
//
|
||||
// Three cases, in the order the rule asks them:
|
||||
// * somebody bet or raised on the final round — they show first;
|
||||
// * the round was checked through — first live player left of the button;
|
||||
// * nobody could bet, because the chips were already in — the last player who
|
||||
// did put money in, on whichever round that was.
|
||||
//
|
||||
// Returns null when there's nothing to call: one player left, or none.
|
||||
showdownOrder(state) {
|
||||
const live = this.liveSeats(state);
|
||||
if (live.length < 2) return null;
|
||||
|
||||
const seatOf = index =>
|
||||
Number.isInteger(index) && live.some(s => s.index === index) ? index : null;
|
||||
|
||||
const streetAggressor = seatOf(state.streetAggressorIndex);
|
||||
if (streetAggressor !== null) {
|
||||
return { index: streetAggressor, reason: "aggressor" };
|
||||
}
|
||||
|
||||
// Nobody could have bet this round, so "no bet on the final round" isn't a
|
||||
// choice anybody made and the seat left of the button hasn't earned the
|
||||
// obligation. It falls to whoever last put money in.
|
||||
if (!this.canStillBet(state)) {
|
||||
const handAggressor = seatOf(state.handAggressorIndex);
|
||||
if (handAggressor !== null) return { index: handAggressor, reason: "allInAggressor" };
|
||||
}
|
||||
|
||||
const order = HoldemState.liveOrderFromButton(state)
|
||||
.filter(index => live.some(s => s.index === index));
|
||||
return order.length > 0 ? { index: order[0], reason: "leftOfButton" } : null;
|
||||
},
|
||||
|
||||
// Winners get their share put back in front of them.
|
||||
creditWinnings(state, payouts) {
|
||||
payouts.forEach(payout => {
|
||||
|
||||
@@ -591,15 +591,33 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
if (!ok) return;
|
||||
|
||||
HoldemState.clearHistory(state);
|
||||
Render.historyFilter = "";
|
||||
document.getElementById("handHistoryFilter").value = "";
|
||||
hooks.save(state);
|
||||
Render.renderAll();
|
||||
Toast.show("Hand history cleared.", { duration: 2500 });
|
||||
});
|
||||
|
||||
// The filter is how the dealer looks at the log, not something about the table, so
|
||||
// it lives on the view: it isn't saved, isn't undoable, and doesn't reach the other
|
||||
// tab. Clearing the history clears it too, since there is nothing left to filter.
|
||||
document.getElementById("handHistoryFilter").addEventListener("input", e => {
|
||||
Render.historyFilter = e.target.value;
|
||||
Render.renderHandHistory();
|
||||
});
|
||||
|
||||
document.getElementById("exportHistoryBtn").addEventListener("click", () => {
|
||||
if ((state.handHistory || []).length === 0) return;
|
||||
// Always the whole night. A filter is for reading the panel; an export that
|
||||
// quietly dropped the hands scrolled past would be a record with holes in it,
|
||||
// and nothing on the CSV would say so.
|
||||
HandHistoryExport.download(state.handHistory, HoldemState.sessionStandings(state),
|
||||
{ notes: state.notes });
|
||||
if (Render.historyFilter) {
|
||||
Toast.show(`Exported all ${state.handHistory.length} hands, not just the ${
|
||||
state.handHistory.filter(h => Render.handMatchesFilter(h, Render.historyFilter)).length} shown.`,
|
||||
{ duration: 3500 });
|
||||
}
|
||||
});
|
||||
|
||||
// The load happens on the first line of this file, long before there's a Toast to
|
||||
|
||||
@@ -967,9 +967,50 @@ const Render = {
|
||||
newest ? newest.handNumber : "",
|
||||
newest ? newest.timestamp : "",
|
||||
newest ? newest.pot : "",
|
||||
// Typing in the filter changes the list without changing the history, and
|
||||
// the redraw is skipped when the signature matches — leave this out and the
|
||||
// box takes input and does nothing.
|
||||
this.historyFilter || "",
|
||||
].join("|");
|
||||
},
|
||||
|
||||
// What the dealer opens the log for is one hand: the one somebody is arguing
|
||||
// about. A night runs to sixty or more, five at a time in the panel, so finding it
|
||||
// meant scrolling and reading every row. A name, an amount, or a hand number
|
||||
// narrows it instead.
|
||||
//
|
||||
// Matching is deliberately loose. "fay" finds Fay whatever case it's typed in;
|
||||
// "190" finds a $190 pot, a $190 payout, or hand 190, because a dealer half
|
||||
// remembering an amount shouldn't have to know which of those they mean; "#12"
|
||||
// pins it to the hand number, for when they do.
|
||||
handMatchesFilter(entry, query) {
|
||||
if (!query) return true;
|
||||
const term = query.trim().toLowerCase();
|
||||
if (!term) return true;
|
||||
|
||||
const handNumber = String(entry.handNumber || "");
|
||||
if (term.startsWith("#")) return handNumber.startsWith(term.slice(1));
|
||||
|
||||
// Only what the row itself shows. Matching the hand's full ledger as well was
|
||||
// the first attempt, on the reasoning that a dealer might hunt for the hand
|
||||
// that broke somebody by the loser's name — but the ledger holds everyone who
|
||||
// put a chip in, so at a table where nobody folds it matched every hand.
|
||||
// Measured on a seven-handed night: "Fay" returned 60 of 60. Searching text the
|
||||
// panel doesn't display is a filter that looks broken even when it's right.
|
||||
const labels = (entry.payouts || []).map(p => String(p.label || "").toLowerCase()).join(" ");
|
||||
if (labels.includes(term)) return true;
|
||||
|
||||
// Amounts, matched on the digits so "$190", "190" and "1,90" all behave.
|
||||
const digits = term.replace(/[^0-9.]/g, "");
|
||||
if (digits) {
|
||||
const amounts = [entry.pot, ...(entry.payouts || []).map(p => p.amount)]
|
||||
.map(a => String(Money.round(Number(a) || 0)));
|
||||
if (amounts.some(a => a.startsWith(digits))) return true;
|
||||
if (handNumber === digits) return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// Rebuilding this panel measured 25.7ms of the 30ms a full re-render costs — and a
|
||||
// full re-render runs after every fold, call and raise. The log only changes when a
|
||||
// hand is settled or the history is cleared, perhaps once every thirty taps, so it
|
||||
@@ -988,10 +1029,29 @@ const Render = {
|
||||
emptyHint.hidden = history.length > 0;
|
||||
document.getElementById("exportHistoryBtn").disabled = history.length === 0;
|
||||
|
||||
const query = this.historyFilter || "";
|
||||
const shown = query ? history.filter(entry => this.handMatchesFilter(entry, query)) : history;
|
||||
|
||||
// How much of the night is being hidden. Without it a filter that matches one
|
||||
// hand looks exactly like a table that only played one, which is the sort of
|
||||
// thing a dealer reads wrong at 2am with somebody leaning over the rail.
|
||||
const count = document.getElementById("handHistoryCount");
|
||||
if (count) {
|
||||
count.hidden = !query || history.length === 0;
|
||||
count.textContent = `${shown.length} of ${history.length}`;
|
||||
}
|
||||
const noMatch = document.getElementById("handHistoryNoMatch");
|
||||
if (noMatch) {
|
||||
noMatch.hidden = !(query && history.length > 0 && shown.length === 0);
|
||||
noMatch.textContent = `No hand matches “${query.trim()}”. The log still has all ${history.length}.`;
|
||||
}
|
||||
const filterBox = document.getElementById("handHistoryFilter");
|
||||
if (filterBox) filterBox.hidden = history.length === 0;
|
||||
|
||||
// Built off-document so the panel is laid out once instead of once per row.
|
||||
const fragment = document.createDocumentFragment();
|
||||
const template = document.getElementById("handHistoryRowTemplate");
|
||||
history.forEach(entry => {
|
||||
shown.forEach(entry => {
|
||||
const row = template.content.firstElementChild.cloneNode(true);
|
||||
row.querySelector(".handHistoryHandNumber").textContent = `Hand #${entry.handNumber}`;
|
||||
row.querySelector(".handHistoryPot").textContent = Money.format(entry.pot);
|
||||
|
||||
@@ -86,6 +86,12 @@ const HoldemState = {
|
||||
// seating as it stands, because by then the people it needs to know about
|
||||
// are exactly the ones who have got up and gone.
|
||||
postedBlinds: null,
|
||||
// Who last bet or raised, on this street and anywhere in the hand. Kept
|
||||
// apart because the showdown rule needs both: normally the aggressor of the
|
||||
// final betting round shows first, but a round nobody could bet in — chips
|
||||
// already all-in — falls back to the last one who could.
|
||||
streetAggressorIndex: null,
|
||||
handAggressorIndex: null,
|
||||
// Player ids that were dealt in the last hand actually dealt. What makes a
|
||||
// seat recognisable as having *just* joined — new to the table, or back
|
||||
// from sitting out — which is the whole question behind owing a blind.
|
||||
@@ -173,7 +179,8 @@ const HoldemState = {
|
||||
// them in rather than making the dealer reset a table mid-session.
|
||||
const defaults = this.createDefault();
|
||||
["smallBlind", "bigBlind", "defaultStack", "street", "currentBet", "lastRaiseSize",
|
||||
"actingSeatIndex", "blindOverride", "postedBlinds"]
|
||||
"actingSeatIndex", "blindOverride", "postedBlinds",
|
||||
"streetAggressorIndex", "handAggressorIndex"]
|
||||
.forEach(key => {
|
||||
if (parsed[key] === undefined) parsed[key] = defaults[key];
|
||||
});
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
// Finding one hand in a night of them.
|
||||
//
|
||||
// What the log is actually opened for is a single hand — the one somebody at the rail
|
||||
// is arguing about. A night runs to sixty or more, five at a time in the panel, and
|
||||
// there was no way to ask for one: the dealer scrolled and read every row.
|
||||
const test = require("node:test");
|
||||
const { describe } = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const { Render } = require("./load");
|
||||
|
||||
const hand = (handNumber, pot, payouts, ledger = []) => ({
|
||||
handNumber, pot, timestamp: Date.now(), payouts, ledger,
|
||||
});
|
||||
|
||||
// A night as the tool records it: labels carry the cards the wizard was shown.
|
||||
const NIGHT = [
|
||||
hand(1, 40, [{ label: "Ann (A♠ K♠)", amount: 40 }], [{ name: "Ann", in: 20 }, { name: "Ben", in: 20 }]),
|
||||
hand(2, 190, [{ label: "Fay", amount: 190 }], [{ name: "Fay", in: 95 }, { name: "Gus", in: 95 }]),
|
||||
hand(12, 19, [{ label: "Ben", amount: 19 }], [{ name: "Ben", in: 10 }, { name: "Ann", in: 9 }]),
|
||||
hand(120, 76, [{ label: "Cal", amount: 38 }, { label: "Dee", amount: 38 }], [{ name: "Cal" }, { name: "Dee" }]),
|
||||
];
|
||||
|
||||
const found = query => NIGHT.filter(h => Render.handMatchesFilter(h, query)).map(h => h.handNumber);
|
||||
|
||||
describe("no filter", () => {
|
||||
test("shows the whole night", () => {
|
||||
assert.deepEqual(found(""), [1, 2, 12, 120]);
|
||||
assert.deepEqual(found(" "), [1, 2, 12, 120]);
|
||||
assert.deepEqual(found(null), [1, 2, 12, 120]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("by name", () => {
|
||||
test("finds the hand somebody won", () => {
|
||||
assert.deepEqual(found("Fay"), [2]);
|
||||
});
|
||||
|
||||
test("case doesn't matter — nobody types a capital at 2am", () => {
|
||||
assert.deepEqual(found("fay"), [2]);
|
||||
assert.deepEqual(found("FAY"), [2]);
|
||||
});
|
||||
|
||||
test("a name inside a label with cards on it still matches", () => {
|
||||
// The wizard writes the label as "Ann (A♠ K♠)", so the name is a substring
|
||||
// rather than the whole cell.
|
||||
assert.deepEqual(found("ann"), [1]);
|
||||
});
|
||||
|
||||
test("matches what the row shows, not everyone who was in the hand", () => {
|
||||
// Gus is in hand 2's ledger — he paid for it — but the row names the winner,
|
||||
// and searching text the panel doesn't display is a filter that looks broken
|
||||
// even when it's right. Measured on a seven-handed night where nobody folded,
|
||||
// matching the ledger returned 60 of 60 for every name at the table.
|
||||
assert.deepEqual(found("gus"), []);
|
||||
});
|
||||
|
||||
test("a split pot is found by either winner", () => {
|
||||
assert.deepEqual(found("cal"), [120]);
|
||||
assert.deepEqual(found("dee"), [120]);
|
||||
});
|
||||
|
||||
test("a name nobody has finds nothing rather than everything", () => {
|
||||
assert.deepEqual(found("zed"), []);
|
||||
});
|
||||
});
|
||||
|
||||
describe("by amount", () => {
|
||||
test("finds a pot", () => {
|
||||
assert.deepEqual(found("190"), [2]);
|
||||
});
|
||||
|
||||
test("a dollar sign and commas are ignored", () => {
|
||||
assert.deepEqual(found("$190"), [2]);
|
||||
assert.deepEqual(found("$1,90"), [2], "typed badly, still found");
|
||||
});
|
||||
|
||||
test("finds a payout that isn't the whole pot", () => {
|
||||
assert.deepEqual(found("38"), [120], "half of a chopped $76");
|
||||
});
|
||||
|
||||
test("a partial amount narrows rather than missing", () => {
|
||||
// Half remembering "something around forty" should still get there.
|
||||
assert.deepEqual(found("4"), [1], "$40");
|
||||
assert.deepEqual(found("19"), [2, 12], "the $190 pot and the $19 one");
|
||||
});
|
||||
|
||||
test("a bare number is an exact hand number, not a prefix of one", () => {
|
||||
// Amounts match on their leading digits, because half a remembered figure is
|
||||
// still a lead. Hand numbers don't: typing 12 to mean the hand is a dealer who
|
||||
// knows which hand they want, and dragging 120 and 128 along with it is noise.
|
||||
// "#12" is there for when they do want the prefix.
|
||||
assert.ok(!found("12").includes(120));
|
||||
});
|
||||
});
|
||||
|
||||
describe("by hand number", () => {
|
||||
test("a bare number matches the hand number as well as amounts", () => {
|
||||
assert.ok(found("12").includes(12));
|
||||
});
|
||||
|
||||
test("a hash pins it to the hand number and nothing else", () => {
|
||||
assert.deepEqual(found("#12"), [12, 120], "12 and 120 both start with 12");
|
||||
assert.deepEqual(found("#2"), [2], "and not the $190 pot of hand 2's neighbours");
|
||||
});
|
||||
|
||||
test("a hash with a number nobody played finds nothing", () => {
|
||||
assert.deepEqual(found("#7"), []);
|
||||
});
|
||||
});
|
||||
|
||||
describe("odd input can't break it", () => {
|
||||
test("punctuation on its own doesn't match everything", () => {
|
||||
assert.deepEqual(found("$"), [], "no digits and no letters left to match on");
|
||||
assert.deepEqual(found("#"), [1, 2, 12, 120], "an empty hand number is a prefix of them all");
|
||||
});
|
||||
|
||||
test("an entry with pieces missing doesn't throw", () => {
|
||||
const broken = { handNumber: 5, pot: 10 };
|
||||
assert.doesNotThrow(() => Render.handMatchesFilter(broken, "ann"));
|
||||
assert.equal(Render.handMatchesFilter(broken, "ann"), false);
|
||||
assert.equal(Render.handMatchesFilter(broken, "10"), true, "the pot is still findable");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,202 @@
|
||||
// Who turns their hand over first.
|
||||
//
|
||||
// A call the dealer makes at every showdown that isn't a fold, and one nobody at the
|
||||
// table volunteers for — everyone would rather see a hand than show one. The tool knew
|
||||
// who last raised and who sits left of the button and said neither.
|
||||
const test = require("node:test");
|
||||
const { describe } = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const { HoldemState, Betting, makeTable } = require("./load");
|
||||
|
||||
const NAMES = ["Ann", "Ben", "Cal", "Dee"];
|
||||
const table = (dealerSeatIndex = 0, stack = 200) => {
|
||||
const state = makeTable({ seatCount: 6, seated: [0, 1, 2, 3], stack, dealerSeatIndex });
|
||||
NAMES.forEach((name, i) => { state.seats[i].name = name; });
|
||||
Betting.beginHand(state);
|
||||
return state;
|
||||
};
|
||||
|
||||
const call = state => {
|
||||
const answer = Betting.showdownOrder(state);
|
||||
return answer && { who: state.seats[answer.index].name, reason: answer.reason };
|
||||
};
|
||||
|
||||
// Everybody left just calls whatever is in front of them, then the street closes.
|
||||
const checkRound = state => {
|
||||
let guard = 0;
|
||||
while (state.actingSeatIndex !== null && guard++ < 12) {
|
||||
const index = state.actingSeatIndex;
|
||||
if (Betting.toCall(state, state.seats[index]) > 0) Betting.call(state, index);
|
||||
else Betting.check(state, index);
|
||||
}
|
||||
Betting.closeStreet(state);
|
||||
};
|
||||
|
||||
describe("a bet on the river", () => {
|
||||
test("the last player to raise shows first", () => {
|
||||
const state = table(0); // blinds Ben and Cal
|
||||
checkRound(state); // pre-flop
|
||||
checkRound(state); // flop
|
||||
checkRound(state); // turn
|
||||
|
||||
Betting.raiseTo(state, state.actingSeatIndex, 20);
|
||||
const raiser = state.seats.findIndex(p => Betting.committed(p) === 20);
|
||||
while (state.actingSeatIndex !== null) Betting.call(state, state.actingSeatIndex);
|
||||
|
||||
assert.deepEqual(call(state), { who: state.seats[raiser].name, reason: "aggressor" });
|
||||
});
|
||||
|
||||
test("a re-raise moves it to the last one, not the first", () => {
|
||||
const state = table(0);
|
||||
checkRound(state); checkRound(state); checkRound(state);
|
||||
|
||||
const first = state.actingSeatIndex;
|
||||
Betting.raiseTo(state, first, 20);
|
||||
const second = state.actingSeatIndex;
|
||||
Betting.raiseTo(state, second, 60);
|
||||
while (state.actingSeatIndex !== null) {
|
||||
const i = state.actingSeatIndex;
|
||||
if (Betting.toCall(state, state.seats[i]) > 0) Betting.call(state, i); else Betting.check(state, i);
|
||||
}
|
||||
|
||||
assert.equal(call(state).who, state.seats[second].name);
|
||||
});
|
||||
|
||||
test("a short all-in still shows first, even though it doesn't reopen the betting", () => {
|
||||
// The rule about reopening is about who may raise. It says nothing about who
|
||||
// shows, and the player who shoved is still the last one who put money in.
|
||||
const state = table(0);
|
||||
checkRound(state); checkRound(state); checkRound(state);
|
||||
|
||||
const bettor = state.actingSeatIndex;
|
||||
Betting.raiseTo(state, bettor, 40);
|
||||
const shortStack = state.actingSeatIndex;
|
||||
// Over the $40 but only by $15, where a full raise would need $40 more. Going
|
||||
// *under* the bet would be a short call, not a short raise, and wouldn't make
|
||||
// them the aggressor at all.
|
||||
state.seats[shortStack].stack = 55;
|
||||
Betting.allIn(state, shortStack);
|
||||
assert.equal(Betting.committed(state.seats[shortStack]), 55, "raised, if not by enough");
|
||||
while (state.actingSeatIndex !== null) {
|
||||
const i = state.actingSeatIndex;
|
||||
if (Betting.toCall(state, state.seats[i]) > 0) Betting.call(state, i); else Betting.check(state, i);
|
||||
}
|
||||
|
||||
assert.equal(call(state).who, state.seats[shortStack].name);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a river checked through", () => {
|
||||
test("the first live player left of the button shows first", () => {
|
||||
const state = table(0); // button Ann
|
||||
checkRound(state); checkRound(state); checkRound(state); checkRound(state);
|
||||
|
||||
assert.deepEqual(call(state), { who: "Ben", reason: "leftOfButton" });
|
||||
});
|
||||
|
||||
test("an earlier street's raiser doesn't carry over to the river", () => {
|
||||
// The rule is about the *final* round. Leading the flop and then checking the
|
||||
// river doesn't oblige anyone.
|
||||
const state = table(0);
|
||||
checkRound(state); // pre-flop
|
||||
Betting.raiseTo(state, state.actingSeatIndex, 20); // leads the flop
|
||||
while (state.actingSeatIndex !== null) Betting.call(state, state.actingSeatIndex);
|
||||
Betting.closeStreet(state);
|
||||
checkRound(state); // turn
|
||||
checkRound(state); // river
|
||||
|
||||
assert.equal(call(state).reason, "leftOfButton");
|
||||
});
|
||||
|
||||
test("it skips a folded seat rather than naming somebody who isn't in the hand", () => {
|
||||
const state = table(0); // button Ann, so Ben would be first
|
||||
checkRound(state); checkRound(state); checkRound(state);
|
||||
Betting.fold(state, 1); // Ben gets out on the river
|
||||
while (state.actingSeatIndex !== null) {
|
||||
const i = state.actingSeatIndex;
|
||||
if (Betting.toCall(state, state.seats[i]) > 0) Betting.call(state, i); else Betting.check(state, i);
|
||||
}
|
||||
Betting.closeStreet(state);
|
||||
|
||||
assert.equal(call(state).who, "Cal", "the next one round who is still in");
|
||||
});
|
||||
});
|
||||
|
||||
describe("everyone all-in before the river", () => {
|
||||
test("the last player who could put money in shows first", () => {
|
||||
// There was no final round to lead, so "checked round" isn't a choice anybody
|
||||
// made and the seat left of the button hasn't earned the obligation.
|
||||
const state = table(0, 30);
|
||||
checkRound(state); // pre-flop
|
||||
|
||||
const shover = state.actingSeatIndex;
|
||||
Betting.allIn(state, shover);
|
||||
while (state.actingSeatIndex !== null) Betting.call(state, state.actingSeatIndex);
|
||||
Betting.closeStreet(state);
|
||||
|
||||
assert.equal(Betting.canStillBet(state), false, "nobody has chips left to bet");
|
||||
assert.deepEqual(call(state), { who: state.seats[shover].name, reason: "allInAggressor" });
|
||||
});
|
||||
|
||||
test("a hand where everyone got in for the blind and nobody raised falls to the button", () => {
|
||||
// Two-dollar stacks against a two-dollar blind: everyone is all-in by calling,
|
||||
// and calling is not aggression. Nobody chose to lead, so nobody is on the hook
|
||||
// and it goes back to the seat left of the button.
|
||||
const state = table(0, 2);
|
||||
checkRound(state);
|
||||
|
||||
assert.equal(Betting.canStillBet(state), false, "nobody has a chip behind");
|
||||
assert.equal(state.handAggressorIndex, null, "and nobody ever raised");
|
||||
const answer = call(state);
|
||||
assert.ok(answer, "there is still a showdown to order");
|
||||
assert.equal(answer.reason, "leftOfButton");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is nothing to call", () => {
|
||||
test("one player left isn't a showdown", () => {
|
||||
const state = table(0);
|
||||
[1, 2, 3].forEach(i => Betting.fold(state, i));
|
||||
assert.equal(Betting.showdownOrder(state), null);
|
||||
});
|
||||
|
||||
test("an aggressor who has since folded doesn't get named", () => {
|
||||
// Can't happen in play — you don't fold after raising unopposed — but the
|
||||
// index is a number on the state and a reset table could hold a stale one.
|
||||
const state = table(0);
|
||||
checkRound(state); checkRound(state); checkRound(state); checkRound(state);
|
||||
state.streetAggressorIndex = 1;
|
||||
state.seats[1].folded = true;
|
||||
|
||||
const answer = call(state);
|
||||
assert.notEqual(answer.who, "Ben");
|
||||
assert.equal(answer.reason, "leftOfButton");
|
||||
});
|
||||
|
||||
test("an index pointing at no seat at all is ignored", () => {
|
||||
const state = table(0);
|
||||
checkRound(state); checkRound(state); checkRound(state); checkRound(state);
|
||||
state.streetAggressorIndex = 99;
|
||||
assert.equal(call(state).reason, "leftOfButton");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the tracking resets when it should", () => {
|
||||
test("a new hand starts with nobody on the hook", () => {
|
||||
const state = table(0);
|
||||
checkRound(state); checkRound(state); checkRound(state);
|
||||
Betting.raiseTo(state, state.actingSeatIndex, 20);
|
||||
assert.notEqual(state.handAggressorIndex, null);
|
||||
|
||||
HoldemState.startNextHand(state);
|
||||
Betting.beginHand(state);
|
||||
assert.equal(state.streetAggressorIndex, null);
|
||||
assert.equal(state.handAggressorIndex, null, "last night's raise isn't this hand's business");
|
||||
});
|
||||
|
||||
test("posting a blind is not aggression", () => {
|
||||
const state = table(0);
|
||||
assert.equal(state.streetAggressorIndex, null);
|
||||
assert.equal(state.handAggressorIndex, null);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user