package oving3.card;

import java.util.ArrayList;

public class CardDeck {
	private ArrayList<Card> deck = new ArrayList<>();

	CardDeck(int n) {
		if (n < 0 || n > 13) {
			throw new IllegalArgumentException("value of n needs to be >= 1 and <= 13");
		}
		char[] suits = { 'S', 'H', 'D', 'C' };
		for (char suit : suits) {
			for (int face = 1; face <= n; face++) {
				deck.add(new Card(suit, face));
			}
		}
	}

	int getCardCount() {
		return deck.size();
	}

	Card getCard(int n) {
		return new Card('S', 1);
	}

	void shufflePerfectly() {
		int n = deck.size();
		if (n < 2) {
			return;
		}
		ArrayList<Card> shuffledDeck = new ArrayList<>();
		for (int i = 0; i < n / 2; i++) {
			shuffledDeck.add(deck.get(i));
			shuffledDeck.add(deck.get(n / 2 + i));
		}
		if (n % 2 != 0) {
			shuffledDeck.add(deck.get(n - 1));
		}
		deck = shuffledDeck;
	}
}
