Advertisement
dimipan80

Full House with Jokers

Aug 18th, 2014
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.91 KB | None | 0 0
  1. /* In most Poker games, the "full house" hand is defined as three cards of the same face
  2.  * + two cards of the same face, other than the first, regardless of the card's suits.
  3.  * The cards faces are "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" and "A".
  4.  * The card suits are "♣", "♦", "♥" and "♠".
  5.  * A special card "Joker" (denoted as "*") is used as wildcard
  6.  * and can replace any other card. Jokers do not have a suite.
  7.  * Jokes can be used several times in a hand.
  8.  * Write a program to generate and print all full houses and print their number. */
  9.  
  10. public class _04_FullHouseWithJokers {
  11.  
  12.     private static String[] faceCards = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
  13.  
  14.     private static char[] suitCards = { '\u2663', '\u2666', '\u2665', '\u2660' };
  15.  
  16.     public static void main(String[] args) {
  17.         int countFullHouses = generateAndPrintAllFullHousesFromDeckCardsWithJokers();
  18.         // TODO Auto-generated method stub
  19.         System.out.println();
  20.         System.out.printf("The Number of all these combinations is: %d full houses!%n",
  21.                 countFullHouses);
  22.     }
  23.  
  24.     private static int generateAndPrintAllFullHousesFromDeckCardsWithJokers() {
  25.         int counter = 0;
  26.         System.out.println("The all combinations of generated full houses with Jokers are:");
  27.         int f1, f2, i, j;
  28.         int[] colors;
  29.         for (f1 = 0; f1 < faceCards.length; f1++) {
  30.             for (f2 = 0; f2 < faceCards.length; f2++) {
  31.                 if (f2 != f1) {
  32.                     colors = new int[5];
  33.                     for (colors[0] = 0; colors[0] < suitCards.length; colors[0]++) {
  34.                         for (colors[1] = colors[0] + 1; colors[1] < suitCards.length; colors[1]++) {
  35.                             for (colors[2] = colors[1] + 1; colors[2] < suitCards.length; colors[2]++) {
  36.                                 for (colors[3] = 0; colors[3] < suitCards.length; colors[3]++) {
  37.                                     for (colors[4] = colors[3] + 1; colors[4] < suitCards.length; colors[4]++) {
  38.                                         for (i = 0; i < 8; i++) {
  39.                                             for (j = 0; j < 4; j++) {
  40.                                                 counter++;
  41.                                                 printTheFirst3Cards(f1, i,
  42.                                                         colors);
  43.                                                 printTheLast2Cards(f2, j,
  44.                                                         colors);
  45.                                             }
  46.                                         }
  47.                                     }
  48.                                 }
  49.                             }
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.         return counter;
  56.     }
  57.  
  58.     private static void printTheFirst3Cards(int face1, int left, int[] colors) {
  59.         char joker = '\u002A';
  60.         switch (left) {
  61.         case 0:
  62.             System.out.printf("(%1$s%2$s %1$s%3$s %1$s%4$s ", faceCards[face1],
  63.                     suitCards[colors[0]], suitCards[colors[1]],
  64.                     suitCards[colors[2]]);
  65.             break;
  66.         case 1:
  67.             System.out.printf("(%1$s%2$s %1$s%3$s %4$s ", faceCards[face1],
  68.                     suitCards[colors[0]], suitCards[colors[1]], joker);
  69.             break;
  70.         case 2:
  71.             System.out.printf("(%1$s%2$s %3$s %1$s%4$s ", faceCards[face1],
  72.                     suitCards[colors[0]], joker, suitCards[colors[2]]);
  73.             break;
  74.         case 3:
  75.             System.out.printf("(%1$s %2$s%3$s %2$s%4$s ", joker,
  76.                     faceCards[face1], suitCards[colors[1]],
  77.                     suitCards[colors[2]]);
  78.             break;
  79.         case 4:
  80.             System.out.printf("(%1$s%2$s %3$s %3$s ", faceCards[face1],
  81.                     suitCards[colors[0]], joker);
  82.             break;
  83.         case 5:
  84.             System.out.printf("(%1$s %2$s%3$s %1$s ", joker, faceCards[face1],
  85.                     suitCards[colors[1]]);
  86.             break;
  87.         case 6:
  88.             System.out.printf("(%1$s %1$s %2$s%3$s ", joker, faceCards[face1],
  89.                     suitCards[colors[2]]);
  90.             break;
  91.         case 7:
  92.             System.out.printf("(%1$s %1$s %1$s ", joker);
  93.             break;
  94.         }
  95.     }
  96.  
  97.     private static void printTheLast2Cards(int face2, int right, int[] colors) {
  98.         char joker = '\u002A';
  99.         switch (right) {
  100.         case 0:
  101.             System.out.printf("%1$s%2$s %1$s%3$s) ", faceCards[face2],
  102.                     suitCards[colors[3]], suitCards[colors[4]]);
  103.             break;
  104.         case 1:
  105.             System.out.printf("%1$s%2$s %3$s) ", faceCards[face2],
  106.                     suitCards[colors[3]], joker);
  107.             break;
  108.         case 2:
  109.             System.out.printf("%1$s %2$s%3$s) ", joker, faceCards[face2],
  110.                     suitCards[colors[4]]);
  111.             break;
  112.         case 3:
  113.             System.out.printf("%1$s %1$s) ", joker);
  114.             break;
  115.         }
  116.     }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement