Monday, 28 November 2011

Java: Texas Hold Em (11)

Ugh, late post, sorry! I spent the better part of 2 days asleep, and I don't even know why, so doing this wasn't exactly a priority! Still, today we get to continue with our Hand Evaluator! Let's see, we had just finished finding straights and flushes, so let's continue that thread of thought and grab a method to find duplicates (encompassing single/double pairs, triples and four-of-a-kinds, thanks Mr. Stigter, for more efficiency!), and then something to calculate the high card in the hand to further calculate the hand's value.

Here's what I got (Yes, I did basically just use Stigter's code, but understanding it took time!):

Here, we go through a simple process of finding duplicates. As in the last post, we go through the list-by-rank (So that in the case of pairs, the higher one is noted first) on line 131, where it's a simple matter of seeing if there's 3 or 4 of a rank, and if so, making a note.
Lines 136-138 are a little different, since you can have 2 pairs, but still relatively simple. As long as the pairs we have now aren't the maximum allowed (2), place the rank of this pair in the array, then increase the number of pairs. Ta-da. One more method for tonight!

This'll be in use to determine the winner if nobody's got shit. Lines 145-146 grab the value type, then the actual value score thing (For scoring! Integer comparison and all that).Lines 149-150 fill out the rest of the ranking array with the integer values of the cards in the hand, the last 2 lines are just in case there end up being more than 5 cards in the hand for some reason.

And uh., that's it for the night, I'm about to go to bed again and just keep putting off going to a professional! See you tomorrow, if I'm conscious! Fwoosh.