codegard1/blackjack

Implement StateMachine class to handle game evaluation

Closed this issue · 2 comments

Instead of using bare functions in a switch statement to govern gameplay, create a StateMachine class to encapsulate all code related to the state of play.

For reference see: State Machines in Games

Also, instead of writing this from scratch, how about using javascript-state-machine ( also on npm )

Currently the "state machine" I have is one function in GameStore: evaluateGame()

This method checks for endgame conditions and then sets nextGameStatus and nextPlayer. Finally, it calls endgameTrap(), which just re-runs evaluateGame() with the new props. This kind of works until you encounter an actual endgame condition, like a player winning or all players staying. Then it becomes unclear how control will pass through the switch, and in practice the results are unpredictable.

As a finite state machine, blackjack would seem to only have three states:
0 | Off
1 | On
2 | Ending

The path is like so:
state machine drawing

This issue is deprecated because it is redundant! Flux by itself is already a "State Machine" that does what I wanted to do anyway. The real issue is that my Flux configuration was a bit confused. I have since improved it.