games: the hand that becomes two, and the bet that has to follow it
Blackjack has a split. It was the last rule missing from a game that has been live for a week, and it is the only move in blackjack that takes chips out of your stack *after* the cards are out — which is most of what there is to get wrong about it. So the state stops pretending. State.Player is gone; there is a slice of Hands, each with its own cards, its own bet, its own outcome and its own payout, and an Active index the player works left to right. Settle runs per hand and rakes per hand: netting them against each other first would mean a player who won one and lost one paid no rake at all, which is not a rake, it's a discount for splitting. The web layer takes the second bet before the move and hands it straight back if the engine refuses — the same shape double already used, except double was staking st.Bet, the whole table's stake, which was the same number as the hand's until today and is now emphatically not. DoubleCost/SplitCost are the active hand's, and the felt would have found this by charging you 300 to double the third hand of a split. The rules that cost money if you guess them: split aces get one card each and no say (a pair of aces is otherwise the best hand in the game, forever), 21 on a split hand is twenty-one and not a natural (it does not pay 3:2 — the test that pins this is the most expensive one in the file), same rank rather than same value (a king and a queen are not a pair), four hands maximum, double after split allowed, and if every hand busts the dealer does not turn over. A live hand outlives a deploy, so State.UnmarshalJSON still reads the old blobs: "player" with no "hands" becomes one hand holding the whole stake. Without it, a player mid-hand at restart is a player whose cards vanished — which is not a decode error, and would not have looked like one. On the felt a hand is now a box with its own spot, and a split is a card lifting out of one hand into a new one with a second stack of chips flying after it from your pile. Verified in a browser against a real pair: chips 4738 -> 4638 on the split, two hands played out, one push and one loss, "Down on the deal. -100", 4738 back. Three hands stack without collision at 390px. Settled hands come back to full brightness — dimming means "not your turn", and when the deal is over they are the thing you are reading. Claude-Session: https://claude.ai/code/session_013M5nD7PgUboJXoDcYHzpuJ
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// The blackjack table.
|
||||
//
|
||||
// The browser holds no game. It sends intents — deal, hit, stand, double — and
|
||||
// the server answers with the cards you're allowed to see plus the *script* of
|
||||
// how they got there: one event per card off the shoe, in the order the shoe
|
||||
// The browser holds no game. It sends intents — deal, hit, stand, double, split
|
||||
// — and the server answers with the cards you're allowed to see plus the *script*
|
||||
// of how they got there: one event per card off the shoe, in the order the shoe
|
||||
// gave them up. This file's job is to play that script back at a human speed
|
||||
// rather than snapping the finished hand into place.
|
||||
//
|
||||
@@ -16,6 +16,10 @@
|
||||
// taken away. Nothing about the money changes on this table without something
|
||||
// crossing the felt to make it change — including the count in the chip bar,
|
||||
// which is deliberately not updated until the chips that justify it have landed.
|
||||
//
|
||||
// Since split, "the spot" is not one place. A hand has a spot, and a split makes
|
||||
// a second hand with a second bet on a second spot — two bets that win and lose
|
||||
// separately, which is the whole point of splitting and has to look like it.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
@@ -25,9 +29,7 @@
|
||||
var FX = window.PeteFX;
|
||||
|
||||
var dealerEl = root.querySelector("[data-dealer]");
|
||||
var playerEl = root.querySelector("[data-player]");
|
||||
var dTotalEl = root.querySelector("[data-dealer-total]");
|
||||
var pTotalEl = root.querySelector("[data-player-total]");
|
||||
var dLabelEl = root.querySelector("[data-dealer-label]");
|
||||
var verdictEl = root.querySelector("[data-verdict]");
|
||||
var betting = root.querySelector("[data-betting]");
|
||||
@@ -36,26 +38,22 @@
|
||||
var dealBtn = root.querySelector("[data-deal]");
|
||||
var msgEl = root.querySelector("[data-table-msg]");
|
||||
|
||||
// The three places a chip can be: your pile (in the bar above), the spot in
|
||||
// front of you, and the house's rack on the felt.
|
||||
// Where the chips live: your pile (in the bar above), a spot in front of each
|
||||
// hand, and the house's rack on the felt.
|
||||
var purseEl = document.querySelector("[data-chips]");
|
||||
var spotEl = root.querySelector("[data-spot]");
|
||||
var stackEl = root.querySelector("[data-stack]");
|
||||
var spotTotalEl = root.querySelector("[data-spot-total]");
|
||||
var houseEl = root.querySelector("[data-house]");
|
||||
|
||||
// The spot owns the chips on the felt and the number under them — see PeteFX.
|
||||
// Nothing is bet until a chip is on it, so `bet` starts at nothing rather than
|
||||
// at a default stake nobody put down.
|
||||
var spot = FX.spot({ spot: spotEl, stack: stackEl, total: spotTotalEl });
|
||||
var handsEl = root.querySelector("[data-hands]");
|
||||
var handTpl = root.querySelector("[data-hand-template]");
|
||||
|
||||
var bet = 0; // what you're building between hands
|
||||
var base = 0; // what one hand of the last deal cost, for standing it back up
|
||||
var busy = false; // a request is in flight, or cards are still landing
|
||||
var hand = null; // the hand as the server last described it
|
||||
var hand = null; // the deal as the server last described it
|
||||
|
||||
var DEAL_MS = 380; // one card's flight, and the gap before the next
|
||||
var FLIP_MS = 450;
|
||||
var BEAT_MS = 600; // the dealer thinking before they draw out
|
||||
var SPLIT_MS = 340; // the card lifting out of the hand it's leaving
|
||||
|
||||
var reduced = FX.reduced;
|
||||
function pace(ms) { return reduced ? 0 : ms; }
|
||||
@@ -80,46 +78,137 @@
|
||||
function cardEl(face) { return CARDS.el(face); }
|
||||
var turnOver = CARDS.turnOver;
|
||||
|
||||
// ---- the hands -------------------------------------------------------------
|
||||
//
|
||||
// A box per hand: its chips, its cards, its total, its own verdict. There is
|
||||
// always at least one, and before a deal that one is where you build your bet —
|
||||
// so the chips you stack are already sitting on the hand they're about to buy.
|
||||
|
||||
var hands = [];
|
||||
|
||||
function makeHand(at) {
|
||||
var el = handTpl.content.firstElementChild.cloneNode(true);
|
||||
var spotEl = el.querySelector("[data-spot]");
|
||||
var box = {
|
||||
el: el,
|
||||
spotEl: spotEl, // where a chip flies to, as opposed to what counts it
|
||||
cards: el.querySelector("[data-cards]"),
|
||||
total: el.querySelector("[data-total]"),
|
||||
verdict: el.querySelector("[data-hand-outcome]"),
|
||||
ranks: [], // what's in it, for a running total while the cards are landing
|
||||
spot: FX.spot({
|
||||
spot: spotEl,
|
||||
stack: el.querySelector("[data-stack]"),
|
||||
total: el.querySelector("[data-spot-total]"),
|
||||
}),
|
||||
};
|
||||
if (at === undefined || at >= hands.length) {
|
||||
handsEl.appendChild(el);
|
||||
hands.push(box);
|
||||
} else {
|
||||
handsEl.insertBefore(el, hands[at].el);
|
||||
hands.splice(at, 0, box);
|
||||
}
|
||||
handsEl.dataset.count = hands.length;
|
||||
return box;
|
||||
}
|
||||
|
||||
// reset tears the row down to n empty hands. It does not preserve chips: a
|
||||
// caller that has some to keep (a deal, whose stake is already on the spot)
|
||||
// reads the amount first and puts it back.
|
||||
function reset(n) {
|
||||
handsEl.innerHTML = "";
|
||||
hands = [];
|
||||
for (var i = 0; i < (n || 1); i++) makeHand();
|
||||
}
|
||||
|
||||
function ensure(n) { while (hands.length < n) makeHand(); }
|
||||
|
||||
// The bet you build between hands is hand zero's.
|
||||
function betSpot() { return hands[0].spot; }
|
||||
|
||||
// live marks the hand you're being asked about, and dims the ones you aren't.
|
||||
//
|
||||
// -1 means nobody is acting — the dealer is drawing, or the deal is over — and
|
||||
// that is *not* the same as every hand being inactive: a settled hand is the
|
||||
// thing you are reading, so it goes back to full brightness rather than sitting
|
||||
// there greyed out. Hence the empty string: it matches neither CSS rule.
|
||||
function live(i) {
|
||||
hands.forEach(function (h, k) {
|
||||
h.el.dataset.live = i < 0 ? "" : k === i ? "1" : "0";
|
||||
});
|
||||
}
|
||||
|
||||
// The running total under a hand, worked out from the cards you can see. The
|
||||
// server sends totals too, but only with the finished state — and a hand you're
|
||||
// playing needs to know what it's holding *now*, not once it's over. It's a
|
||||
// readout, never a decision: every ruling is the server's.
|
||||
var TEN = { K: 10, Q: 10, J: 10 };
|
||||
function totalOf(ranks) {
|
||||
var total = 0, aces = 0;
|
||||
ranks.forEach(function (r) {
|
||||
if (r === "A") { aces++; total += 11; }
|
||||
else total += TEN[r] || parseInt(r, 10) || 0;
|
||||
});
|
||||
while (total > 21 && aces > 0) { total -= 10; aces--; }
|
||||
return { total: total, soft: aces > 0 };
|
||||
}
|
||||
|
||||
function showTotal(box) {
|
||||
if (!box.ranks.length) { box.total.classList.add("hidden"); return; }
|
||||
var v = totalOf(box.ranks);
|
||||
box.total.textContent = v.total + (v.soft ? " (soft)" : "");
|
||||
box.total.classList.remove("hidden");
|
||||
}
|
||||
|
||||
var SHORT = {
|
||||
blackjack: "Blackjack", win: "Won", dealer_bust: "Won",
|
||||
lose: "Lost", bust: "Bust", push: "Push",
|
||||
};
|
||||
|
||||
// A hand's own result, on the hand. With one hand this says the same thing as
|
||||
// the pill above it and is a bit redundant; with four it is the only way to
|
||||
// read what happened, because "you win" is not true of all of them.
|
||||
function showHandVerdict(box, h) {
|
||||
var text = h && SHORT[h.outcome];
|
||||
if (!text) { box.verdict.classList.add("hidden"); return; }
|
||||
box.verdict.textContent = text;
|
||||
box.verdict.classList.remove("hidden");
|
||||
}
|
||||
|
||||
// ---- the money on the felt -------------------------------------------------
|
||||
|
||||
// stake moves chips from your pile onto the spot: the bet you build before a
|
||||
// deal, and the second bet a double puts down beside it.
|
||||
function stake(amount, from) {
|
||||
return spot.pour(from || purseEl, amount);
|
||||
}
|
||||
|
||||
// settleChips is what the felt does about the outcome, after the cards have
|
||||
// finished telling you what it is. It reads the same two numbers the ledger
|
||||
// moved: `bet` (already off your pile since the deal) and `payout` (what comes
|
||||
// back — stake plus winnings less rake, or nothing at all).
|
||||
// finished telling you what it is. Each hand is paid on its own, in order, left
|
||||
// to right — because each hand *is* its own bet, and a split that lost one and
|
||||
// won the other has to be watchable as exactly that.
|
||||
function settleChips(final) {
|
||||
var payout = final.payout || 0;
|
||||
var back = payout - final.bet; // what the house is adding, if anything
|
||||
var chain = Promise.resolve();
|
||||
(final.hands || []).forEach(function (h, i) {
|
||||
chain = chain.then(function () {
|
||||
var box = hands[i];
|
||||
if (!box) return;
|
||||
var payout = h.payout || 0;
|
||||
|
||||
if (payout <= 0) {
|
||||
// The house takes it. The stack goes to the rack and doesn't come back.
|
||||
return spot.sweep(houseEl, final.bet, { gap: 45, lift: 0.6, fade: true });
|
||||
}
|
||||
|
||||
// The house pays first, into the spot beside your stake, so you watch the
|
||||
// winnings arrive on top of the bet that earned them.
|
||||
return spot
|
||||
.pour(houseEl, back, { gap: 60 })
|
||||
.then(function () { return wait(back > 0 ? 380 : 200); })
|
||||
// Paid, then swept up: the whole lot comes back to your pile, and only then
|
||||
// does the number in the bar move.
|
||||
.then(function () { return spot.sweep(purseEl, payout, { gap: 40, lift: 0.8 }); });
|
||||
if (payout <= 0) {
|
||||
// The house takes it. The stack goes to the rack and doesn't come back.
|
||||
return box.spot.sweep(houseEl, h.bet, { gap: 45, lift: 0.6, fade: true });
|
||||
}
|
||||
// The house pays first, into the spot beside the stake, so you watch the
|
||||
// winnings arrive on top of the bet that earned them.
|
||||
var back = payout - h.bet;
|
||||
return box.spot
|
||||
.pour(houseEl, back, { gap: 60 })
|
||||
.then(function () { return wait(back > 0 ? 340 : 160); })
|
||||
.then(function () { return box.spot.sweep(purseEl, payout, { gap: 40, lift: 0.8 }); });
|
||||
});
|
||||
});
|
||||
return chain;
|
||||
}
|
||||
|
||||
function totals(v) {
|
||||
if (v.total) {
|
||||
pTotalEl.textContent = v.total + (v.soft ? " (soft)" : "");
|
||||
pTotalEl.classList.remove("hidden");
|
||||
} else {
|
||||
pTotalEl.classList.add("hidden");
|
||||
}
|
||||
// While the hole card is down, the dealer's total is only what's showing —
|
||||
// so say so, rather than printing a number that quietly means something else.
|
||||
// While the hole card is down, the dealer's total is only what's showing — so
|
||||
// say so, rather than printing a number that quietly means something else.
|
||||
function dealerTotal(v) {
|
||||
if (v.dealer && v.dealer.length) {
|
||||
dTotalEl.textContent = v.hole ? v.dealer_total + " showing" : String(v.dealer_total);
|
||||
dTotalEl.classList.remove("hidden");
|
||||
@@ -128,19 +217,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
// paint puts a hand on the felt with no animation. This is the resume path:
|
||||
// you reloaded, or Pete restarted, and your cards are simply there — including
|
||||
// the stake, which is still on the spot because the server still has it.
|
||||
// paint puts a deal on the felt with no animation. This is the resume path: you
|
||||
// reloaded, or Pete restarted, and your cards are simply there — including the
|
||||
// stakes, which are still on their spots because the server still has them.
|
||||
function paint(v) {
|
||||
dealerEl.innerHTML = "";
|
||||
playerEl.innerHTML = "";
|
||||
if (!v) { setPhase(null); spot.render(0); return; }
|
||||
if (!v) { reset(1); setPhase(null); return; }
|
||||
|
||||
reset(v.hands.length || 1);
|
||||
v.hands.forEach(function (h, i) {
|
||||
var box = hands[i];
|
||||
(h.cards || []).forEach(function (c) {
|
||||
box.cards.appendChild(cardEl(c));
|
||||
box.ranks.push(c.rank);
|
||||
});
|
||||
box.spot.render(v.phase === "done" ? 0 : h.bet);
|
||||
showTotal(box);
|
||||
showHandVerdict(box, v.phase === "done" ? h : null);
|
||||
});
|
||||
|
||||
v.player.forEach(function (c) { playerEl.appendChild(cardEl(c)); });
|
||||
v.dealer.forEach(function (c) { dealerEl.appendChild(cardEl(c)); });
|
||||
if (v.hole) dealerEl.appendChild(cardEl(null));
|
||||
spot.render(v.phase === "done" ? 0 : v.bet);
|
||||
totals(v);
|
||||
dealerTotal(v);
|
||||
setPhase(v);
|
||||
}
|
||||
|
||||
@@ -155,12 +253,17 @@
|
||||
|
||||
function verdict(v) {
|
||||
var text = VERDICTS[v.outcome] || "";
|
||||
// Across several hands "you win" is a claim about the money, not about the
|
||||
// cards: you can win one, lose one, and still be up. The pill reports the
|
||||
// deal; the badge on each hand reports the hand.
|
||||
if ((v.hands || []).length > 1) {
|
||||
text = v.net > 0 ? "You're up on the deal." : v.net < 0 ? "Down on the deal." : "All square.";
|
||||
}
|
||||
if (!text) { verdictEl.classList.add("hidden"); return; }
|
||||
if (v.net > 0) text += " +" + v.net.toLocaleString();
|
||||
else if (v.net < 0) text += " " + v.net.toLocaleString();
|
||||
verdictEl.textContent = text;
|
||||
verdictEl.classList.remove("hidden");
|
||||
playerEl.dataset.won = v.net > 0 ? "1" : v.net < 0 ? "-1" : "0";
|
||||
|
||||
// The one thing in this room that gets confetti. A natural is rare, it pays
|
||||
// 3:2, and if everything celebrated then nothing would.
|
||||
@@ -176,15 +279,20 @@
|
||||
// setPhase swaps the controls: bet between hands, act during one.
|
||||
function setPhase(v) {
|
||||
hand = v;
|
||||
var live = !!v && v.phase === "player";
|
||||
betting.classList.toggle("hidden", live);
|
||||
actions.classList.toggle("hidden", !live);
|
||||
var acting = !!v && v.phase === "player";
|
||||
betting.classList.toggle("hidden", acting);
|
||||
actions.classList.toggle("hidden", !acting);
|
||||
|
||||
if (live) {
|
||||
if (acting) {
|
||||
var dbl = actions.querySelector('[data-move="double"]');
|
||||
var spl = actions.querySelector('[data-move="split"]');
|
||||
if (dbl) dbl.disabled = !v.can_double;
|
||||
if (spl) spl.disabled = !v.can_split;
|
||||
live(v.active || 0);
|
||||
} else {
|
||||
live(-1);
|
||||
}
|
||||
if (!v || v.phase !== "player") verdictEl.classList.toggle("hidden", !(v && v.outcome));
|
||||
if (!acting) verdictEl.classList.toggle("hidden", !(v && v.outcome));
|
||||
}
|
||||
|
||||
// ---- the script -----------------------------------------------------------
|
||||
@@ -209,38 +317,77 @@
|
||||
|
||||
if (!settles) money();
|
||||
|
||||
// Whatever the server says the stake is, that's what has to be on the spot.
|
||||
// Two things get here: a double, which puts a second bet down beside the
|
||||
// first, and a deal whose bet was typed rather than stacked (you kept last
|
||||
// hand's number and just pressed Deal). Either way the chips go down before
|
||||
// the card they're buying does.
|
||||
if (final && final.bet > spot.amount) {
|
||||
var extra = final.bet - spot.amount;
|
||||
chain = chain.then(function () { return stake(extra); });
|
||||
// A deal whose bet was typed rather than stacked (you kept last hand's number
|
||||
// and just pressed Deal) has chips to put down before the first card does.
|
||||
// Everything else that costs money — a double, a split — announces itself as
|
||||
// an event, and pays for itself there.
|
||||
if (final && final.hands && final.hands.length && events.length && events[0].kind === "deal") {
|
||||
var want = final.hands[0].bet;
|
||||
var have = betSpot().amount;
|
||||
if (want > have) {
|
||||
chain = chain.then(function () { return betSpot().pour(purseEl, want - have); });
|
||||
}
|
||||
}
|
||||
|
||||
events.forEach(function (e) {
|
||||
chain = chain.then(function () {
|
||||
var box;
|
||||
switch (e.kind) {
|
||||
case "deal":
|
||||
// Clear the felt, but not the stake: those chips are yours, they are
|
||||
// already on the spot, and they are what this deal is riding on.
|
||||
var staked = betSpot().amount;
|
||||
dealerEl.innerHTML = "";
|
||||
playerEl.innerHTML = "";
|
||||
playerEl.dataset.won = "0";
|
||||
reset(1);
|
||||
betSpot().render(staked);
|
||||
verdictEl.classList.add("hidden");
|
||||
FX.sfx("shuffle");
|
||||
return;
|
||||
|
||||
case "player_card":
|
||||
playerEl.appendChild(cardEl(e.card));
|
||||
ensure(e.hand + 1);
|
||||
box = hands[e.hand];
|
||||
box.cards.appendChild(cardEl(e.card));
|
||||
box.ranks.push(e.card.rank);
|
||||
showTotal(box);
|
||||
live(e.hand);
|
||||
FX.sfx("deal");
|
||||
return wait(DEAL_MS);
|
||||
|
||||
case "split":
|
||||
// The second card lifts out of the hand it was in and becomes a hand
|
||||
// of its own, and the bet that follows it is a second bet: the same
|
||||
// chips again, out of your pile, onto a spot that didn't exist a
|
||||
// moment ago.
|
||||
var src = hands[e.hand];
|
||||
var moved = src.cards.lastElementChild;
|
||||
var stake = src.spot.amount;
|
||||
var fresh = makeHand(e.hand + 1);
|
||||
if (moved) moved.classList.add("bj-splitting");
|
||||
FX.sfx("deal", { v: 1 });
|
||||
return wait(SPLIT_MS).then(function () {
|
||||
if (moved) {
|
||||
moved.classList.remove("bj-splitting");
|
||||
fresh.cards.appendChild(moved);
|
||||
}
|
||||
fresh.ranks.push(src.ranks.pop());
|
||||
showTotal(src);
|
||||
showTotal(fresh);
|
||||
return fresh.spot.pour(purseEl, stake);
|
||||
});
|
||||
|
||||
case "double":
|
||||
// The stake goes down again on that hand, and only that hand.
|
||||
box = hands[e.hand];
|
||||
return box.spot.pour(purseEl, box.spot.amount);
|
||||
|
||||
case "dealer_card":
|
||||
// The dealer takes a moment before the first card they draw out.
|
||||
// Card, card, card with no breath in between is a machine dealing;
|
||||
// the pause is the only thing on this table that plays as suspense.
|
||||
var beat = drew ? Promise.resolve() : think();
|
||||
drew = true;
|
||||
live(-1);
|
||||
return beat.then(function () {
|
||||
dealerEl.appendChild(cardEl(e.card));
|
||||
FX.sfx("deal", { v: 1 });
|
||||
@@ -256,6 +403,7 @@
|
||||
case "reveal":
|
||||
// The hole card turns over. Its face is in the final hand — this is
|
||||
// the first moment the server has been willing to say what it was.
|
||||
live(-1);
|
||||
if (!hole) hole = dealerEl.querySelector('.pete-card[data-face="down"]');
|
||||
if (hole && final && final.dealer && final.dealer[1]) {
|
||||
turnOver(hole, final.dealer[1]);
|
||||
@@ -271,12 +419,16 @@
|
||||
return chain.then(function () {
|
||||
if (!final) { paint(null); money(); return; }
|
||||
|
||||
totals(final);
|
||||
dealerTotal(final);
|
||||
if (!settles) { setPhase(final); return; }
|
||||
|
||||
// The hand is over: nothing is on offer while the money is moving. Hit and
|
||||
// Stand go now, and Deal comes back at the far end.
|
||||
// The deal is over: nothing is on offer while the money is moving. The
|
||||
// actions go now, and Deal comes back at the far end.
|
||||
actions.classList.add("hidden");
|
||||
live(-1);
|
||||
(final.hands || []).forEach(function (h, i) {
|
||||
if (hands[i]) showHandVerdict(hands[i], h);
|
||||
});
|
||||
verdict(final);
|
||||
// The chips move, and the bar catches up with them when they arrive. The
|
||||
// betting controls come back last, once the felt is clear: offering Deal
|
||||
@@ -284,16 +436,20 @@
|
||||
// has to refuse.
|
||||
return settleChips(final)
|
||||
.then(money)
|
||||
.then(function () { return standing(final.bet); })
|
||||
.then(function () { return standing(base || (final.hands[0] && final.hands[0].bet)); })
|
||||
.then(function () { setPhase(final); });
|
||||
});
|
||||
}
|
||||
|
||||
// standing leaves your bet up for the next hand, the way you would at a table:
|
||||
// the stake that just settled goes straight back on the spot. It costs nothing
|
||||
// — chips on the spot are a proposal until you press Deal — and it's what keeps
|
||||
// the number in the panel honest, because otherwise a settled hand leaves
|
||||
// "your bet: 300" printed over an empty spot.
|
||||
// one hand's stake goes straight back on the spot. It costs nothing — chips on
|
||||
// the spot are a proposal until you press Deal — and it's what keeps the number
|
||||
// in the panel honest, because otherwise a settled hand leaves "your bet: 300"
|
||||
// printed over an empty spot.
|
||||
//
|
||||
// It's one hand's worth, not the whole deal's: a split cost you four hundred,
|
||||
// and standing four hundred back up on one spot would be betting a stranger's
|
||||
// money on your behalf.
|
||||
function standing(amount) {
|
||||
var money = window.PeteGames.view();
|
||||
if (!amount || !money || money.chips < amount) {
|
||||
@@ -303,7 +459,7 @@
|
||||
}
|
||||
bet = amount;
|
||||
showBet();
|
||||
return stake(amount);
|
||||
return betSpot().pour(purseEl, amount);
|
||||
}
|
||||
|
||||
// think is the dealer's beat: a pause with something to look at, so it reads as
|
||||
@@ -331,7 +487,8 @@
|
||||
say(err.message, "bad");
|
||||
// Whatever we thought was on the felt, the server is the authority on it.
|
||||
return window.PeteGames.refresh().then(function (v) {
|
||||
if (v && !v.hand) spot.render(0);
|
||||
if (v && !v.hand) { reset(1); setPhase(null); }
|
||||
else if (v && v.hand) paint(v.hand);
|
||||
});
|
||||
})
|
||||
.then(function () { busy = false; });
|
||||
@@ -368,8 +525,9 @@
|
||||
// but the spot's total moves now, so a Deal pressed mid-flight still knows
|
||||
// the chip is on its way and doesn't put a second one down.
|
||||
var target = bet;
|
||||
var spot = betSpot();
|
||||
spot.amount = bet;
|
||||
FX.fly(btn, spotEl, { denom: d }).then(function () {
|
||||
FX.fly(btn, hands[0].spotEl, { denom: d }).then(function () {
|
||||
if (bet >= target) spot.render(target); // unless Clear got there first
|
||||
});
|
||||
});
|
||||
@@ -378,8 +536,8 @@
|
||||
var clearBtn = root.querySelector("[data-bet-clear]");
|
||||
if (clearBtn) {
|
||||
clearBtn.addEventListener("click", function () {
|
||||
if (busy || !spot.amount) { bet = 0; showBet(); return; }
|
||||
spot.sweep(purseEl, null, { gap: 40, lift: 0.7 });
|
||||
if (busy || !betSpot().amount) { bet = 0; showBet(); return; }
|
||||
betSpot().sweep(purseEl, null, { gap: 40, lift: 0.7 });
|
||||
bet = 0;
|
||||
showBet();
|
||||
});
|
||||
@@ -388,6 +546,7 @@
|
||||
if (dealBtn) {
|
||||
dealBtn.addEventListener("click", function () {
|
||||
if (bet <= 0) { say("Put something on it first.", "bad"); return; }
|
||||
base = bet; // one hand's worth, which is what a split doubles and a stand puts back
|
||||
send("/api/games/blackjack/deal", { bet: bet });
|
||||
});
|
||||
}
|
||||
@@ -403,15 +562,17 @@
|
||||
if (/^(input|textarea|select)$/i.test((e.target.tagName || ""))) return;
|
||||
if (!hand || hand.phase !== "player" || busy) return;
|
||||
|
||||
var move = { h: "hit", s: "stand", d: "double" }[e.key.toLowerCase()];
|
||||
var move = { h: "hit", s: "stand", d: "double", p: "split" }[e.key.toLowerCase()];
|
||||
if (!move) return;
|
||||
if (move === "double" && !hand.can_double) return;
|
||||
if (move === "split" && !hand.can_split) return;
|
||||
e.preventDefault();
|
||||
send("/api/games/blackjack/move", { move: move });
|
||||
});
|
||||
|
||||
// The money bar owns the first fetch; the table picks up whatever it found,
|
||||
// including a hand left sitting on the felt by a reload or a redeploy.
|
||||
// including a deal left sitting on the felt by a reload or a redeploy.
|
||||
reset(1);
|
||||
var resumed = false;
|
||||
window.PeteGames.onUpdate(function (v) {
|
||||
if (!resumed) {
|
||||
|
||||
Reference in New Issue
Block a user