Public
Edited
Dec 25, 2023
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
spinthebottle
Insert cell
Insert cell
Insert cell
Insert cell
x
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Deck = function(spec = {}) {
//inside out https://en.wikipedia.org/wiki/Fisher–Yates_shuffle
const shuffleDeck = (shuffled, card, i, deck) => { //shuffle a fresh deck
const j = Math.floor(Math.random() * i)
if (j != i) shuffled[i] = shuffled[j]
shuffled[j] = deck[i]
return shuffled
},
init = function() {
spec.discard = [] //clear discard
spec.shuffled = spec.deck.reduce(shuffleDeck, [])
}
spec.deck= spec.deck || [...deckofcards] //source deck

init()
// spec.shuffled = init()
// spec.discard = []
return {
draw: function() {//without replacement
const card = spec.shuffled.splice(Math.floor(Math.random() * spec.shuffled.length), 1)[0] //return element, not the wrpaping array

spec.discard.push(card)
console.log("draw", card, spec.shuffled, spec.discard)

return card
},
shuffle: function() {
init()
console.log("shuffle", spec.shuffled, spec.discard)

},
getDeck: function() {
console.log("getDeck", spec.shuffled, spec.discard)

return spec.shuffled
},
getDiscard: function() {
console.log("getDiscard", spec.shuffled, spec.discard)
return spec.discard
}

}
}
Insert cell
Insert cell
candylanddeck= [ //candyland cards
["red"],["red"],["red"],["red"],["red"],["red"],
["orange"],["orange"],["orange"],["orange"],["orange"],["orange"],
["gold"],["gold"],["gold"],["gold"],["gold"],["gold"],
["green"],["green"],["green"],["green"],["green"],["green"],
["blue"],["blue"],["blue"],["blue"],["blue"],["blue"],
["purple"],["purple"],["purple"],["purple"],["purple"],["purple"],
["character1"],
["character2"],
["character3"],
["character4"],
["character5"],
["character6"],
["red", "red"],["red", "red"],["red", "red"],["red", "red"],
["orange", "orange"],["orange", "orange"],["orange", "orange"],
["gold", "gold"],["gold", "gold"],["gold", "gold"],["gold", "gold"],
["green", "green"],["green", "green"],["green", "green"],
["blue", "blue"],["blue", "blue"],["blue", "blue"],["blue", "blue"],
["purple", "purple"],["purple", "purple"],["purple", "purple"],["purple", "purple"]
]
Insert cell
wheeloffortune = ["bankrupt1", 5000, 5001, 9001, 7001, 3002, 8001, 550, 400, 5002, 600, 350, 5003, 9002, "bankrupt2", 650, "free play", 7002, "lose a turn", 8002, 5004, 450, 5005, 3001]
Insert cell
Insert cell
Insert cell
deck.getDeck()
Insert cell
Insert cell
playerSelector = Inputs.checkbox(["Red", "Blue", "Green", "Orange", "Purple", "Black"], {label: "Players:", value: ["Red", "Blue", "Green"]})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
plainspinner = "M0 -80L-11.5 -60L11.5 -60L0 -80ZM-2 38L-11.5 58L11.5 58L2 38L-2 38ZM-2 -62L-2 40L2 40L2 -62L-2 -62Z"
Insert cell
bottle = "M11.0528 -16.3104C12.7196 -14.5178 14.7952 -12.4893 15.8488 -10.2564C16.9023 -8.0235 16.8866 -5.46038 16.8709 -3.03879C16.808 4.4147 16.7923 11.8682 16.7923 19.3217C16.7923 26.1462 16.7923 32.9864 16.7923 39.8109C16.7923 42.6728 14.465 45 11.6031 45H-11.8109C-14.6728 45 -17 42.6728 -17 39.8109V-3.11741C-17 -6.73408 -15.8364 -10.2564 -13.6192 -13.1183C-12.943 -13.9831 -12.204 -14.8165 -11.402 -15.6185C-10.49 -16.5305 -9.98681 -17.7571 -10.0025 -19.0308C-10.0025 -19.2666 -10.0025 -19.5025 -10.0183 -19.7384C-10.0183 -21.3423 -10.034 -22.9462 -9.98681 -24.5501C-9.89246 -28.3397 -9.67231 -32.1608 -8.94898 -35.8876C-8.58731 -37.7588 -7.86398 -39.5829 -7.53376 -41.4541C-7.42369 -42.0516 -7.39224 -42.6806 -7.48659 -43.2782C-7.62811 -44.1902 -7.97405 -44.9921 -7.97405 -45.9356C-7.97405 -46.8476 -7.75391 -47.7597 -7.53376 -48.6403C-7.43941 -49.0019 -7.36079 -49.3793 -7.45514 -49.741C-7.64383 -50.4329 -8.63449 -50.48 -9.05905 -51.0619C-9.90819 -52.2097 -9.0905 -53.452 -8.08412 -54.1596C-7.54949 -54.537 -6.93623 -54.8358 -6.29152 -54.9144C-5.45811 -55.0087 -4.60898 -54.9773 -3.77557 -54.993C-2.73775 -55.0087 -1.6842 -54.993 -0.64637 -54.993C0.658775 -54.993 1.96392 -54.993 3.26907 -54.993C5.21893 -54.993 9.59038 -55.0716 9.38596 -51.9424C9.29161 -50.5272 7.90784 -50.8103 7.53044 -49.7882C7.2474 -49.0019 7.84494 -47.9641 8.08081 -47.225C8.59972 -45.5739 7.86066 -44.6147 7.45182 -43.0423C7.1845 -41.973 7.73487 -40.7779 8.08081 -39.7716C9.22871 -36.4379 9.70045 -32.7898 10.0307 -29.2989C10.3923 -25.4936 10.4552 -21.6725 10.4081 -17.8514C10.4395 -17.2853 10.6597 -16.735 11.0528 -16.3104Z"
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more