mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Monocolored decks generation
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14125,6 +14125,7 @@ src/main/java/forge/deck/generate/Generate3ColorDeck.java svneol=native#text/pla
|
||||
src/main/java/forge/deck/generate/Generate5ColorDeck.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/generate/GenerateColoredDeckBase.java -text
|
||||
src/main/java/forge/deck/generate/GenerateDeckUtil.java -text
|
||||
src/main/java/forge/deck/generate/GenerateMonoColorDeck.java -text
|
||||
src/main/java/forge/deck/generate/GenerateThemeDeck.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/generate/package-info.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/io/DeckFileHeader.java -text
|
||||
|
||||
@@ -18,6 +18,8 @@ import forge.Singletons;
|
||||
import forge.deck.generate.Generate2ColorDeck;
|
||||
import forge.deck.generate.Generate3ColorDeck;
|
||||
import forge.deck.generate.Generate5ColorDeck;
|
||||
import forge.deck.generate.GenerateColoredDeckBase;
|
||||
import forge.deck.generate.GenerateMonoColorDeck;
|
||||
import forge.deck.generate.GenerateThemeDeck;
|
||||
import forge.game.player.PlayerType;
|
||||
import forge.item.CardDb;
|
||||
@@ -66,7 +68,7 @@ public class DeckgenUtil {
|
||||
* @return {@link forge.deck.Deck}
|
||||
*/
|
||||
public static Deck buildColorDeck(final String[] selection, PlayerType pt) {
|
||||
ItemPoolView<CardPrinted> cards = null;
|
||||
|
||||
final Deck deck;
|
||||
|
||||
// Replace "random" with "AI" for deck generation code
|
||||
@@ -74,22 +76,20 @@ public class DeckgenUtil {
|
||||
selection[i] = COLOR_VALS.get(selection[i]);
|
||||
}
|
||||
|
||||
// 2, 3, and 5 colors.
|
||||
if (selection.length == 2) {
|
||||
final Generate2ColorDeck gen = new Generate2ColorDeck(
|
||||
selection[0], selection[1]);
|
||||
cards = gen.get2ColorDeck(60, pt);
|
||||
GenerateColoredDeckBase gen = null;
|
||||
|
||||
if (selection.length == 1) {
|
||||
gen = new GenerateMonoColorDeck(selection[0]);
|
||||
} else if (selection.length == 2) {
|
||||
gen = new Generate2ColorDeck(selection[0], selection[1]);
|
||||
} else if (selection.length == 3) {
|
||||
gen = new Generate3ColorDeck(selection[0], selection[1], selection[2]);
|
||||
} else {
|
||||
gen = new Generate5ColorDeck();
|
||||
}
|
||||
else if (selection.length == 3) {
|
||||
final Generate3ColorDeck gen = new Generate3ColorDeck(
|
||||
selection[0], selection[1], selection[2]);
|
||||
cards = gen.get3ColorDeck(60, pt);
|
||||
}
|
||||
else {
|
||||
final Generate5ColorDeck gen = new Generate5ColorDeck();
|
||||
cards = gen.get5ColorDeck(60, pt);
|
||||
}
|
||||
|
||||
|
||||
ItemPoolView<CardPrinted> cards = gen == null ? null : gen.getDeck(60, pt);
|
||||
|
||||
// After generating card lists, build deck.
|
||||
deck = new Deck();
|
||||
deck.getMain().addAll(cards);
|
||||
@@ -131,8 +131,8 @@ public class DeckgenUtil {
|
||||
|
||||
/** @return {@link forge.deck.Deck} */
|
||||
public static Deck getRandomColorDeck(PlayerType pt) {
|
||||
final int[] colorCount = new int[] {2, 3, 5};
|
||||
final int count = colorCount[(int) (Math.round(Math.random() * 2))];
|
||||
final int[] colorCount = new int[] {1, 2, 3, 5};
|
||||
final int count = colorCount[MyRandom.getRandom().nextInt(colorCount.length)];
|
||||
final String[] selection = new String[count];
|
||||
|
||||
// A simulated selection of "random 1" will trigger the AI selection process.
|
||||
@@ -287,14 +287,7 @@ public class DeckgenUtil {
|
||||
public static boolean colorCheck(final String[] colors0) {
|
||||
boolean result = true;
|
||||
|
||||
if (colors0.length == 1) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Sorry, single color generated decks aren't supported yet."
|
||||
+ "\n\rPlease choose at least one more color for this deck.",
|
||||
"Generate deck: 1 color", JOptionPane.ERROR_MESSAGE);
|
||||
result = false;
|
||||
}
|
||||
else if (colors0.length == 4) {
|
||||
if (colors0.length == 4) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Sorry, four color generated decks aren't supported yet."
|
||||
+ "\n\rPlease use 2, 3, or 5 colors for this deck.",
|
||||
|
||||
@@ -78,7 +78,7 @@ public class Generate2ColorDeck extends GenerateColoredDeckBase {
|
||||
}
|
||||
|
||||
|
||||
public final ItemPoolView<CardPrinted> get2ColorDeck(final int size, final PlayerType pt) {
|
||||
public final ItemPoolView<CardPrinted> getDeck(final int size, final PlayerType pt) {
|
||||
addCreaturesAndSpells(size, cmcLevels, cmcAmounts, pt);
|
||||
|
||||
// Add lands
|
||||
|
||||
@@ -77,7 +77,7 @@ public class Generate3ColorDeck extends GenerateColoredDeckBase {
|
||||
* the pt
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final ItemPoolView<CardPrinted> get3ColorDeck(final int size, final PlayerType pt) {
|
||||
public final ItemPoolView<CardPrinted> getDeck(final int size, final PlayerType pt) {
|
||||
addCreaturesAndSpells(size, cmcLevels, cmcAmounts, pt);
|
||||
|
||||
// Add lands
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Generate5ColorDeck extends GenerateColoredDeckBase {
|
||||
* a PlayerType
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final ItemPoolView<CardPrinted> get5ColorDeck(final int size, final PlayerType pt) {
|
||||
public final ItemPoolView<CardPrinted> getDeck(final int size, final PlayerType pt) {
|
||||
addCreaturesAndSpells(size, cmcLevels, cmcAmounts, pt);
|
||||
|
||||
// Add lands
|
||||
|
||||
@@ -39,6 +39,7 @@ import forge.game.player.PlayerType;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.MyRandom;
|
||||
@@ -100,6 +101,9 @@ public abstract class GenerateColoredDeckBase {
|
||||
addCmcAdjusted(spells, spellCnt, cmcLevels, cmcAmounts);
|
||||
}
|
||||
|
||||
public ItemPoolView<CardPrinted> getDeck(final int size, final PlayerType pt) {
|
||||
return null; // all but theme deck do override this method
|
||||
}
|
||||
|
||||
protected void addSome(int cnt, List<CardPrinted> source) {
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
|
||||
99
src/main/java/forge/deck/generate/GenerateMonoColorDeck.java
Normal file
99
src/main/java/forge/deck/generate/GenerateMonoColorDeck.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck.generate;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import forge.card.MagicColor;
|
||||
import forge.card.ColorSet;
|
||||
import forge.deck.generate.GenerateDeckUtil.FilterCMC;
|
||||
import forge.error.BugReporter;
|
||||
import forge.game.player.PlayerType;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.properties.ForgeProps;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Generate2ColorDeck class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: Generate2ColorDeck.java 19765 2013-02-20 03:01:37Z myk $
|
||||
*/
|
||||
public class GenerateMonoColorDeck extends GenerateColoredDeckBase {
|
||||
@Override protected final float getLandsPercentage() { return 0.39f; }
|
||||
@Override protected final float getCreatPercentage() { return 0.36f; }
|
||||
@Override protected final float getSpellPercentage() { return 0.25f; }
|
||||
|
||||
final List<FilterCMC> cmcLevels = Arrays.asList(
|
||||
new GenerateDeckUtil.FilterCMC(0, 2),
|
||||
new GenerateDeckUtil.FilterCMC(3, 4),
|
||||
new GenerateDeckUtil.FilterCMC(5, 6),
|
||||
new GenerateDeckUtil.FilterCMC(7, 20));
|
||||
final int[] cmcAmounts = {10, 8, 5, 3};
|
||||
|
||||
// mana curve of the card pool
|
||||
// 20x 0 - 2
|
||||
// 16x 3 - 4
|
||||
// 12x 5 - 6
|
||||
// 4x 7 - 20
|
||||
// = 52x - card pool (before further random filtering)
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Generate2ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param clr1
|
||||
* a {@link java.lang.String} object.
|
||||
* @param clr2
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public GenerateMonoColorDeck(final String clr1) {
|
||||
|
||||
if (clr1.equals("AI")) {
|
||||
int color1 = r.nextInt(5);
|
||||
colors = ColorSet.fromMask(MagicColor.WHITE << color1);
|
||||
} else {
|
||||
colors = ColorSet.fromNames(clr1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final ItemPoolView<CardPrinted> getDeck(final int size, final PlayerType pt) {
|
||||
addCreaturesAndSpells(size, cmcLevels, cmcAmounts, pt);
|
||||
|
||||
// Add lands
|
||||
int numLands = (int) (getLandsPercentage() * size);
|
||||
|
||||
tmpDeck.append("numLands:").append(numLands).append("\n");
|
||||
|
||||
addBasicLand(numLands);
|
||||
tmpDeck.append("DeckSize:").append(tDeck.countAll()).append("\n");
|
||||
|
||||
adjustDeckSize(size);
|
||||
tmpDeck.append("DeckSize:").append(tDeck.countAll()).append("\n");
|
||||
if (ForgeProps.getProperty("showdeck/1color", "false").equals("true")) {
|
||||
BugReporter.reportBug(tmpDeck.toString());
|
||||
}
|
||||
|
||||
return tDeck;
|
||||
}
|
||||
}
|
||||
@@ -106,15 +106,15 @@ public enum CDeckgen implements ICDoc {
|
||||
switch (colorCount0) {
|
||||
case 2:
|
||||
genConstructed.getMain().addAll(
|
||||
(new Generate2ColorDeck("AI", "AI")).get2ColorDeck(60, PlayerType.HUMAN));
|
||||
(new Generate2ColorDeck("AI", "AI")).getDeck(60, PlayerType.HUMAN));
|
||||
break;
|
||||
case 3:
|
||||
genConstructed.getMain().addAll(
|
||||
(new Generate3ColorDeck("AI", "AI", "AI")).get3ColorDeck(60, PlayerType.HUMAN));
|
||||
(new Generate3ColorDeck("AI", "AI", "AI")).getDeck(60, PlayerType.HUMAN));
|
||||
break;
|
||||
case 5:
|
||||
genConstructed.getMain().addAll(
|
||||
(new Generate5ColorDeck()).get5ColorDeck(60, PlayerType.HUMAN));
|
||||
(new Generate5ColorDeck()).getDeck(60, PlayerType.HUMAN));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Generate2ColorDeckTest {
|
||||
@Test(enabled = false)
|
||||
public void generate2ColorDeckTest1() {
|
||||
final Generate2ColorDeck gen = new Generate2ColorDeck("white", "blue");
|
||||
final ItemPoolView<CardPrinted> cardList = gen.get2ColorDeck(60, null);
|
||||
final ItemPoolView<CardPrinted> cardList = gen.getDeck(60, null);
|
||||
Assert.assertNotNull(cardList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Generate3ColorDeckTest {
|
||||
@Test(timeOut = 1000, enabled = false)
|
||||
public void generate3ColorDeckTest1() {
|
||||
final Generate3ColorDeck gen = new Generate3ColorDeck("white", "blue", "black");
|
||||
final ItemPoolView<CardPrinted> cardList = gen.get3ColorDeck(60, null);
|
||||
final ItemPoolView<CardPrinted> cardList = gen.getDeck(60, null);
|
||||
Assert.assertNotNull(cardList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Generate5ColorDeckTest {
|
||||
@Test(timeOut = 1000, enabled = false)
|
||||
public void generate5ColorDeckTest1() {
|
||||
final Generate5ColorDeck gen = new Generate5ColorDeck();
|
||||
final ItemPoolView<CardPrinted> cardList = gen.get5ColorDeck(60, null);
|
||||
final ItemPoolView<CardPrinted> cardList = gen.getDeck(60, null);
|
||||
Assert.assertNotNull(cardList);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user