Better C # Poker Framework Design?

I write poker environments in C # and I don’t like the design I have. My goal is to have a game engine that can quickly launch multiple AI agents against each other in batch mode and play multiple AI agents against several people (possibly through the Silverlight client). I would like to increase efficiency, but maintain flexibility - for example, it should be able to play games such as Limit Hold'em, No-Limit Hold'em, Limit 7-Card Stud, etc.

My current design is pretty awkward and inflexible:

  • HandHistory: contains all the information about the current hand (players, bets made, etc.).
  • IPlayer: each player defines a GetAction (HandHistory history) method.
  • GameEngine: Defines a Play (HandInfo info) method that returns a HandHistory object.
  • PotManager: manages the bank and determines how much each player needs and how much they can win (for example, if they have unequal stacks and all-in).
  • BetManager: manages bets and determines when a round of betting is completed.

The HandInfo class contains all the information on how to set up your hand. Then the Play method looks something like this:

HandHistory Play(HandInfo info) { PotManager pots = new PotManager(info); BetManager bets = new BetManager(info); HandHistory history = CreateHistory(info); bets.CollectBlinds(); if(!bets.GameOver) { DealHoleCards(); if(bets.PlayersThatCanStillBet > 1) bets.CollectBets(); if(!bets.GameOver) { DealFlop(); ... and on and on } } return history; } 
Problems arise because there are so many things to consider, such as collecting blinds, etc. The Pot and Bet manager classes become a nightmare and are invariably riddled with bugs. In addition, my engine design only supports one type of game (Hold'em), unlike the others.

My top ranking is the first for efficiency, as the engine is used primarily as an AI simulator over billions of hands. However, I would like to think that there is a more elegant way in which this could be done.

+6
c # oop poker
source share
3 answers

My first thought is code for readability and lack of redundancy in the first place, and performance optimization (which, I believe, means what you mean by efficiency) in the past. It is usually difficult to predict where the neck of the performance bottle will be, and a slightly slower application is better than a buggy or an unsupported system. It's easy to use a product like dotTrace when you're ready for optimization if you find it not fast enough.

As for your desire to add functionality, I recommend getting better at refactoring . This is one of the main contributors to TDD: write the least amount of code to do some of the functionality, and then reorganize any code smells. And using TDD, you can make sure that when you implement, say, Stud, your Hold'em is still working.

A good place to start working with refactoring, since it looks like you are already facing maintainability problems, is to try to ensure that each class has one responsibility (the first from SOLID priciples ). Your sample method has many responsibilities: making bets, dealing, game history, etc.

+3
source share

I really liked the IOpponent interface that was written by John Gietzen for the AI ​​Battleship tournament. I would like to look at its scope for inspiration.

What is the best battleship fighter?

Oh, and I recently saw this: http://visualstudiogallery.msdn.microsoft.com/en-us/ba4638ad-a2d2-49e5-ae46-94e0f747cae0?SRC=VSIDE

+1
source share

An example of a ready-made evaluator of the 7 and 5-card Texas Hold'em test can be found here and further explained here . This can help you with productivity. All reviews are welcome at the email address found in it.

0
source share

All Articles