Monday 5 December 2011

Java: Texas Hold Em (12)

Okay, back on track! To make up for the previous week, I'll be doing Sat-Sun updates for the next 2 weeks! We should be done with the evaluator comfortably this week, allowing us to move on, and we'll soon be out of the comfort zone of someone else's code, which I'm kinda worried about, but oh well.

We left off last week at calculating any duplicates, as well as the high card of a hand, so the progression from this point would be to have a bunch of private methods for use in the constructor that actually as "Does this hand contain x?" for each of the possible hand value types. Here we go:



First off, the most basic hand is 1 pair, so to ask if the hand is a pair, we need:
- Ask if numPairs (from calculateDuplicates) is 1. If it's at 0, we have no pairs, and if it's at 2, we have...2 pairs. Why did I type that out.
- We then need to tell the program what type to hold (if it's one pair, mark it as such) and what rank the pair is.
- Beyond this, we should fill out the rest of the ranking array with the high cards, in order, in the event of a tie. Check it:


Okay, line by line I think is the general consensus on how I should do this, so:
Line 158: If we have 1 pair...
Lines 159-160: Then the type of the hand is evaluated at one pair, and the most important part of ranking (the hand type, then the rank etc) is set to the integer representation of this. (In the case of one pair, 1, with high card being 0 and so on)
Lines 161-162: Also, set the ranking of the pair to the next index of rankings.
Line 163: Start index at 2, since our first 2 slots of the ranking array are filled.
Line 164: For every card in the hand...
Lines 165-166: Get the rank of the card, and as long as it's not one of the pair...(we've already got the pair's rank)
Line 167: Set the next index of rankings to the rank of the current card, and increment the index.
Lines 168-169: And if for some reason we've got enough cards that we go out of range, break from the loop.
Line 171: Also, return true, since the method is supposed to ask if there is actually one and only one pair in the hand.
Lines 172-173: ...if number of pairs is NOT 1, just return false, and be done with it.


This one is pretty similar, so let's check it out:
Lines 177-179: Same as above, but with 2 pairs instead of one.
Lines 180-181: Since we have 2 pairs, just getting the rank of one will not suffice, so we need the high and low ranks, so let's grab those.
Lines 182-183: Get our rankings array, then put both pair-ranks into it.
Lines 184-189: For every card in the hand, grab the card's rank, and as long as it's not one of the 2 pairs, put it into the ranking array, then break from the loop.
Lines 190-193: Same as isOnePair, return true at the end if there was 2 pairs, and false otherwise.


See you tomorrow, where we'll be repeating this dreary process for 2 higher hand types! Comments/questions and such welcome, yo. Now to get back to doing other work, ciao!

4 comments:

  1. I had to go back and re read from part 9, but I'm getting the hang of this. This is literally my first java project.

    ReplyDelete
  2. Welcome back. Make sure you don't push yourself too hard with those weekend updates.

    ReplyDelete
  3. We missed you. (:

    ReplyDelete
  4. The complexaty of this has surpassed me.

    ReplyDelete