Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Junky

Thread: Making aliases

  1. #1
    Tenma5l7 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default 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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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
    }

  3. #3
    Tenma5l7 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    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.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Tenma5l7 View Post
    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 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.


    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.
    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.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Quote Originally Posted by Tenma5l7 View Post
    Each Hand object has a boolean variable called win.
    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.
    Tenma5l7 likes this.

  6. #6
    Tenma5l7 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    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

  1. problem making a gui
    By niba10 in forum AWT / Swing
    Replies: 2
    Last Post: 04-04-2011, 09:37 AM
  2. making an exe from .jar
    By ron2794 in forum NetBeans
    Replies: 3
    Last Post: 02-04-2011, 09:28 AM
  3. Need help making a GUI
    By DrKilljoy in forum New To Java
    Replies: 21
    Last Post: 07-15-2010, 04:44 AM
  4. Need help making .jar
    By yoodidoo in forum Eclipse
    Replies: 4
    Last Post: 08-03-2009, 09:57 PM
  5. Replies: 3
    Last Post: 07-15-2009, 07:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •