Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Arrays;
- public class Main
- {
- public static void main(String[] args) {
- int[] playerCards = {2, 2, 3, 3, 4};
- int[] playerSuits = new int[5];
- String[] suits = { "Spades", "Clubs", "Hearts", "Diamonds" };
- String[] cards = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
- Random rand = new Random();
- for(int i = 0; i < playerCards.length; i++)
- {
- int randomCard = rand.nextInt(13) + 2;
- int randomSuit = rand.nextInt(4) + 1;
- // playerCards[i] = randomCard;
- playerSuits[i] = randomSuit;
- }
- Arrays.sort(playerCards);
- Arrays.sort(playerSuits);
- int highestCard = 0;
- boolean isSuitAllSame = false;
- boolean isRoyalFlush = false;
- boolean isStraightFlush = false;
- boolean isFlush = false;
- boolean isStraight = false;
- int pairs = 0;
- boolean isThree = false;
- boolean isFour = false;
- //--------------------------------------------------
- int firstSuit = playerSuits[0];
- int k;
- for(k = 0; k < playerSuits.length; k++)
- {
- if(firstSuit != playerSuits[k])
- {
- break;
- }
- }
- if(k == playerSuits.length) isSuitAllSame = true;
- int[] temp = new int[5];
- int tempCount = 0;
- for(int i = 0; i < playerCards.length; i++)
- {
- if(playerCards[i] >= 10 && playerCards[i] <= 14)
- {
- for(int j = 0; j < temp.length; j++)
- {
- if(temp[j] == 0)
- {
- temp[j] = playerCards[i];
- tempCount++;
- break;
- }
- if(temp[j] == playerCards[i])
- break;
- }
- }
- }
- if(tempCount == 5 && isSuitAllSame)
- {
- isRoyalFlush = true;
- }
- else
- {
- int l;
- for(l = 0; l < playerCards.length; l++)
- {
- if(l != (playerCards.length - 1) && playerCards[l] != playerCards[l + 1] - 1)
- {
- break;
- }
- }
- if(l == playerCards.length)
- {
- if(isSuitAllSame)
- isStraightFlush = true;
- else
- isStraight = true;
- }
- else if(isSuitAllSame)
- {
- isFlush = true;
- }
- else
- {
- int highestCardCount = 0;
- int currentRank = playerCards[0];
- for(int i = 0; i < playerCards.length; i++)
- {
- if(playerCards[i] == currentRank)
- {
- highestCardCount++;
- if(highestCardCount == 2)
- {
- pairs++;
- }
- else if(highestCardCount == 3)
- {
- isThree = true;
- pairs--;
- }
- else if(highestCardCount == 4)
- {
- isThree = false;
- pairs = 0;
- isFour = true;
- break;
- }
- }
- else
- {
- currentRank = playerCards[i];
- highestCardCount = 1;
- }
- }
- }
- }
- //----------------------------------------------------
- if(!isSuitAllSame && !isStraight && pairs == 0 && !isThree && !isFour)
- {
- for(int i = 0; i < playerCards.length; i++)
- {
- if(playerCards[i] > highestCard)
- {
- highestCard = playerCards[i];
- }
- }
- }
- for(int i = 0; i < playerCards.length; i++)
- {
- String printedRank = cards[playerCards[i] - 2];
- String printedSuit = suits[playerSuits[i] - 1];
- System.out.println(printedRank + " of " + printedSuit);
- }
- System.out.println();
- if(isRoyalFlush)
- {
- System.out.println("It's a royal flush!");
- }
- else if(isStraightFlush)
- {
- System.out.println("It's a straight flush!");
- }
- else if(isFour)
- {
- System.out.println("It's a four of a kind!");
- }
- else if(isThree && pairs == 1)
- {
- System.out.println("It's a full house!");
- }
- else if(isStraight)
- {
- System.out.println("It's a straight!");
- }
- else if(isThree)
- {
- System.out.println("It's a three of a kind!");
- }
- else if(pairs == 2)
- {
- System.out.println("It's two pairs!");
- }
- else if(pairs == 1)
- {
- System.out.println("It's a pair!");
- }
- else
- {
- String printedHighCard = cards[highestCard - 2];
- System.out.println("High card is a(n) " + printedHighCard);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement