JSFiddle - React, Tailwind, and code Playground
21 calc
by Christopher O
JavaScript
// Setings
let seat = 1; // clockwise from dealer
let players = 2;
let decks = 6;
let cutAtDeck = 5;
let handsToPlay = 3;
let betsAlKaufman = [5,15,35,75,150,300,600,1200];
// Vars
/* Cards: ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen and king */
/* Suites: hearts, clubs, spades, diamonds */
let cards = [1,2,3,4,5,6,7,8,9,10,10,10,10]; // 1 = ace.
let shoe = [];
// -------------------------------------------------
// -------------------------------------------------
// Build first shoe
buildShoe();
console.log("shoe.length: "+shoe.length);
let dealt = {};
// Deal hands
for (let handNum = handsToPlay; handNum >= 1; handNum--) {
dealt = {};
dealOne();
dealOne();
//console.log("Hand "+handNum+":\n"+JSON.stringify(dealt)+"\n\n");
console.log(dealt)
}
// -------------------------------------------------
// -------------------------------------------------
function dealOne() {
for (var i = 0; i < players; i++) {
let card = shoe.pop();
if(!dealt[String(i)]) dealt[String(i)] = [];
dealt[String(i)].push(card);
// console.log("Player "+i+": "+card);
}
// dealer
let card = shoe.pop();
if(!dealt["d"]) dealt["d"] = [];
dealt["d"].push(card);
// console.log("Dealer: "+card);
}
function buildShoe() {
for (let deckNum = decks - 1; deckNum >= 0; deckNum--) {
shoe = shoe.concat(shuffle(cards)); // Spades
shoe = shoe.concat(shuffle(cards)); // Hearts
shoe = shoe.concat(shuffle(cards)); // Diamonds
shoe = shoe.concat(shuffle(cards)); // Clubs
}
shoe = shuffle(shoe);
shoe = shuffle(shoe);
}
function shuffle(array) {
let currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] =...