Advertisement
Razhagal

FullHouseWithJokers

May 20th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1.  
  2. public class E04FullHouseJokers {
  3.    
  4.     public static void main(String[] args) {
  5.         String[] faces = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
  6.         char[] suits = { '♣', '♦', '♠', '♥' };
  7.         char joker = '*';
  8.        
  9.         int currentFoundIndex = 0;
  10.         String numberAsBinary = "";
  11.        
  12.         String[] currentCards = new String[5];
  13.         String[] tempCards = new String[5];
  14.        
  15.         int counter = 0;
  16.         for (int i = 0; i < faces.length; i++) {
  17.             for (int q = 0; q < faces.length; q++) {
  18.                 if (q == i) {
  19.                     continue;
  20.                 }
  21.                 for (int suit = 0; suit < suits.length; suit++) {
  22.                    
  23.                     for (int suitTriple = 0; suitTriple < 3; suitTriple++) {
  24.                         currentCards[suitTriple] = faces[i] + suits[(suit+suitTriple)%suits.length];
  25.                     }
  26.                    
  27.                     for (int fourthSuit = 0; fourthSuit < suits.length; fourthSuit++) {
  28.                         for (int fifthSuit = fourthSuit + 1; fifthSuit < suits.length; fifthSuit++) {
  29.                             currentCards[3] = faces[q] + suits[fourthSuit];
  30.                             currentCards[4] = faces[q] + suits[fifthSuit];
  31.                            
  32.                             for (int j = 0; j < 32; j++) {
  33.                                 tempCards = currentCards.clone(); // save current hand
  34.                                 numberAsBinary = Integer.toBinaryString(j);
  35.                                 currentFoundIndex = numberAsBinary.indexOf('1');
  36.                                 while(currentFoundIndex != -1) {
  37.                                     currentCards[numberAsBinary.length() - 1 - currentFoundIndex] =
  38.                                             Character.toString(joker);
  39.                                     currentFoundIndex = numberAsBinary.
  40.                                             indexOf('1', currentFoundIndex + 1);
  41.                                 }
  42.                                
  43.                                 counter++;
  44.                                 printCards(currentCards);
  45.                                 currentCards = tempCards;
  46.                             }
  47.                         }
  48.                     }
  49.                 }
  50.             }
  51.         }
  52.         System.out.println(counter + " full houses");
  53.     }
  54.  
  55.     public static void printCards(String[] cards) {
  56.         System.out.print("(");
  57.        
  58.         for (int i = 0; i < cards.length; i++) {
  59.             if (i != 0) System.out.print(' '); // better formatting
  60.             System.out.print(cards[i]);
  61.         }
  62.        
  63.         System.out.println(')');
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement