# Dessign patterns poker game

This topic is 3889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I am a multimedia student. For a project we have to create a poker game (texas hold'em) in 3D. At this moment we are analyzing the game. When we were drawing the class diagram we thought it could be usefull to use design patterns. Only i'm not such an expert in design patterns. May be someone can help us defining the patterns we could use in a texas hold'em poker game. For example could the decorator pattern be usefull to decorate a player object like a dealer, small or big blind. I hope someone can help!

##### Share on other sites
The position of the big blind, small blind and dealer is a property of the table (so that it remains in place even if a player leaves while being one of them).

I'd say the game representation (cards, players, tables, pots, stacks) is pretty straightforward to get. The actual trouble appears when you start implementing the "who won?" algorithm.

##### Share on other sites
Quote:
 Original post by ToohrVykThe actual trouble appears when you start implementing the "who won?" algorithm.

Well, isn't that just a question of "who has the best hand?". Evaluating different hands isn't that tough since there is a limited amount of different hands and you'll just need to find the best.

One way to evaluate the hand is to put the cards in a 2D table where x is the suit and y is the card rank (ace should be regarded as 1 and 14). You can use additional tables for speeding up some of the evaluations.

I made an evaluator object which contained the following rule objects:

RoyalFlush
StraightFlush
Four of a kind
Fullhouse
Flush
Straight
Three of a kind
Two pair
One Pair
High Card

For example:

Fullhouse : Find a rank with 3 cards and a rank with 2 cards both starting from the highest. If found, then add those play hand.

Three of a kind : Find a rank with 3 cards starting from the highest. If found, then add those three cards and 2 highest available cards to the play hand.

You'll need to start the card evaluation from the most valuable hand (ie. straight flush or royal flush) in order to make these rules work.

Since each hand has an value assigned, it is easy to compare which player has the best hand. If two players happen to have the a hand with the same value, you can compare them simply by checking which one has bigger cards.

Good luck!

##### Share on other sites
You could implement the high-level construct of the game using the Model-View-Controller pattern. In this case, the Model corresponds to the game as a whole and which, itself, consists of the rules, dealer/SB/BB buttons, the pot, the deck, player hands, etc. The View queries the model for details it needs to present the game graphically (note that the View controls presentation its not where low-level rendering code belongs.) You can implement other facets as Controllers, the human and AI players can be implemented as controllers for instance.

You might also want to consider implementing players as Model/Controller pairs inside the game model, leaving the top level Controller for less player-oriented tasks, forwarding messages to the Model (who can route to the players' Model/Controller) when appropriate.

##### Share on other sites
If you are allowed to use 3rd party libraries consider looking at this

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 16
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632659
• Total Posts
3007692
• ### Who's Online (See full list)

There are no registered users currently online

×