Published
Edited
Aug 8, 2019
Insert cell
md`# Poker Now Shuffle logic`
Insert cell
Random = require('random-js@1.0.8')
Insert cell
random = new Random(Random.engines.mt19937().autoSeed())
Insert cell
values = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
Insert cell
suits = ['d', 'h', 'c', 's']
Insert cell
originalDeck =
suits.reduce((memo, suit) =>
[...memo, ...values.map(value => `${value}${suit}`)], []
)
Insert cell
{
let deck = random.shuffle([...originalDeck])

let actors = {
table: [],
player0: [],
player1: [],
player2: []
}

for (let playerIndex = 0; playerIndex <= 2; playerIndex++) {
let cardsIndex = [
playerIndex,
(playerIndex + 3)
]

actors[`player${playerIndex}`] = [
deck[cardsIndex[0]],
deck[cardsIndex[1]]
]

deck[cardsIndex[0]] = null
deck[cardsIndex[1]] = null
}
deck = deck.filter(card => card)

actors['table'] = deck.splice(0, 5)

return actors
}
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