Tuesday, 20 December 2011

Java: Texas Hold Em (25)

Okay, so it turns out the ConsoleClient is pretty confusing, and requires the Table anyway, so we'll be doing the Table! Yay! Ooh, there's a problem though. You probably don't remember (I didn't), but when the Hand class was created, I left out the constructor that takes an ArrayList or something as a parameter. We need to go back and fix that so our table runs smoother!

Here's how we do it:

Put the method declaration wherever you want in Hand.java, the parameter here is a Collection. A Collection is a basic interface that encompasses a few different types of collections, so its not its own class. Most important, it encompasses LinkedLists and ArrayLists.
Lines 34-35 just cover the error case, and lines 37-38 loop through the given collection and adds each card to the hand.

Easy! We can move on to the Table now. This is a big class, roughly 400 lines! Let's try to get through it, and hopefully it all makes sense! Or at least, mostly makes sense. I'll try going through it as fast as possible, probably 50-60 lines a day (Not counting today, since we had to fix the Hand and I don't want to go over 2 screens per post).

Let's start with a general blueprint. Since the Table will be controlling the general game flow, we're going to want to give it more than just a couple of players and a deck. We'll want to specify the high blind, the current bet, the maximum bet, the amount in the pot and the maximum allowable raises per player per round.
On top of this, we'll want variables to hold the dealer, the players, the current active/acting player as well as positions of these players.
Finally, we'll actually want a deck to play with, and a collection variable of some sort to hold the shared cards. A boolean to hold whether the game is over or not would be nice too. So let's get to getting those variables in place, and finish the constructor!

Okay, here we go! Lines 13-31 we discussed, and that's fine. Setting the max raises to 4 because that's what Mr. Stigter did, and I'm afraid to do anything different that I don't for sure have an opinion on because I'm a giant child.
The activePlayers variable will (I think) hold the players that haven't gone broke, and actor holds the player whose turn it currently is! Everything else should be straightforward until the constructor!

So there, we now have a constructor to deal with. Creating the table requires the highBlind, which, as I understand it, is the minimum bet for the hand. At this point, lines 33-37 just fill in some details, the high blind, initializing the player arrays, the deck and the shared hole cards!

Bam, boom, woop. Done for the day! Questions and comments welcome, see you tomorrow for 60 or so lines of code!


  1. This is interesting.

  2. I like the (I think) in there. I don't feel so alone.

  3. Our first bugfix! Yay! Before you know it we'll be pokering it up.

  4. 400 lines! That sounds like a lot! (inless it was coke)