Thursday, 8 December 2011

Java: Texas Hold Em (15)

Busy, busy! Just gonna throw my post out there today, and be done with it :P Today we get through Four of a Kind and Straight Flush, tomorrow, we finish this class (bloody finally) with the Royal Flush and the Constructor that actually uses everything we've made!

Fwoomp (That's the sound of code falling into place):


Four of a Kind only makes use of 4 cards (hurr), so we need the 5th to be a kicker, meaning we get that for-loop. Yay?
Lines 247-250: Standard stuff, if there's a quadRank, set the hand type, then place info in the rankings array.
Lines 251-257: More stuff we've seen a lot of before. Loop over the cards, extract the rank, and if it's not part of the quadruple, add it to our ranking array. Once we've got it, leave the loop.
Lines 258-260: ...More standard! Man, this IS a repetitive class. Return true, finally, unless there was no quadruple!


At least repetition makes it easier to understand. Constant exposure has a way of doing that. This one is as straightforward as any of them.
Line 264: If we've got a straight AND a flush (which has the same rank as the straight)....
Lines 265-267: Let the computer know we got a straight flush and put the info into our ranking array.
Lines 268-270: Return true/false depending!

Good thing that was so fast, I've got other stuff to do! See you tomorrow for the end of this class! Questions/comments welcome!

4 comments:

  1. We're finally into the meat of the game, this is getting easier and easier to follow along.

    ReplyDelete
  2. Hah, don't worry, Mike, it's going to get a hell of a lot tougher.

    ReplyDelete