diff --git a/JoshHeaps.Net/Pages/Casino.cshtml b/JoshHeaps.Net/Pages/Casino.cshtml
index 35326d0..ac47a88 100644
--- a/JoshHeaps.Net/Pages/Casino.cshtml
+++ b/JoshHeaps.Net/Pages/Casino.cshtml
@@ -19,6 +19,15 @@
+
+
+
Chop a pot without setting up a table.
++ Uneven pots โ someone all-in for less โ need the side-pot walkthrough on the + full table. +
+Click a seat at the table to edit their name, cards, chips and anything else.
'; @@ -415,22 +428,6 @@ const Render = { }, }; -const Money = { - format(amount) { - const value = Number(amount) || 0; - return `$${value.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; - }, - - // "+$40.00" / "-$40.00" rather than "$-40.00" โ a standings column is read at a - // glance, and the sign belongs out front where the eye lands first. - formatSigned(amount) { - const value = Number(amount) || 0; - if (value > 0) return `+${this.format(value)}`; - if (value < 0) return `-${this.format(Math.abs(value))}`; - return this.format(0); - }, -}; - if (typeof module !== "undefined" && module.exports) { - module.exports = { Render, Money }; + module.exports = { Render }; } diff --git a/JoshHeaps.Net/wwwroot/js/casino/holdem/splitCalculator.js b/JoshHeaps.Net/wwwroot/js/casino/holdem/splitCalculator.js new file mode 100644 index 0000000..22252c2 --- /dev/null +++ b/JoshHeaps.Net/wwwroot/js/casino/holdem/splitCalculator.js @@ -0,0 +1,53 @@ +// Pure math for chopping one pot between tied players. No DOM. +// +// A dealer can't push half a chip across the felt, so this works in whole chips of +// whatever the smallest denomination in play is: everyone gets the same stack, and +// whatever won't divide is called out separately as odd chips. House rule for those +// is that they go to the first player left of the button, one at a time. +const SplitCalculator = { + // Everything is done in cents to keep 0.1 + 0.2 out of a payout. + toCents(amount) { + return Math.round((Number(amount) || 0) * 100); + }, + + split(potAmount, ways, chipAmount) { + const potCents = this.toCents(potAmount); + const chipCents = Math.max(1, this.toCents(chipAmount)); + const players = Math.max(1, Math.floor(Number(ways) || 0)); + + if (potCents <= 0) { + return { valid: false, each: 0, oddChips: 0, chip: chipCents / 100, dust: 0, players }; + } + + const wholeChips = Math.floor(potCents / chipCents); + // Left over when the pot itself isn't a whole number of the smallest chip โ + // usually means the dealer picked the wrong denomination, so it's surfaced + // rather than silently rolled into someone's stack. + const dustCents = potCents - wholeChips * chipCents; + + const chipsEach = Math.floor(wholeChips / players); + const oddChips = wholeChips - chipsEach * players; + + return { + valid: true, + players, + each: (chipsEach * chipCents) / 100, + oddChips, + chip: chipCents / 100, + dust: dustCents / 100, + }; + }, + + // Sanity check for the UI: what the split actually hands out has to equal the pot. + accountedFor(result) { + return ( + Math.round(result.each * 100) * result.players + + Math.round(result.chip * 100) * result.oddChips + + Math.round(result.dust * 100) + ) / 100; + }, +}; + +if (typeof module !== "undefined" && module.exports) { + module.exports = SplitCalculator; +}