Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* In most Poker games, the "full house" hand is defined as three cards of the same face
- * + two cards of the same face, other than the first, regardless of the card's suits.
- * The cards faces are "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" and "A".
- * The card suits are "♣", "♦", "♥" and "♠".
- * A special card "Joker" (denoted as "*") is used as wildcard
- * and can replace any other card. Jokers do not have a suite.
- * Jokes can be used several times in a hand.
- * Write a program to generate and print all full houses and print their number. */
- public class _04_FullHouseWithJokers {
- private static String[] faceCards = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
- private static char[] suitCards = { '\u2663', '\u2666', '\u2665', '\u2660' };
- public static void main(String[] args) {
- int countFullHouses = generateAndPrintAllFullHousesFromDeckCardsWithJokers();
- // TODO Auto-generated method stub
- System.out.println();
- System.out.printf("The Number of all these combinations is: %d full houses!%n",
- countFullHouses);
- }
- private static int generateAndPrintAllFullHousesFromDeckCardsWithJokers() {
- int counter = 0;
- System.out.println("The all combinations of generated full houses with Jokers are:");
- int f1, f2, i, j;
- int[] colors;
- for (f1 = 0; f1 < faceCards.length; f1++) {
- for (f2 = 0; f2 < faceCards.length; f2++) {
- if (f2 != f1) {
- colors = new int[5];
- for (colors[0] = 0; colors[0] < suitCards.length; colors[0]++) {
- for (colors[1] = colors[0] + 1; colors[1] < suitCards.length; colors[1]++) {
- for (colors[2] = colors[1] + 1; colors[2] < suitCards.length; colors[2]++) {
- for (colors[3] = 0; colors[3] < suitCards.length; colors[3]++) {
- for (colors[4] = colors[3] + 1; colors[4] < suitCards.length; colors[4]++) {
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 4; j++) {
- counter++;
- printTheFirst3Cards(f1, i,
- colors);
- printTheLast2Cards(f2, j,
- colors);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return counter;
- }
- private static void printTheFirst3Cards(int face1, int left, int[] colors) {
- char joker = '\u002A';
- switch (left) {
- case 0:
- System.out.printf("(%1$s%2$s %1$s%3$s %1$s%4$s ", faceCards[face1],
- suitCards[colors[0]], suitCards[colors[1]],
- suitCards[colors[2]]);
- break;
- case 1:
- System.out.printf("(%1$s%2$s %1$s%3$s %4$s ", faceCards[face1],
- suitCards[colors[0]], suitCards[colors[1]], joker);
- break;
- case 2:
- System.out.printf("(%1$s%2$s %3$s %1$s%4$s ", faceCards[face1],
- suitCards[colors[0]], joker, suitCards[colors[2]]);
- break;
- case 3:
- System.out.printf("(%1$s %2$s%3$s %2$s%4$s ", joker,
- faceCards[face1], suitCards[colors[1]],
- suitCards[colors[2]]);
- break;
- case 4:
- System.out.printf("(%1$s%2$s %3$s %3$s ", faceCards[face1],
- suitCards[colors[0]], joker);
- break;
- case 5:
- System.out.printf("(%1$s %2$s%3$s %1$s ", joker, faceCards[face1],
- suitCards[colors[1]]);
- break;
- case 6:
- System.out.printf("(%1$s %1$s %2$s%3$s ", joker, faceCards[face1],
- suitCards[colors[2]]);
- break;
- case 7:
- System.out.printf("(%1$s %1$s %1$s ", joker);
- break;
- }
- }
- private static void printTheLast2Cards(int face2, int right, int[] colors) {
- char joker = '\u002A';
- switch (right) {
- case 0:
- System.out.printf("%1$s%2$s %1$s%3$s) ", faceCards[face2],
- suitCards[colors[3]], suitCards[colors[4]]);
- break;
- case 1:
- System.out.printf("%1$s%2$s %3$s) ", faceCards[face2],
- suitCards[colors[3]], joker);
- break;
- case 2:
- System.out.printf("%1$s %2$s%3$s) ", joker, faceCards[face2],
- suitCards[colors[4]]);
- break;
- case 3:
- System.out.printf("%1$s %1$s) ", joker);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement