Results 1 to 6 of 6
Thread: Making aliases
- 06-19-2011, 11:31 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
Making aliases
Hi all, this is my first post here and I am new to programming, so please bear with me. Also let me know if I am posting this in the wrong section.
I'm making a Texas Holdem program, and in it I have a Texas Holdem class and a Hand class. Each Hand object has a boolean variable called win. In the Texas Holdem class I am comparing more than two hands with each other and it is spitting out a winner. My question is, is there any way that, if there is a tie, I can make each respective win variable equal to each other so that if i set one to false, the other Hand one is also set to false? I am checking with up to ten hands, so I need to be able to, if a Hand beats another hand at the game, the one it beats is set to false, which immediately sets all the equal ones to false.
Is there any way to do this in Java?
Thanks for your considerations, sorry if my explanation is bad, and apologies if I'm posting in the wrong section.
-
I wonder if you should not use a boolean which is a two-state variable, and instead use a multistate variable such as either an int (1 for win, 0 for tie, -1 for loss), or perhaps even better and easier to debug, an enum:
Java Code:public enum WinState { PLAYING, // no winner yet WIN, // won the game TIE, // more than one winner LOSE // lost the game }
- 06-19-2011, 11:49 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
Fubarable, thanks for your consideration.
If I did use an enum instead, likewise, is there a way that if i send one enum to, say, lose, it would automatically send all the ones that it was just tied to to lose? I don't know that much about enum, but it seems to me like it would be the same as a variable in that respect. My problem is that when I'm checking to see who wins, when two hands tie, my iterator moves to the next one, but if the second tied hand is set to false by my third hand, the first hand still says win.
-
I don't understand your statement above. You'll likely have several classes and objects at work here including Dealer, Player, Card, Deck, Hand, etc... and overseeing all of them will likely be a Game object that will check for winners and losers at the appropriate time. It will be the object that would compare the relative scores of each hand and decide if there is one winner, or a tie, and then assign the winnings accordingly.
You can sort the hands by score for instance and then iterating through and looking for ties would be easy. There are a lot of ways to skin this cat.I don't know that much about enum, but it seems to me like it would be the same as a variable in that respect. My problem is that when I'm checking to see who wins, when two hands tie, my iterator moves to the next one, but if the second tied hand is set to false by my third hand, the first hand still says win.
- 06-20-2011, 12:51 AM #5
Personally I wouldn't do this. Think about a Hand in isolation. It doesn't know if it is a winning hand nor does it need to know. However the "thing" controlling the game does need to know which is the winning Hand.
What you can do is have a Collection of winning Hands. Insert the first Hand (it is winning so far). Then compare each subsequent Hand to the winning Hand. If it is a worse Hand move on, if it is the same Hand add it to the Collection, if it is a better Hand clear the Collection and add the new Hand. At the end you will have one or more winning Hands in the Collection.
- 06-20-2011, 01:30 AM #6
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
Junky I think that would work great, Thanks to both of you with your help.
Fubarable I do indeed have all such classes, named exactly as you named them, xD
That is indeed what I was doing, but it seems that what I was looking for doesn't exist, so I think Junky's suggestion will work just fine.
Thanks everyone for the help.
Similar Threads
-
problem making a gui
By niba10 in forum AWT / SwingReplies: 2Last Post: 04-04-2011, 08:37 AM -
making an exe from .jar
By ron2794 in forum NetBeansReplies: 3Last Post: 02-04-2011, 08:28 AM -
Need help making a GUI
By DrKilljoy in forum New To JavaReplies: 21Last Post: 07-15-2010, 03:44 AM -
Need help making .jar
By yoodidoo in forum EclipseReplies: 4Last Post: 08-03-2009, 08:57 PM -
How would I go about making something like this...
By split in forum New To JavaReplies: 3Last Post: 07-15-2009, 06:10 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks