aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/decks
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2015-07-13 03:31:02 +0200
committerEduardo Pedroni <ep625@york.ac.uk>2015-07-13 03:31:02 +0200
commit19183986d37c5ca1a31a5b308bace92b87430ffe (patch)
treefc2bf0fc6bed0fa836a8c1401f16d967b639b491 /src/eu/equalparts/cardbase/decks
parente319b8b0790d442d836958df41302af91d750313 (diff)
Added some statistics functionality, TDD
Diffstat (limited to 'src/eu/equalparts/cardbase/decks')
-rw-r--r--src/eu/equalparts/cardbase/decks/Deck.java12
-rw-r--r--src/eu/equalparts/cardbase/decks/ReferenceDeck.java30
-rw-r--r--src/eu/equalparts/cardbase/decks/StandaloneDeck.java12
-rw-r--r--src/eu/equalparts/cardbase/decks/Statistics.java80
4 files changed, 134 insertions, 0 deletions
diff --git a/src/eu/equalparts/cardbase/decks/Deck.java b/src/eu/equalparts/cardbase/decks/Deck.java
new file mode 100644
index 0000000..1f28d60
--- /dev/null
+++ b/src/eu/equalparts/cardbase/decks/Deck.java
@@ -0,0 +1,12 @@
+package eu.equalparts.cardbase.decks;
+
+public abstract class Deck {
+
+ public String name = "Unnamed Deck";
+ public int plains = 0,
+ islands = 0,
+ swamps = 0,
+ mountains = 0,
+ forests = 0;
+
+}
diff --git a/src/eu/equalparts/cardbase/decks/ReferenceDeck.java b/src/eu/equalparts/cardbase/decks/ReferenceDeck.java
new file mode 100644
index 0000000..9e8695b
--- /dev/null
+++ b/src/eu/equalparts/cardbase/decks/ReferenceDeck.java
@@ -0,0 +1,30 @@
+package eu.equalparts.cardbase.decks;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import eu.equalparts.cardbase.cards.Card;
+import eu.equalparts.cardbase.utils.UID;
+
+public class ReferenceDeck extends Deck {
+
+ public Map<String, Integer> cardReferences = new HashMap<String, Integer>();
+
+ public ReferenceDeck() {
+
+ }
+
+ public ReferenceDeck(StandaloneDeck deck) {
+ this.name = deck.name;
+ this.plains = deck.plains;
+ this.islands = deck.islands;
+ this.swamps = deck.swamps;
+ this.mountains = deck.mountains;
+ this.forests = deck.forests;
+
+ for (Card card : deck.cards) {
+ cardReferences.put(UID.makeHash(card), card.count);
+ }
+ }
+
+}
diff --git a/src/eu/equalparts/cardbase/decks/StandaloneDeck.java b/src/eu/equalparts/cardbase/decks/StandaloneDeck.java
new file mode 100644
index 0000000..4c6d25c
--- /dev/null
+++ b/src/eu/equalparts/cardbase/decks/StandaloneDeck.java
@@ -0,0 +1,12 @@
+package eu.equalparts.cardbase.decks;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import eu.equalparts.cardbase.cards.Card;
+
+public class StandaloneDeck extends Deck {
+
+ public Set<Card> cards = new HashSet<Card>();
+
+}
diff --git a/src/eu/equalparts/cardbase/decks/Statistics.java b/src/eu/equalparts/cardbase/decks/Statistics.java
new file mode 100644
index 0000000..9efc82a
--- /dev/null
+++ b/src/eu/equalparts/cardbase/decks/Statistics.java
@@ -0,0 +1,80 @@
+package eu.equalparts.cardbase.decks;
+
+import eu.equalparts.cardbase.cards.Card;
+
+public final class Statistics {
+
+ private Statistics() {}
+
+
+
+ public static double calculatePercentage(StandaloneDeck deck, String type) {
+ double allCardsByType = count(deck, type);
+ double allCards = count(deck);
+ return allCardsByType / allCards;
+ }
+
+ public static int count(StandaloneDeck deck, String type) {
+ int count = type.contains("Land") ? countBasicLands(deck) : 0;
+ for (Card card : deck.cards) {
+ if (card.type != null &&
+ card.type.contains(type)) {
+ count += card.count;
+ }
+ }
+ return count;
+ }
+
+ public static int count(StandaloneDeck deck) {
+ int totalCards = countBasicLands(deck);
+
+ for (Card card : deck.cards) {
+ totalCards += card.count;
+ }
+
+ return totalCards;
+ }
+
+ private static int countBasicLands(StandaloneDeck deck) {
+ return deck.plains +
+ deck.islands +
+ deck.swamps +
+ deck.mountains +
+ deck.forests;
+ }
+
+ public static int[] computeDistribution(StandaloneDeck deck, String type) {
+ int arraySize = 0;
+ for (Card card : deck.cards) {
+ if (card.type != null && card.type.contains(type))
+ if (card.cmc != null && card.cmc >= arraySize)
+ arraySize = card.cmc + 1;
+ }
+
+ int[] costs = new int[arraySize];
+ for (Card card : deck.cards) {
+ if (card.type != null && card.type.contains(type))
+ if (card.cmc != null)
+ costs[card.cmc] += card.count;
+ }
+
+ return costs;
+ }
+
+ public static int[] computeDistribution(StandaloneDeck deck) {
+ int arraySize = 0;
+ for (Card card : deck.cards) {
+ if (card.cmc != null && card.cmc >= arraySize)
+ arraySize = card.cmc + 1;
+ }
+
+ int[] costs = new int[arraySize];
+ for (Card card : deck.cards) {
+ if (card.cmc != null)
+ costs[card.cmc] += card.count;
+ }
+
+ return costs;
+ }
+
+}