games: you buy the deck, and win it back a card at a time
Solitaire, Vegas rules — the only shape solitaire has ever had as a gambling game. You don't win or lose the deal: the stake buys the deck outright, and every card you get home to a foundation pays a fifty-second of the tier's multiple back. Cash the board whenever you like and keep what you've banked, so a board that has gone dead is a decision rather than a wall. No undo: the stake is spent the moment the deck is bought, and an undo would be a way to walk a losing board backwards until it wins. Three deals, and the two dials are the whole difficulty of Klondike. Patient draws one with unlimited passes and pays 1.4x, so it takes 38 cards home to get square. Vegas draws three, three times round, 2.2x, square at 24. Cutthroat draws three and gives you one pass, 3.4x, square at 16 — most of those boards never clear, and you're ahead long before they would. internal/games/klondike is the same pure reducer as the other two, and Pays() is one function for the same reason hangman's is. Two fuzzers hold the deck together: no sequence of moves can lose or duplicate a card, and the board stays well-formed. They earned their keep immediately — the first thing they caught was a recycle that reversed the waste. It flips as a block, so the card drawn first comes out first, and reversing it would have dealt a different game on every pass and quietly broken the seed in the audit log. The browser never sees the stock or a face-down card, which here is most of the deck rather than blackjack's one hole card: a column sends how many cards are under it, never which. The table re-renders and animates the difference. Blackjack plays back a script because a hand only ever grows at one end; solitaire moves runs from anywhere to anywhere and an auto-finish moves eleven cards at once, so a script of "append this card there" would be a second engine over here and it would be the one that's wrong. Instead the board on screen is always exactly the board the server says exists, and each card is played from where it just was to where it now is. The events supply only what a diff can't: where a newly-revealed card came from, and what the board is worth. The rules are mirrored in JS on purpose, and only to light up the columns a held card can go to. Being shown where a card goes is the game teaching you; being told no after you commit is the game scolding you. The server still decides, and a disagreement snaps the board back to what it says. Two things came out into the open rather than being copied, which is the rule this room runs on: casino-cards.js (the deck — faces, pips, the flip) and PeteFX.spot() (the pile of chips and the number under it, which now owns the rule that the number is a readout of the pile). Blackjack uses both. Not yet driven in a browser.
This commit is contained in:
@@ -144,6 +144,78 @@
|
||||
return Promise.all(each);
|
||||
}
|
||||
|
||||
// A bet spot: the pile of chips sitting on it, and the number printed under
|
||||
// the pile.
|
||||
//
|
||||
// The rule the whole room is built on lives in here, which is why it's one
|
||||
// object and not two variables on a table: **the number is a readout of the
|
||||
// pile, never the other way round.** There is no way to change one without the
|
||||
// other, so a settled game can't leave "your bet: 300" printed over an empty
|
||||
// circle, and a payout can't be counted before the chips that justify it have
|
||||
// landed.
|
||||
//
|
||||
// els: {spot, stack, total}. Blackjack's spot holds the stake; solitaire's
|
||||
// holds what you've banked, which grows a card at a time. Same object.
|
||||
function spot(els) {
|
||||
var api = {
|
||||
// What the pile is holding. Written by render, and readable by a table that
|
||||
// needs to know whether a chip is already on its way down.
|
||||
amount: 0,
|
||||
|
||||
render: function (n) {
|
||||
api.amount = n || 0;
|
||||
els.stack.innerHTML = "";
|
||||
if (els.spot) els.spot.dataset.live = api.amount > 0 ? "1" : "0";
|
||||
if (!api.amount) {
|
||||
if (els.total) els.total.classList.add("hidden");
|
||||
return;
|
||||
}
|
||||
chipsFor(api.amount).forEach(function (d, i) {
|
||||
var c = disc(d);
|
||||
c.style.setProperty("--i", i);
|
||||
c.style.setProperty("--spin", jitter(i, 12).toFixed(1) + "deg");
|
||||
c.style.animationDelay = (reduced ? 0 : i * 40) + "ms";
|
||||
els.stack.appendChild(c);
|
||||
});
|
||||
if (els.total) {
|
||||
els.total.textContent = api.amount.toLocaleString();
|
||||
els.total.classList.remove("hidden");
|
||||
}
|
||||
},
|
||||
|
||||
// pour throws a run of chips onto the spot and grows the pile as each one
|
||||
// lands — by the value of the chip that landed, so the total under the pile
|
||||
// counts up the way the chips do. The last chip carries the remainder,
|
||||
// because chipsFor caps how many chips it will make you watch and the pile
|
||||
// still has to end on the real number.
|
||||
pour: function (from, amount, opts) {
|
||||
if (amount <= 0) return Promise.resolve();
|
||||
var base = api.amount;
|
||||
var chips = chipsFor(amount, 8);
|
||||
var run = 0;
|
||||
return flyMany(from, els.spot, chips, Object.assign({
|
||||
onLand: function (d, i) {
|
||||
run += d;
|
||||
api.render(base + (i === chips.length - 1 ? amount : run));
|
||||
},
|
||||
}, opts || {}));
|
||||
},
|
||||
|
||||
// sweep sends chips off the spot to somewhere else — your pile, or the
|
||||
// house's rack. The spot is emptied *now* rather than when they land, so
|
||||
// nothing that is already in the air can be bet a second time.
|
||||
sweep: function (to, amount, opts) {
|
||||
var n = amount == null ? api.amount : amount;
|
||||
var left = api.amount - n;
|
||||
if (n <= 0) return Promise.resolve();
|
||||
var chain = flyMany(els.spot, to, chipsFor(n, 8), Object.assign({ gap: 40, lift: 0.8 }, opts || {}));
|
||||
api.render(left > 0 ? left : 0);
|
||||
return chain;
|
||||
},
|
||||
};
|
||||
return api;
|
||||
}
|
||||
|
||||
// burst: confetti out of a point. Saved for the things worth celebrating.
|
||||
function burst(target, opts) {
|
||||
if (reduced) return Promise.resolve();
|
||||
@@ -242,6 +314,7 @@
|
||||
jitter: jitter,
|
||||
fly: fly,
|
||||
flyMany: flyMany,
|
||||
spot: spot,
|
||||
burst: burst,
|
||||
count: count,
|
||||
centre: centre,
|
||||
|
||||
Reference in New Issue
Block a user