-2

These are my class designs: enter image description here

I also have Controllers where I can create table, create users add users to table, deal hands simulate user bets using PostMan (Above classes are game engine classes, I did not share controllers in spring boot. It is all API)

Somehow, I am not able to stitch them all together as a complete game.

Here is what I tried:

Finite State Machine: I think possible states in the game is: Collect Blinds, Deal Hands, GamePlay (where fold, bet and raise takes place), ShowDown. Then I tried to understand what would happen in states and got confused.

Then I tried to implement the logic with chain of responsibility, it looks like we have a chain of activities: collect blinds, deal hands, gameplay (itself is also chain of actions like folds, bets, raises) and updates inside them.

In practice, I was not able to achieve this. Does anyone has an idea how to put them together using design patterns?

Sunuba
  • 21
  • 2
  • Did you try keeping at the same time multiple state machines? I mean one for the game and one for the state of each player in the game. – FluidCode Sep 13 '21 at 11:57
  • 4
    "Does anyone has an idea how to put them together using design patterns?" <- [this answer is worth reading at this stage](https://softwareengineering.stackexchange.com/a/227880/136413) – Philip Kendall Sep 13 '21 at 12:21
  • @FluidCode actually no. this give me some idea as well. – Sunuba Sep 14 '21 at 06:02
  • Is it possible for those of you who put downvote bring your arguments? It is just easy to downvote right? If there is nothing you can fix then go away. – Sunuba Sep 17 '21 at 10:19

1 Answers1

1

State is about data, not discrete state machines. State Machines help you understand the emergent states.

If you consider state as all of data overall, you just need to be able to query different views of the data.

Relational Data doesn't have to be SQL, but it's easier to think that way. Your implementation could easily model "record" vectors in memory and implement JOINs using for-loops and lookups.

Entities and Lookups

  • Tables: ID, TableNumber
  • Holders: ID, Name, CashBalance
  • Games: ID, TableID, StartingHoldersJSON

Current Game

  • Cards: Suit, Value, HolderID, (GameID)
  • Bets: ..., (GameID)
  • GameHolders: IsInGame, HolderID, IsDealer, (GameID)

Game Events

  • CardPlayed
  • BetPlayed
  • ....
  • WinEarned
  • LossIncurred

Game Processes

  • When CardPlayed, update Card in [Current Game]
  • When all Game Events are processed, Query [Current Game] for Outcomes or Next Dealer move, and add corresponding Game Event.
  • And more...

Hopefully you see how a working system emerges.

Kind Contributor
  • 802
  • 4
  • 12