I\'m facing a challenge understanding how to program a web version of a card gam
ID: 651155 • Letter: I
Question
I'm facing a challenge understanding how to program a web version of a card game that is completely stateless.
I create my object graph when the game begins and distribute cards to PlayerA and PlayerB so I lay them out on the screen. At this point I could assume that HTML and the querystring is what holds at least someof my state and just keep a snapshot copy of the game state on the server-side for the sole purpose of validating the inputs I receive from the web clients.
Still it appears to me that the state of the game is by its nature mutable: cards are being dealt from the deck, etc.
Am I just not getting it? Or should I just strive to minimize the side-effects of my functions to the objects that I take as my input? How would you design a stateless card game?
Explanation / Answer
A single player game can be completely stateless if the entire description of the game is transmitted on each request. A chess game against a computer program implemented by your server could just send the complete position after each move.
It's hard to see how a multiplayer game can be completely stateless - someone has to keep track of who the players are and who needs to be informed of state changes, and at least remember the state "in transit" long enough for all the players to receive it.
In any case, the primary role of the server can be just to relay bags of bits among the clients, and only need to keep track of where the bits are supposed to go. Depending on the nature of the game, the bits may need to be authenticated in some way to prevent cheating, for example by adding a checksum to the parts the clients aren't supposed to be able to change.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.