Skip to content

Instantly share code, notes, and snippets.

@sax1johno
Last active June 21, 2022 15:03
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 sax1johno/a9f8663adc39b2ed799d3fb0d0faa83e to your computer and use it in GitHub Desktop.
Save sax1johno/a9f8663adc39b2ed799d3fb0d0faa83e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const betMachine = Machine(
{
"id": "StandardBet",
"initial": "waitingForPlayerAction",
"bettingOrder": [
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"a",
"b"
],
"currentPlayerPosition": 0,
states: {
"waitingForPlayerAction": {
},
"processingPlayerAction": {
}
},
amountDue: 0, // Amount due by each player
players: {
"a": {
"amountIn": 0,
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"b": {
"amountIn": 0,
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"c": {
"amountIn": 0,
"betHistory": [],
"bank": 10000,
"status": "unseated"
},
"d": {
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"e": {
"amountIn": 0,
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"f": {
"amountIn": 0,
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"g": {
"amountIn": 0,
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"h": {
"amountIn": 0,
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"i": {
"amountIn": 0,
"betHistory": [],
"bank": 10000,
"status": "seated"
}
}
},
{
"actions": {},
"guards": {},
"activities": {},
"actions": {}
}
)
const texasMachine = Machine(
{
id: "TexasHoldEm",
initial: "creating",
context: {
pot: 0,
ante: 0,
sb: 50,
bb: 100,
currentPlayerPosition: 0,
tablePositions: [
"button",
"smallBlind",
"bigBlind",
"underTheGun",
"underTheGunPlusOne",
"middlePosition",
"lowJack",
"highJack",
"cutoff"
],
playerPositions: [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i"
],
players: {
"a": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"b": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"c": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "unseated"
},
"d": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"e": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"f": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"g": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"h": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "seated"
},
"i": {
"cards": [],
"betHistory": [],
"bank": 10000,
"status": "seated"
}
}
},
states: {
creating: {
// Create a new game
entry: ["beforeCreate", "create", "buyIn"],
exit: ["afterCreate"],
on: {
start: {
target: "startGame",
},
},
},
startGame: {
// Starting a new Round
entry: ["beforeStartingGame", "setDealer", "setBlinds", "updateRake", "startGame"],
exit: ["afterStartingGame"],
on: {
next: {
"target": "forcedBetRound"
}
},
},
forcedBetRound: {
// The prompt card is being dealt
entry: ["beforeForcedBetRound", "takeSmallBlind", "takeBigBlind", "takeAnte"],
exit: ["afterForceBetRound"],
on: {
next: {
target: "dealHoleCards"
}
},
},
dealHoleCards: {
// The response cards are being dealt to all users
entry: ["beforeDealHoleCards", "dealHoleCards"],
exit: ["afterDealHoleCards"],
on: {
next: {
target: "preFlopBet",
}
},
},
preFlopBet: {
// Players are choosing their response cards
entry: ["beforePreFlopBet", "preFlopBet"],
exit: ["afterPreFlopBet"],
on: {
next: {
target: "dealFlop",
},
complete: {
"target": "computeWinner"
}
},
},
dealFlop: {
// The dealer is choosing the winning card
entry: ["beforeDealFlop", "dealFlop"],
exit: ["afterDealFlop"],
on: {
next: {
target: "preTurnBettingRound",
}
},
},
preTurnBettingRound: {
// award the winner the trophy
entry: ["beforePreTurnBettingRound", "preTurnBettingRound"],
exit: ["afterPreTurnBettingRound"],
on: {
next: {
target: "dealTurn"
},
complete: {
"target": "computeWinner"
}
},
},
dealTurn: {
// Finish up the current round
entry: ["beforeDealTurn", "dealTurn"],
exit: ["afterDealTurn"],
on: {
next: {
"target": "preRiverBettingRound"
},
},
},
preRiverBettingRound: {
entry: [ "beforePreRiverBettingRound", "preRiverBettingRound"],
exit: ["afterPreRiverBettingRound"],
on: {
next: {
"target": "dealRiver"
},
complete: {
"target": "computeWinner"
}
}
},
dealRiver: {
entry: [ "beforeDealRiver", "dealRiver"],
exit: [ "afterDealRiver" ],
on: {
next: {
"target": "finalBettingRound"
}
}
},
finalBettingRound: {
entry: [ "beforeFinalBettingRound", "finalBettingRound"],
exit: ["afterFinalBettingRound"],
on: {
complete: {
"target": "computeWinner"
}
}
},
computeWinner: {
// End the game and wrap up
entry: ["beforeComputeWinner", "computeWinner"],
type: "final",
},
},
},
{
activities: {},
guards: {},
actions: {
log: (context, event) => {
console.log(JSON.stringify(event));
},
setEndingRoundTimer: assign((context, event) => {
return {
currentStateTimer: 2 * TICKS_PER_SECOND,
};
}),
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment