mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Prevent generated decks with restricted pools coming out too small due to trying to add dual lands not in pool
This commit is contained in:
@@ -467,6 +467,11 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
return Lists.newArrayList(Iterables.filter(this.roAllCards, predicate));
|
return Lists.newArrayList(Iterables.filter(this.roAllCards, predicate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(String name) {
|
||||||
|
return allCardsByName.containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<PaperCard> iterator() {
|
public Iterator<PaperCard> iterator() {
|
||||||
return this.roAllCards.iterator();
|
return this.roAllCards.iterator();
|
||||||
|
|||||||
@@ -46,7 +46,12 @@ public class DeckGenPool implements IDeckGenPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(PaperCard card) {
|
public boolean contains(PaperCard card) {
|
||||||
return cards.containsKey(card.getName());
|
return contains(card.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(String name) {
|
||||||
|
return cards.containsKey(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -153,9 +153,8 @@ public abstract class DeckGeneratorBase {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addBasicLand(int cnt)
|
protected void addBasicLand(int cnt) {
|
||||||
{
|
|
||||||
addBasicLand(cnt, null);
|
addBasicLand(cnt, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,32 +268,32 @@ public abstract class DeckGeneratorBase {
|
|||||||
protected static Map<String, Integer> countLands(ItemPool<PaperCard> outList) {
|
protected static Map<String, Integer> countLands(ItemPool<PaperCard> outList) {
|
||||||
// attempt to optimize basic land counts according
|
// attempt to optimize basic land counts according
|
||||||
// to color representation
|
// to color representation
|
||||||
|
|
||||||
Map<String, Integer> res = new TreeMap<String, Integer>();
|
Map<String, Integer> res = new TreeMap<String, Integer>();
|
||||||
// count each card color using mana costs
|
// count each card color using mana costs
|
||||||
// TODO: count hybrid mana differently?
|
// TODO: count hybrid mana differently?
|
||||||
for (Entry<PaperCard, Integer> cpe : outList) {
|
for (Entry<PaperCard, Integer> cpe : outList) {
|
||||||
|
|
||||||
int profile = cpe.getKey().getRules().getManaCost().getColorProfile();
|
int profile = cpe.getKey().getRules().getManaCost().getColorProfile();
|
||||||
|
|
||||||
if ((profile & MagicColor.WHITE) != 0) {
|
if ((profile & MagicColor.WHITE) != 0) {
|
||||||
increment(res, MagicColor.Constant.BASIC_LANDS.get(0), cpe.getValue());
|
increment(res, MagicColor.Constant.BASIC_LANDS.get(0), cpe.getValue());
|
||||||
} else if ((profile & MagicColor.BLUE) != 0) {
|
}
|
||||||
|
else if ((profile & MagicColor.BLUE) != 0) {
|
||||||
increment(res, MagicColor.Constant.BASIC_LANDS.get(1), cpe.getValue());
|
increment(res, MagicColor.Constant.BASIC_LANDS.get(1), cpe.getValue());
|
||||||
} else if ((profile & MagicColor.BLACK) != 0) {
|
}
|
||||||
|
else if ((profile & MagicColor.BLACK) != 0) {
|
||||||
increment(res, MagicColor.Constant.BASIC_LANDS.get(2), cpe.getValue());
|
increment(res, MagicColor.Constant.BASIC_LANDS.get(2), cpe.getValue());
|
||||||
} else if ((profile & MagicColor.RED) != 0) {
|
}
|
||||||
|
else if ((profile & MagicColor.RED) != 0) {
|
||||||
increment(res, MagicColor.Constant.BASIC_LANDS.get(3), cpe.getValue());
|
increment(res, MagicColor.Constant.BASIC_LANDS.get(3), cpe.getValue());
|
||||||
} else if ((profile & MagicColor.GREEN) != 0) {
|
}
|
||||||
|
else if ((profile & MagicColor.GREEN) != 0) {
|
||||||
increment(res, MagicColor.Constant.BASIC_LANDS.get(4), cpe.getValue());
|
increment(res, MagicColor.Constant.BASIC_LANDS.get(4), cpe.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void increment(Map<String, Integer> map, String key, int delta)
|
protected static void increment(Map<String, Integer> map, String key, int delta) {
|
||||||
{
|
|
||||||
final Integer boxed = map.get(key);
|
final Integer boxed = map.get(key);
|
||||||
map.put(key, boxed == null ? delta : boxed.intValue() + delta);
|
map.put(key, boxed == null ? delta : boxed.intValue() + delta);
|
||||||
}
|
}
|
||||||
@@ -377,22 +376,21 @@ public abstract class DeckGeneratorBase {
|
|||||||
* @return dual land names
|
* @return dual land names
|
||||||
*/
|
*/
|
||||||
protected List<String> getDualLandList() {
|
protected List<String> getDualLandList() {
|
||||||
|
|
||||||
final List<String> dLands = new ArrayList<String>();
|
final List<String> dLands = new ArrayList<String>();
|
||||||
|
|
||||||
if (colors.countColors() > 3) {
|
if (colors.countColors() > 3) {
|
||||||
dLands.add("Rupture Spire");
|
addCardNameToList("Rupture Spire", dLands);
|
||||||
dLands.add("Undiscovered Paradise");
|
addCardNameToList("Undiscovered Paradise", dLands);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colors.countColors() > 2) {
|
if (colors.countColors() > 2) {
|
||||||
dLands.add("Evolving Wilds");
|
addCardNameToList("Evolving Wilds", dLands);
|
||||||
dLands.add("Terramorphic Expanse");
|
addCardNameToList("Terramorphic Expanse", dLands);
|
||||||
}
|
}
|
||||||
for (Entry<Integer, String[]> dual : dualLands.entrySet()) {
|
for (Entry<Integer, String[]> dual : dualLands.entrySet()) {
|
||||||
if (colors.hasAllColors(dual.getKey())) {
|
if (colors.hasAllColors(dual.getKey())) {
|
||||||
for (String s : dual.getValue()) {
|
for (String s : dual.getValue()) {
|
||||||
dLands.add(s);
|
addCardNameToList(s, dLands);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -413,10 +411,16 @@ public abstract class DeckGeneratorBase {
|
|||||||
for (Entry<Integer, String[]> dual : dualLands.entrySet()) {
|
for (Entry<Integer, String[]> dual : dualLands.entrySet()) {
|
||||||
if (!colors.hasAllColors(dual.getKey())) {
|
if (!colors.hasAllColors(dual.getKey())) {
|
||||||
for (String s : dual.getValue()) {
|
for (String s : dual.getValue()) {
|
||||||
dLands.add(s);
|
addCardNameToList(s, dLands);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dLands;
|
return dLands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addCardNameToList(String cardName, List<String> cardNameList) {
|
||||||
|
if (pool.contains(cardName)) { //avoid adding card if it's not in pool
|
||||||
|
cardNameList.add(cardName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,5 @@ public interface IDeckGenPool {
|
|||||||
PaperCard getCard(String name, String edition, int artIndex);
|
PaperCard getCard(String name, String edition, int artIndex);
|
||||||
Iterable<PaperCard> getAllCards();
|
Iterable<PaperCard> getAllCards();
|
||||||
Iterable<PaperCard> getAllCards(Predicate<PaperCard> filter);
|
Iterable<PaperCard> getAllCards(Predicate<PaperCard> filter);
|
||||||
|
boolean contains(String name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user