"Check condition" state in state machine for conditional exceptions

Game development with Board Game Arena Studio
Post Reply
User avatar
Paxcow
Posts: 3
Joined: 23 July 2017, 01:03

"Check condition" state in state machine for conditional exceptions

Post by Paxcow »

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?
User avatar
robinzig
Posts: 461
Joined: 11 February 2021, 18:23

Re: "Check condition" state in state machine for conditional exceptions

Post by robinzig »

Whatever you do, you're going to need to check for this on both the client side (to give the player the correct choices in the 2-player variant) and the server side (to deal with the result of the discard, as well as to do the auto draw). So the client-side code you mention in your second option is always going to be needed anyway, as are checks in your action-handling function and the "state function" for your "game" state. I don't see why you'd further complicate this by adding additional possibilities to the state machine - but I guess it's up to you.

(Note that you can't have any logic in the state machine file - it's basically just a static configuration file. It would be the handler of that "game state" in your .game.php file that looks up whether it's a 2-player game or not, and moves to the appropriate next state. But the way you've described this, I don't see that there are any additional states in the 2-player variant, just additional things that happen in the existing ones. That's just my way of seeing it though, the alternative is equally valid.)
Post Reply

Return to “Developers”