2011-05-21 00:48:40 -07:00
|
|
|
package magic.data;
|
|
|
|
|
|
|
|
import java.io.PrintStream;
|
2011-08-10 08:28:35 -07:00
|
|
|
import java.util.Arrays;
|
2011-05-21 00:48:40 -07:00
|
|
|
import java.util.Collection;
|
2011-06-23 20:29:10 -07:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2020-01-15 12:02:42 -08:00
|
|
|
|
2016-01-29 08:42:11 -08:00
|
|
|
import magic.model.MagicCardDefinition;
|
|
|
|
import magic.model.MagicColor;
|
2016-01-30 04:32:52 -08:00
|
|
|
import magic.model.MagicManaCost;
|
2016-01-29 08:42:11 -08:00
|
|
|
import magic.model.MagicRarity;
|
2016-10-26 01:46:59 -07:00
|
|
|
import magic.translate.MText;
|
2016-01-29 08:42:11 -08:00
|
|
|
|
2011-05-21 00:48:40 -07:00
|
|
|
public class CardStatistics {
|
|
|
|
|
2016-01-29 12:19:44 -08:00
|
|
|
// translatable strings
|
|
|
|
private static final String _S1 = "Land";
|
|
|
|
private static final String _S2 = "Creature";
|
|
|
|
private static final String _S3 = "Artifact";
|
|
|
|
private static final String _S4 = "Enchantment";
|
|
|
|
private static final String _S5 = "Instant";
|
|
|
|
private static final String _S6 = "Sorcery";
|
|
|
|
private static final String _S7 = "Planeswalker";
|
|
|
|
|
|
|
|
|
2015-02-11 15:02:26 -08:00
|
|
|
private static final List<String> MANA_CURVE_TEXT = Collections.unmodifiableList(
|
2015-05-15 17:50:06 -07:00
|
|
|
Arrays.asList(
|
|
|
|
"X", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9+"
|
|
|
|
)
|
2015-02-11 15:02:26 -08:00
|
|
|
);
|
|
|
|
|
2015-02-12 05:38:52 -08:00
|
|
|
public static final List<MagicIcon> MANA_CURVE_ICONS = Collections.unmodifiableList(
|
2015-05-15 17:50:06 -07:00
|
|
|
Arrays.asList(
|
|
|
|
MagicIcon.MANA_X,
|
|
|
|
MagicIcon.MANA_0,
|
|
|
|
MagicIcon.MANA_1,
|
|
|
|
MagicIcon.MANA_2,
|
|
|
|
MagicIcon.MANA_3,
|
|
|
|
MagicIcon.MANA_4,
|
|
|
|
MagicIcon.MANA_5,
|
|
|
|
MagicIcon.MANA_6,
|
|
|
|
MagicIcon.MANA_7,
|
|
|
|
MagicIcon.MANA_8,
|
|
|
|
MagicIcon.MANA_9
|
|
|
|
)
|
2015-02-11 15:02:26 -08:00
|
|
|
);
|
2015-02-11 15:14:23 -08:00
|
|
|
public static final int MANA_CURVE_SIZE = MANA_CURVE_TEXT.size();
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2016-10-26 01:46:59 -07:00
|
|
|
public static final List<String> TYPE_NAMES = Collections.unmodifiableList(Arrays.asList(MText.get(_S1),
|
|
|
|
MText.get(_S2),
|
|
|
|
MText.get(_S3),
|
|
|
|
MText.get(_S4),
|
|
|
|
MText.get(_S5),
|
|
|
|
MText.get(_S6),
|
|
|
|
MText.get(_S7)
|
2015-05-15 17:50:06 -07:00
|
|
|
)
|
2015-02-11 15:02:26 -08:00
|
|
|
);
|
|
|
|
public static final int NR_OF_TYPES = TYPE_NAMES.size();
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2015-02-11 15:02:26 -08:00
|
|
|
public static final List<MagicIcon> TYPE_ICONS = Collections.unmodifiableList(
|
2015-05-15 17:50:06 -07:00
|
|
|
Arrays.asList(
|
|
|
|
MagicIcon.LAND,
|
|
|
|
MagicIcon.CREATURE,
|
2016-01-29 08:42:11 -08:00
|
|
|
MagicIcon.ARTIFACT,
|
2015-05-15 17:50:06 -07:00
|
|
|
MagicIcon.ENCHANTMENT,
|
2016-01-29 08:42:11 -08:00
|
|
|
MagicIcon.INSTANT,
|
|
|
|
MagicIcon.SORCERY,
|
|
|
|
MagicIcon.PLANESWALKER
|
2015-05-15 17:50:06 -07:00
|
|
|
)
|
2015-02-11 15:02:26 -08:00
|
|
|
);
|
2015-12-31 02:54:52 -08:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
private final Collection<MagicCardDefinition> cards;
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-12-04 14:38:55 -08:00
|
|
|
public int totalCards;
|
2012-08-26 01:56:30 -07:00
|
|
|
public final int[] totalTypes=new int[NR_OF_TYPES];
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
private final int[] totalRarity=new int[MagicRarity.length];
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-10-03 01:17:01 -07:00
|
|
|
private double averageCost;
|
|
|
|
private double averageValue;
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
public final int[] colorCount=new int[MagicColor.NR_COLORS];
|
|
|
|
public final int[] colorMono=new int[MagicColor.NR_COLORS];
|
2016-02-16 04:28:21 -08:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
public final int[] colorLands=new int[MagicColor.NR_COLORS];
|
2016-02-16 04:28:21 -08:00
|
|
|
public final int[] colorArtifacts=new int[MagicColor.NR_COLORS];
|
|
|
|
public final int[] colorCreatures=new int[MagicColor.NR_COLORS];
|
|
|
|
public final int[] colorEnchantments=new int[MagicColor.NR_COLORS];
|
|
|
|
public final int[] colorInstants=new int[MagicColor.NR_COLORS];
|
|
|
|
public final int[] colorSorcery=new int[MagicColor.NR_COLORS];
|
|
|
|
public final int[] colorPlaneswalkers=new int[MagicColor.NR_COLORS];
|
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
public final int[] manaCurve=new int[MANA_CURVE_SIZE];
|
2012-10-03 01:17:01 -07:00
|
|
|
public int monoColor;
|
|
|
|
public int multiColor;
|
|
|
|
public int colorless;
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
public CardStatistics(final Collection<MagicCardDefinition> cards) {
|
|
|
|
this.cards=cards;
|
|
|
|
createStatistics();
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
private void createStatistics() {
|
2016-02-16 04:28:21 -08:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
for (final MagicCardDefinition card : cards) {
|
2016-02-16 04:28:21 -08:00
|
|
|
|
2011-11-10 18:54:44 -08:00
|
|
|
//ignore tokens
|
2017-07-11 16:14:19 -07:00
|
|
|
if (card.isToken() || card.isInvalid()) {
|
2011-11-10 18:54:44 -08:00
|
|
|
continue;
|
|
|
|
}
|
2011-11-20 22:51:08 -08:00
|
|
|
|
|
|
|
totalCards++;
|
2012-08-26 01:56:30 -07:00
|
|
|
totalRarity[card.getRarity()]++;
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2016-02-16 04:28:21 -08:00
|
|
|
int count = 0;
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
for (final MagicColor color : MagicColor.values()) {
|
|
|
|
|
|
|
|
if (color.hasColor(card.getColorFlags())) {
|
|
|
|
index = color.ordinal();
|
|
|
|
colorCount[index]++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (card.isLand() && card.getManaSource(color) > 0) {
|
|
|
|
colorLands[color.ordinal()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (card.hasColor(color)) {
|
|
|
|
if (card.isCreature()) {
|
|
|
|
colorCreatures[color.ordinal()]++;
|
|
|
|
}
|
|
|
|
if (card.isArtifact()) {
|
|
|
|
colorArtifacts[color.ordinal()]++;
|
|
|
|
}
|
|
|
|
if (card.isEnchantment()) {
|
|
|
|
colorEnchantments[color.ordinal()]++;
|
|
|
|
}
|
|
|
|
if (card.isInstant()) {
|
|
|
|
colorInstants[color.ordinal()]++;
|
|
|
|
}
|
|
|
|
if (card.isSorcery()) {
|
|
|
|
colorSorcery[color.ordinal()]++;
|
|
|
|
}
|
|
|
|
if (card.isPlaneswalker()) {
|
|
|
|
colorPlaneswalkers[color.ordinal()]++;
|
2012-08-26 01:56:30 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
}
|
2016-01-30 04:32:52 -08:00
|
|
|
}
|
2016-02-16 04:28:21 -08:00
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
colorless++;
|
|
|
|
} else if (count == 1) {
|
|
|
|
colorMono[index]++;
|
|
|
|
monoColor++;
|
|
|
|
} else {
|
|
|
|
multiColor++;
|
|
|
|
}
|
|
|
|
|
2016-01-30 04:32:52 -08:00
|
|
|
if (card.hasX()) {
|
|
|
|
manaCurve[0]++;
|
|
|
|
} else if (card.getCost() != MagicManaCost.NONE) {
|
|
|
|
final int convertedCost = card.getConvertedCost();
|
|
|
|
manaCurve[convertedCost + 1 >= MANA_CURVE_SIZE ? MANA_CURVE_SIZE - 1 : convertedCost + 1]++;
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2016-01-30 04:32:52 -08:00
|
|
|
averageCost += card.getConvertedCost();
|
|
|
|
averageValue += card.getValue();
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2016-02-16 04:28:21 -08:00
|
|
|
if (card.isLand()) {
|
|
|
|
totalTypes[0]++;
|
|
|
|
}
|
2016-01-30 04:32:52 -08:00
|
|
|
if (card.isCreature()) {
|
|
|
|
totalTypes[1]++;
|
|
|
|
}
|
|
|
|
if (card.isArtifact()) {
|
|
|
|
totalTypes[2]++;
|
|
|
|
}
|
|
|
|
if (card.isEnchantment()) {
|
|
|
|
totalTypes[3]++;
|
|
|
|
}
|
|
|
|
if (card.isInstant()) {
|
|
|
|
totalTypes[4]++;
|
|
|
|
}
|
|
|
|
if (card.isSorcery()) {
|
|
|
|
totalTypes[5]++;
|
|
|
|
}
|
|
|
|
if (card.isPlaneswalker()) {
|
|
|
|
totalTypes[6]++;
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
final int total=totalCards-totalTypes[0];
|
|
|
|
if (total>0) {
|
|
|
|
averageValue /= total;
|
|
|
|
averageCost /= total;
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2018-04-07 17:59:14 -07:00
|
|
|
void printStatistics(final PrintStream stream) {
|
2011-05-21 00:48:40 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
stream.print("Cards : "+totalCards);
|
|
|
|
for (int index=0;index<NR_OF_TYPES;index++) {
|
|
|
|
stream.print(" "+TYPE_NAMES.get(index)+" : "+totalTypes[index]);
|
|
|
|
}
|
|
|
|
stream.println();
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
for (int index=0;index<MagicRarity.length;index++) {
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
stream.print(MagicRarity.values()[index].getName() + " : " + totalRarity[index] + " ");
|
|
|
|
}
|
|
|
|
stream.println();
|
|
|
|
stream.printf("Average Cost : %.2f Value : %.2f\n", averageCost, averageValue);
|
|
|
|
stream.println("Monocolor : "+monoColor+" Multicolor : "+multiColor+" Colorless : "+colorless);
|
2011-05-21 00:48:40 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
for (final MagicColor color : MagicColor.values()) {
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
final int index=color.ordinal();
|
|
|
|
stream.print("Color "+color.getName()+" : "+colorCount[index]);
|
|
|
|
stream.print(" Mono : "+colorMono[index]);
|
|
|
|
stream.print(" Lands : "+colorLands[index]);
|
2013-06-23 18:33:35 -07:00
|
|
|
stream.println();
|
|
|
|
}
|
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
for (int index=0;index<MANA_CURVE_SIZE;index++) {
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2012-08-26 01:56:30 -07:00
|
|
|
stream.print(MANA_CURVE_TEXT.get(index)+" = "+manaCurve[index]+" ");
|
|
|
|
}
|
|
|
|
stream.println();
|
|
|
|
}
|
2016-01-29 05:01:45 -08:00
|
|
|
|
|
|
|
public int getMaxManaCurve() {
|
|
|
|
return Arrays.stream(manaCurve).max().orElse(0);
|
|
|
|
}
|
2011-06-05 20:10:51 -07:00
|
|
|
}
|