optimized formats calculation for decks,

added some comments to deckmanagers
This commit is contained in:
Maxmtg
2014-01-24 06:55:38 +00:00
parent 7c105ca398
commit 34b36a8ef2
3 changed files with 29 additions and 31 deletions

View File

@@ -170,14 +170,7 @@ public class GameFormat implements Comparable<GameFormat> {
return this.allowedSetCodes_ro.isEmpty() || this.allowedSetCodes_ro.contains(setCode);
}
public boolean isDeckLegal(final Deck deck) {
CardPool allCards = new CardPool(); // will count cards in this pool to enforce restricted
allCards.addAll(deck.getMain());
if (deck.has(DeckSection.Sideboard))
allCards.addAll(deck.get(DeckSection.Sideboard));
if (deck.has(DeckSection.Commander))
allCards.addAll(deck.get(DeckSection.Commander));
private boolean isPoolLegal(final CardPool allCards) {
for (Entry<PaperCard, Integer> poolEntry : allCards) {
if (!filterRules.apply(poolEntry.getKey())) {
return false; //all cards in deck must pass card predicate to pass deck predicate
@@ -192,6 +185,20 @@ public class GameFormat implements Comparable<GameFormat> {
}
return true;
}
private static CardPool getAllDecksCards(final Deck deck) {
CardPool allCards = new CardPool(); // will count cards in this pool to enforce restricted
allCards.addAll(deck.getMain());
if (deck.has(DeckSection.Sideboard))
allCards.addAll(deck.get(DeckSection.Sideboard));
if (deck.has(DeckSection.Commander))
allCards.addAll(deck.get(DeckSection.Commander));
return allCards;
}
public boolean isDeckLegal(final Deck deck) {
return isPoolLegal(getAllDecksCards(deck));
}
/*
* (non-Javadoc)
@@ -297,8 +304,9 @@ public class GameFormat implements Comparable<GameFormat> {
public Iterable<GameFormat> getAllFormatsOfDeck(Deck deck) {
List<GameFormat> result = new ArrayList<GameFormat>();
CardPool allCards = GameFormat.getAllDecksCards(deck);
for(GameFormat gf : naturallyOrdered) {
if (gf.isDeckLegal(deck))
if (gf.isPoolLegal(allCards))
result.add(gf);
}
if( result.isEmpty())