tag:blogger.com,1999:blog-67149613031735078562024-03-05T21:47:53.889-08:00Coding TortoiseMe, slowly learning how to code, efficiently or not.heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.comBlogger133125tag:blogger.com,1999:blog-6714961303173507856.post-2939395050348457422012-01-18T02:04:00.000-08:002012-01-18T02:04:57.145-08:00Oh shit...Okay, so, the thing that made me cut down to 2 posts a week? Kind of a (way) bigger deal than I thought. I'm going to have to go on hiatus for a....while. But at least if you're subscribed, you'll know exactly when I'm back?<br />
<br />
I'm sorry, but I barely get 5 free minutes to myself every day, let alone the 30-60 I need to work on the code then post it.heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com10tag:blogger.com,1999:blog-6714961303173507856.post-71864929960394661172012-01-12T16:12:00.000-08:002012-01-12T16:12:25.187-08:00Java: Texas Hold Em - Debugging (3)Okay, so, super super busy of late, going to have to significantly cut down my post-output to like, 2 a week on Tue/Thu. Just a heads up. So this'll be the last post this week.<br />
<br />
Here, I'll give you a link to the files needed, and you can run the file for yourself!<br />
<a name='more'></a><a href="http://www.megaupload.com/?d=FRC7S4E8">http://www.megaupload.com/?d=FRC7S4E8</a>
<br />
<br />
The file is within<b> src/texasholdem</b>, run <b>ConsoleClient.java</b> and play around with it! I know it looks crap, being text-only, but that's the job of the programmer. Be bored to shit with your creation. Here's a few screens from my round. These won't be as applicable to you guys as if you had played the round yourself, so yeah. Let me know if you find any issues I missed!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl_K2Li2rkaiVuc6Ty3dfgTW0T53E7WojD_eRd_aEqK3RaXIqdQZ579C2c3sQdqm03H8PTNsFafs__PcfB_yDZdvr2KHFNnGzLRJw-117HWzcLov5jbaCShU38zMyXNbiE9cTnUiqFTkU/s1600/debug_6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl_K2Li2rkaiVuc6Ty3dfgTW0T53E7WojD_eRd_aEqK3RaXIqdQZ579C2c3sQdqm03H8PTNsFafs__PcfB_yDZdvr2KHFNnGzLRJw-117HWzcLov5jbaCShU38zMyXNbiE9cTnUiqFTkU/s400/debug_6.png" width="400" /></a></div>
<br />
I don't want to show every step of the way, 'cause that gets real boring real fast, so I've just shown a few key points. The start of the hand and the pot after the big and small blinds, after which is basically just a buttload of checking, raising etc etc. It seems to work well, but it's just not very entertaining.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqcEz5N0gup0EQJkT8POC0XX_loWueLUzkg5bG_qU8WfWO9keCXoVkoSYH-u5EM6y7p4a6h1pOm0flUF3jpcmsf35j0e4iNWsxjc7jA2-rQGbAlI3xr0pEfq2DXh1dNiVjx4A7DU4Vrb0/s1600/debug_7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqcEz5N0gup0EQJkT8POC0XX_loWueLUzkg5bG_qU8WfWO9keCXoVkoSYH-u5EM6y7p4a6h1pOm0flUF3jpcmsf35j0e4iNWsxjc7jA2-rQGbAlI3xr0pEfq2DXh1dNiVjx4A7DU4Vrb0/s1600/debug_7.png" /></a></div>
<br />
Over here, we have the end of the hand, with everyone still in the game, the pot at this point is 560, 'cause I raised a lot for no reason and bam! I won. Go me! And yes, I picked this round because it was the only one I did win.<br />
<br />
The scoring system looks okay, and Buttface's score is higher than Facebutt's, since the Queen pair beats all kinds of hell out of the Five pair...<br />
<br />
Looks good to me. You guys?heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com4tag:blogger.com,1999:blog-6714961303173507856.post-66784510704133593962012-01-11T21:36:00.000-08:002012-01-11T21:36:45.726-08:00No PostSorry, cannot complete a post for today. See you tomorrow.heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com3tag:blogger.com,1999:blog-6714961303173507856.post-22230297795217161022012-01-10T19:53:00.000-08:002012-01-10T19:53:58.190-08:00Java: Texas Hold Em - Debugging (2)Woo, change to the titling, because I kept losing track of what number we were on, and I can't count past 40 anyway. Okay, so we looked at the folding, and that seems to work. We should still see if we can stop the New Hand message appearing twice, so let's do that, then tomorrow we can move on to testing another action.<br />
<br />
<a name='more'></a><br /><br />
Let's go through this logically. There's 2 messages that say the same thing, but the main method for this only calls the <b>ConsoleClient </b>class. Since nothing else is done, the issue must be within the constructor, since no methods are applies to the client object.<br />
<br />
The constructor....<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtSatfXUEgwWOumMkp-dUPIdHuzd3NaEv8EsmQ5u4eM2sRZB8ZtUZrN77pz__IKhoyjvpxuDiKlZHVB964ejA1tOeAUtTj6zOcAxCmXQu4arh6aq1lya7DRkvjQBnqwGmlDRNHlPushiY/s1600/debug_3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtSatfXUEgwWOumMkp-dUPIdHuzd3NaEv8EsmQ5u4eM2sRZB8ZtUZrN77pz__IKhoyjvpxuDiKlZHVB964ejA1tOeAUtTj6zOcAxCmXQu4arh6aq1lya7DRkvjQBnqwGmlDRNHlPushiY/s1600/debug_3.png" /></a></div>
<br />
...has only 1 method that could be printing out this message, which is the <i>start()</i> method. Going to the <b>Table </b>class we'll want to look for something that happens at the start of the hands, and we have our <i>resetHand </i>method. As we can see on the highlighted lines below...<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxoh9aTVM8JidYtz2FgXRfyieg4VAKHOBAF6P9tm6QSMkGrltVK4nUHRcZERar3vLDMxPLjuF7_k8-RqmtTyxe6J7ytSmxr0oFyjRTwWeJux3iZe48ZVn2foDI6Q8OWfcvkdGHjmvr05o/s1600/debug_4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxoh9aTVM8JidYtz2FgXRfyieg4VAKHOBAF6P9tm6QSMkGrltVK4nUHRcZERar3vLDMxPLjuF7_k8-RqmtTyxe6J7ytSmxr0oFyjRTwWeJux3iZe48ZVn2foDI6Q8OWfcvkdGHjmvr05o/s1600/debug_4.png" /></a></div>
<br />
<br />
...there's a message sent out twice. Once through the client's method, and once through <i>notifyMessage</i>. So we have a choice (probably). <i>notifyMessage</i> uses the client's <i>messageReceived</i> method. Back to the <b>ConsoleClient</b>, we see that <i>messageReceived </i>used a simple System.out.println, and <i>handStarted</i> uses the simple string formatting. Both so the same damn thing, so let's comment out the line of code within the <i>handStarted </i>method to get the following result...<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdMv99OXdgw9dWvZEQ6qw3e5vg6LgeRkptWRNwivoqw4o6WJ4rovSv3CIQNqMaQ8m88V6Jg4mQ_8BHTyFB6iUk3I-K-WVWN-QYxV5YJfAh-746YuRSp7TtcYj-WsAMgp_LHitknSiHyUI/s1600/debug_5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdMv99OXdgw9dWvZEQ6qw3e5vg6LgeRkptWRNwivoqw4o6WJ4rovSv3CIQNqMaQ8m88V6Jg4mQ_8BHTyFB6iUk3I-K-WVWN-QYxV5YJfAh-746YuRSp7TtcYj-WsAMgp_LHitknSiHyUI/s1600/debug_5.png" /></a></div>
<br />
Ta-da! Looks like that worked out fine. Tomorrow I guess we'll play a quick round and see if the pot/bets are working fine! See you then! Questions and comments welcome! Also, sorry this was late, I kinda forgot about it until just now, ha.heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com3tag:blogger.com,1999:blog-6714961303173507856.post-67609274224551472292012-01-09T18:10:00.000-08:002012-01-09T18:10:00.756-08:00Java: Texas Hold Em (36) - Debugging the clientOkay, folks, going to keep it short. Today, I'll show you some screens of how the client works inside the IDE and point out some stuff that might need fixing. This'll not only give you the opportunity to thing about how it's going on, but what I might have missed so you can suggest a fix of your own!<br />
<br />
Here we go:<br />
<a name='more'></a>Okay, to start this, we just run the console client. In Netbeans, you do this by hitting Shift+F6 with <b>ConsoleClient.java </b>open. Just F6 will try to run the main class of the active project, but that's not what we want.<br />
<br />
The below should pop up for us:<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTTe53HDPs7TAS_Y91yai0jC99XyGgzsJ9Aco5iygDDcxaM9iqoHnymefsdq6r4FpaK-EFeG2ZW7kBc9wDVn1svSH_NA61OX5Prz0DZnDVXv7imEZWvBGz-ELJ1pbHCuxbvrTD12bA1yI/s1600/debug_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTTe53HDPs7TAS_Y91yai0jC99XyGgzsJ9Aco5iygDDcxaM9iqoHnymefsdq6r4FpaK-EFeG2ZW7kBc9wDVn1svSH_NA61OX5Prz0DZnDVXv7imEZWvBGz-ELJ1pbHCuxbvrTD12bA1yI/s1600/debug_1.png" /></a></div>
<br />
Hey, there's no GUI yet, right? So of course its ugly, but we can still make sure it works. Straight away, we see New Hand come up twice. I've no idea why this is. Could be something to look into.<br />
<b>note: I named the bots Buttface, Facebutt and Pirate Joe. I am not a mature person, and just so you're not confused as to what those are!</b><br />
First person to the left of dealer posts the small blind (Not necessarily displayed here. It'll be on the board in the GUI.) then Facebutt does his thing.<br />
<br />
Ah, that's why there was a "CHEAT" in the strings. It shows you the opponents cards. Either this will stay to the client and not be displayed, or they're there purely for debug purposes! Woohoo! The player's cards are shown, so that's fair enough etc etc. Pirate Joe's turn, he calls, because he's a dummy bot and they don't do much...<br />
Oh here we go, Player's turn! Now, as part of the debugging process, you want to test both that what's supposed to happen happens, and that it's not so easily broken!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQunT6SZN-hFXTG5xdMUmnDl_dxtjYmkdeZX4WMQ5m9rh9nv1PEYpsM43o5rlYdapY3ghRsiYsMyc4aQDeK4SX1gMcz2X55Uo08Z2E0PuIuAn7iA37ADycerJnCaoiF6e7mQjmrPWurSw/s1600/debug_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQunT6SZN-hFXTG5xdMUmnDl_dxtjYmkdeZX4WMQ5m9rh9nv1PEYpsM43o5rlYdapY3ghRsiYsMyc4aQDeK4SX1gMcz2X55Uo08Z2E0PuIuAn7iA37ADycerJnCaoiF6e7mQjmrPWurSw/s1600/debug_2.png" /></a></div>
<br />
Oh dear. I thought anything starting with an "F" would make me fold. Maybe it's the spaces etc. No? But just F works. This isn't so much a debug issue as me misreading the code from earlier. The highlighted bit at the bottom of the screenshot actually reads:<br />
<i>"If the command starts with whatever the input is as a WHOLE (but lowercase)..."</i><br />
which means the commands accepted would be "f", "fo", "fol" or "fold". Learning experience! And then I folded. So the game continued without me until a new hand came around! Well, it looks like that much is working, at least!<br />
<br />
And that's it. Sorry it was short, but I've been super busy of late! See you tomorrow, questions and comments welcome! See ya tomorrow!<br />
<br />heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com3tag:blogger.com,1999:blog-6714961303173507856.post-77127836804964080002012-01-06T16:48:00.000-08:002012-01-06T16:48:33.419-08:00Java: Texas Hold Em (35)Almost there, folks! Today we get to the point where the functionality only needs to be debugged, and thus is pretty much done! So next week is debugging, and if we have time, depending on how riddled with errors the code is, get to the GUI.<br />
<br />
Let's stop talking about getting to tat point now, and actually get there!<br />
<br />
<a name='more'></a><br /><br />
Our final method in the console client is the <i>act</i> method. This'll carry out actions for the game and its about 40 lines long without comments.
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIZLg0S37ZefjW7yr-UAv2WPFjlThyphenhyphen7kfTjyGpcdmJFZHHxt7Y_qMxoxq047u2wBdVMpcfEwOkG_Mff7JspaREvWYWJSUI9pnQMaYHvjXi0yE6Cn2u_J6ljU_AiXwHNhN8TtY5gArUPpM/s1600/c_client_5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="199" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIZLg0S37ZefjW7yr-UAv2WPFjlThyphenhyphen7kfTjyGpcdmJFZHHxt7Y_qMxoxq047u2wBdVMpcfEwOkG_Mff7JspaREvWYWJSUI9pnQMaYHvjXi0yE6Cn2u_J6ljU_AiXwHNhN8TtY5gArUPpM/s400/c_client_5.png" width="400" /></a></div>
<br />
First portion! This just creates a string for us, telling us what actions are available, now with added grammar! Easy enough to understand, right?<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilPE4tGmEE8us6Us9rbhO2_Kg9eIa5ySt6OKftjVSykTGYG3XSAa841t4G9m5b05Mg8XZi4fgETiOziiLJe3npWbE23YDSYHg8KMOKpKAAlpw42nQFtDN6hzTMhyAGiti-qM5JwXlHJ1k/s1600/c_client_6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilPE4tGmEE8us6Us9rbhO2_Kg9eIa5ySt6OKftjVSykTGYG3XSAa841t4G9m5b05Mg8XZi4fgETiOziiLJe3npWbE23YDSYHg8KMOKpKAAlpw42nQFtDN6hzTMhyAGiti-qM5JwXlHJ1k/s1600/c_client_6.png" /></a></div>
<br />
<b>Lines 102-104</b> complete our string building process, giving the prompt its own cozy little variable and creating an action that we'll be using in the next part.<br />
<br />
As explained in the in-code-commentary, the prompt will show when an action is not selected, at which point a try-catch block is executed. At this point, the chosen action is returned and there's happy fun. No further explanation is needed, I hope? It's all up there in grey!<br />
<br />
Questions and comments are wholly welcome, as usual, and I'll see you next week for debugs!<br />
<br />heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com3tag:blogger.com,1999:blog-6714961303173507856.post-11219251615696486222012-01-05T14:40:00.000-08:002012-01-05T14:40:01.985-08:00Java: Texas Hold Em (34)Ah, for those unaware, debugging is the process of finding/identifying errors (bugs) and removing them from some program. Doing this is mostly uninteresting, and in the case of the <b>ConsoleClient</b>, just involves me running the entire class and seeing what it does, then trying to find out why it does that.<br />
<br />
I was going to document the debugging, but only after we were done with the class, since errors crop up in the form of methods we've not covered, and it'd get confusing :)<br />
<br />
For now, though, lets get to finishing the <b>ConsoleClient</b>. Looking at the Client interface, there's 7 or so more methods to go! Here we go:<br />
<a name='more'></a><br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipv4bWS0oVFDmWfyQ-gpfxr7Hdmpl2lPEZfz5jjGYjTVaij8_SbzbWdBGv1ExKOsS9lIVdRtrU-nP_z8UdZiEKPeEijS77ay7k989clVQlHg0JHCHhK1A1Juv8L4qtXdEKfT7BV45_RCY/s1600/c_client_3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="197" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipv4bWS0oVFDmWfyQ-gpfxr7Hdmpl2lPEZfz5jjGYjTVaij8_SbzbWdBGv1ExKOsS9lIVdRtrU-nP_z8UdZiEKPeEijS77ay7k989clVQlHg0JHCHhK1A1Juv8L4qtXdEKfT7BV45_RCY/s400/c_client_3.png" width="400" /></a></div>
<br />
These are more simple methods that don't really bear explanation, but they do exist, and you do need to see them, and having too much in a post means nobody gives a flying crap about anything in it, so we won't even be finishing today!<br />
<br />
However, just to go over them real quick: Nothing happens when someone joins the table. That's all handled in the constructor. Other than that, everything above just prints out a different message, making use of string formats!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb2ZXD3Dg-ksBTH5Hr7dKA0hfnB3wXOGOysQLtGqKaEO0-9bvt7TZnXATsY3klJJBtKqir-MRgviSNbnm4ytd6b_Ffu0DfjQTp2S-fje0IbWQLFYEBpXJVRrjjJ4eSyaMrlLCl8lqwyPE/s1600/c_client_4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb2ZXD3Dg-ksBTH5Hr7dKA0hfnB3wXOGOysQLtGqKaEO0-9bvt7TZnXATsY3klJJBtKqir-MRgviSNbnm4ytd6b_Ffu0DfjQTp2S-fje0IbWQLFYEBpXJVRrjjJ4eSyaMrlLCl8lqwyPE/s1600/c_client_4.png" /></a></div>
<br />
I went over more lines than I needed, above, so it looks like more than it is, but honestly, its super easy. The first method, written without regard to screenshot-width would only be 3 lines. Get the player's cards and when they have 2, print them out.<br />
<br />
The last method mentions that a player has taken their turn and just string formats it all in.<br />
<br />
<br />
Man, I am sorry these are so simple, especially after the tough stuff we've already been over, but having made use of all the other classes we've gone over, there's not much for this class to do!<br />
<br />
Tomorrow, we'll do the final method in this class. Really, the only one with any real length to it, and then it'll be done. This means next week, we'll get to debugging the console client (which makes use of all the other classes we've used, directly or otherwise) until it appears to be working fine. After that, we either start on the bots or the GUI. Probably the GUI, fuck programming AI =<<br />
<br />
Questions and comments are welcome, so go crazy! See you!<br />
<br />
<br />
<br />
<span style="font-size: x-small;"><br /></span><br />
<span style="font-size: x-small;">Also, check it, I got a sweet mention in <a href="http://iamsuchaderp.blogspot.com/2012/01/new-year-new-phone.html">DWei</a>'s blog since I'm so good at suggesting things, apparently! Acknowledge me!</span>heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com4tag:blogger.com,1999:blog-6714961303173507856.post-76750543387045309532012-01-04T18:01:00.000-08:002012-01-04T18:01:11.864-08:00Java: Texas Hold Em (33) - The Console ClientHullo again! I meant to make this post in advance to get up here so I could have today off, but then I didn't, so I'm stuck here :(<br />
<br />
Today we start on our <b>ConsoleClient</b>, which should be the final piece to our functionality. Maybe, I honestly don't quite get either of the clients, so there will probably be a load of debugging to do. Probably some which I won't be able to do. But that's enough optimism, let's get down to the client!<br />
<a name='more'></a><br /><br />
Okay, so briefly, the console client will essentially...handle stuff. Not the graphic end of it, but what actually goes on, it'll print stuff out and let players know what's going on and stuff, I'll show you some time. Note that in the code, there'll be a <b>DummyBot</b>. I don't want you to worry about this. It's icky, and gets into the AI, which is undeveloped my the actual guy who actually wrote this code (You'll recall I'm a filthy copycat), and the Dummy just calls and folds or whatever.<br />
After playing with this (not the code, the actual outcome), it's clear there's a tonne of debugging that I'll need to do, but hey, the core concepts are there, so there.
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh65eJtd0ZcmRgVS4fARR9nUlfKaLSZS8BKut_6rgpFHhxLCue3BQt66Cu6xBJ3MNkBvCiwa96wFccJv-LmYlfl0-4f-iFHgedn9Cl9h__G6Mw4punQkVkMwUSUGwl6YExG8qw_hnniALw/s1600/c_client_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="258" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh65eJtd0ZcmRgVS4fARR9nUlfKaLSZS8BKut_6rgpFHhxLCue3BQt66Cu6xBJ3MNkBvCiwa96wFccJv-LmYlfl0-4f-iFHgedn9Cl9h__G6Mw4punQkVkMwUSUGwl6YExG8qw_hnniALw/s400/c_client_1.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
This should require very little in the way of explanation. The big blind and starting cash are set as static variables, as well as a buffered reader for the console. That's pretty much there to take in info. Please ignore the starting cash being less than the big blind, I was just messing around and forgot to change it!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The constructor itself does nothing extraordinary either. We see the buffered reader initialized, a table created, then populated and finally started off. Easy.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnxX_e9_Wxh4288A3kSqQyXRiXkl5e7lEr49LkT1qg9t_zFz1qwdIkGyAFxjPF7DIODVdAiSPgJpOog-t9QUios2NSXwlC2RbYyJ2lsQxo_ulKGrzzOTE2_HWJWZ07IXjsnSSGo5wolzc/s1600/c_client_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="175" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnxX_e9_Wxh4288A3kSqQyXRiXkl5e7lEr49LkT1qg9t_zFz1qwdIkGyAFxjPF7DIODVdAiSPgJpOog-t9QUios2NSXwlC2RbYyJ2lsQxo_ulKGrzzOTE2_HWJWZ07IXjsnSSGo5wolzc/s400/c_client_2.png" width="400" /></a></div>
<br />
The rest of the class is populated with (mostly) small methods to deal with things, here we see the <i>messageReceived </i>method which simply prints out a message, as well as the main method. The existence of a main method means we can run this class on its own now, and it'll create an instance of itself, which will run the constructor, which will initialize the reader and do table stuff!<br />
<br />
Exciting? Exciting. Probably. Remember, since this class extends the <b>Client</b> interface that we went over before, it'll have all the same methods, so feel free to go back and look at them. Tomorrow, we'll cover some more and so on. See you then, and hopefully something will require a bit more explanation!<br />
<br />
Questions/comments welcome as always.heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com5tag:blogger.com,1999:blog-6714961303173507856.post-66134526446936899342012-01-03T18:12:00.000-08:002012-01-03T18:12:00.843-08:00Java: The Map InterfaceHi again! I'll be going through the Map interface today in a little more detail, just so you know how it works. It's pretty cool. If you've done other programming, you might know this interface as a <b>dictionary</b>, which is what I likened it to before.<br />
<br />
<br />
<a name='more'></a>As I've mentioned before, the <b>map</b> is an object that maps keys to values, much like a dictionary would map words to meanings. Because of this likeness, a map cannot contain duplicate keys.<br />
<br />
Unfortunately, each key can only map to at most 1 value, but you can work around this by making the value a list to contain all values. Silly, and where our dictionary likeness falls apart, but only a little. Here's a screenshot of a class that makes use of the map interface:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgciLlv9QOX2jogXRB3sO4KR_KxUyAsoK_60W2MMnb8NuyGRGLFRUaNk3Urv88iWMjvNXlgP-IX3j71ilSYZfJ0gvRkdvIPcd2kAroSDUbPZXUHdKG2psW9q1_FlaaMgpQui1v0FGaS4aY/s1600/Map_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgciLlv9QOX2jogXRB3sO4KR_KxUyAsoK_60W2MMnb8NuyGRGLFRUaNk3Urv88iWMjvNXlgP-IX3j71ilSYZfJ0gvRkdvIPcd2kAroSDUbPZXUHdKG2psW9q1_FlaaMgpQui1v0FGaS4aY/s1600/Map_1.png" /></a></div>
<br />
There's nothing in there, since the <b>Map</b>'s an interface, but the method names should give you an idea of how one functions. Standard "<i>size</i>' and <i>'isEmpty'</i> methods shouldn't give you any trouble. The <i>'contains....'</i> methods should also be self-explanatory; a boolean saying whether the map contains the given key, or mapped value.<br />
<br />
So on and so forth! It's basically a nice way to hold things and their attributes nicely. In our case, we've held players and their hand values as values and keys!<br />
<br />
So there you have it. A neat little interface that does sweet backflips or something, I don't know. See you tomorrow for the start of our <b>ConsoleClient</b>!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com3tag:blogger.com,1999:blog-6714961303173507856.post-56435926690405605752012-01-02T14:45:00.000-08:002012-01-02T14:45:01.262-08:00Java: Texas Hold Em (32)Hullo! Finishing off the table class today so tomorrow we can go through a tutorial of the <b>Map</b> class. After that, we'll be messing with the <b>ConsoleClient </b>to complete our functionality, then put aside a few days to test it all out so we can be confident that we're set to move onto the GUI and so on and so forth!<br />
<br />
<br />
<a name='more'></a>There's more <b>Map</b> work in today's code, but it'll all be made clear soon! Until I do go into detail, think of a map kind of like a dictionary that maps meanings to words. The word in the dictionary corresponds to the key of the map, and every meaning corresponds to a different value for that key. Enough to tide you over?<br />
<br />
Here's the code, then! This method grabs the active players, mapped and sorted based on the value of their hands:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxEU7PxlIIypxbHFy421oME_ghYuG0gUPv86NM1nK3yzwprbWWUD8OjOXjy7Qdf24IoYgabdhTtU5euei7AZadjAsPRrj-a2NXTMKqBnq7Nu1_TcqbzIEP0iQXWamefZP7yfI8LXlcE-c/s1600/table_13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxEU7PxlIIypxbHFy421oME_ghYuG0gUPv86NM1nK3yzwprbWWUD8OjOXjy7Qdf24IoYgabdhTtU5euei7AZadjAsPRrj-a2NXTMKqBnq7Nu1_TcqbzIEP0iQXWamefZP7yfI8LXlcE-c/s1600/table_13.png" /></a></div>
<br />
The only thing I'd like to make note of in this screenshot is <b>lines 337-340</b>. The reason this is being done is that we're, in the next lines, adding a player to that variable. If it hasn't been initialized on <b>line 335</b> because there was nothing to populate it with, and we try to add things to it, an error is thrown!<br />
Otherwise, probably self-explanatory, if you look at the commentary! If not, let me know!<br />
<br />
For our second screenshot, we'll probably need a little more explanation, even with the comments!<br />
First is the parameter list for our <i>notifyMessage </i>method. It could easily have been "String...", but Object means we can use anything. We can now put as many arguments as we want into this method call, as long as we have 1 for the <b>String message</b> part. All other parameters are passed to <b>args</b>. Looking back on previous uses of <i>notifyMessage</i> should clear any confusion up!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB_F1hfwV2UmG_u1YM9J4hGkzVzVLPrTzgdO8duVHQYN2aYPohqMBaQAfg_HInD9DaVSKQG5uRYnrc2gs2Es9HdteBWYjpMvfcEYKYqNfX9xEE-hNSCjWD3tCRZNtJvYQvi_OyRvGhluM/s1600/table_14.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB_F1hfwV2UmG_u1YM9J4hGkzVzVLPrTzgdO8duVHQYN2aYPohqMBaQAfg_HInD9DaVSKQG5uRYnrc2gs2Es9HdteBWYjpMvfcEYKYqNfX9xEE-hNSCjWD3tCRZNtJvYQvi_OyRvGhluM/s1600/table_14.png" /></a></div>
<br />
And uh...that's it! Let me know if you need anything gone over or clarified, any and all questions welcome as well as general commentary, and I'll see you tomorrow for a short tutorial on <b>Maps!</b>heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com2tag:blogger.com,1999:blog-6714961303173507856.post-246569377149002132011-12-30T14:58:00.000-08:002011-12-30T14:58:04.394-08:00Java: Texas Hold Em (31)Okay, today I'll try leaving in the commentary to the code, leaving my posting text to stuff like this, that's not directly code related!<br />
<br />
Today we'll be looking at the method that handles showdowns in the game, enjoy!<br />
<a name='more'></a><br /><br />
(This method barely fits into one screenshot, so I'll be doing a smaller method afterwards, too)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkURjT3qefAOB0Zp5f995e6-ZE7NEMDj-I6nhrLxGvMFJjYoxfF-B_ye4N9QfBWnKVGcC1IGLlOQd63-32HB51mSj7ru8i-NYN26GUGJAupBYK_697OtXHck6zf7kg-MBKt7MFZEufTfU/s1600/table_11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkURjT3qefAOB0Zp5f995e6-ZE7NEMDj-I6nhrLxGvMFJjYoxfF-B_ye4N9QfBWnKVGcC1IGLlOQd63-32HB51mSj7ru8i-NYN26GUGJAupBYK_697OtXHck6zf7kg-MBKt7MFZEufTfU/s1600/table_11.png" /></a></div>
<br />
Apart from the section where I state I have no idea what the balls is going on, the commentary should be sufficient that I don't need to explain it again here! (Do I? Vote or comment it, then!).<br />
I will, however, do my best to explain what happens while not quite knowing:<br />
The method <b>getWinners</b> appears later in the code. We'll cover that on Monday, but what it does (not important how it does it to understand what's going on. The core concept of abstraction!) is returns the active players mapped and sorted by hand value, sorted in descending order.<br />
<br />
I should probably mention that a <b>Map</b> takes 2 parameters within its angle-brackets, as you might have noticed. The <b>Map</b> is an object that maps keys to values. The first parameter covers the type of keys present while the second covers the types of values mapped to these keys! You'll probably see in more detail on Monday when we go over the <b>getWinners</b> method. I'll even go through a tutorial on Tuesday, since the <b>Table </b>will be done by the end of Monday!<br />
<br />
Anyway, here's just a little bit extra so we can finish this class comfortably at the start of next week. This lets a player win the pot!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir_MmbFRx4QILj6HHtCLHI39hD7gPbn8WxVs0vGtlATzOjJlfcXEaTK-cRL1FE99gGqwNet9WZkCpQ8J3DTJFuySxGaCLzYmi7BptMk31tyv2KgjF1f6CCfZwIlXxYPuivhb9p595cU0Y/s1600/table_12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir_MmbFRx4QILj6HHtCLHI39hD7gPbn8WxVs0vGtlATzOjJlfcXEaTK-cRL1FE99gGqwNet9WZkCpQ8J3DTJFuySxGaCLzYmi7BptMk31tyv2KgjF1f6CCfZwIlXxYPuivhb9p595cU0Y/s1600/table_12.png" /></a></div>
<br />
Self-explanatory, right? Good! If not, leave a question in the comments! Everything you throw at me is welcome! See you on Monday!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com5tag:blogger.com,1999:blog-6714961303173507856.post-4208217089588570972011-12-29T17:13:00.000-08:002011-12-29T17:55:30.196-08:00Java: Texas Hold Em (30)Okay, in the receding phase of my migraine, which means I can stick around longer, but I'm still not at full operating capacity! Still, I figure we can get through the huge method, which will actually take a little bit OVER the 2 screenshots I wanted to limit my posts to, but only by like, 2-3 lines.<br />
<br />
The reason the method is so large is that it's responsible for the entire round of betting, so there's a big chunk of stuff and a switch statement to boot. Also, switch statements make use of "<b>break;</b>" so that inflates the length of the code a bit.<br />
<br />
Here it is:<br />
<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAG-mIoGFBqsnwMdQlpFgbwZPs2sDbQnIPuFV6InFg-dYHABVvrJRWHPs4Vaw3bC4jePQvQzuMFSelYMIm5K2O2qbVuFQNcr5nQOvj4rWRyiw3ZF4gTpj7AMfLtRXUwhMDV-5R6iNZbzE/s1600/table_8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAG-mIoGFBqsnwMdQlpFgbwZPs2sDbQnIPuFV6InFg-dYHABVvrJRWHPs4Vaw3bC4jePQvQzuMFSelYMIm5K2O2qbVuFQNcr5nQOvj4rWRyiw3ZF4gTpj7AMfLtRXUwhMDV-5R6iNZbzE/s1600/table_8.png" /></a></div>
<br />
When you see comments in the code, its when I didn't quite get something on the first go-through, so I just kept the original commentary in. I should be doing this anyway, but eh. I (mostly) take them out for screenshots, then feel too lazy to put them back in, so I'm chucking the blame on you guys.<br />
<b>Line 165 </b>speaks for itself, determining the number of players to act in this round.<br />
While I won't be able to get what these lines do at any later date, <b>lines 166-175 </b>ARE commented, so bear no further mention here!<br />
<b>Line 176 </b>makes use of that method we've seen before, notifying everyone that something happened! (Bets being set in above statements) and <b>line 177 </b>sets the small blind.<br />
<br />
<b>Lines 178 onward </b>cover the while loop, which will loop as long as there's still a player to take their turn this round. This basically covers each person's turn in the round, and is huge (more in the next 2 screens!).<br />
First off, <b>lines 179-183 </b>get through the basics. Rotating the actor so the same person doesn't go twice, grabbing a boolean to determine if the player is in the small blind position or not, then telling the player to act, based on the determined list of allowed actions.<br />
<b>Lines 184-190 </b>is a barrier to ensure that the player picks a move in the list of allowed actions. If not, throw the error!<br />
<b>Line 191 </b>just lowers the players left to act by 1, ensuring the loop will eventually end.<br />
<br />
Now that we've got all that sorted, we need to go through the switch statement that takes care of whatever action the player picked in the first part of this method!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqMNSpKxTLwy9ktdpMLa1nBFmKuJ8eKUMgY0zNIXnSRIWdPUiAWZmVG6MlvWq-l1pSwP4RIqMfXEQOvrQBsEqgIC9siwzRkPxb1rvae4icfdAou5eDzde1MV2RFWnlU8EmK6gkC3SE73c/s1600/table_9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqMNSpKxTLwy9ktdpMLa1nBFmKuJ8eKUMgY0zNIXnSRIWdPUiAWZmVG6MlvWq-l1pSwP4RIqMfXEQOvrQBsEqgIC9siwzRkPxb1rvae4icfdAou5eDzde1MV2RFWnlU8EmK6gkC3SE73c/s1600/table_9.png" /></a></div>
<br />
Okay, lets go through these by case instead of lines!<br />
<u style="font-weight: bold;">Case: Check</u> - This is just the act of...not acting. Move on.<br />
<u style="font-weight: bold;">Case: Call</u> - Increase the pot by bet amount, unless you're in the small blind position, in which case increase the pot by (bet - small blind), which will be half the bet.<br />
<u style="font-weight: bold;">Case: Bet</u> - bet the minimum amount, then increase the pot by that amount. This also means that everyone gets to act again, so that value will be reset for the while loop (<b>line 204</b>)<br />
<u style="font-weight: bold;">Case: Raise</u> - Increase the current bet by the minimum to raise, then put that amount into the pot. At this point, if the raise limit hasn't been reached, reset the players to act counter. If the limit HAS been reached, set the acting players to 1 less than everyone (so it doesn't loop back to this player, who's ended their turn).<br />
<u style="font-weight: bold;">Case: Fold</u> - Remove all the player's cards, then kick the player off the active players. If you were the second last player, and folded, then the if-statement sets the acting players to 0 (preventing the loop executing again) and declares the final player as winner!<br />
<u style="font-weight: bold;">Default</u> - Just in case something goes wrong, the default throws an error!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEged8blM25TrROb36PctzUnjuv2SLCJTkxmPgRMAj3R_ccdrrJYNnlXTuLVY46xcgq71O9FhT66x94MBPwieSMqlawmCb16OzbyeYrGO-U9W9nvK7FHLQkfsN56i6qB16oP0eIQR4fxkIs/s1600/table_10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEged8blM25TrROb36PctzUnjuv2SLCJTkxmPgRMAj3R_ccdrrJYNnlXTuLVY46xcgq71O9FhT66x94MBPwieSMqlawmCb16OzbyeYrGO-U9W9nvK7FHLQkfsN56i6qB16oP0eIQR4fxkIs/s1600/table_10.png" /></a></div>
<br />
To finish this method off, if the current player is broke, set their all-in to the current pot, then let everyone know the player has acted.<br />
<br />
END. FUCKING. LOOP.<br />
<br />
My fingers are tired, I'm off to chill out in bed until my head is totally chilled out! See ya tomorrow, questions and comments welcome. And just so you know, I did not like this method. It's big and a little unwieldy, even if it is sorta manageable. Blah!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com6tag:blogger.com,1999:blog-6714961303173507856.post-4289255389562626962011-12-28T17:26:00.000-08:002011-12-28T17:26:53.517-08:00Java: Texas Hold Em (29)Well, got a migraine today, so sorry, folks, can't give you the big one I promised. Instead, I'll cover it whenever this blasted thing is gone, and cover the method that returns a player's allowed actions tonight.<br />
<br />
Here it is, short as possible:<br />
<a name='more'></a><br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2rGD1SNMRIqxOsKcc-Ljz_pXL1dHFDgYA4vMIx1Mlg0nWibRVu5_JBl1tgcWMQKMnw-8opnzhoXekF-11k3y2mI-OX8bN8aOaeHJcx69akEntQ8VyjVKvRX9v-Fbd-uYH1vcanUmSVao/s1600/table_7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2rGD1SNMRIqxOsKcc-Ljz_pXL1dHFDgYA4vMIx1Mlg0nWibRVu5_JBl1tgcWMQKMnw-8opnzhoXekF-11k3y2mI-OX8bN8aOaeHJcx69akEntQ8VyjVKvRX9v-Fbd-uYH1vcanUmSVao/s1600/table_7.png" /></a></div>
<br />
As you can see on the method declaration, this method returns a set of actions, so, what the players can do!<br />
To know what players can do, we should probably know what the player's bet is.<br />
<b>Lines 245-249 </b>cover the first half of the main if-statement, which is what happens if this player has no bet down. The rest of this block says that our actions can include <i>checking </i>as well as (assuming you haven't hit your raise limit) <i>betting</i>.<br />
<b>Lines 250-262 </b>cover the second half of our statement, itself having some nested if-statements.<br />
First, if the player's bet is lower than the table's bet (<b>line 251</b>), add the ability to <i>call.</i> As long as the raising limit hasn't been hit, also allow <i>raises</i>.<br />
Otherwise, (<b>lines 256-259</b>) just add the ability to <i>check</i> and <i>raise</i> (if the limit hasn't been hit).<br />
<br />
Just to finish it off, on <b>line 263</b>, allow players to <i>fold </i>all the time, then return all the available actions.<br />
<br />
<br />
Easy and short, now I can tend to my head. Like a goddamn jackhammer in my brain. See you tomorrow, hopefully, questions and comments welcome.heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com4tag:blogger.com,1999:blog-6714961303173507856.post-74148935382488398322011-12-27T15:12:00.000-08:002011-12-27T15:12:06.474-08:00Java: 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!<br />
<br />
<a name='more'></a><br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4LgQmH3uspdXoAyjbRj1SfRyiMsb4sKncTgahrgkW12kKChEhEQluknJ2kK7OjmHfAnctMOhokQQXuadvaMRDAy5YWWFUnPGxiVTK7y85cMibjSj3Rh4AcgX8Wb2msqm4TvMRp96FJTs/s1600/table_5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4LgQmH3uspdXoAyjbRj1SfRyiMsb4sKncTgahrgkW12kKChEhEQluknJ2kK7OjmHfAnctMOhokQQXuadvaMRDAy5YWWFUnPGxiVTK7y85cMibjSj3Rh4AcgX8Wb2msqm4TvMRp96FJTs/s1600/table_5.png" /></a></div>
<br />
Here we go, first is the hand reset.<br />
<b>Line 130 </b>simply clears the board of cards. Look back if you don't remember this method!<br />
<b>Line 131 </b>makes stuff know that something on the table has changed (the removal of cards ^)<br />
<b>Line 132</b>, also self explanatory, clears the active players from the previous hand!<br />
<b>Lines 133-138 </b>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.<br />
<b>Line 139</b> 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.<br />
<b>Lines 140-143 </b>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.<br />
<b>Lines 144-146</b> start each player's hand and<br />
<b>Line 147 </b>sends a message to the table letting the players know what just happened.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ2GZrDEBNJkeeLRwzlqLSHmCmEW2xI-7VhIkNsDoAoMY1mjpTJnu-0Rwz2KJ7byXnkT_nWCkRdbnVNwg_2N-hLLvcgu8jY9PKMsxprZ8JXSfsbHWpPiY62mORfscbnW_T9eyVuvs2ORU/s1600/table_6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ2GZrDEBNJkeeLRwzlqLSHmCmEW2xI-7VhIkNsDoAoMY1mjpTJnu-0Rwz2KJ7byXnkT_nWCkRdbnVNwg_2N-hLLvcgu8jY9PKMsxprZ8JXSfsbHWpPiY62mORfscbnW_T9eyVuvs2ORU/s1600/table_6.png" /></a></div>
<br />
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.<br />
The "else" portion on <b>lines 159-160 </b>should probably never be run into, but being an exceptional circumstance if it did, we should throw an exception!<br />
<br />
The main body makes use of 2 loops. First is the <b>do-while</b> loop on <b>lines 152-155</b>. 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!<br />
<b>Lines 153-154 </b>loops the actor position to the next (? Stupid confusing modulus!) position, then sets the actor to the new position.<br />
<b>Line 155 </b>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!<br />
<b>Lines 156-157 </b>send the message to each player, telling them who's up.<br />
<br />
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! :Pheddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com4tag:blogger.com,1999:blog-6714961303173507856.post-19129258721957344382011-12-23T11:38:00.000-08:002011-12-23T11:38:17.983-08:00Humbug!Hey, so, a friend I've not seen in a long time just made it into town! I'll be skipping today's posts, and Monday's post in the interest of having a pretend social life for half a week!<br />
<br />
Maybe I should have packaged this as a long weekend for the purposes of Christmas? Yeah, let's do that! See you guys on Tuesday, and Merry fuckin' Christmas to all!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com5tag:blogger.com,1999:blog-6714961303173507856.post-23928475450021016422011-12-22T16:25:00.000-08:002011-12-22T16:25:55.339-08:00Java: Texas Hold Em (27)Okay, back for a second post, it's late and I'm busy though, so deal with it being short! Four short methods totaling about 30 lines of code! We'll be covering a method to deal with each of the blinds and 2 for dealing out cards:<br />
<a name='more'></a><br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0i1Rk-IFkjRmP-FP1gDLSspgj2XdG3rekcqny4r7QhhpRu9JQg4TSobEH4B5nyXq6Y9VGXiA94YeAqQzxdWD3wXG0r-sCSgL4zHppxfFnW4aJvqeKHZWo-d0jaK8P6I6wDMFIyt-RJ3U/s1600/table_4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0i1Rk-IFkjRmP-FP1gDLSspgj2XdG3rekcqny4r7QhhpRu9JQg4TSobEH4B5nyXq6Y9VGXiA94YeAqQzxdWD3wXG0r-sCSgL4zHppxfFnW4aJvqeKHZWo-d0jaK8P6I6wDMFIyt-RJ3U/s1600/table_4.png" /></a></div>
<br />
<u style="font-weight: bold;">postSmallBlind:</u> Yay, we get to deal with the small blind first! Work our way up and all that.<br />
<b>Line 101</b> is simple. The small blind should be half the big, so store that value.<br />
<b>Line 102 </b>makes sure the active player posts that amount as the small blind. I know it uses the same method name, but <i>actor.post...()</i> is part of the player class! Not this one, so it's okay! Perhaps a little confusing, but still perfectly valid.<br />
<b> Line 103 </b>increases the pot by the specified amount and...<br />
<b>Line 104 </b>actually notifies people that some stuff happened.<br />
<br />
<u style="font-weight: bold;">postBigBlind:</u> This one is easier, now. Not only do we not need to half the big blind, but we've seen all this stuff in the above method! No need to go through it twice, eh?<br />
<br />
<u style="font-weight: bold;">dealHoleCards:</u> Hole cards! A silly name, I keep thinking they're the community cards, since the pit in front of all the players is visible to everyone. But it isn't, it's the personal cards! Like a personal hole? I'll definitely remember it now.<br />
<b>Lines 114-117</b> loops through each present player in the game. For each player, it sets the hand to 2 cards dealt from the deck, then has the client update the player info based on what just happened.<br />
<b>Line 118 </b>is just a general message to everyone, specifying who the dealer is, and giving them false credit. Everything's corrupt nowadays. But hey, look, it's making use of string formatting!<br />
<br />
<u style="font-weight: bold;">dealCommunityCards: </u>Ooh, this one takes parameters. The phasename is some bullshit name. For the phase. There's no real use for it, functionality-wise. noOfCards should speak for itself.<br />
<b>Lines 122-124</b> goes through, and for each card required, just adds one from the deck. Simple enough.<br />
<b>Line 125 </b>makes sure the board is updated!<br />
<b>Line 126 </b>gives more false credit through more string formatting!<br />
<br />
That WAS short. Shorter than I expected, maybe I can even have a minute or 2 to myself today, then! See you tomorrow! Questions/comments welcome!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com5tag:blogger.com,1999:blog-6714961303173507856.post-72106751093539818072011-12-22T16:09:00.000-08:002011-12-22T16:09:33.035-08:00Java: Texas Hold Em (26)Okay, post 1 of 2 for today! I'll take a break after this to type up the second, since I had this prepared for yesterday! This one contains a few administrative methods, the main game loop, a way to add players and a way to start the game over. The second screenshot is a huge method to take care of actually playing an individual hand. Here goes:<br />
<br />
<a name='more'></a><br /><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZe702wuuJo4LQlZUj-7Vr1ygMSMyrGcNp4TUNkaboQIt0aRSzEYd0fxX6cXh-cYFF8kRvXm056FlYcaeEOocTbQHNZInt9ikYB5VV9fxQ55mVZn2T9y06jAcd_V4f5sdrw9pQqQdfUM8/s1600/table_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZe702wuuJo4LQlZUj-7Vr1ygMSMyrGcNp4TUNkaboQIt0aRSzEYd0fxX6cXh-cYFF8kRvXm056FlYcaeEOocTbQHNZInt9ikYB5VV9fxQ55mVZn2T9y06jAcd_V4f5sdrw9pQqQdfUM8/s1600/table_2.png" /></a></div>
<br />
So, 3 methods in our first screenshot, let's go through them:<br />
<u style="font-weight: bold;"><br /></u><br />
<u style="font-weight: bold;">addPlayer:</u> This one is very simple. Since the players are just an array (the class variables, remember), we can just add a new player to the game by adding one to the array, and nothing else!<br />
<u style="font-weight: bold;"><br /></u><br />
<u style="font-weight: bold;">start:</u> If you remember the text-clock we wrote a while back, you'll remember that the start method is the main loop for the program to run.<br />
<b>Line 48</b> resets the game (using a method defined later. Next, in fact) so that when the game is started there's nothing left over from the previous one.<br />
<b>Line 49-50 </b>is the main loop. Here, we see that while the game isn't over (the game over boolean switch in the class variables), we'll play a hand (the method for which is defined later in this post).<br />
<b>Line 52</b> is executed when the main loop is dead, which happens when the game is over. This just notifies players that, hey, its game over!<br />
<br />
<u style="font-weight: bold;">resetGame:</u> This method just has to reset a few variables to the default so when a new game starts, everything goes smooth.<br />
<b>Lines 56-58 </b>reset the dealer, the current player and the gameOver switch.<br />
<b>Lines 59-60</b> uh...does something. For each player. It looks like, from the wording alone, that for each player, it makes them rejoin the table? I'm honestly not sure though. I've flagged this in my IDE so I can test it out once the <b>ConsoleClient </b>is done with! Got any ideas in the meantime?<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH01FxS3CH4KTE1VPyb7eP0TMuFRmyl4iTOi7LgDY-YdTiMuAwdz_ulfs4IMT_TBa3XAOop5X6rrN5B9RUnhdAXVxiKJPGj6aXp1x-kBPKbUb0tLN_bDbb8fI8Yi0epE1NvXWBi0S76LE/s1600/table_3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH01FxS3CH4KTE1VPyb7eP0TMuFRmyl4iTOi7LgDY-YdTiMuAwdz_ulfs4IMT_TBa3XAOop5X6rrN5B9RUnhdAXVxiKJPGj6aXp1x-kBPKbUb0tLN_bDbb8fI8Yi0epE1NvXWBi0S76LE/s1600/table_3.png" /></a></div>
<br />
Here's our doozy of a method. All methods you don't recognize will be defined later on in this class, or in the console client, just infer what they do from what they're called!<br />
<br />
<b>Line 68-73</b> starts the pre-dealing actions. Reset the hand, move to the next player (from the dealer. Who doesn't deal, because the computer does that...hm...), do the small blind dealy, move to the next player to deal with the big blind, then set the bet!<br />
<b>Line 75 </b>will simply deal the hole cards so that players have something to work with!<br />
<b>Line 76</b> presumably deals with a betting round. Circling the players, making them raise or whatever.<br />
<b>Lines 77-80 </b>say that if there's more than 1 player, deal the community cards out. Then go through another round of bets.<br />
<b>Lines 81-84 </b>go through the main part of the turn, dealing community cards (again? We'll have to inspect that method later!) and going through another betting round.<br />
<b>Lines 85-89</b> Okay, what's a river? Also, what's Google? Guess we'll find out later! The bet is doubled and another betting round occurs.<br />
<b>Lines 90+ </b>Oh god, a showdown?? The suspense is killing me!<br />
<br />
<br />
So that's the post! I'll make a short one for today, since I'm busy, it should be up in an hour or so! See ya later, Questions & comments welcome.heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com1tag:blogger.com,1999:blog-6714961303173507856.post-28158812966192826622011-12-21T14:58:00.001-08:002011-12-21T14:58:44.139-08:00Technical DifficultiesSomething is wrong with my computer, so I can't write a post; all my info is on there! It's being fixed, though, so I'll double post tomorrow, see you then!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com6tag:blogger.com,1999:blog-6714961303173507856.post-40991731721962297362011-12-20T12:00:00.000-08:002011-12-20T12:03:44.772-08:00Java: Texas Hold Em (25)Okay, so it turns out the <b>ConsoleClient </b>is pretty confusing, and requires the <b>Table </b>anyway, so we'll be doing the <b>Table</b>! Yay! Ooh, there's a problem though. You probably don't remember (I didn't), but when the <b>Hand </b>class was created, I left out the constructor that takes an ArrayList or something as a parameter. We need to go back and fix that so our table runs smoother!<br />
<br />
<a name='more'></a><br />
Here's how we do it:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjstqZaJaCJUVZtwj2C0hGjhq5BPFL64FfI9jjKyWvbTS-MG5EVJXWIPcglDUIYZb6XeFkfTR7GmopRDZmv22zOsbp5Q8FxF6aAUjd3lfkCaWY9vvBYAverXUof7h4JmUbuMuni9CJGh6I/s1600/hand_6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjstqZaJaCJUVZtwj2C0hGjhq5BPFL64FfI9jjKyWvbTS-MG5EVJXWIPcglDUIYZb6XeFkfTR7GmopRDZmv22zOsbp5Q8FxF6aAUjd3lfkCaWY9vvBYAverXUof7h4JmUbuMuni9CJGh6I/s1600/hand_6.png" /></a></div>
Put the method declaration wherever you want in <b>Hand.java</b>, the parameter here is a <i>Collection</i>. A Collection is a basic interface that encompasses a few different types of collections, so its not its own class. Most important, it encompasses <b>LinkedLists</b> and <b>ArrayLists</b>.<br />
<b>Lines 34-35 </b>just cover the error case, and <b>lines 37-38 </b>loop through the given collection and adds each card to the hand.<br />
<br />
Easy! We can move on to the <b>Table </b>now. This is a big class, roughly 400 lines! Let's try to get through it, and hopefully it all makes sense! Or at least, mostly makes sense. I'll try going through it as fast as possible, probably 50-60 lines a day (Not counting today, since we had to fix the <b>Hand </b>and I don't want to go over 2 screens per post).<br />
<br />
Let's start with a general blueprint. Since the Table will be controlling the general game flow, we're going to want to give it more than just a couple of players and a deck. We'll want to specify the high blind, the current bet, the maximum bet, the amount in the pot and the maximum allowable raises per player per round.<br />
On top of this, we'll want variables to hold the dealer, the players, the current active/acting player as well as positions of these players.<br />
Finally, we'll actually want a deck to play with, and a collection variable of some sort to hold the shared cards. A boolean to hold whether the game is over or not would be nice too. So let's get to getting those variables in place, and finish the constructor!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFirOoJnrdTIJi6yz2_AssElPL3ABYsnjffLGrdyCylDkWeOLZKmGbXLD0jzRnaHfsyNzpNHnnUc1xgLMTz4MhAl0Zh3zW_Ce1HphQ2UZz4BS5EnWUNxC4gItaTeJCih3Drqeg9OrLV1s/s1600/table_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFirOoJnrdTIJi6yz2_AssElPL3ABYsnjffLGrdyCylDkWeOLZKmGbXLD0jzRnaHfsyNzpNHnnUc1xgLMTz4MhAl0Zh3zW_Ce1HphQ2UZz4BS5EnWUNxC4gItaTeJCih3Drqeg9OrLV1s/s1600/table_1.png" /></a></div>
<br />
Okay, here we go! <b>Lines 13-31 </b>we discussed, and that's fine. Setting the max raises to 4 because that's what Mr. Stigter did, and I'm afraid to do anything different that I don't for sure have an opinion on because I'm a giant child.<br />
The <i>activePlayers </i>variable will (I think) hold the players that haven't gone broke, and <i>actor </i>holds the player whose turn it currently is! Everything else should be straightforward until the constructor!<br />
<br />
So there, we now have a constructor to deal with. Creating the table requires the highBlind, which, as I understand it, is the minimum bet for the hand. At this point, <b>lines 33-37</b> just fill in some details, the high blind, initializing the player arrays, the deck and the shared hole cards!<br />
<br />
Bam, boom, woop. Done for the day! Questions and comments welcome, see you tomorrow for 60 or so lines of code!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com5tag:blogger.com,1999:blog-6714961303173507856.post-90571510078248123352011-12-19T12:32:00.000-08:002011-12-19T12:32:38.814-08:00Java: Texas Hold Em (24)What's up, guys? Today we're back to the card game! We can probably finish it up today, but be aware that the actual <b>act</b> method is long, although it is just a switch statement, so not necessarily complex. I'll leave it to last so we can get the easy stuff out of the way, first.<br />
<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6rRkGZCzJVweiEETvaZPuWaMKx3onq5e5mkgMzRdjGpv6jTExoPPAbYoEdHivdg3BtcoJGe6lH6ncZRELgdoY2G7_KQQFbGIvq82HSozuQzLQsxOBLLHf2T2oU9sDy0xP99SRkjY7xm4/s1600/player_7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6rRkGZCzJVweiEETvaZPuWaMKx3onq5e5mkgMzRdjGpv6jTExoPPAbYoEdHivdg3BtcoJGe6lH6ncZRELgdoY2G7_KQQFbGIvq82HSozuQzLQsxOBLLHf2T2oU9sDy0xP99SRkjY7xm4/s1600/player_7.png" /></a></div>
<br />
Okay, here's 3 of the 4 remaining methods in this class! I'll be honest, I'm not sure what the <b>publicClone</b> method is used for, but looking over the code it <i>SEEMS </i>like it's what's visible to other players, with no client so you can't be affected by them. It would make sense, but don't be surprised if I'm wrong!<br />
<br />
Our first method is simple, the player wins a hand. The result is also simple, they get all the money!<br />
<br />
Next, we have the <b>publicClone </b>which, as I said before, I'm not sure about, but have a theory! According to this theory, <b>line 164 </b>is where a player is created without a client to control it, made to mimic the player at all times without having any control capabilities.<br />
<b>Lines 165-167 </b>would then be there to keep track of the player's stats that other players should be made aware of!<br />
<br />
Finally, we have a <b>toString </b>method so we can easily display the player when printing out a message. I've kept the <b>@Override </b>so you know what it looks like. All it does is make sure this method overrides the default <b>toString</b>. This is just to let the compiler know you intentionally took a method's name, instead of accidentally doing so. It's good practice to keep it in, so I'll just keep doing that from now on!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3ZDqdxRA7_oWuhBtan6RSAWuD_zDoTZrgo_KJQzcyYZTvz9efgXntw9cYn9ZV_kP19OwsxgSRtVAT_MJYqzzzljYmv-2tFiChYWFkk7tsDWANigJEL6yUZK0s97hvUtfrNeYuw1PgYaI/s1600/player_8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3ZDqdxRA7_oWuhBtan6RSAWuD_zDoTZrgo_KJQzcyYZTvz9efgXntw9cYn9ZV_kP19OwsxgSRtVAT_MJYqzzzljYmv-2tFiChYWFkk7tsDWANigJEL6yUZK0s97hvUtfrNeYuw1PgYaI/s1600/player_8.png" /></a></div>
<br />
Here we go, the huge switch statement! Guess we have to go through this slowly!<br />
<b>Line 123 </b>is the method declaration, as we know, and the parameters hold a set of actions that are currently allowed (not calculated by the player) as well as what the bets are currently.<br />
<b>Line 124 </b>actually sets the action of the player. Is it setting the action to a collection of actions? Hm, I'm not sure, and I can't test it until I've got my <b>ConsoleClient </b>in place, so we'll have to wait to find out!<br />
<b>Line 125 </b>is the start of our switch statement, using the action as the actual switch, and <b>line 156 </b>returns that action when the switch is done operating.<br />
Now for each of the cases. As you can see, there's one case for every potential action, let's go through them.<br />
<b><br /></b><br />
<b>Line 126 - CHECK: </b>Basically passing your turn. This does absolutely nothing other than return CHECK as your action!<br />
<b><br /></b><br />
<b>Line 128 - CALL: </b>Doing something? Madness! In this case, you're matching the table's bet, so <b>line 129 </b>is determining how much more you need to pay to make your current bet match the table bet..<br />
<b>Lines 130-131 </b>are saying "If you have to pay more than you have to call, just throw in what you DO have"<br />
<b>Lines 133-134 </b>remove the cash from the player and raise his/her bet by the corresponding amount!<br />
<b><br /></b><br />
<b>Line 136 - BET: </b>This here actually puts in the bet, with <b>lines 137-140</b> determining how much to bet, or whether you need to put in all the cash you got, same as with calling.<br />
Similar to calling, <b>lines 141-142 </b>remove the cash from the player, adding the amount to his/her betting pool.<br />
<b>Line 143 </b>increments the number of raises that have happened. Remember that variable? I barely do! This'll probably be the first "raise" since the action is BET and not, uh, RAISE<br />
<br />
<b>Line 145 - RAISE: </b>This case is pretty much the same as above, but it increases the current bet by whatever disparity existed between the current bet and your last bet. So if the current bet was 80 and it was 50 last time around, a RAISE would increase the current bet by (80 - 50 = ) 30, making it (80 + 30 = ) 110.<br />
<br />
<b>Line 152 - FOLD: </b>Back to easy cases! Folding just takes you out of the round, so nothing needs be done except the elimination of your hand!<br />
<br />
<br />
That's it for tonight, tomorrow, we move to the <b>ConsoleClient </b>or the <b>Table</b>, I guess I'll flip a coin to decide which one! See you then, questions and comments welcome!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com5tag:blogger.com,1999:blog-6714961303173507856.post-5737844307467016202011-12-18T15:42:00.000-08:002011-12-18T15:43:30.724-08:00Java: String Formatting (Pictures!) and the Switch StatementOkay so, apparently no pictures is a huge no-no, so I'll briefly show you how string formatting works with the power of screenshots! And yeah, looking back on yesterday's post, I agree, it was kinda shitty, so, sorry about that :P<br />
<br />
So, string formatting! First, we need to formulate a template string in which data will be entered later!<br />
<a name='more'></a><br />
Then we need to somehow calculate the data to put in, same as you would with any other output that takes a variable, and finally, we format the string! Let me show you how:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwSy8IZ-b3R5I3HYiyF9spbMyavR0d1Js61kwVzKibRHMptQwwNWQMvqUA-RVUQBfmJbKzBetpo5rlzg6hHdKqAyHrW05flhXR87jHbYjA5Rars5Ax0ZUW3nLphdafCaygyPXsGcUf9o4/s1600/format.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwSy8IZ-b3R5I3HYiyF9spbMyavR0d1Js61kwVzKibRHMptQwwNWQMvqUA-RVUQBfmJbKzBetpo5rlzg6hHdKqAyHrW05flhXR87jHbYjA5Rars5Ax0ZUW3nLphdafCaygyPXsGcUf9o4/s1600/format.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Okay, <b>Line 114 </b>is our template. As you can see, there are 3 percentage signs followed by a letter, so the template has 3 spaces for data in it, The "<i>%s</i>" denotes a string, and "<i>%d</i>" denotes a decimal integer!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i>Note: If you want to print a percent sign, you must place 2 of them in a row so the computer doesn't read is as trying to place a formatted spot in</i></b></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i><br /></i></b></div>
<div class="separator" style="clear: both; text-align: left;">
Our data can be collected however, a prompt from the user, or a method that performs some calculation. For the sake of ease, on <b>lines 116-118</b> I've just created the Strings and integer directly! Sure, I could have put both names into 1 string, but then I don't get to illustrate what happens when you have 2 of a data type in the strong.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Next, we want to call the String.format method on our string (<b>Lines 120-121</b>), taking 1 parameter plus the number of formatted spots. In our case, 3 formatted spots means 4 parameters! Each parameter after the first corresponds to a formatted position, in order of appearance.</div>
<div class="separator" style="clear: both; text-align: left;">
So FIRST_NAME takes the spot of the first <b>%s</b>, LAST_NAME takes the spot of the second <b>%s</b> and USER_AGE takes the spot of the 3rd formatted space, which is a <b>%d</b>.</div>
<div class="separator" style="clear: both; text-align: left;">
<b><i>Note: If you have the wrong data type in place (Say I mixed up USER_AGE and FIRST_NAME, heads will roll, and programs will crash!</i></b></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i><br /></i></b></div>
<div class="separator" style="clear: both; text-align: left;">
String.format returns the string given, but fully formatted, so either print it directly, or save it to a variable, as I have, then print it as in <b>line 123</b>.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
At the bottom of the screenshot, in the black box, is the output, if you needed to visualize that, too! </div>
<div class="separator" style="clear: both; text-align: left;">
Much better than typing "System.out.println( "My name is" + FIRST_NAME + " " + LAST_NAME +..." don't you think?</div>
<div class="separator" style="clear: both; text-align: left;">
I really hope that was a sufficient explanation this time! Let me know if you're still having trouble!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<hr />
<br />
<div>
Second half of today's post: A quick refresher on switch statements! Okay, so they're basically if-statements for larger groups, where typing <b>else if {...</b> a bunch of times can get really annoying! The general way this works is having a <b>switch</b> as the opening for a block of statements, followed by a bunch of <b>case </b>keywords, like so...</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2bNc0qgfOJ1Mx4ZH8iu-HQh0OU2zC93CPcTrSPgKPZBflTF8X5_lpy_BNSy3jWLJXIv2iQtxaltzTZ5yT9-w5L023kFw9uvTVKwX3pH9ZzL7PpAXzQxccUE_brekGqk1V3UI__wwgwzw/s1600/switch.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2bNc0qgfOJ1Mx4ZH8iu-HQh0OU2zC93CPcTrSPgKPZBflTF8X5_lpy_BNSy3jWLJXIv2iQtxaltzTZ5yT9-w5L023kFw9uvTVKwX3pH9ZzL7PpAXzQxccUE_brekGqk1V3UI__wwgwzw/s1600/switch.png" /></a></div>
<div>
Here, I have a method that takes an int that's composed entirely of a <b>switch-statement</b>, on <b>Line 16</b> we can see the declaration which takes some value as it's argument. This value doesn't need to be an integer, it can be anything, as long as the cases correspond to it!</div>
<div>
<br /></div>
<div>
For each position that a special message appears for, I create a case (<b>Lines 17, 20 </b>& <b>23</b>), each followed by the value of <b>position</b> that they're triggered on. Inside each <b>case </b>block is a statement (or sequence of statements) to be executed in that case, followed by a <b>break</b> to leave the switch (If you already determine position to be "1", why go through all the other cases?).</div>
<div>
<br /></div>
<div>
If the position is 1, print out first place, if 2, print second and so on. Not necessary, but often used, is the <b>default </b>keyword. This is invoked if none of the cases match the switch-variable! In our case, if you're not of the top 3, you're a damn loser! Got it? Let's test it out now!</div>
<div>
<br /></div>
<div>
The second part of our picture is a simple <b>for-loop</b>, going through 0-4 and calling our method for each value. The final part of the picture shows the integer put into the method followed by the output!</div>
<div>
<br /></div>
<div>
I had pictures, that means I was coherent this time, right? Right? Let me know if there are still any troubles though, by any means! All questions and comments welcome, see you tomorrow for an actual switch statement in action!</div>heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com6tag:blogger.com,1999:blog-6714961303173507856.post-63849818714224791632011-12-17T15:30:00.000-08:002011-12-17T15:30:31.083-08:00Java: String FormattingFirst off: To Damian in the comments: The game could kick the player when its discovered they're broke, but that's not up to the player class! It's up to either the <b>Table </b>or the <b>ConsoleClient</b>!<br />
<br />
Okay! Short post today, just covering string formatting. We saw in some code there was a string returned that looked roughly like:<br />
<br />
<i>"This is the message, %s, %f"</i><br />
<i><br /></i><br />
...within a method that took 2 more parameters. When printed out this way, the first parameter, the string, is the format of the message to be printed out. A percentage sign followed by a letter denotes where you'll want to put data in afterwards.<br />
<br />
<a name='more'></a><br /><br />
Think of the string as the template, and any <i>%_ </i>as data to be put into said template. An 's' denotes a string, 'f' denotes a float (real number in standard notation) and 'c' is for single characters. There are more, but this is just the general idea. Once you have your template in place...<br />
<br />
<i>"This is a template, it was written by %s who spend %f minutes on it"</i><br />
<i><br /></i><br />
...you can place a string and a float in there, in that order, probably in the form of some variable, like so:<br />
<br />
<i>String USER_NAME = "heddin";</i><br />
<i>float TIME_SPENT = 1.0;</i><br />
<i><br /></i><br />
...and then you print by having the string followed by 2 more parameters, like so:<br />
<br />
<i>String myString = String.format(`This is a template, it was written by %s who spent %f minutes on it`, USER_NAME, TIME_SPENT);</i><br />
<i><br /></i><br />
It`s really not hard, play with it if you`re having troubles getting it! Or just ask a question in the comments! Comments also welcome, and see you tomorrow for another refresher dealy! See ya!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com4tag:blogger.com,1999:blog-6714961303173507856.post-59170789588062729002011-12-16T15:20:00.000-08:002011-12-16T15:23:00.195-08:00Java: Texas Hold Em (23)Hey hey, time for another post. Last time we left off at <i>getCash</i> for the <b>Player </b>class, after a number of <i>get </i>methods and some other crap. Luckily, there's a buttload more of <i>get </i>methods to go through, so we still have some easy stuff around. Just a heads up though, on Monday we'll go through a larger method that uses the switch-statement.<br />
<br />
This week is my final make-up week where I make weekend posts, so tomorrow, as promised, I'll cover string formatting in more detail, and on Sunday I'll actually refresh us all on the switch statement, just in case you need it!<br />
<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3x-GkXb8P_uLrkrcP6hvLYPzN18iFqgjsBXF-IH9xf6wahkpvqRj2ILbxcbHux-vxagEFQXM6l6_g7PYbJe24NV3O3NdXXLN9JCuvaaOM1-e3jdvdiQ4tu_Qi0W5VqOUUBZ4mfQ7xvGQ/s1600/player_5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3x-GkXb8P_uLrkrcP6hvLYPzN18iFqgjsBXF-IH9xf6wahkpvqRj2ILbxcbHux-vxagEFQXM6l6_g7PYbJe24NV3O3NdXXLN9JCuvaaOM1-e3jdvdiQ4tu_Qi0W5VqOUUBZ4mfQ7xvGQ/s1600/player_5.png" /></a></div>
<br />
Here we go, a bunch more <i>get </i>methods, just returning values that are otherwise private, making them accessible to stuff outside this specific class, without allowing them to be changed. But you probably knew that's why we use <i>get</i> instead of just calling the variable :P<br />
<br />
<i>isBroke </i>is similarly simple, just returning whether or not the player in question is out of cash!<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBXx6dbu7M673SKGjBvhE2Czu20pay4mezdAXaGT2zNjhANkZkPw_dQbObVWJRptujbVJ7719-uECnq2giEKJ4rwjhiJ-FuBISRcX3HhDh5JFBopOw0W1hkBAkSYYveQmMl5mkbIcIoOg/s1600/player_6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBXx6dbu7M673SKGjBvhE2Czu20pay4mezdAXaGT2zNjhANkZkPw_dQbObVWJRptujbVJ7719-uECnq2giEKJ4rwjhiJ-FuBISRcX3HhDh5JFBopOw0W1hkBAkSYYveQmMl5mkbIcIoOg/s1600/player_6.png" /></a></div>
<br />
Oh no, actual methods! We've just got some ways to post the blinds here, setting the action to whatever type of blind it is, then removing the cash from the player and adding the amount to the bet.<br />
Really easy stuff for now, eh?<br />
Finally, we have a couple of methods here relating to the All In Pot, 1 to get how much there is, and 1 to set how much there is.<br />
<br />
Get ready to ramp up the difficulty curve on Monday, folks! But not by too much! Questions and comments welcome, see you tomorrow for string formatting!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com4tag:blogger.com,1999:blog-6714961303173507856.post-25668610723234039702011-12-15T16:42:00.000-08:002011-12-15T16:42:39.735-08:00Java: Texas Hold Em (22)Hi, people! Going to just make this as brief as I can today, don`t feel up to much. The <b>Player </b>class has 177 lines when I got rid of all the (rightfully present) comments, so you can keep track of how far we have to go before the end.<br />
<br />
Let`s get right into some methods now, with a few <i>get...() </i>methods and <i>reset...()</i> methods (among others) as you might expect would be needed in a round-based game:<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9nShkz3iWL7zI0q7w2UttBh2kKhiFvUDRTfcCgHy5mu0zD62rIyonHnJ5sfrGDHoMOorPDjlQh4srP05Ge4MTobQd8MPTSacHGOPP8dAfeBStWGO6zfhQsf3gm5G9ASn3vv1BzrBkG20/s1600/player_3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9nShkz3iWL7zI0q7w2UttBh2kKhiFvUDRTfcCgHy5mu0zD62rIyonHnJ5sfrGDHoMOorPDjlQh4srP05Ge4MTobQd8MPTSacHGOPP8dAfeBStWGO6zfhQsf3gm5G9ASn3vv1BzrBkG20/s1600/player_3.png" /></a></div>
<br />
Here we have our getClient method, separate from the others for whatever reason. Didn`t really sink in until I uploaded the screenshot, though, so it can stay.<br />
<br />
<b>Line 39</b> marks the beginning of the <i>resetHand() </i>method that we saw used in the constructor. This should remove all cards from the player`s hand (Think about it less in terms of programming, and more what would actually happen in a game. The player doesn`t get to hold onto his hand!). At this point, the boolean flag should be changed to reflect this, and with a new hand comes a new bet.<br />
<br />
<b>Line 45 </b>starts the method that goes about resetting the bet. Fairly self-explanatory, all bet-related amounts are reset to 0, and the last-action variable is also reset.<br />
<br />
Easy so far, right? Well, sorry to burst your bubble, but (heh, bubble butt.)...<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh79D1gk5Cqj5MR0mujeJUElL3LuH3MdSgDUC-ATtAlU5Eq3iKC-0NLew3NnqxsxjDe7cbg0UgF8xehedGBoAIs1Jc0v2JDfm9bkSBFYAbw_qt4Pmd4OM_1Gb5Y1xyFYc8DsQ0d4XpqmmI/s1600/player_4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="446" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh79D1gk5Cqj5MR0mujeJUElL3LuH3MdSgDUC-ATtAlU5Eq3iKC-0NLew3NnqxsxjDe7cbg0UgF8xehedGBoAIs1Jc0v2JDfm9bkSBFYAbw_qt4Pmd4OM_1Gb5Y1xyFYc8DsQ0d4XpqmmI/s640/player_4.png" width="640" /></a></div>
<br />
Oh my god, a method that takes more than 5 lines! This is used to set the hole cards (The one's unique to this player). To give the player cards, we should first remove all cards they currently hold. I would assume that the resetHand method takes care of this, but it's best to be careful!<br />
The next little chunk makes sure there are actual cards to put into the hand.<br />
<b>Line 57-60</b> are what happens if the number of cards is legal (2 personal cards, since 3 are public), and just adds the cards. I'm still confused about the string being thrown out starting with "[CHEAT]...", since, as far as I can tell, there's no cheating at all. Weird, but, I'll keep it in for now, and remove it when we're closer to completion assuming there's not some other use for it I haven't thought of.<br />
<b>Lines 61-62 </b>just cover the case of personal cards not being 2, a simple exception is thrown!<br />
<br />
Finally for tonight, we have a few more <i>get</i> methods and then the boolean method to specify if the player actually has cards. Think of it as <i>getHasCards</i>, but named in a less ridiculous manner.<br />
<br />
See you guys tomorrow! 100 lines to go! Q's and comments welcome!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com4tag:blogger.com,1999:blog-6714961303173507856.post-51733482660352051482011-12-14T15:10:00.000-08:002011-12-14T15:10:24.509-08:00Java: Texas Hold Em (21)Alrighty, I looked over the <b>ConsoleClient </b>class, and uh, I was lost, so let's do the <b>Player </b>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.<br />
<br />
After that, we can just do the <b>Table </b>class, leaving <b>ConsoleClient </b>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...<br />
<a name='more'></a><br /><br />
So, our <b>Player </b>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 <b>Client</b> that'll be responsible for actual behavior.<br />
<br />
So let's get through the instance variables and the constructor, shall we?<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDkPBdVzLz8kXjh_U7n-v0q-mRS0Yf9coxRE5MTFLGHmcr1rVhIEU4apwyWM5MKnYIc5RZdq0crxOnxd4ZNiKYsozbBzAAJVhAuPsMcsj9uKPJjCe5AgfBV68YBh8L9CxDgFW9K6BQl20/s1600/player_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDkPBdVzLz8kXjh_U7n-v0q-mRS0Yf9coxRE5MTFLGHmcr1rVhIEU4apwyWM5MKnYIc5RZdq0crxOnxd4ZNiKYsozbBzAAJVhAuPsMcsj9uKPJjCe5AgfBV68YBh8L9CxDgFW9K6BQl20/s1600/player_1.png" /></a></div>
<br />
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!<br />
<br />
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, <i>bet, raises, allInPot, action </i>and<i> hasCards</i>. 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.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA6cyC2vvfMl1hWX4F_CcfQil_PSWjA6iT7vcuqYWWV6wpFUXMrUbz23uDK0jFgNGIQnYv6XZgALBidXNYSngafqplGH9aLVWhGMTcq1jWk4VD00WWshaqnahP_r9hRzP7eGlvlsoDwnc/s1600/player_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA6cyC2vvfMl1hWX4F_CcfQil_PSWjA6iT7vcuqYWWV6wpFUXMrUbz23uDK0jFgNGIQnYv6XZgALBidXNYSngafqplGH9aLVWhGMTcq1jWk4VD00WWshaqnahP_r9hRzP7eGlvlsoDwnc/s1600/player_2.png" /></a></div>
<br />
That's it, just set each of the initial variables and we're golden. <b>Line 33</b>, 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.<br />
<br />
That's it for the night, folks. Enjoy the rest of your day, and I'll see you tomorrow! Questions/comments welcome!heddinhttp://www.blogger.com/profile/00709039314809864188noreply@blogger.com5