Implemented hand filtering properly using deck land ratio

Made hand filtering optional and disabled by default
This commit is contained in:
austinio7116
2018-05-30 07:19:54 +01:00
committed by maustin
parent e11fe9db8b
commit e6af43b060
7 changed files with 53 additions and 5 deletions

View File

@@ -37,6 +37,8 @@ public class StaticData {
private Predicate<PaperCard> brawlPredicate; private Predicate<PaperCard> brawlPredicate;
private Predicate<PaperCard> modernPredicate; private Predicate<PaperCard> modernPredicate;
private boolean filteredHandsEnabled = false;
// Loaded lazily: // Loaded lazily:
private IStorage<SealedProduct.Template> boosters; private IStorage<SealedProduct.Template> boosters;
private IStorage<SealedProduct.Template> specialBoosters; private IStorage<SealedProduct.Template> specialBoosters;
@@ -209,6 +211,14 @@ public class StaticData {
return brawlPredicate; return brawlPredicate;
} }
public void setFilteredHandsEnabled(boolean filteredHandsEnabled){
this.filteredHandsEnabled = filteredHandsEnabled;
}
public boolean getFilteredHandsEnabled(){
return filteredHandsEnabled;
}
public PaperCard getCardByEditionDate(PaperCard card, Date editionDate) { public PaperCard getCardByEditionDate(PaperCard card, Date editionDate) {
PaperCard c = this.getCommonCards().getCardFromEdition(card.getName(), editionDate, CardDb.SetPreference.LatestCoreExp, card.getArtIndex()); PaperCard c = this.getCommonCards().getCardFromEdition(card.getName(), editionDate, CardDb.SetPreference.LatestCoreExp, card.getArtIndex());

View File

@@ -20,6 +20,7 @@ package forge.game;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.*; import com.google.common.collect.*;
import forge.GameCommand; import forge.GameCommand;
import forge.StaticData;
import forge.card.CardStateName; import forge.card.CardStateName;
import forge.game.ability.AbilityFactory; import forge.game.ability.AbilityFactory;
import forge.game.ability.AbilityUtils; import forge.game.ability.AbilityUtils;
@@ -1567,6 +1568,7 @@ public class GameAction {
//check initial hand //check initial hand
List<Card> lib1 = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable()); List<Card> lib1 = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable());
List<Card> hand1 = lib1.subList(0,p1.getMaxHandSize()); List<Card> hand1 = lib1.subList(0,p1.getMaxHandSize());
System.out.println(hand1.toString());
//shuffle //shuffle
List shuffledCards = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable()); List shuffledCards = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable());
@@ -1574,22 +1576,38 @@ public class GameAction {
//check a second hand //check a second hand
List<Card> hand2 = shuffledCards.subList(0,p1.getMaxHandSize()); List<Card> hand2 = shuffledCards.subList(0,p1.getMaxHandSize());
System.out.println(hand2.toString());
//choose better hand according to land count //choose better hand according to land count
if(getHandScore(hand1)>getHandScore(hand2)){ float averageLandRatio = getLandRatio(lib1);
if(getHandScore(hand1, averageLandRatio)>getHandScore(hand2, averageLandRatio)){
p1.getZone(ZoneType.Library).setCards(shuffledCards); p1.getZone(ZoneType.Library).setCards(shuffledCards);
} }
p1.drawCards(p1.getMaxHandSize()); p1.drawCards(p1.getMaxHandSize());
} }
private int getHandScore(List<Card> hand){ private float getLandRatio(List<Card> deck){
int landCount = 0;
for(Card c:deck){
if(c.isLand()){
landCount++;
}
}
if (landCount == 0 ){
return 0;
}
return new Float(landCount)/new Float(deck.size());
}
private float getHandScore(List<Card> hand, float landRatio){
int landCount = 0; int landCount = 0;
for(Card c:hand){ for(Card c:hand){
if(c.isLand()){ if(c.isLand()){
landCount++; landCount++;
} }
} }
return Math.abs(3-landCount); float averageCount = landRatio * hand.size();
return Math.abs(averageCount-landCount);
} }
public void startGame(GameOutcome lastGameOutcome) { public void startGame(GameOutcome lastGameOutcome) {
@@ -1612,8 +1630,11 @@ public class GameAction {
game.setAge(GameStage.Mulligan); game.setAge(GameStage.Mulligan);
for (final Player p1 : game.getPlayers()) { for (final Player p1 : game.getPlayers()) {
if (StaticData.instance().getFilteredHandsEnabled() ) {
drawStartingHand(p1); drawStartingHand(p1);
} else {
p1.drawCards(p1.getStartingHandSize());
}
// If pl has Backup Plan as a Conspiracy draw that many extra hands // If pl has Backup Plan as a Conspiracy draw that many extra hands

View File

@@ -101,6 +101,7 @@ public enum CSubmenuPreferences implements ICDoc {
lstControls.add(Pair.of(view.getCbRandomArtInPools(), FPref.UI_RANDOM_ART_IN_POOLS)); lstControls.add(Pair.of(view.getCbRandomArtInPools(), FPref.UI_RANDOM_ART_IN_POOLS));
lstControls.add(Pair.of(view.getCbEnforceDeckLegality(), FPref.ENFORCE_DECK_LEGALITY)); lstControls.add(Pair.of(view.getCbEnforceDeckLegality(), FPref.ENFORCE_DECK_LEGALITY));
lstControls.add(Pair.of(view.getCbPerformanceMode(), FPref.PERFORMANCE_MODE)); lstControls.add(Pair.of(view.getCbPerformanceMode(), FPref.PERFORMANCE_MODE));
lstControls.add(Pair.of(view.getCbFilteredHands(), FPref.FILTERED_HANDS));
lstControls.add(Pair.of(view.getCbCloneImgSource(), FPref.UI_CLONE_MODE_SOURCE)); lstControls.add(Pair.of(view.getCbCloneImgSource(), FPref.UI_CLONE_MODE_SOURCE));
lstControls.add(Pair.of(view.getCbRemoveSmall(), FPref.DECKGEN_NOSMALL)); lstControls.add(Pair.of(view.getCbRemoveSmall(), FPref.DECKGEN_NOSMALL));
lstControls.add(Pair.of(view.getCbCardBased(), FPref.DECKGEN_CARDBASED)); lstControls.add(Pair.of(view.getCbCardBased(), FPref.DECKGEN_CARDBASED));

View File

@@ -69,6 +69,7 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
private final JCheckBox cbWorkshopSyntax = new OptionsCheckBox("Workshop Syntax Checker"); private final JCheckBox cbWorkshopSyntax = new OptionsCheckBox("Workshop Syntax Checker");
private final JCheckBox cbEnforceDeckLegality = new OptionsCheckBox("Deck Conformance"); private final JCheckBox cbEnforceDeckLegality = new OptionsCheckBox("Deck Conformance");
private final JCheckBox cbPerformanceMode = new OptionsCheckBox("Performance Mode"); private final JCheckBox cbPerformanceMode = new OptionsCheckBox("Performance Mode");
private final JCheckBox cbFilteredHands = new OptionsCheckBox("Filtered Hands");
private final JCheckBox cbImageFetcher = new OptionsCheckBox("Automatically Download Missing Card Art"); private final JCheckBox cbImageFetcher = new OptionsCheckBox("Automatically Download Missing Card Art");
private final JCheckBox cbCloneImgSource = new OptionsCheckBox("Clones Use Original Card Art"); private final JCheckBox cbCloneImgSource = new OptionsCheckBox("Clones Use Original Card Art");
private final JCheckBox cbScaleLarger = new OptionsCheckBox("Scale Image Larger"); private final JCheckBox cbScaleLarger = new OptionsCheckBox("Scale Image Larger");
@@ -175,6 +176,9 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
pnlPrefs.add(cbPerformanceMode, titleConstraints); pnlPrefs.add(cbPerformanceMode, titleConstraints);
pnlPrefs.add(new NoteLabel("Disables additional static abilities checks to speed up the game engine. (Warning: breaks some 'as if had flash' scenarios when casting cards owned by opponents)."), descriptionConstraints); pnlPrefs.add(new NoteLabel("Disables additional static abilities checks to speed up the game engine. (Warning: breaks some 'as if had flash' scenarios when casting cards owned by opponents)."), descriptionConstraints);
pnlPrefs.add(cbFilteredHands, titleConstraints);
pnlPrefs.add(new NoteLabel("Generates two starting hands and keeps the one with the closest to average land count for the deck. (Requires restart)"), descriptionConstraints);
pnlPrefs.add(cbCloneImgSource, titleConstraints); pnlPrefs.add(cbCloneImgSource, titleConstraints);
pnlPrefs.add(new NoteLabel("When enabled clones will use their original art instead of the cloned card's art."), descriptionConstraints); pnlPrefs.add(new NoteLabel("When enabled clones will use their original art instead of the cloned card's art."), descriptionConstraints);
@@ -641,6 +645,11 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
return cbPerformanceMode; return cbPerformanceMode;
} }
/** @return {@link javax.swing.JCheckBox} */
public JCheckBox getCbFilteredHands() {
return cbFilteredHands;
}
/** @return {@link javax.swing.JCheckBox} */ /** @return {@link javax.swing.JCheckBox} */
public JCheckBox getCbCloneImgSource() { public JCheckBox getCbCloneImgSource() {
return cbCloneImgSource; return cbCloneImgSource;

View File

@@ -117,6 +117,10 @@ public class SettingsPage extends TabPage<SettingsScreen> {
"Performance Mode", "Performance Mode",
"Disables additional static abilities checks to speed up the game engine. (Warning: breaks some 'as if had flash' scenarios when casting cards owned by opponents)."), "Disables additional static abilities checks to speed up the game engine. (Warning: breaks some 'as if had flash' scenarios when casting cards owned by opponents)."),
1); 1);
lstSettings.addItem(new BooleanSetting(FPref.FILTERED_HANDS,
"Filtered Hands",
"Generates two starting hands and keeps the one with the closest to average land count for the deck. (Requires restart)"),
1);
lstSettings.addItem(new BooleanSetting(FPref.UI_CLONE_MODE_SOURCE, lstSettings.addItem(new BooleanSetting(FPref.UI_CLONE_MODE_SOURCE,
"Clones Use Original Card Art", "Clones Use Original Card Art",
"When enabled clones will use their original art instead of the cloned card's art."), "When enabled clones will use their original art instead of the cloned card's art."),

View File

@@ -173,6 +173,8 @@ public final class FModel {
magicDb.setBrawlPredicate(formats.get("Brawl").getFilterRules()); magicDb.setBrawlPredicate(formats.get("Brawl").getFilterRules());
magicDb.setModernPredicate(formats.getModern().getFilterRules()); magicDb.setModernPredicate(formats.getModern().getFilterRules());
magicDb.setFilteredHandsEnabled(preferences.getPrefBoolean(FPref.FILTERED_HANDS));
blocks = new StorageBase<>("Block definitions", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "blocks.txt", magicDb.getEditions())); blocks = new StorageBase<>("Block definitions", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "blocks.txt", magicDb.getEditions()));
questPreferences = new QuestPreferences(); questPreferences = new QuestPreferences();
conquestPreferences = new ConquestPreferences(); conquestPreferences = new ConquestPreferences();

View File

@@ -154,6 +154,7 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
ENFORCE_DECK_LEGALITY ("true"), ENFORCE_DECK_LEGALITY ("true"),
PERFORMANCE_MODE ("false"), PERFORMANCE_MODE ("false"),
FILTERED_HANDS ("false"),
DEV_MODE_ENABLED ("false"), DEV_MODE_ENABLED ("false"),
DEV_WORKSHOP_SYNTAX ("false"), DEV_WORKSHOP_SYNTAX ("false"),