Refactor set's legality

This commit is contained in:
Oleg Agafonov 2019-03-04 02:31:51 +04:00
parent 106a5d94b2
commit 8df43cfbb6
8 changed files with 110 additions and 150 deletions

View file

@ -1,17 +1,13 @@
package mage.deck;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.SetType;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Extended extends Constructed {
@ -22,13 +18,11 @@ public class Extended extends Constructed {
GregorianCalendar cutoff;
if (current.get(Calendar.MONTH) > 9) {
cutoff = new GregorianCalendar(current.get(Calendar.YEAR) - 3, Calendar.SEPTEMBER, 1);
}
else {
} else {
cutoff = new GregorianCalendar(current.get(Calendar.YEAR) - 4, Calendar.SEPTEMBER, 1);
}
for (ExpansionSet set: Sets.getInstance().values()) {
if (set.getReleaseDate().after(cutoff.getTime()) &&
(set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION)) {
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.isStandardLegal() && set.getReleaseDate().after(cutoff.getTime())) {
setCodes.add(set.getCode());
}
}
@ -38,6 +32,6 @@ public class Extended extends Constructed {
banned.add("Ponder");
banned.add("Preordain");
banned.add("Stoneforge Mystic");
}
}

View file

@ -1,15 +1,13 @@
package mage.deck;
import java.util.Date;
import java.util.GregorianCalendar;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.SetType;
import java.util.Date;
import java.util.GregorianCalendar;
/**
*
* @author fireshoes
*/
public class Frontier extends Constructed {
@ -19,8 +17,7 @@ public class Frontier extends Constructed {
Date cutoff = new GregorianCalendar(2014, 6, 18).getTime(); // M15 release date
for (ExpansionSet set : Sets.getInstance().values()) {
if ((set.getReleaseDate().after(cutoff) || set.getReleaseDate().equals(cutoff))
&& (set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION)) {
if (set.isStandardLegal() && (set.getReleaseDate().after(cutoff) || set.getReleaseDate().equals(cutoff))) {
setCodes.add(set.getCode());
}
}

View file

@ -1,24 +1,19 @@
package mage.deck;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.cards.decks.Deck;
import mage.constants.SetType;
import java.util.*;
/**
* This class represents a deck from any past standard.
*
* <p>
* This class was originally made to work with the historical standard ruleset.
* Data taken from http://thattournament.website/historic-tournament.php (site
* changed, originally http://mtgt.nfshost.com/historic-tournament.php)
*
* <p>
* If there are any questions or corrections, feel free to contact me.
*
* @author Marthinwurer (at gmail.com)
@ -30,54 +25,54 @@ public class HistoricalType2 extends Constructed {
* Kamigawa/Ravnica standard, where rotation stabilized.
*/
protected static final String[][] standards = {
// 1st standard: The Dark, Fallen Empires, and 4th.
{"DRK", "FEM", "4ED"},
// 2nd standard: 4th, Fallen Empires, Ice Age, Chronicles, Homelands,
// Alliances, and Mirage.
{"FEM", "4ED", "ICE", "CHR", "HML", "ALL", "MIR"},
// 3rd standard: 4th, Chronicles, Alliances, Mirage, Visions.
{"4ED", "CHR", "ALL", "MIR", "VIS"},
// 4th Standard: Ice Age, Homelands, Alliances, Mirage, Visions, 5th,
// and Weatherlight.
{"ICE", "HML", "ALL", "MIR", "VIS", "5ED", "WTH"},
// 5th Standard: Mirage, Visions, 5th, Weatherlight, Tempest,
// Stronghold, and Exodus.
{"MIR", "VIS", "5ED", "WTH", "TMP", "STH", "EXO"},
// 6th Standard: 5th, Tempest, Stronghold, Exodus, Urza's Saga, Urza's
// Legacy, Urza's Destiny.
{"5ED", "TMP", "STH", "EXO", "USG", "ULG"},
// 7th Standard: Tempest, Stronghold, Exodus, Urza's Saga, Urza's
// Legacy, 6th, Urza's Destiny.
{"TMP", "STH", "EXO", "USG", "ULG", "6ED", "UDS"},
// 8th Standard: Urza's Saga, Urza's Legacy, 6th, Urza's Destiny,
// Mercadian Masques, Nemesis, Prophecy.
{"USG", "ULG", "6ED", "UDS", "MMQ", "NEM", "PCY"},
// 9th Standard
{"6ED", "MMQ", "NEM", "PCY", "INV", "PLS"},
// 10th Standard
{"7ED", "MMQ", "NEM", "PCY", "INV", "PLS", "APC"},
// 11th Standard
{"7ED", "INV", "APC", "PLS", "ODY", "TOR", "JUD"},
// 12th Standard
{"7ED", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG"},
// 13th Standard
{"8ED", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG"},
// 14th Standard
{"8ED", "ONS", "LGN", "SCG", "MRD", "DST", "5DN"},
// 15th Standard
{"8ED", "MRD", "DST", "5DN", "CHK", "BOK", "SOK"},
// 16th Standard
{"9ED", "MRD", "DST", "5DN", "CHK", "BOK", "SOK"},
// 17th Standard
{"9ED", "CHK", "BOK", "SOK", "RAV", "GPT", "DIS", "CSP"},
// 18th Standard
{"9ED", "RAV", "GPT", "DIS", "CSP", "TSP", "TSB", "PLC", "FUT"},
// 19th Standard
{"10E", "RAV", "GPT", "DIS", "CSP", "TSP", "TSB", "PLC", "FUT"},
// 20th Standard
{"10E", "CSP", "TSP", "TSB", "PLC", "FUT", "LRW", "MOR", "SHM", "EVE"},
// 21st Standard
{"10E", "LRW", "MOR", "SHM", "EVE", "ALA", "CON", "ARB"}
// 1st standard: The Dark, Fallen Empires, and 4th.
{"DRK", "FEM", "4ED"},
// 2nd standard: 4th, Fallen Empires, Ice Age, Chronicles, Homelands,
// Alliances, and Mirage.
{"FEM", "4ED", "ICE", "CHR", "HML", "ALL", "MIR"},
// 3rd standard: 4th, Chronicles, Alliances, Mirage, Visions.
{"4ED", "CHR", "ALL", "MIR", "VIS"},
// 4th Standard: Ice Age, Homelands, Alliances, Mirage, Visions, 5th,
// and Weatherlight.
{"ICE", "HML", "ALL", "MIR", "VIS", "5ED", "WTH"},
// 5th Standard: Mirage, Visions, 5th, Weatherlight, Tempest,
// Stronghold, and Exodus.
{"MIR", "VIS", "5ED", "WTH", "TMP", "STH", "EXO"},
// 6th Standard: 5th, Tempest, Stronghold, Exodus, Urza's Saga, Urza's
// Legacy, Urza's Destiny.
{"5ED", "TMP", "STH", "EXO", "USG", "ULG"},
// 7th Standard: Tempest, Stronghold, Exodus, Urza's Saga, Urza's
// Legacy, 6th, Urza's Destiny.
{"TMP", "STH", "EXO", "USG", "ULG", "6ED", "UDS"},
// 8th Standard: Urza's Saga, Urza's Legacy, 6th, Urza's Destiny,
// Mercadian Masques, Nemesis, Prophecy.
{"USG", "ULG", "6ED", "UDS", "MMQ", "NEM", "PCY"},
// 9th Standard
{"6ED", "MMQ", "NEM", "PCY", "INV", "PLS"},
// 10th Standard
{"7ED", "MMQ", "NEM", "PCY", "INV", "PLS", "APC"},
// 11th Standard
{"7ED", "INV", "APC", "PLS", "ODY", "TOR", "JUD"},
// 12th Standard
{"7ED", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG"},
// 13th Standard
{"8ED", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG"},
// 14th Standard
{"8ED", "ONS", "LGN", "SCG", "MRD", "DST", "5DN"},
// 15th Standard
{"8ED", "MRD", "DST", "5DN", "CHK", "BOK", "SOK"},
// 16th Standard
{"9ED", "MRD", "DST", "5DN", "CHK", "BOK", "SOK"},
// 17th Standard
{"9ED", "CHK", "BOK", "SOK", "RAV", "GPT", "DIS", "CSP"},
// 18th Standard
{"9ED", "RAV", "GPT", "DIS", "CSP", "TSP", "TSB", "PLC", "FUT"},
// 19th Standard
{"10E", "RAV", "GPT", "DIS", "CSP", "TSP", "TSB", "PLC", "FUT"},
// 20th Standard
{"10E", "CSP", "TSP", "TSB", "PLC", "FUT", "LRW", "MOR", "SHM", "EVE"},
// 21st Standard
{"10E", "LRW", "MOR", "SHM", "EVE", "ALA", "CON", "ARB"}
};
/**
@ -109,15 +104,6 @@ public class HistoricalType2 extends Constructed {
@Override
public boolean validate(Deck deck) {
// debug code for finding set info
// System.out.println();
// for (ExpansionSet set : Sets.getInstance().values()) {
// if (set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION) {
// System.out.println("Set:\t" + set.getCode() + "\t" + set.getReleaseDate() + "\t" + set.getName() + "\t" + set.getBlockName());
// }
// }
Map<String, String> leastInvalid = null;
boolean valid = false;
@ -187,9 +173,8 @@ public class HistoricalType2 extends Constructed {
// Get the sets in that time period.
// (code taken from standard.java)
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getReleaseDate().after(start.getTime())
&& set.getReleaseDate().before(end.getTime())
&& (set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION)) {
if (set.isStandardLegal() && set.getReleaseDate().after(start.getTime())
&& set.getReleaseDate().before(end.getTime())) {
setCodes.add(set.getCode());
}
}

View file

@ -1,10 +1,8 @@
package mage.deck;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.SetType;
import java.util.Date;
import java.util.GregorianCalendar;
@ -19,8 +17,7 @@ public class Modern extends Constructed {
Date cutoff = new GregorianCalendar(2003, 6, 28).getTime(); // Eight edition release date
for (ExpansionSet set : Sets.getInstance().values()) {
if ((set.getReleaseDate().after(cutoff) || set.getReleaseDate().equals(cutoff))
&& (set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION)) {
if (set.isStandardLegal() && (set.getReleaseDate().after(cutoff) || set.getReleaseDate().equals(cutoff))) {
setCodes.add(set.getCode());
}
}

View file

@ -1,17 +1,13 @@
package mage.deck;
import java.util.Date;
import java.util.GregorianCalendar;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.SetType;
import java.util.Date;
import java.util.GregorianCalendar;
/**
*
* @author LevelX2
*/
public class ModernNoBannedList extends Constructed {
@ -21,8 +17,8 @@ public class ModernNoBannedList extends Constructed {
Date cutoff = new GregorianCalendar(2003, 6, 28).getTime(); // Eight edition release date
for (ExpansionSet set : Sets.getInstance().values()) {
if ((set.getReleaseDate().after(cutoff) || set.getReleaseDate().equals(cutoff))
&& (set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION)) {
if (set.isStandardLegal()
&& (set.getReleaseDate().after(cutoff) || set.getReleaseDate().equals(cutoff))) {
setCodes.add(set.getCode());
}
}

View file

@ -24,8 +24,7 @@ public class Standard extends Constructed {
Calendar cal = Calendar.getInstance();
cal.setTime(set.getReleaseDate());
// Fall sets are normally released during or after September
return set.getSetType() == SetType.EXPANSION
&& (cal.get(Calendar.MONTH) > 7);
return set.getSetType() == SetType.EXPANSION && (cal.get(Calendar.MONTH) > 7);
}
public static List<String> makeLegalSets() {
@ -53,13 +52,10 @@ public class Standard extends Constructed {
}
}
}
// Get all sets released on or after the second most recent fall set's release
for (ExpansionSet set : sets) {
if ((set.getSetType() == SetType.CORE
|| set.getSetType() == SetType.EXPANSION
|| set.getSetType() == SetType.SUPPLEMENTAL_STANDARD_LEGAL)
&& !set.getReleaseDate().before(earliestDate)) {
// && !set.getReleaseDate().after(current.getTime()))) {
boolean isDateCompatible = earliestDate != null && !set.getReleaseDate().before(earliestDate) /*!set.getReleaseDate().after(current.getTime())*/; // no after date restrict for early tests and beta
if (set.isStandardLegal() && isDateCompatible) {
codes.add(set.getCode());
}
}

View file

@ -1,25 +1,20 @@
package mage.deck;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.cards.decks.Deck;
import mage.constants.SetType;
import java.util.*;
/**
* This class represents a deck conforming to the rules contained in the
* subreddit /r/SuperStandard.
*
* <p>
* This class was originally made to work with the historical standard ruleset.
* Data taken from http://thattournament.website/historic-tournament.php (site
* changed, originally http://mtgt.nfshost.com/historic-tournament.php)
*
* <p>
* If there are any questions or corrections, feel free to contact me.
*
* @author Marthinwurer (at gmail.com)
@ -32,28 +27,28 @@ public class SuperType2 extends Constructed {
* Data taken from http://thattournament.website/historic-tournament.php
*/
protected static final String[][] standards = {
// 11th Standard
{"7ED", "INV", "APC", "PLS", "ODY", "TOR", "JUD"},
// 12th Standard
{"7ED", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG"},
// 13th Standard
{"8ED", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG"},
// 14th Standard
{"8ED", "ONS", "LGN", "SCG", "MRD", "DST", "5DN"},
// 15th Standard
{"8ED", "MRD", "DST", "5DN", "CHK", "BOK", "SOK"},
// 16th Standard
{"9ED", "MRD", "DST", "5DN", "CHK", "BOK", "SOK"},
// 17th Standard
{"9ED", "CHK", "BOK", "SOK", "RAV", "GPT", "DIS", "CSP"},
// 18th Standard
{"9ED", "RAV", "GPT", "DIS", "CSP", "TSP", "TSB", "PLC", "FUT"},
// 19th Standard
{"10E", "RAV", "GPT", "DIS", "CSP", "TSP", "TSB", "PLC", "FUT"},
// 20th Standard
{"10E", "CSP", "TSP", "TSB", "PLC", "FUT", "LRW", "MOR", "SHM", "EVE"},
// 21st Standard
{"10E", "LRW", "MOR", "SHM", "EVE", "ALA", "CON", "ARB"}
// 11th Standard
{"7ED", "INV", "APC", "PLS", "ODY", "TOR", "JUD"},
// 12th Standard
{"7ED", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG"},
// 13th Standard
{"8ED", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG"},
// 14th Standard
{"8ED", "ONS", "LGN", "SCG", "MRD", "DST", "5DN"},
// 15th Standard
{"8ED", "MRD", "DST", "5DN", "CHK", "BOK", "SOK"},
// 16th Standard
{"9ED", "MRD", "DST", "5DN", "CHK", "BOK", "SOK"},
// 17th Standard
{"9ED", "CHK", "BOK", "SOK", "RAV", "GPT", "DIS", "CSP"},
// 18th Standard
{"9ED", "RAV", "GPT", "DIS", "CSP", "TSP", "TSB", "PLC", "FUT"},
// 19th Standard
{"10E", "RAV", "GPT", "DIS", "CSP", "TSP", "TSB", "PLC", "FUT"},
// 20th Standard
{"10E", "CSP", "TSP", "TSB", "PLC", "FUT", "LRW", "MOR", "SHM", "EVE"},
// 21st Standard
{"10E", "LRW", "MOR", "SHM", "EVE", "ALA", "CON", "ARB"}
};
/**
@ -159,9 +154,9 @@ public class SuperType2 extends Constructed {
// Get the sets in that time period.
// (code taken from standard.java)
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getReleaseDate().after(start.getTime())
&& set.getReleaseDate().before(end.getTime())
&& (set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION)) {
if (set.isStandardLegal()
&& set.getReleaseDate().after(start.getTime())
&& set.getReleaseDate().before(end.getTime())) {
setCodes.add(set.getCode());
}
}

View file

@ -1,4 +1,3 @@
package mage.cards;
import mage.ObjectColor;
@ -255,9 +254,7 @@ public abstract class ExpansionSet implements Serializable {
}
if (needsLegendCreature) {
if (booster.stream().noneMatch(card -> card.isLegendary() && card.isCreature())) {
return false;
}
return booster.stream().anyMatch(card -> card.isLegendary() && card.isCreature());
}
// TODO: add partner check
@ -311,9 +308,7 @@ public abstract class ExpansionSet implements Serializable {
// check that we don't have 3 or more uncommons/rares of the same color
if (magicColors.stream().anyMatch(color -> uncommonWeight.get(color) >= 180)) {
// reject only part of the boosters
if (RandomUtil.nextDouble() < rejectSameColorUncommonsProbability) {
return false;
}
return !(RandomUtil.nextDouble() < rejectSameColorUncommonsProbability);
}
return true;
@ -610,8 +605,13 @@ public abstract class ExpansionSet implements Serializable {
}
public boolean isEternalLegal() {
return setType != SetType.CUSTOM_SET
&& setType != SetType.JOKESET;
// any official sets except un-sets
return setType != SetType.CUSTOM_SET && setType != SetType.JOKESET;
}
public boolean isStandardLegal() {
// any official sets that was in standard
return setType == SetType.CORE || setType == SetType.EXPANSION || setType == SetType.SUPPLEMENTAL_STANDARD_LEGAL;
}
public void removeSavedCards() {