Esempio n. 1
0
  private IHand generateRandomPair(StandardDeckFactory deckFactory) {
    SortedHand randomHand = new SortedHand();

    ArrayList<Card> cards = pickNRandomDifferentCards(4);

    IDeck deck = deckFactory.build();
    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    builder.add(deck.pickRandom(cards.get(0).rank()));
    builder.add(deck.pickRandom(cards.get(0).rank()));
    builder.add(cards.get(1));
    builder.add(cards.get(2));
    builder.add(cards.get(3));

    return new SortedHand(builder.build());
  }
Esempio n. 2
0
  private IHand generateRandomFourOfAKind(StandardDeckFactory deckFactory) {

    SortedHand randomHand = new SortedHand();

    Rank randomRank = Rank.getRandomRank();

    IDeck deck = deckFactory.build();
    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    builder.add(deck.pickRandom(randomRank));
    builder.add(deck.pickRandom(randomRank));
    builder.add(deck.pickRandom(randomRank));
    builder.add(deck.pickRandom(randomRank));
    builder.add(deck.dealTopCard());

    return new SortedHand(builder.build());
  }
Esempio n. 3
0
  private IHand generateRandomFullHouse(StandardDeckFactory deckFactory) {

    SortedHand randomHand = new SortedHand();

    Rank randomTrips = Rank.getRandomRank();
    Rank randomPair = null;
    while ((randomPair = Rank.getRandomRank()) == randomTrips) {}

    IDeck deck = deckFactory.build();
    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    builder.add(deck.pickRandom(randomTrips));
    builder.add(deck.pickRandom(randomTrips));
    builder.add(deck.pickRandom(randomTrips));
    builder.add(deck.pickRandom(randomPair));
    builder.add(deck.pickRandom(randomPair));

    return new SortedHand(builder.build());
  }