Esempio n. 1
0
 public Deck() {
   for (Card.Suit suit : Card.Suit.values()) {
     for (Card.Rank rank : Card.Rank.values()) {
       cards.add(new Card(rank, suit));
     }
   }
 }
Esempio n. 2
0
	/**
	 * Clear deck and initialize it with 52 * NUM_DECKS new cards. 
	 */
	private void initializeDeck() {
		deck.clear();
		
		for(int i = 0; i < NUM_DECKS; i++)
		{
			for(Card.Rank rank: Card.Rank.values()) {
				for(Card.Suit suit: Card.Suit.values()) {
					deck.add(new Card(rank, suit));
				}
			}
		}

		Collections.shuffle(deck, new Random());		
	}
Esempio n. 3
0
  @Override
  public void create(int numberOfSuits, int numberOfRanks) {
    this.numberOfRanks = numberOfRanks;
    this.numberOfSuits = numberOfSuits;
    logger.info(
        format("*** Creating Deck with %s suits and %s ranks ***", numberOfSuits, numberOfRanks));

    List<Card.Suit> suits = Arrays.asList(Card.Suit.values()).subList(0, numberOfSuits);
    List<Card.Rank> ranks = Arrays.asList(Card.Rank.values()).subList(0, numberOfRanks);
    cards =
        suits
            .stream()
            .flatMap(suit -> ranks.stream().map(rank -> new Card(rank, suit)))
            .collect(toList());
  }