Tuesday, 6 December 2011

Java: Texas Hold Em (13)

Ahoy there. Today we're going to continue on the same train of thought as yesterday, this time making a boolean method for the next 2 hand value types: Three of a Kind and Straight. Let's dive right into it, since there's no administrative stuff to go through:

Yeesh, I'm getting sick of these already. But let's do it anyway so we can move on to something else eventually:
Line 186: If our tripleRank actually has a value that's valid as part of the enumeration, we have a thee-of-a-kind, so in that case...
Lines 187-189: These lines are similar to yesterday's stuff. Set the type to be a triple, then fill in the ranking array with that information, as well as the number value of the triple.
Lines 190-191: Starting at the 3rd slot in the ranking array (first 2 taken up by the hand type and its rank), go through every card in the hand....
Line 192: Grab the cards rank.
Lines 193-197: If the card isn't part of the triple (If it's rank is different), place its value into the ranking array. When we get out of bounds, break out of the loop.
Lines 198-200: We should have no problem with these lines, we've seen them twice before, and will see them in the future. Return true when done, if the triple exists, and if not, do nothing and return false.

That wasn't so bad, right? Thankfully, the next one is shorter still, so we should be able to go over it even faster:
Line 204: Similar to above, if the straight rank is valid (These will be tested as part of the constructor, so don't worry that as of now it's at -1, but saving the constructor to last!)...
Lines 205-207: Same as above, set the type to be Straight, then set the 2 ranking array slots to reflect that, as well as the rank of the straight. Since a straight uses up all 5 cards, there's no need to go through the hand to grab any leftovers, the event of a tie can only go as far as multiple straights, which is solved by rank of straight.
Lines 208-210: Standard "return true, unless no straight, then return false" lines!

Bam, done for the day! That second half was pretty quick, so I get to kick back and chill out for a little bit before I'm forced to get some real work done, see ya tomorrow! Questions/comments welcome, as always!


  1. The shorter one is still over my head!

  2. I like where this is going.