Skip to content

Instantly share code, notes, and snippets.

@magicspon
Last active April 26, 2020 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magicspon/dd00cf3a38c82aa0a7357602aea5968e to your computer and use it in GitHub Desktop.
Save magicspon/dd00cf3a38c82aa0a7357602aea5968e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const playerMachine = {
id: "player",
initial: "waiting",
states: {
waiting: {
on: {
PLAY: "playing",
},
},
playing: {
on: {
FOLD: "folded",
CHECK: "waiting",
BET: "betting",
},
},
betting: {
on: {
CALL: "waiting",
RAISE: "waiting",
FOLD: "folded",
},
},
folded: {
type: "final",
entry: ["onFold"],
},
}, }
const players = Array.from({ length: 5 }, (_, i) => `player-${i}`).reduce(
(acc, curr, index) => ({
...acc,
[curr]: { on: { NEXT: `player-${(index + 1) % 5}` }, ...playerMachine },
}),
{}
) // ?
const game = Machine(
{
id: "player",
initial: "player-0",
states: players,
},
{
actions: {
onFold: () => {
console.log("folded")
},
},
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment