public double getDraftValue(Deck d) {
      double value = 0;
      double divider = 0;

      if (d.getMain().isEmpty()) {
        return 0;
      }

      double best = 1.0;

      for (Entry<PaperCard, Integer> kv : d.getMain()) {
        PaperCard evalCard = kv.getKey();
        int count = kv.getValue();
        if (DraftRankCache.getRanking(evalCard.getName(), evalCard.getEdition()) != null) {
          double add = DraftRankCache.getRanking(evalCard.getName(), evalCard.getEdition());
          // System.out.println(evalCard.getName() + " is worth " + add);
          value += add * count;
          divider += count;
          if (best > add) {
            best = add;
          }
        }
      }

      if (divider == 0 || value == 0) {
        return 0;
      }

      value /= divider;

      return (20.0 / (best + (2 * value)));
    }
Exemple #2
0
  // NOTE: ART indices are "1" -based
  public void add(String cardName, String setCode, final int artIndex, final int amount) {
    PaperCard cp = StaticData.instance().getCommonCards().getCard(cardName, setCode, artIndex);
    boolean isCommonCard = cp != null;
    if (!isCommonCard) {
      cp = StaticData.instance().getVariantCards().getCard(cardName, setCode);
    }

    boolean artIndexExplicitlySet =
        artIndex > 0
            || Character.isDigit(cardName.charAt(cardName.length() - 1))
                && cardName.charAt(cardName.length() - 2) == CardDb.NameSetSeparator;
    int artCount = 1;

    if (cp != null) {
      setCode = cp.getEdition();
      cardName = cp.getName();
      artCount =
          isCommonCard ? StaticData.instance().getCommonCards().getArtCount(cardName, setCode) : 1;
    } else {
      cp = StaticData.instance().getCommonCards().createUnsuportedCard(cardName);
    }

    if (artIndexExplicitlySet || artCount <= 1) {
      // either a specific art index is specified, or there is only one art, so just add the card
      this.add(cp, amount);
    } else {
      // random art index specified, make sure we get different groups of cards with different art
      int[] artGroups = MyRandom.splitIntoRandomGroups(amount, artCount);
      for (int i = 1; i <= artGroups.length; i++) {
        int cnt = artGroups[i - 1];
        if (cnt <= 0) continue;
        PaperCard cp_random =
            isCommonCard
                ? StaticData.instance().getCommonCards().getCard(cardName, setCode, i)
                : StaticData.instance().getVariantCards().getCard(cardName, setCode, i);
        this.add(cp_random, cnt);
      }
    }
  }