diff --git a/JoshHeaps.Net/wwwroot/css/casino/holdem.css b/JoshHeaps.Net/wwwroot/css/casino/holdem.css index 8d9ca2e..f7bfe3a 100644 --- a/JoshHeaps.Net/wwwroot/css/casino/holdem.css +++ b/JoshHeaps.Net/wwwroot/css/casino/holdem.css @@ -1480,6 +1480,12 @@ body.hasActionBar #holdemSidebar { font-variant-numeric: tabular-nums; } +.actionRunout { + margin-left: auto; + color: #d8b46a; + font-size: 0.74rem; +} + .actionWho { margin-left: auto; color: #9c9c9c; diff --git a/JoshHeaps.Net/wwwroot/js/casino/holdem/actionBar.js b/JoshHeaps.Net/wwwroot/js/casino/holdem/actionBar.js index d440315..3673f21 100644 --- a/JoshHeaps.Net/wwwroot/js/casino/holdem/actionBar.js +++ b/JoshHeaps.Net/wwwroot/js/casino/holdem/actionBar.js @@ -74,6 +74,16 @@ const ActionBar = { players.textContent = `${remaining} ${remaining === 1 ? "player" : "players"}`; row.appendChild(players); + // Nobody is being asked to act because nobody can — say so, or the bar just + // looks like it's waiting for something. + if (Betting.isRunningOut(this.state) && !Betting.isHandOver(this.state)) { + const runout = document.createElement("span"); + runout.className = "actionRunout"; + const stillIn = Betting.liveSeats(this.state).length; + runout.textContent = `All-in — running out the board (${stillIn} players)`; + row.appendChild(runout); + } + const index = this.state.actingSeatIndex; if (index !== null && index !== undefined && !Betting.isHandOver(this.state)) { const player = this.state.seats[index]; diff --git a/JoshHeaps.Net/wwwroot/js/casino/holdem/betting.js b/JoshHeaps.Net/wwwroot/js/casino/holdem/betting.js index c944c2d..234b85e 100644 --- a/JoshHeaps.Net/wwwroot/js/casino/holdem/betting.js +++ b/JoshHeaps.Net/wwwroot/js/casino/holdem/betting.js @@ -70,7 +70,19 @@ const Betting = { for (let step = 1; step <= count; step++) { const index = this.seatAt(state, fromIndex, step); const player = state.seats[index]; - if (player.inHand && !player.folded && this.stackOf(state, player) >= 0) return index; + if (player.inHand && !player.folded) return index; + } + return null; + }, + + // Who the dealer asks next. A player who is all-in is still in the hand and still + // wins pots, but has no decision left, so the action passes over them. + nextToAct(state, fromIndex) { + const count = state.seatCount; + for (let step = 1; step <= count; step++) { + const index = this.seatAt(state, fromIndex, step); + const player = state.seats[index]; + if (player.inHand && !player.folded && this.stackOf(state, player) > this.EPSILON_CHIPS) return index; } return null; }, @@ -156,7 +168,7 @@ const Betting = { }, passAction(state, index) { - state.actingSeatIndex = this.isStreetComplete(state) ? null : this.nextLiveIndex(state, index); + state.actingSeatIndex = this.isStreetComplete(state) ? null : this.nextToAct(state, index); }, // ---- Street and hand boundaries ---- @@ -185,24 +197,51 @@ const Betting = { const nextStreetIndex = this.STREETS.indexOf(state.street || "preflop") + 1; state.street = this.STREETS[nextStreetIndex] || "river"; - if (this.liveSeats(state).length <= 1) { + // It takes two players with chips to have a bet. Once everyone left is all-in + // the rest of the board is just dealt out. + if (!this.canStillBet(state)) { state.actingSeatIndex = null; return; } // After the flop the first live player left of the button acts — which heads-up // is the big blind, since the button is the small blind. Naming the big blind - // directly also covers a button parked on a seat nobody is sitting in. + // directly also covers a button parked on a seat nobody is sitting in, and it + // still has to be someone with chips left to bet. const { bbIndex, headsUp } = HoldemState.getBlindSeats(state); - state.actingSeatIndex = headsUp && bbIndex !== null && !state.seats[bbIndex].folded + const bigBlindCanAct = + headsUp && + bbIndex !== null && + !state.seats[bbIndex].folded && + this.stackOf(state, state.seats[bbIndex]) > this.EPSILON_CHIPS; + + state.actingSeatIndex = bigBlindCanAct ? bbIndex - : this.nextLiveIndex(state, state.dealerSeatIndex); + : this.nextToAct(state, state.dealerSeatIndex); }, isHandOver(state) { return this.liveSeats(state).length <= 1; }, + // Players still in the hand who have chips left to put in. Fewer than two of them + // means the betting is finished even though the hand isn't. + seatsWithChips(state) { + return this.liveSeats(state).filter(s => this.stackOf(state, s.player) > this.EPSILON_CHIPS); + }, + + EPSILON_CHIPS: 0.004, + + canStillBet(state) { + return this.liveSeats(state).length > 1 && this.seatsWithChips(state).length > 1; + }, + + // True when the hand is still live but nobody can bet again — the dealer is just + // running the board out. + isRunningOut(state) { + return this.liveSeats(state).length > 1 && !this.canStillBet(state); + }, + // Deals a fresh betting round: blinds posted, action to the seat after the big // blind, which is where a dealer expects to be looking when the cards go out. beginHand(state) { @@ -232,8 +271,11 @@ const Betting = { state.lastRaiseSize = bb || 0; // Heads-up the button is the small blind and acts first before the flop; with - // three or more it's the seat after the big blind. - state.actingSeatIndex = headsUp ? sbIndex : this.nextLiveIndex(state, bbIndex); + // three or more it's the seat after the big blind. Either way, a blind big + // enough to put that player all-in leaves them nothing to decide. + state.actingSeatIndex = headsUp + ? (this.stackOf(state, state.seats[sbIndex]) > this.EPSILON_CHIPS ? sbIndex : this.nextToAct(state, sbIndex)) + : this.nextToAct(state, bbIndex); }, // Winners get their share put back in front of them.