[rate.plugin] take into account that some cards were printed several times and need to be displayed with the same probability.

This commit is contained in:
magenoxx 2010-12-08 18:01:12 +00:00
parent e45a8ad1e0
commit 50702a026d
2 changed files with 16 additions and 1 deletions

View file

@ -67,7 +67,7 @@ public class RateThread extends Thread {
} }
protected Card getRandomUniqueNonLandCard(Card previousCard) { protected Card getRandomUniqueNonLandCard(Card previousCard) {
int count = CardsStorage.getAllCards().size(); int count = CardsStorage.getUniqueCards().size();
Card card1 = CardsStorage.getAllCards().get((int)(Math.random()*count)); Card card1 = CardsStorage.getAllCards().get((int)(Math.random()*count));
while (card1.getCardType().contains(CardType.LAND) || card1.getName().equals(previousCard)) { while (card1.getCardType().contains(CardType.LAND) || card1.getName().equals(previousCard)) {
card1 = CardsStorage.getAllCards().get((int)(Math.random()*count)); card1 = CardsStorage.getAllCards().get((int)(Math.random()*count));

View file

@ -1,7 +1,9 @@
package org.mage.plugins.rating.cards; package org.mage.plugins.rating.cards;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
@ -9,14 +11,27 @@ import mage.sets.Sets;
public class CardsStorage { public class CardsStorage {
private static List<Card> allCards = new ArrayList<Card>(); private static List<Card> allCards = new ArrayList<Card>();
private static List<Card> uniqueCards = new ArrayList<Card>();
static { static {
for (ExpansionSet set: Sets.getInstance().values()) { for (ExpansionSet set: Sets.getInstance().values()) {
allCards.addAll(set.createCards()); allCards.addAll(set.createCards());
} }
Set<String> names = new HashSet<String>();
for (Card card : allCards) {
if (!names.contains(card.getName())) {
uniqueCards.add(card);
names.add(card.getName());
}
}
System.out.println("cards=" + allCards.size() + ", unique cards=" + uniqueCards.size());
} }
public static List<Card> getAllCards() { public static List<Card> getAllCards() {
return allCards; return allCards;
} }
public static List<Card> getUniqueCards() {
return uniqueCards;
}
} }