Last active
April 26, 2020 21:24
-
-
Save magicspon/dd00cf3a38c82aa0a7357602aea5968e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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