How would I deal 13 cards to 4 players? I have my program below, but I'm stuck.
This is my work so far. I'm new to this programming but I'm trying! I know there are a lot of things wrong with this, but bear with me I'm learning.
public class Project_BridgeDeal { static String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; static String[] ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; public static void main(String[] args) { } public static void unwrap(int[] pack) { int[] deck = new int[52]; unwrap(deck); for (int i = 0; i < deck.length; i++) deck[i] = i; } public static void shuffle(int[] pack) { shuffle(deck); for (int i = 0; i < deck.length; i++) { int index = (int)(Math.random() * deck.length); int temp = deck[i]; deck[i] = deck[index]; deck[index] = temp; } } public static int[] deal(int[] pack, int n, int offset) { final int CARDS_PER_HAND = 13; int[] north = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 0); showHand(north, "North was dealt: "); int[] east = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 1); showHand(east, "East was dealt:"); int[] south = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 2); showHand(south, "South was dealt:"); int[] west = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 3); showHand(west, "West was dealt: "); }
I did a program like this before, but without dealing them out.
Here is a sample run of the program:public class ProgramDeck { public static void main(String[] args) { String[] suit = { "Clubs", "Diamonds", "Hearts", "Spades" }; String[] rank = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" }; int SUITS = suit.length; int RANKS = rank.length; int N = SUITS * RANKS; // build the deck String[] deck = new String[N]; for (int i = 0; i < RANKS; i++) for (int j = 0; j < SUITS; j++) deck[SUITS*i + j] = rank[i] + " of " + suit[j]; // shuffle the deck for (int i = 0; i < N; i++) { int r = i + (int) (Math.random() * (N-i)); String t = deck[r]; deck[r] = deck[i]; deck[i] = t; } // print the shuffled deck for (int i = 0; i < N; i++) System.out.println(deck[i]); } }
North was dealt:
2 of Spades
6 of Spades
8 of Spades
2 of Hearts
3 of Hearts
8 of Hearts
10 of Hearts
6 of Diamonds
8 of Diamonds
Queen of Diamonds
King of Diamonds
4 of Clubs
5 of Clubs
East was dealt:
5 of Spades
King of Spades
6 of Hearts
9 of Hearts
Jack of Hearts
Queen of Hearts
Ace of Hearts
2 of Diamonds
4 of Diamonds
10 of Diamonds
Ace of Diamonds
9 of Clubs
Jack of Clubs
South was dealt:
3 of Spades
4 of Spades
9 of Spades
Jack of Spades
Ace of Spades
7 of Hearts
3 of Diamonds
5 of Diamonds
7 of Diamonds
Jack of Diamonds
3 of Clubs
7 of Clubs
King of Clubs
West was dealt:
7 of Spades
10 of Spades
Queen of Spades
4 of Hearts
5 of Hearts
King of Hearts
9 of Diamonds
2 of Clubs
6 of Clubs
8 of Clubs
10 of Clubs
Queen of Clubs
Ace of Clubs