Wednesday, 14 December 2011

Java: Texas Hold Em (21)

Alrighty, I looked over the ConsoleClient class, and uh, I was lost, so let's do the Player class instead! It's a little long, about 300 lines before I do anything to it, like make it ugly and remove vast amounts of comments, but we'll get through it.

After that, we can just do the Table class, leaving ConsoleClient to the end of the functional code, at which point we have bots and GUIs to do. See, this is why people rarely code from scratch, and just modify other peoples' code, it takes way too long otherwise. But I suppose in the heart of learning...


So, our Player class. Blueprint time? Definitely. What's a player need to keep track of? Well, players have names, and obviously we need to keep track of their hand, and the cash they have remaining. Their current bet, and the last action they took. How much they would be putting in if they went all in, whether or not they have cards (for dealing purposes), how many bets have gone through so far in the current round, and finally (I think?), the player class needs to have a Client that'll be responsible for actual behavior.

So let's get through the instance variables and the constructor, shall we?


Here we have it, just a bunch of variables that haven't been initialized. Look through 'em. I don't think I missed anything, but what do I know!

Done? Good. Now to actually construct the player. A lot of the variables above only take place during play, so they're not needed to construct. For instance, bet, raises, allInPot, action and hasCards. And by for instance, I mean, all of them. Which leaves us with the name, the starting cash and the client (Handled by the console client or table, no worries about constructing this yourself), as well as a hand to later populate.


That's it, just set each of the initial variables and we're golden. Line 33, the brown-highlighted method is used later in this class, don't worry about it. It just makes sure the hand is empty on start, just in case! So, yeah.

That's it for the night, folks. Enjoy the rest of your day, and I'll see you tomorrow! Questions/comments welcome!

5 comments:

  1. Well that alone seems simple 'nuff

    ReplyDelete
  2. Uh oh, if you get confused over the ConsoleClient, there's no telling how I'll understand it haha.

    ReplyDelete
  3. But you do learn better when you learn it from scratch.

    I don't blame you though. Your method is how I passed computing science.

    ReplyDelete
  4. A Client that'll be responsible for actual behavior? So the others are irresponsible? or do I just not understand computers enough?

    ReplyDelete