Tuesday 27 December 2011

Java: Texas Hold Em (28)

Yar, hope everyone had themselves a good weekend, I sure did! If I recall right, we left off at the table dealing out the community cards, which means today we'll be covering a method to reset the hand, and another to switch players for turn rotation and such. Let's get to it, no more partying for you!




Here we go, first is the hand reset.
Line 130 simply clears the board of cards. Look back if you don't remember this method!
Line 131 makes stuff know that something on the table has changed (the removal of cards ^)
Line 132, also self explanatory, clears the active players from the previous hand!
Lines 133-138 hold a for-loop that goes through every player in the game (active players aren't the same as players in the game. An active player is taking part in the betting [not folded], so there ARE players to loop over). Each player has their hand reset, and as long as they aren't broke, add the player to the new round for betting.
Line 139 flips the dealer to the next position. The modulus (the '%' sign is modulus, it's like division, but returns the remainder!) appears to make sure the final player never gets to deal, which is weird, but again, that's an issue for the testing portion, when the functionality is done with.
Lines 140-143 are also fairly easy to read, setting the dealer based on the position, shuffling the deck, setting the active player to the dealer, then setting the minimum bet.
Lines 144-146 start each player's hand and
Line 147 sends a message to the table letting the players know what just happened.


Final method for the day (night), and this will actually perform the actor rotation/who's turn it is. At the highest level, we have an if-else statement where almost everything in the method is in the "if" section.
The "else" portion on lines 159-160 should probably never be run into, but being an exceptional circumstance if it did, we should throw an exception!

The main body makes use of 2 loops. First is the do-while loop on lines 152-155. Just a quick recap, the do-while loop is the same as a while loop, but it checks validity at the end of the loop instead of the beginning. Because of this, the loop is guaranteed to execute at least once!
Lines 153-154 loops the actor position to the next (? Stupid confusing modulus!) position, then sets the actor to the new position.
Line 155 validates the loop as long as the actor isn't part of the active players. This is because, if the active players DO contain the player who's turn it is, there's no need to switch positions, but if it doesn't, then a folded or broke player gets a turn. Which is silly!
Lines 156-157 send the message to each player, telling them who's up.

That's that for the night, hope I didn't overload anyone after the weekend! Tough shit if I did, though, 'cause tomorrow we're only doing 1 method, which happens to be something like 70 lines long on its own! Have fun until then, though! :P

4 comments:

  1. Oddly enough, the final method is shorter but takes more of my thinking time.

    ReplyDelete
  2. Thats a good amount for after a weekend!

    ReplyDelete
  3. Let FareCompare guide you to the cheapest flights from Hanoi to Danang Hanoi to Danang - Book Vietnam Airline. Big discount, Cheapest price, 24/7 support – Tel: (84-1) 682-28-10-87.
    Flights from Hanoi to Hue: Search on ebookers for cheap Hanoi to Hue
    flights and airline tickets from HAN to HUI with fare calendar. Get our lowest airfare or ...Hanoi to Hue - Book Vietnam Airline. Big discount, Cheapest price, 24/7 support – Tel: (84-1) 682-28-10-87.

    ReplyDelete