The complete project is available here https://github.com/JohnBrod/PokerBots. It had estimated that I would be finished early this year and unusually that turned out to be accurate.
A little bit on the design
The real challenge in this project was coming up with a design that made sense for the communication between the object I had originally called the dealer and the other programs that were acting as players. The communication went like this:
Dealer tells player to make a bet.
Dealer waits for player to respond.
Player responds and dealer reacts.
This part of the design is set in stone, there isn't any way that I can change this interaction because I'm dealing with the real world. The difficulty was really in the dealer, as well as being restricted to this type of communication the dealer was doing way too much. So, the majority of the thinking involved how to simplify the dealer. The best solution for me was to separate out all these responsibilities into other objects by delegating at every opportunity. This resulted in the dealer being replaced by a number of objects that fulfilled the dealers roles.
For example:
The main entry point is an object that handles playing a tournament. This object will announce the players before delegating to an object that can deal a hand. When the hand is finished the tournament will decide whether to play another hand or not.
This pattern is repeated throughout, all the way to an object that takes bets from the external players.
The resulting communicaton
Communication in the game |
DealsTexasHoldEm and DistributesWinnings fire and a message and leave it at that, no response is necessary.
There's a lot more going out here, such as how the winnings are decided and how hands are ranked, but for those it's best to read the code.
No comments:
Post a Comment