Wednesday 7 December 2011

Java: Texas Hold Em (14)

There appears to be some trouble with understanding the coding that's been going on. That's fine, I'm not exactly 100% on everything, either. The thing to remember is you need to know exactly what you're trying to do with some code, and then work out all the steps required for getting there, bit by bit. Computers are dumb, you can't just say "Throw me the ball". You need to take it in small steps. "This is the ball. Picking something up involves... Now pick up the ball. Swing your arm in x direction and release the ball..."


Luckily, a lot of the time, coding involves modifying someone else's code instead of creating stuff from scratch, so you have the option of looking at what steps are being taken, then thinking of how you can do whatever you want from that point onward. Here's today's code:

Okay, so we (probably) know that a Flush is all cards sharing the same suit. This means that the rank of each card can be anything, without even relative value to each other, meaning each and every one of the cards will count as a tie-breaker in the event of 2 people getting flushes. See Line 218? I didn't think it through and just thought the highest card would matter, the others be damned, so I had that to replace the entire for-loop just underneath. Turns out I was wrong! Let's go through the method then!

Line 214-217: We've seen these lines before. If the flushSuit variable isn't -1, we have a flush, so set the type to that and place it in the ranking array. Then start the loop index at 1.
Lines 219-221: For every card in the given hand, if the card's suit is that of the flush (Just in case! Weird errors -can- pop up), store the card's rank in a variable...
Line 225: Then put the integer representation of that rank into the rankings array.
Lines 222-224: This just makes sure the first card iterated over counts as the highest ranking card!

And the rest, we've seen before! Next up, the Full House.



Ooh, look, another short one. This is because the full house, being a triple and a double (damned if I'm typing out the proper name for 'em) fill up the hand, leaving no room for tie-breakers (or as they're called elsewhere, kickers). So no for-loop to go over the cards to extract then! Huzzah.

Line 235: If there's a triple, and a pair...
Line 236: Set the hand type to a full house...
Line 237-239: Then grab the rank of the triple and pair, and add then to the ranking array.
And the rest has become too tedious to type out! But hey, we're done with this for today!

See you tomorrow for more, questions and comments welcome!

2 comments: