Page 1 of 1

Looking to chat with a developer on finite state/game logic

Posted: 07 May 2022, 02:24
by ImaginaryPet
Hi,

So I love boardgamearena and I'm currently in a programming course and we've chosen for a group project to do essentially a bga clone as a portfolio piece. I'm really quite a bit confused on finite state machines, the state pattern vs command pattern and how to implement a design for game logic to be plug-and-play into a game website system. We'll be using a MERN (MongoDB, Express, React, Node) stack. I was wondering would anyone be willing to spare some time to talk to me about the general concepts of implementing the game logic design. From the BGA documentation I know it's a finite state where there are possible actions that lead to other states but I'm confused on how to make that work with multiple players etc. Thanks

Re: Looking to chat with a developer on finite state/game logic

Posted: 07 May 2022, 08:07
by tchobello
hello...

you deal with player's actions in 'activeplayer' type state.
Once a JS listener is triggered, PHP receives the informations via xxx.action.php, makes back-end job and notifies front-end what is to be shown.

when you need to switch to another player or to a multiplayer state, you move to a 'game' type state and do the back-end stuff before moving to a new game state (activeplayer or multipleactiveplayer).

Re: Looking to chat with a developer on finite state/game logic

Posted: 07 May 2022, 10:26
by junibegood
If you're familiar with classic web development, the part than can be confusing is the websocket mechanism. In a classic web software, requests are always initiated by the client (user's web browser), which are basically of two types :
  • GET : you ask the server about the current game situation
  • POST : you inform the server about a user action so that it updates its database
The limit with this system, for real time games, is that you (the client) never know when the game situation changes, unless you ask (by sending a GET request). Websockets allow requests initiated by the server. This is very important, because in an architecture with multiple clients and one server, we want the game to be managed by the server (also because server side program is the only one we can trust for rules enforcement). Everytime the game situation changes, websockets allow the server to notify the clients, so they can update the players screens. There is no need for the clients to check regularly : "Hey, server, did something change since last time I asked ?"

Let's imagine a simple card game, like Spades, for example. A player turn will look like this :
  • Initial state : it's "player 1" turn
  • Player 1 clicks a card from his hand : his browser sends that information to the server
  • The server makes all required changes in the database, like moving the card from the player hand to the table.
  • The server notifies all players that player 1 played this card
  • All players browsers update their screens. For example, the card player will appear above player 1 panel, then slide to the game table and stay there.
  • The server notifies all players that it's now player 2's turn. Player 2 screen will now display a status message like "You must play a card" and maybe some kind of highlight around cards the player may click now. Other players screens will now display a message like "Player 2 must play a card".
  • Final state : it's "player 2" turn. Rince and repeat
The server handles all game mechanics. Everytime something happens that requires un update on players screens, it sends a notification. In my example, the notification was linked to another player's action, but it's not always the case. The server may perform actions and send notifications "on its own". For example, if the card played by player 1 was the last card to play in the current round, the server will detect this and perform several actions in the database like :
  • Update players scores
  • Move all cards frome the table back to the deck
  • Shuffle the deck
  • Deal new hands to all players
All these actions will trigger notifications to the clients so they may update the players screens.

Re: Looking to chat with a developer on finite state/game logic

Posted: 07 May 2022, 20:31
by ImaginaryPet
Ah I just saw both of these replies. Thank you so much for getting back to me. I do have familiarity with classic web dev as well as websockets using rails action cable. I guess I'm more concerned about some of the backend gamestate logic. Unfortunately, I'm not using, nor will I be able to use PHP. Junibegood would there be any chance you could spare some time today to talk to me on discord? If not I totally understand. I'm more confused about the game state machine that bga implements.

Re: Looking to chat with a developer on finite state/game logic

Posted: 07 May 2022, 21:18
by Tisaac
ImaginaryPet wrote: 07 May 2022, 20:31 Ah I just saw both of these replies. Thank you so much for getting back to me. I do have familiarity with classic web dev as well as websockets using rails action cable. I guess I'm more concerned about some of the backend gamestate logic. Unfortunately, I'm not using, nor will I be able to use PHP. Junibegood would there be any chance you could spare some time today to talk to me on discord? If not I totally understand. I'm more confused about the game state machine that bga implements.
You can pm on discord from the bga dev server

Re: Looking to chat with a developer on finite state/game logic

Posted: 07 May 2022, 21:47
by ImaginaryPet
Tisaac wrote: 07 May 2022, 21:18
ImaginaryPet wrote: 07 May 2022, 20:31 Ah I just saw both of these replies. Thank you so much for getting back to me. I do have familiarity with classic web dev as well as websockets using rails action cable. I guess I'm more concerned about some of the backend gamestate logic. Unfortunately, I'm not using, nor will I be able to use PHP. Junibegood would there be any chance you could spare some time today to talk to me on discord? If not I totally understand. I'm more confused about the game state machine that bga implements.
You can pm on discord from the bga dev server
Amazing! Thank you! I just joined and sent you a friend request. I'm Kevin