Пример #1
0
 public static Suit fromIndex(int index) {
   return Suit.values()[index];
 }
Пример #2
0
 static {
   for (Suit s : Suit.values()) {
     sMap.put(s.ordinal(), s);
   }
 }
Пример #3
0
  private void addCode(String code) {
    List<HoleCards> ret = Lists.newArrayList();

    Preconditions.checkArgument(code.length() >= 2 && code.length() <= 7, code);

    if (exact.matcher(code).matches()) {
      HoleCards hc =
          new HoleCards(Card.parseCard(code.substring(0, 2)), Card.parseCard(code.substring(2, 4)));
      ret.add(hc);
      return;
    }

    Matcher plusMatch = plusPat.matcher(code);

    SingleCode start = null;
    SingleCode stop = null;

    if (plusMatch.matches()) {
      start = parseSingleCode(plusMatch.group(1));
      stop = new SingleCode(start);

      boolean toEnd = code.charAt(code.length() - 1) == '+';

      if (toEnd) {
        if (start.rankGrand == start.rankPetit) {
          stop.rankPetit = CardRank.ACE;
          stop.rankGrand = CardRank.ACE;

        } else {
          stop.rankPetit = CardRank.getFromZeroBasedValue(start.rankGrand.getIndex() - 1);
        }
      }
    }

    Matcher begStopMatch = begStopPat.matcher(code);

    if (begStopMatch.matches()) {
      start = parseSingleCode(begStopMatch.group(1));
      stop = parseSingleCode(begStopMatch.group(2));

      // Vérifier que la fin est plus grande que le début
      if (start.rankPetit.getIndex() > stop.rankPetit.getIndex()) {
        SingleCode tmp = stop;
        stop = start;
        start = tmp;
      }
    }

    Preconditions.checkNotNull(stop, code);

    CardRank rank1 = start.rankGrand;
    CardRank rank2 = start.rankPetit;

    // pairs
    if (rank1 == rank2) {

      CardRank toRank = stop.rankGrand;

      for (int rankIndex = rank1.getIndex(); rankIndex <= toRank.getIndex(); ++rankIndex) {
        CardRank rank = CardRank.getFromZeroBasedValue(rankIndex);

        Suit suit1;
        Suit suit2;
        for (int i = 0; i < 4; ++i) {
          suit1 = Suit.fromIndex(i);
          for (int j = i + 1; j < 4; ++j) {
            suit2 = Suit.fromIndex(j);

            ret.add(new HoleCards(Card.getCard(suit1, rank), Card.getCard(suit2, rank)));
          }
        }
      }
    } else {
      boolean suited = start.suited;
      boolean unSuited = start.unsuited;

      Preconditions.checkState(rank1.getIndex() > rank2.getIndex());

      int toRank2Index = stop.rankPetit.getIndex();

      for (int rankIndex = rank2.getIndex(); rankIndex <= toRank2Index; ++rankIndex) {
        CardRank rank = CardRank.getFromZeroBasedValue(rankIndex);
        Preconditions.checkNotNull(rank, code + "r index " + rankIndex);

        Suit suit1;
        Suit suit2;
        for (int i = 0; i < 4; ++i) {
          suit1 = Suit.fromIndex(i);

          if (suited) {
            suit2 = Suit.fromIndex(i);
            ret.add(new HoleCards(Card.getCard(suit1, rank1), Card.getCard(suit2, rank)));
          }

          if (unSuited) {
            for (int j = 0; j < 4; ++j) {
              // We only want unsuited
              if (unSuited && j == i) continue;
              suit2 = Suit.fromIndex(j);

              ret.add(new HoleCards(Card.getCard(suit1, rank1), Card.getCard(suit2, rank)));
            }
          }
        }
      }
    }

    for (HoleCards hc : ret) {
      Preconditions.checkState(!cards.contains(hc), hc.toString() + "  " + this.toString());
      cards.add(hc);
      cardsList.add(hc);

      ++totalHands;

      if (hc.getHigherRank() != hc.getLowerRank()) {
        this.rankFreq[hc.getHigherRank().getIndex()]++;
        this.rankFreq[hc.getLowerRank().getIndex()]++;
      } else {
        this.rankFreq[hc.getHigherRank().getIndex()]++;
      }
      // log.debug("hc {} {} {}", hc.getCards(), hc.getCards()[0].index, hc.getCards()[1].index);

    }
  }