#How to handle arbitrary number of child states?

1 messages · Page 1 of 1 (latest)

old nymph
#

Imagine a card game that has two sides, but each side can have arbitrary number of players. One side can have 4 players but the other side can have only 1 player. Each player has its own but identical machine.
How should I define such scenario in xstate?

old nymph
#

Maybe I can add an Absent state to each player.

#

And hardcode 4 players on each side

#

4 is the maximum per side

worthy kindle
#

are these players distributed across different computers or are they all playing through the same computer?

old nymph
#

It can be both

#

But why would it matter?

worthy kindle
#

I think it could change how you want to model it

old nymph
#

It's intended for multiple players on different devices.

#

But I can simulate all in my local testing

worthy kindle
#

gotcha!

#

also curious if is there a server coordinating the game?

old nymph
#

There has to be one if it's supporting multiplayer gameplay

worthy kindle
#

Okay so each player is really communicating with the server as a proxy

old nymph
#

Not sure if this matters too. The FSM doesn't care if the commands are received via network or local function calls.

#

It should be fine as long as it knows what commands are? Not how they are sent?

worthy kindle
#

ya totally

#

so are you thinking each computer will have a state machine of each player?

#

which have to be synced together across each computer?

#
context: {
  sideOne: [...],
  sideTwo: [...]
}
old nymph
#

If it's hosted as an online game, I guess a server handles all the logic and pushes the whole game state to every player and receives actions from the players.
No machine on the player clients.

#

Thanks for the link, I'll take a look.