"Check condition" state in state machine for conditional exceptions
Posted: 29 January 2024, 11:31
Hello,
i have a quite straightforward state machine diagram, but in a couple of situation, the normal flow of the game has an a conditional exception resulting in an optional state or action.
For example, with a basic draft mechanic, players have to select a card to play simultaneously (multiplayer state) and then the remaining cards are passed to next player (game state).
In a 2 players game, though, the rules say that before passing the cards to next player you have to discard one card, and that after you receive the cards from the player before you you must draw one card from the deck.
I could build a state machine like
PLAYER_SELECT_CARD (multiactive) => IS_2_PLAYERS_? (game): YES =>DISCARD_CARD; NO => PASS_CARDS
DISCARD_CARD (multiactive) etc. etc.
Or, I could manage this rule at the client level and add the "discard card" action as part of the PLAYER_SELECT_CARD state, nesting the action in an IF condition.
Since everything would happen before the PASS_CARD state transition, I am not even worried about UNDO, since other players would not be affected, therefore it doesn't look like I would need private states...
For the DRAW_CARD state it would be even easier, I could merge the PASS_CARD and DRAW_CARD in the same game state action, with the proper IF.
Am I missing something? Would you recommend making the State machine very explicit, adding all these °conditional check° states?
i have a quite straightforward state machine diagram, but in a couple of situation, the normal flow of the game has an a conditional exception resulting in an optional state or action.
For example, with a basic draft mechanic, players have to select a card to play simultaneously (multiplayer state) and then the remaining cards are passed to next player (game state).
In a 2 players game, though, the rules say that before passing the cards to next player you have to discard one card, and that after you receive the cards from the player before you you must draw one card from the deck.
I could build a state machine like
PLAYER_SELECT_CARD (multiactive) => IS_2_PLAYERS_? (game): YES =>DISCARD_CARD; NO => PASS_CARDS
DISCARD_CARD (multiactive) etc. etc.
Or, I could manage this rule at the client level and add the "discard card" action as part of the PLAYER_SELECT_CARD state, nesting the action in an IF condition.
Since everything would happen before the PASS_CARD state transition, I am not even worried about UNDO, since other players would not be affected, therefore it doesn't look like I would need private states...
For the DRAW_CARD state it would be even easier, I could merge the PASS_CARD and DRAW_CARD in the same game state action, with the proper IF.
Am I missing something? Would you recommend making the State machine very explicit, adding all these °conditional check° states?