Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 19 of 19

Thread: Problem with my poker program

  1. #1
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Question Problem with my poker program

    This section of code is where I am testing the algorithm to catch a winning hand i.e. two pair, flush, straight, etc... It is able to find everything except a full house following an XXYYY pattern and two pairs. I'm not getting any errors and doesn't seem to be reaching the part of the code where it searches for that full house and two pair. How should I change the code to find it?

    package chapter7Project;
     
    import java.util.ArrayList;
     
    public class test {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
     
    		ArrayList<String> hand = new ArrayList<String>();                 //hand I will use for testing for two pair
    		hand.add("13 Spades");                                                    //change the card values here for finding out other combos (1-13 or ace-king)
    		hand.add("1 Diamonds");
    		hand.add("2 Spades");
    		hand.add("2 Spades");
    		hand.add("13 Spades");
    		ArrayList<Integer> hCard = new ArrayList<Integer>();//ArrayLists for testing for combos
    		ArrayList<String> hSuit = new ArrayList<String>();
     
     
    //separate cards and suits
    		for(String i : hand)
    		{
    			i = i.trim();//removes spaces at the beginning
    			int j = 0;
    			boolean done = false;
    			String acard = "";
    			while(!done)
    			{
    				if(i.substring(j, j+1).equalsIgnoreCase(" "))//changes face cards to numbers
    				{
    					if(acard.equalsIgnoreCase("Jack"))
    					{
    						acard = "11";
    					}
    					if(acard.equalsIgnoreCase("Queen"))
    					{
    						acard = "12";
    					}
    					if(acard.equalsIgnoreCase("King"))
    					{
    						acard = "13";
     
    					}
    					if(acard.equalsIgnoreCase("Ace"))
    					{
    						acard = "1";
    					}
    					hCard.add(Integer.parseInt(acard.trim()));
    					done = true;
    				}
    				acard += i.substring(j, j+1);
    				j++;	
    			}		
    		}
    //gets each suit
    		for(String i : hand)
    		{
    			i = i.trim();
    			int j = i.length()-1;
    			String asuit = "";
    			boolean done = false;
    			while(!i.substring(j, j+1).equalsIgnoreCase(" "))
    			{
    				j--;
    			}
    			j++;
    			while(!done)
    			{
    				asuit += i.substring(j, j+1);
     
    				if(i.substring(j, j+1).equalsIgnoreCase(" ")||j==i.length()-1)
    				{
    					hSuit.add(asuit.trim());
    					done = true;
    				}
    				j++;	
    			}
    		}
     
     
     
    //puts the cards in numerical order
    		int j = 0;
     
    		ArrayList<Integer> greatest = new ArrayList<Integer>();//contains the cards placed in numerical order
    		ArrayList<String> boobs = new ArrayList<String>();
    		boobs.add("");
    		boobs.add("");
    		boobs.add("");
    		boobs.add("");
    		boobs.add("");                              //fills the arraylists with 5 slots
    		greatest.add(0);
    		greatest.add(0);
    		greatest.add(0);
    		greatest.add(0);
    		greatest.add(0);
    		int i = 0;
    //algorithm for putting the cards in numerical order
    //by adding 1 to 'j' for each card its greater than
    //sorts from least to greatest
    		while(greatest.contains(0))
    		{
    			for(int a : hCard)
    			{
    				j = 0;
    				int index = i;
    				for(int c : hCard)//checks if one card is bigger than another
    				{
    					if(a > c)
    						j++;
    					if ( a == c)//if the cards are the same, it looks for the next available slot
    					{
    						int b = greatest.indexOf(a);
    						if(b == 4)
    						{
    							j = 3;
    							break;
    						}
    						else if (b==3)
    						{
    							if(greatest.get(4) == 0){
    								j = 4;
    							}
    							else
    							{
    								j = 2;
    							}
    							break;
    						}
    						else if (b==2)
    						{
    							if(greatest.get(3) == 0)
    							{
    								j = 3;
    							}
    							else if(a == greatest.get(3))
    							{
    								j = 4;
    							}
    							else
    							{
    								j = 1;
    							}
    							break;
    						}
    						else if(b==1)
    						{
    							if(greatest.get(2) == 0)
    							{
    								j = 2;
    							}
    							else if(a == greatest.get(2))
    							{
    								j=3;
    								if(a == greatest.get(3))
    								{
    									j=4;
    								}
    							}
    							else
    							{
    								j = 1;
    							}
    							break;
    						}
    						else if(b==0)
    						{
    							if(a == greatest.get(1))
    							{	
    								j = 2;
    								if( a == greatest.get(2))
    									j=3;
    							}
    							else
    							{	
    								j = 1;
    							}
    							break;
    						}
    					}
    				}
    				greatest.set(j,a);//puts the card in the slot where it's supposed to be
    				boobs.set(j, hSuit.get(index));//gets the suit where the card is and puts it in the same index as the card put in greatest
    				i++;
    			}
    			hCard.removeAll(hCard);//removes all cards from  hcCArd
    			hCard.addAll(greatest);//puts the sorted cards in hCard
    			hSuit.removeAll(hSuit);//does the same for the suits
    			hSuit.addAll(boobs);
    			System.out.println(hCard);
    			System.out.println(hSuit);
    		}
    		boolean pair = false;
    		boolean twoPair = false;
    		boolean threeOfAKind = false;
    		boolean straight = false;
    		boolean flush = false;
    		boolean fullHouse = false;
    		boolean fourOfAKind = false;
    		boolean straightFlush = false;
    		boolean royalFlush = false;
     
     
    		//checks for royal flush
    		if(hCard.contains(1)&&hCard.contains(10)&&hCard.contains(11)&&hCard.contains(12)&&hCard.contains(13))//checks for 10-ace
    		{
     
    			int check = 0;
    			String k = hSuit.get(0);
    			for(String a : hSuit)//checks if the suits are all the same
    			{
    				if(a.equalsIgnoreCase(k))
    				{
    					check++;
    				}
    				if(check==5)
    				{
    					royalFlush = true;
    				}
    			}
     
    		}
     
    		//checks for pair, 2 pair, 3 of a kind, full house, and four for of a kind
    		int l = 0;
    		while( l <= hCard.size()-1)//finds the first matching pair
    		{
    			if(hCard.get(l) != hCard.get(l+1))
    				l++;
    			else
    			{
    				break;
    			}
    		}
    		if(hCard.get(l) == hCard.get(l+1)&&l<hCard.size())//if there's a pair, it goes through here to search for other possibilities
    		{
    			System.out.println(l);
    			if(l <= 1)
    			{
    				l++;
    				System.out.println(l);
    				if(hCard.get(l) == hCard.get(l+1))//three of a kind if true
    				{
    					if(l < 2)
    					{
    						l++;
    						System.out.println(l);
    						if(hCard.get(l) != hCard.get(l+1))// checks for a full house
    						{
    							if(l < 3)
    							{
    								l++;
    								System.out.println(l);
    								if(hCard.get(l) == hCard.get(l+1))//if three of a kind then pair, XXXYY, then full house is true
    								{
    									fullHouse = true;	
    								}
     
    							}
    						}
    						if(hCard.get(l) == hCard.get(l+1))//checks for four of a kind
    						{
    							fourOfAKind = true;	
    						}
    						else//else it's a three of a kind
    						{
    							threeOfAKind = true;
    						}
    					}
    					else// if 'l' is too big then three of a kind is true
    					{
    						threeOfAKind = true;
     
    					}
    				}
    				else if(l < 1)//looks for two pair and full house patter, yyxxx
    				{
    					l++;
    					System.out.println(l);
     //section where i need help
    					if(hCard.get(l) != hCard.get(l-1)&&hCard.get(l) == hCard.get(l+1))   //checks if the next card is equal to the last and is equal to the next                               
    					{
    						if(l < 2)
    						{
    							l++;
    							System.out.println(l);
    							if(hCard.get(l) == hCard.get(l+1)&&hCard.get(l+1)==hCard.get(l+2))//checks for a three of a kind
    							{
    								fullHouse = true;
    							}
    						}
    						else if(fullHouse == false)
    						{
    							twoPair = true;                                                                    
    						}
    					}
    				}
     
    			}
    			else
    			{
    				if(hCard.get(l) != hCard.get(l-1)&&hCard.get(l) == hCard.get(l+1))//looks specifically for a two pair
    				{
    					if(l < 2)
    					{
    						l++;
    						System.out.println(l);
    						if(hCard.get(l) == hCard.get(l+1)&&hCard.get(l+1)!=hCard.get(l+2))//looks if the two pair is seperated or together
    						{
    							twoPair = true;
    						}
    						if(hCard.get(l) != hCard.get(l+1)&&hCard.get(l+1)==hCard.get(l+2))
    						{
    							twoPair = true;
    						}                                                                                                      //down to here
    					}
    				}
    			}
    			if(twoPair == false && fullHouse == false && threeOfAKind == false && fourOfAKind == false)//if everything else is false, pair is at least true
    				pair = true;
    		}
     
    //looks for a flush
    		int check = 0;
    		String k = hSuit.get(0);
    		for(String a : hSuit)
    		{
    			if(a.equalsIgnoreCase(k))
    			{
    				check++;
    			}
    		}
    		if(check==5)
    		{
    			flush = true;
    		}
     
    //looks for a straight
    		if(hCard.get(1) == (hCard.get(0)+1) && hCard.get(2)== (hCard.get(1)+1) && hCard.get(3) == hCard.get(2)+1 && hCard.get(4) == hCard.get(3)+1)
    		{
    			straight = true;
    		}
    		else if(hCard.contains(1) && hCard.contains(10) && hCard.contains(11) && hCard.contains(12) && hCard.contains(13))
    		{
    			straight = true;
    		}
    //if straight and flush are true, then you have a straight flush
    		if(straight == true && flush == true && royalFlush == false)
    		{
    			straightFlush = true;
                            straight = false;
                            flush = false;
    		}
     
    //looks if anything is one
    		if(royalFlush == true)
    		{
    			System.out.println("HOLY FUCK BALLS, ROYAL FLUSH!!");
    		}
    		if(pair == true)
    		{
    			System.out.println("pair");
    		}
    		if(twoPair == true)
    		{
    			System.out.println("two pair");
    		}
    		if(threeOfAKind == true)
    		{
    			System.out.println("three of a kind");
    		}
    		if(fullHouse == true)
    		{
    			System.out.println("full house");
    		}
    		if(fourOfAKind == true)
    		{
    			System.out.println("four of a kind");
    		}
    		if(flush == true)
    		{
    			System.out.println("flush");
    		}
     
    		if(straight == true)
    		{
    			System.out.println("straight");
    		}
    		if(straightFlush == true)
    		{
    			System.out.println("straight flush");
    		}
    	}
    }
    Last edited by aesguitar; March 25th, 2012 at 02:15 PM. Reason: added comments in the code


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    One problem I see with the code is that there are no comments explaining the logic.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    I added comments, could you help me now?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    Some other items:
    l is a very hard variable name to see because it looks like a 1
    There is no way to tell which println statement was executed when you print out a number without a label:
    System.out.println(l);
    You have lots of these. You need to add a label to each one so you can tell which one executed:
    System.out.println("l1=" +l);
    changing the 1 to 2 etc so they are all different. Then you can find which one was executed.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    Can you explain the logic you want to use to find a full house, three of a kind or two pairs?
    Your comments don't explain what logic you want to use.

    The question is:
    Do you have good logic in your design but have not coded the program to follow the logic
    Or the logic is bad.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    The logic I'm using is:

    If there is a pair, look at the next cardB.
    If cardB is not equal to cardA, then see if the next 2 cards are the same as cardB.
    If they are, then it is a full house.

    For the two pair:

    If there is a pair, look at the next card.
    If the next card is not equal to the pair, then check to see if the next card is equal to it.
    If not that, then go to the next to cards and check if they are equal.
    Two pair if either statements are true.

    My logic isn't flawed, but I don't quite know how to fix the code to match the logic flow. Another problem is that the code is hard to read because of all the braces, sorry about that.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    I think you need to consider the possible hands based on where the beginning of the first pair is found.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    That's what this block of code does:

    int l = 0;
    		while( l <= hCard.size()-1)//finds the first matching pair
    		{
    			if(hCard.get(l) != hCard.get(l+1))
    				l++;
    			else
    			{
    				break;
    			}
    		}

    It goes through the hand and sees if cardA == cardB
    if it doesn't, then it goes to the next card.
    Once it finds a matching pair, it breaks the while loop

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    One flaw in the logic you posted: it not possible to have a full house if the first card of the found pair is the second card.

    The results of the loop you just posted is what I am talking about. You need to used the index to the first card in the pair to control the possible hands. If the index is 3, there is only a pair.
    Last edited by Norm; March 25th, 2012 at 02:15 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    It checks for that here:

    if(hCard.get(l) != hCard.get(l-1)&&hCard.get(l) == hCard.get(l+1))   //checks if the next card is equal to the last and is equal to the next                               
    	{
    		if(l < 2)
    		{
    			l++;
    			System.out.println(l);
    			if(hCard.get(l) == hCard.get(l+1)&&hCard.get(l+1)==hCard.get(l+2))//checks for a three of a kind
    			{
    				fullHouse = true;
    			}
    		}
    		else if(fullHouse == false)
    		{
    			twoPair = true;                                                                    
    		}
    	}

    if l < 2 then that means it is currently looking at the 2nd card. So there is no way that it will look for a full house if it == equals 2 or more

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    Your logic listed in post #6 leaves those detail out.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    My bad for that, before every check for a win if statement is another if statement that checks for where the index is. Do you see any outstanding issues with the code now?

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    The issue for me is the logic. I would write straight forward code based on the first pair index value:
    0/5 - fh & 4oak & 3oak & 2p & p  xxxyy xxyyy xxxx? xxx?? xxyy? xx?yy xx???
    1/4 - 40ak & 3oak & 2p & p         xxxx xxx? xxyy xx??
    2/3 - 3oak   & p                         xxx  xx?
    3/2 - p                                      xx
    4/1 - hc                                    -
    When that code worked, then I might consider optimizing it.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    I think that's what I did. It looks at the index, and then based off of that, it looks for the combinations afterwards.

    //that's what these if statements are for
    if(l<x)
    {
        ...
    }

    x being some number between 1 and 3

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    My code would look like:
    if(idx == 3) {
      // pair only
    }else if (idx == 2) {
      // 3oak or pair
    etc

    Not a range of index values, a specific index value.
    If you don't understand my answer, don't ignore it, ask a question.

  16. The Following User Says Thank You to Norm For This Useful Post:

    aesguitar (March 25th, 2012)

  17. #16
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    OOOHHHH, I see what you mean. Give me a few minutes

  18. #17
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    Here's the updated code:

    package help;
     
    import java.util.ArrayList;
     
    public class Test {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
     
    		ArrayList<String> hand = new ArrayList<String>();                 //hand I will use for testing for two pair
    		hand.add("1 Spades");                                                    //change the card values here for finding out other combos (1-13 or ace-king)
    		hand.add("2 spades");
    		hand.add("11 Spades");
    		hand.add("12 Spades");
    		hand.add("13 Spades");
    		ArrayList<Integer> hCard = new ArrayList<Integer>();//ArrayLists for testing for combos
    		ArrayList<String> hSuit = new ArrayList<String>();
     
     
    		//separate cards and suits
    		for(String i : hand)
    		{
    			i = i.trim();//removes spaces at the beginning
    			int j = 0;
    			boolean done = false;
    			String acard = "";
    			while(!done)
    			{
    				if(i.substring(j, j+1).equalsIgnoreCase(" "))//changes face cards to numbers
    				{
    					if(acard.equalsIgnoreCase("Jack"))
    					{
    						acard = "11";
    					}
    					if(acard.equalsIgnoreCase("Queen"))
    					{
    						acard = "12";
    					}
    					if(acard.equalsIgnoreCase("King"))
    					{
    						acard = "13";
     
    					}
    					if(acard.equalsIgnoreCase("Ace"))
    					{
    						acard = "1";
    					}
    					hCard.add(Integer.parseInt(acard.trim()));
    					done = true;
    				}
    				acard += i.substring(j, j+1);
    				j++;	
    			}		
    		}
    		//gets each suit
    		for(String i : hand)
    		{
    			i = i.trim();
    			int j = i.length()-1;
    			String asuit = "";
    			boolean done = false;
    			while(!i.substring(j, j+1).equalsIgnoreCase(" "))
    			{
    				j--;
    			}
    			j++;
    			while(!done)
    			{
    				asuit += i.substring(j, j+1);
     
    				if(i.substring(j, j+1).equalsIgnoreCase(" ")||j==i.length()-1)
    				{
    					hSuit.add(asuit.trim());
    					done = true;
    				}
    				j++;	
    			}
    		}
     
     
     
    		//puts the cards in numerical order
    		int j = 0;
     
    		ArrayList<Integer> greatest = new ArrayList<Integer>();//contains the cards placed in numerical order
    		ArrayList<String> boobs = new ArrayList<String>();
    		boobs.add("");
    		boobs.add("");
    		boobs.add("");
    		boobs.add("");
    		boobs.add("");                              //fills the arraylists with 5 slots
    		greatest.add(0);
    		greatest.add(0);
    		greatest.add(0);
    		greatest.add(0);
    		greatest.add(0);
    		int i = 0;
    		//algorithm for putting the cards in numerical order
    		//by adding 1 to 'j' for each card its greater than
    		//sorts from least to greatest
    		while(greatest.contains(0))
    		{
    			for(int a : hCard)
    			{
    				j = 0;
    				int index = i;
    				for(int c : hCard)//checks if one card is bigger than another
    				{
    					if(a > c)
    						j++;
    					if ( a == c)//if the cards are the same, it looks for the next available slot
    					{
    						int b = greatest.indexOf(a);
    						if(b == 4)
    						{
    							j = 3;
    							break;
    						}
    						else if (b==3)
    						{
    							if(greatest.get(4) == 0){
    								j = 4;
    							}
    							else
    							{
    								j = 2;
    							}
    							break;
    						}
    						else if (b==2)
    						{
    							if(greatest.get(3) == 0)
    							{
    								j = 3;
    							}
    							else if(a == greatest.get(3))
    							{
    								j = 4;
    							}
    							else
    							{
    								j = 1;
    							}
    							break;
    						}
    						else if(b==1)
    						{
    							if(greatest.get(2) == 0)
    							{
    								j = 2;
    							}
    							else if(a == greatest.get(2))
    							{
    								j=3;
    								if(a == greatest.get(3))
    								{
    									j=4;
    								}
    							}
    							else
    							{
    								j = 1;
    							}
    							break;
    						}
    						else if(b==0)
    						{
    							if(a == greatest.get(1))
    							{	
    								j = 2;
    								if( a == greatest.get(2))
    									j=3;
    							}
    							else
    							{	
    								j = 1;
    							}
    							break;
    						}
    					}
    				}
    				greatest.set(j,a);//puts the card in the slot where it's supposed to be
    				boobs.set(j, hSuit.get(index));//gets the suit where the card is and puts it in the same index as the card put in greatest
    				i++;
    			}
    			hCard.removeAll(hCard);//removes all cards from  hcCArd
    			hCard.addAll(greatest);//puts the sorted cards in hCard
    			hSuit.removeAll(hSuit);//does the same for the suits
    			hSuit.addAll(boobs);
    			System.out.println(hCard);
    			System.out.println(hSuit);
    		}
    		boolean pair = false;
    		boolean twoPair = false;
    		boolean threeOfAKind = false;
    		boolean straight = false;
    		boolean flush = false;
    		boolean fullHouse = false;
    		boolean fourOfAKind = false;
    		boolean straightFlush = false;
    		boolean royalFlush = false;
     
     
    		//checks for royal flush
    		if(hCard.contains(1)&&hCard.contains(10)&&hCard.contains(11)&&hCard.contains(12)&&hCard.contains(13))//checks for 10-ace
    		{
     
    			int check = 0;
    			String k = hSuit.get(0);
    			for(String a : hSuit)//checks if the suits are all the same
    			{
    				if(a.equalsIgnoreCase(k))
    				{
    					check++;
    				}
    				if(check==5)
    				{
    					royalFlush = true;
    				}
    			}
     
    		}
     
    		//checks for pair, 2 pair, 3 of a kind, full house, and four for of a kind
    		int l = 0;
    		while( l < hCard.size()-1)//finds the first matching pair
    		{
    			if(hCard.get(l) != hCard.get(l+1))
    				l++;
    			else
    			{
    				break;
    			}
    		}
    		if(l == 3)
    		{
    			pair = true;
    		}
    		else if(l==2)
    		{
    			if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l)==hCard.get(l+2))
    			{
    				threeOfAKind = true;
    			}
    			else
    			{
    				pair = true;
    			}
    		}
    		else if(l==1)
    		{
    			if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l+2)==hCard.get(l)&&hCard.get(l+3)==hCard.get(l))
    			{
    				fourOfAKind = true;
    			}
    			else if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l)==hCard.get(l+2)&&hCard.get(l+3)!=hCard.get(l))
    			{
    				threeOfAKind = true;
    			}
    			else if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l)!=hCard.get(l+2)&&hCard.get(l+2)==hCard.get(l+3))
    			{
    				twoPair = true;
    			}
    			else
    			{
    				pair = true;
    			}
    		}
    		else if(l==0)
    		{
    			if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l+2)==hCard.get(l)&&hCard.get(l+3)==hCard.get(l))
    			{
    				fourOfAKind = true;
    			}
    			else if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l)==hCard.get(l+2)&&hCard.get(l+3)!=hCard.get(l)&&hCard.get(l+3)==hCard.get(l+4))
    			{
    				fullHouse = true;
    			}
    			else if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l)!=hCard.get(l+2)&&hCard.get(l+2)==hCard.get(l+3)&&hCard.get(l+3)==hCard.get(l+4))
    			{
    				fullHouse = true;
    			}
    			else if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l)==hCard.get(l+2)&&hCard.get(l+3)!=hCard.get(l))
    			{
    				threeOfAKind = true;
    			}
    			else if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l)!=hCard.get(l+2)&&hCard.get(l+2)==hCard.get(l+3))
    			{
    				twoPair = true;
    			}
    			else if(hCard.get(l)==hCard.get(l+1)&&hCard.get(l)!=hCard.get(l+2)&&hCard.get(l+2)!=hCard.get(l+3)&&hCard.get(l+3)==hCard.get(l+4))
    			{
    				twoPair = true;
    			}
    			else
    			{
    				pair = true;
    			}
    		}
     
    		//looks for a flush
    		int check = 0;
    		String k = hSuit.get(0);
    		for(String a : hSuit)
    		{
    			if(a.equalsIgnoreCase(k))
    			{
    				check++;
    			}
    		}
    		if(check==5 && royalFlush == false)
    		{
    			flush = true;
    		}
     
    		//looks for a straight
    		if(hCard.get(1) == (hCard.get(0)+1) && hCard.get(2)== (hCard.get(1)+1) && hCard.get(3) == hCard.get(2)+1 && hCard.get(4) == hCard.get(3)+1)
    		{
    			straight = true;
    		}
    		else if(hCard.contains(1) && hCard.contains(10) && hCard.contains(11) && hCard.contains(12) && hCard.contains(13)&&royalFlush == false)
    		{
    			straight = true;
    		}
    		//if straight and flush are true, then you have a straight flush
    		if(straight == true && flush == true && royalFlush == false)
    		{
    			straightFlush = true;
    			straight = false;
    			flush = false;
    		}
     
    		//looks if anything is one
    		if(royalFlush == true)
    		{
    			System.out.println("HOLY FUCK BALLS, ROYAL FLUSH!!");
    		}
    		if(pair == true)
    		{
    			System.out.println("pair");
    		}
    		if(twoPair == true)
    		{
    			System.out.println("two pair");
    		}
    		if(threeOfAKind == true)
    		{
    			System.out.println("three of a kind");
    		}
    		if(fullHouse == true)
    		{
    			System.out.println("full house");
    		}
    		if(fourOfAKind == true)
    		{
    			System.out.println("four of a kind");
    		}
    		if(flush == true)
    		{
    			System.out.println("flush");
    		}
    		if(straight == true)
    		{
    			System.out.println("straight");
    		}
    		if(straightFlush == true)
    		{
    			System.out.println("straight flush");
    		}
    	}
    }

    Thank you, it works flawlessly now. Would you like the code for the whole game now, as a reward?

  19. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Problem with my poker program

    Glad you got it working.
    No thanks on the code.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #19
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Problem with my poker program

    Alrighty then.

Similar Threads

  1. I'm making a program that recognizes cards say for poker
    By Lurie1 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: February 13th, 2012, 03:44 PM
  2. anyone into poker?
    By KingOfClubs in forum Java Networking
    Replies: 1
    Last Post: May 6th, 2011, 03:45 AM
  3. 2 Player Poker Game Troubles
    By Kaltonse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 21st, 2010, 12:20 PM
  4. help building up GUI for poker game
    By Pencil in forum AWT / Java Swing
    Replies: 5
    Last Post: October 26th, 2010, 02:53 PM
  5. Please help Me out with this poker Problem
    By ckrisasa in forum Java Networking
    Replies: 1
    Last Post: November 29th, 2009, 01:31 AM