mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
checkstyle and refactor
This commit is contained in:
@@ -1,10 +1,18 @@
|
|||||||
package forge.game;
|
package forge.game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum GameEndReason.
|
||||||
|
*/
|
||||||
public enum GameEndReason {
|
public enum GameEndReason {
|
||||||
|
/** The All opponents lost. */
|
||||||
AllOpponentsLost,
|
AllOpponentsLost,
|
||||||
// Noone won
|
// Noone won
|
||||||
Draw, // Having little idea how they can reach a draw, so I didn't enumerate possible reasons here
|
/** The Draw. */
|
||||||
|
Draw, // Having little idea how they can reach a draw, so I didn't enumerate
|
||||||
|
// possible reasons here
|
||||||
// Special conditions, they force one player to win and thus end the game
|
// Special conditions, they force one player to win and thus end the game
|
||||||
|
|
||||||
WinsGameSpellEffect // ones that could be both hardcoded (felidar) and scripted ( such as Mayael's Aria )
|
/** The Wins game spell effect. */
|
||||||
|
WinsGameSpellEffect // ones that could be both hardcoded (felidar) and
|
||||||
|
// scripted ( such as Mayael's Aria )
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.slightlymagic.maxmtg.Predicate;
|
import net.slightlymagic.maxmtg.Predicate;
|
||||||
|
|
||||||
import forge.card.CardRules;
|
import forge.card.CardRules;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
|
|
||||||
@@ -22,44 +21,78 @@ public final class GameFormat {
|
|||||||
private final Predicate<CardPrinted> filterRules;
|
private final Predicate<CardPrinted> filterRules;
|
||||||
private final Predicate<CardPrinted> filterPrinted;
|
private final Predicate<CardPrinted> filterPrinted;
|
||||||
|
|
||||||
|
/**
|
||||||
public GameFormat(final String fName, final List<String> sets, final List<String> bannedCards)
|
* Instantiates a new game format.
|
||||||
{
|
*
|
||||||
name = fName;
|
* @param fName the f name
|
||||||
allowedSetCodes = Collections.unmodifiableList(sets);
|
* @param sets the sets
|
||||||
bannedCardNames = Collections.unmodifiableList(bannedCards);
|
* @param bannedCards the banned cards
|
||||||
filterRules = buildFilterRules();
|
*/
|
||||||
filterPrinted = buildFilterPritned();
|
public GameFormat(final String fName, final List<String> sets, final List<String> bannedCards) {
|
||||||
|
this.name = fName;
|
||||||
|
this.allowedSetCodes = Collections.unmodifiableList(sets);
|
||||||
|
this.bannedCardNames = Collections.unmodifiableList(bannedCards);
|
||||||
|
this.filterRules = this.buildFilterRules();
|
||||||
|
this.filterPrinted = this.buildFilterPritned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Predicate<CardPrinted> buildFilterPritned() {
|
private Predicate<CardPrinted> buildFilterPritned() {
|
||||||
Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(bannedCardNames);
|
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
||||||
Predicate<CardPrinted> allowSets = allowedSetCodes == null || allowedSetCodes.isEmpty()
|
final Predicate<CardPrinted> allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue
|
||||||
? CardPrinted.Predicates.Presets.isTrue
|
: CardPrinted.Predicates.printedInSets(this.allowedSetCodes, true);
|
||||||
: CardPrinted.Predicates.printedInSets(allowedSetCodes, true);
|
|
||||||
return Predicate.and(banNames, allowSets);
|
return Predicate.and(banNames, allowSets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Predicate<CardPrinted> buildFilterRules() {
|
private Predicate<CardPrinted> buildFilterRules() {
|
||||||
Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(bannedCardNames);
|
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
||||||
Predicate<CardPrinted> allowSets = allowedSetCodes == null || allowedSetCodes.isEmpty()
|
final Predicate<CardPrinted> allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue
|
||||||
? CardPrinted.Predicates.Presets.isTrue
|
: Predicate.brigde(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.fnGetRules);
|
||||||
: Predicate.brigde(CardRules.Predicates.wasPrintedInSets(allowedSetCodes), CardPrinted.fnGetRules);
|
|
||||||
return Predicate.and(banNames, allowSets);
|
return Predicate.and(banNames, allowSets);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() { return name; }
|
/**
|
||||||
public Predicate<CardPrinted> getFilterRules() { return filterRules; }
|
* Gets the name.
|
||||||
public Predicate<CardPrinted> getFilterPrinted() { return filterPrinted; }
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSetLegal(String setCode) { return allowedSetCodes.isEmpty() || allowedSetCodes.contains(setCode); }
|
/**
|
||||||
|
* Gets the filter rules.
|
||||||
|
*
|
||||||
|
* @return the filter rules
|
||||||
|
*/
|
||||||
|
public Predicate<CardPrinted> getFilterRules() {
|
||||||
|
return this.filterRules;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the filter printed.
|
||||||
|
*
|
||||||
|
* @return the filter printed
|
||||||
|
*/
|
||||||
|
public Predicate<CardPrinted> getFilterPrinted() {
|
||||||
|
return this.filterPrinted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is sets the legal.
|
||||||
|
*
|
||||||
|
* @param setCode the set code
|
||||||
|
* @return true, if is sets the legal
|
||||||
|
*/
|
||||||
|
public boolean isSetLegal(final String setCode) {
|
||||||
|
return this.allowedSetCodes.isEmpty() || this.allowedSetCodes.contains(setCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
return this.name + " (format)";
|
||||||
return name + " (format)";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,52 @@
|
|||||||
package forge.game;
|
package forge.game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum GameLossReason.
|
||||||
|
*/
|
||||||
public enum GameLossReason {
|
public enum GameLossReason {
|
||||||
|
|
||||||
DidNotLoseYet, // a winner must have this status by the end of the game
|
/** The Did not lose yet. */
|
||||||
|
DidNotLoseYet, // a winner must have this status by the end of the game
|
||||||
|
|
||||||
Conceded, // rule 104.3a
|
/** The Conceded. */
|
||||||
LifeReachedZero, // rule 104.3b
|
Conceded, // rule 104.3a
|
||||||
Milled, // 104.3c
|
/** The Life reached zero. */
|
||||||
Poisoned, // 104.3d
|
LifeReachedZero, // rule 104.3b
|
||||||
|
/** The Milled. */
|
||||||
|
Milled, // 104.3c
|
||||||
|
/** The Poisoned. */
|
||||||
|
Poisoned, // 104.3d
|
||||||
|
|
||||||
// 104.3e and others
|
// 104.3e and others
|
||||||
SpellEffect
|
/** The Spell effect. */
|
||||||
|
SpellEffect
|
||||||
|
|
||||||
/*DoorToNothingness, // Door To Nothingness's ability activated
|
/*
|
||||||
|
* DoorToNothingness, // Door To Nothingness's ability activated
|
||||||
|
*
|
||||||
|
* // TODO: Implement game logics for the ones below Transcendence20Life, //
|
||||||
|
* When you have 20 or more life, you lose the game. FailedToPayPactUpkeep,
|
||||||
|
* // Pacts from Future Sight series (cost 0 but you must pay their real
|
||||||
|
* cost at next turn's upkeep, otherwise GL) PhageTheUntouchableDamage, //
|
||||||
|
* Whenever Phage deals combat damage to a player, that player loses the
|
||||||
|
* game. PhageTheUntouchableWrongETB, // When Phage the Untouchable ETB, if
|
||||||
|
* you didn't cast it from your hand, you lose the game.
|
||||||
|
* NefariousLichLeavesTB, // When Nefarious Lich leaves the battlefield, you
|
||||||
|
* lose the game. NefariousLichCannotExileGrave, // If damage would be dealt
|
||||||
|
* to you, exile that many cards from your graveyard instead. If you can't,
|
||||||
|
* you lose the game. LichWasPutToGraveyard, // When Lich is put into a
|
||||||
|
* graveyard from the battlefield, you lose the game. FinalFortune, // same
|
||||||
|
* as Warrior's Oath - lose at the granted extra turn's end step
|
||||||
|
* ImmortalCoilEmptyGraveyard, // When there are no cards in your graveyard,
|
||||||
|
* you lose the game. ForbiddenCryptEmptyGraveyard, // If you would draw a
|
||||||
|
* card, return a card from your graveyard to your hand instead. If you
|
||||||
|
* can't, you lose the game.
|
||||||
|
*
|
||||||
|
* // Amulet of quoz skipped for using ante, // Form of the Squirrel and
|
||||||
|
* Rocket-Powered Turbo Slug skipped for being part of UN- set
|
||||||
|
*/
|
||||||
|
|
||||||
// TODO: Implement game logics for the ones below
|
// refer to
|
||||||
Transcendence20Life, // When you have 20 or more life, you lose the game.
|
// http://gatherer.wizards.com/Pages/Search/Default.aspx?output=standard&text=+[%22lose+the+game%22]
|
||||||
FailedToPayPactUpkeep, // Pacts from Future Sight series (cost 0 but you must pay their real cost at next turn's upkeep, otherwise GL)
|
// for more cards when they are printed
|
||||||
PhageTheUntouchableDamage, // Whenever Phage deals combat damage to a player, that player loses the game.
|
|
||||||
PhageTheUntouchableWrongETB, // When Phage the Untouchable ETB, if you didn't cast it from your hand, you lose the game.
|
|
||||||
NefariousLichLeavesTB, // When Nefarious Lich leaves the battlefield, you lose the game.
|
|
||||||
NefariousLichCannotExileGrave, // If damage would be dealt to you, exile that many cards from your graveyard instead. If you can't, you lose the game.
|
|
||||||
LichWasPutToGraveyard, // When Lich is put into a graveyard from the battlefield, you lose the game.
|
|
||||||
FinalFortune, // same as Warrior's Oath - lose at the granted extra turn's end step
|
|
||||||
ImmortalCoilEmptyGraveyard, // When there are no cards in your graveyard, you lose the game.
|
|
||||||
ForbiddenCryptEmptyGraveyard, // If you would draw a card, return a card from your graveyard to your hand instead. If you can't, you lose the game.
|
|
||||||
|
|
||||||
// Amulet of quoz skipped for using ante,
|
|
||||||
// Form of the Squirrel and Rocket-Powered Turbo Slug skipped for being part of UN- set
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// refer to http://gatherer.wizards.com/Pages/Search/Default.aspx?output=standard&text=+[%22lose+the+game%22] for more cards when they are printed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,91 @@
|
|||||||
package forge.game;
|
package forge.game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class GamePlayerRating.
|
||||||
*
|
*
|
||||||
* @author Max
|
* @author Max
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class GamePlayerRating {
|
public class GamePlayerRating {
|
||||||
boolean hasWonTheCoin;
|
|
||||||
|
|
||||||
protected int turnsMade = 0;
|
/** The has won the coin. */
|
||||||
protected int openingHandSize = 7;
|
private boolean hasWonTheCoin;
|
||||||
protected int timesMulliganed = 0;
|
|
||||||
|
|
||||||
protected GameLossReason lossReason = GameLossReason.DidNotLoseYet;
|
/** The turns made. */
|
||||||
protected String lossSpellName;
|
private int turnsMade = 0;
|
||||||
|
|
||||||
|
/** The opening hand size. */
|
||||||
|
private int openingHandSize = 7;
|
||||||
|
|
||||||
|
/** The times mulliganed. */
|
||||||
|
private int timesMulliganed = 0;
|
||||||
|
|
||||||
|
/** The loss reason. */
|
||||||
|
private GameLossReason lossReason = GameLossReason.DidNotLoseYet;
|
||||||
|
|
||||||
|
/** The loss spell name. */
|
||||||
|
private String lossSpellName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the loss reason.
|
||||||
|
*
|
||||||
|
* @return the loss reason
|
||||||
|
*/
|
||||||
public final GameLossReason getLossReason() {
|
public final GameLossReason getLossReason() {
|
||||||
return lossReason;
|
return this.lossReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLossReason(GameLossReason loseCondition, String spellName) {
|
/**
|
||||||
lossReason = loseCondition;
|
* Sets the loss reason.
|
||||||
lossSpellName = spellName;
|
*
|
||||||
|
* @param loseCondition the lose condition
|
||||||
|
* @param spellName the spell name
|
||||||
|
*/
|
||||||
|
public void setLossReason(final GameLossReason loseCondition, final String spellName) {
|
||||||
|
this.lossReason = loseCondition;
|
||||||
|
this.lossSpellName = spellName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the loss spell name.
|
||||||
|
*
|
||||||
|
* @return the loss spell name
|
||||||
|
*/
|
||||||
public String getLossSpellName() {
|
public String getLossSpellName() {
|
||||||
return lossSpellName;
|
return this.lossSpellName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the opening hand size.
|
||||||
|
*
|
||||||
|
* @return the opening hand size
|
||||||
|
*/
|
||||||
public final int getOpeningHandSize() {
|
public final int getOpeningHandSize() {
|
||||||
return openingHandSize;
|
return this.openingHandSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify has mulliganed.
|
||||||
|
*/
|
||||||
public final void notifyHasMulliganed() {
|
public final void notifyHasMulliganed() {
|
||||||
timesMulliganed++;
|
this.timesMulliganed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the mulligan count.
|
||||||
|
*
|
||||||
|
* @return the mulligan count
|
||||||
|
*/
|
||||||
public final int getMulliganCount() {
|
public final int getMulliganCount() {
|
||||||
return timesMulliganed;
|
return this.timesMulliganed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify opening hand size.
|
||||||
|
*
|
||||||
|
* @param newHand the new hand
|
||||||
|
*/
|
||||||
public final void notifyOpeningHandSize(final int newHand) {
|
public final void notifyOpeningHandSize(final int newHand) {
|
||||||
openingHandSize = newHand;
|
this.openingHandSize = newHand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,63 +3,141 @@ package forge.game;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>GameInfo class.</p>
|
* <p>
|
||||||
|
* GameInfo class.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// This class might be divided in two parts: the very summary (immutable with only getters) and
|
// This class might be divided in two parts: the very summary (immutable with
|
||||||
|
// only getters) and
|
||||||
// GameObserver class - who should be notified of any considerable ingame event
|
// GameObserver class - who should be notified of any considerable ingame event
|
||||||
public final class GameSummary {
|
public final class GameSummary {
|
||||||
protected String playerWinner = "Nobody";
|
|
||||||
protected String playerGotFirstTurn = "Nobody";
|
|
||||||
protected int lastTurnNumber = 0;
|
|
||||||
|
|
||||||
protected GameEndReason winCondition;
|
/** The player winner. */
|
||||||
protected String spellEffectWin;
|
private String playerWinner = "Nobody";
|
||||||
protected final Map<String, GamePlayerRating> playerRating = new HashMap<String, GamePlayerRating>();
|
|
||||||
|
|
||||||
public GameSummary(String... names)
|
/** The player got first turn. */
|
||||||
{
|
private String playerGotFirstTurn = "Nobody";
|
||||||
for (String n : names) {
|
|
||||||
playerRating.put(n, new GamePlayerRating());
|
/** The last turn number. */
|
||||||
|
private int lastTurnNumber = 0;
|
||||||
|
|
||||||
|
/** The win condition. */
|
||||||
|
private GameEndReason winCondition;
|
||||||
|
|
||||||
|
/** The spell effect win. */
|
||||||
|
private String spellEffectWin;
|
||||||
|
|
||||||
|
/** The player rating. */
|
||||||
|
private final Map<String, GamePlayerRating> playerRating = new HashMap<String, GamePlayerRating>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new game summary.
|
||||||
|
*
|
||||||
|
* @param names the names
|
||||||
|
*/
|
||||||
|
public GameSummary(final String... names) {
|
||||||
|
for (final String n : names) {
|
||||||
|
this.playerRating.put(n, new GamePlayerRating());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void end( final GameEndReason condition, String winner, String spellEffect )
|
/**
|
||||||
{
|
* End.
|
||||||
winCondition = condition;
|
*
|
||||||
playerWinner = winner;
|
* @param condition the condition
|
||||||
spellEffectWin = spellEffect;
|
* @param winner the winner
|
||||||
|
* @param spellEffect the spell effect
|
||||||
|
*/
|
||||||
|
public void end(final GameEndReason condition, final String winner, final String spellEffect) {
|
||||||
|
this.winCondition = condition;
|
||||||
|
this.playerWinner = winner;
|
||||||
|
this.spellEffectWin = spellEffect;
|
||||||
}
|
}
|
||||||
public final boolean isDraw() { return null == playerWinner; }
|
|
||||||
public final boolean isWinner(String name) { return name != null && name.equals(playerWinner); }
|
|
||||||
public String getWinner() { return playerWinner; }
|
|
||||||
|
|
||||||
public GameEndReason getWinCondition() { return winCondition; }
|
/**
|
||||||
public GamePlayerRating getPlayerRating(String name) { return playerRating.get(name); }
|
* Checks if is draw.
|
||||||
|
*
|
||||||
|
* @return true, if is draw
|
||||||
|
*/
|
||||||
|
public boolean isDraw() {
|
||||||
|
return null == this.playerWinner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is winner.
|
||||||
|
*
|
||||||
|
* @param name the name
|
||||||
|
* @return true, if is winner
|
||||||
|
*/
|
||||||
|
public boolean isWinner(final String name) {
|
||||||
|
return (name != null) && name.equals(this.playerWinner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the winner.
|
||||||
|
*
|
||||||
|
* @return the winner
|
||||||
|
*/
|
||||||
|
public String getWinner() {
|
||||||
|
return this.playerWinner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the win condition.
|
||||||
|
*
|
||||||
|
* @return the win condition
|
||||||
|
*/
|
||||||
|
public GameEndReason getWinCondition() {
|
||||||
|
return this.winCondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player rating.
|
||||||
|
*
|
||||||
|
* @param name the name
|
||||||
|
* @return the player rating
|
||||||
|
*/
|
||||||
|
public GamePlayerRating getPlayerRating(final String name) {
|
||||||
|
return this.playerRating.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the turn game ended.
|
||||||
|
*
|
||||||
|
* @return the turn game ended
|
||||||
|
*/
|
||||||
public int getTurnGameEnded() {
|
public int getTurnGameEnded() {
|
||||||
return lastTurnNumber;
|
return this.lastTurnNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setPlayerWhoGotFirstTurn(String playerName)
|
/**
|
||||||
{
|
* Sets the player who got first turn.
|
||||||
playerGotFirstTurn = playerName;
|
*
|
||||||
|
* @param playerName the new player who got first turn
|
||||||
|
*/
|
||||||
|
public void setPlayerWhoGotFirstTurn(final String playerName) {
|
||||||
|
this.playerGotFirstTurn = playerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify next turn.
|
||||||
|
*/
|
||||||
public void notifyNextTurn() {
|
public void notifyNextTurn() {
|
||||||
lastTurnNumber++;
|
this.lastTurnNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the win spell effect.
|
||||||
|
*
|
||||||
|
* @return the win spell effect
|
||||||
|
*/
|
||||||
public String getWinSpellEffect() {
|
public String getWinSpellEffect() {
|
||||||
return spellEffectWin;
|
return this.spellEffectWin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,22 +4,47 @@ package forge.game;
|
|||||||
* GameType is an enum to determine the type of current game. :)
|
* GameType is an enum to determine the type of current game. :)
|
||||||
*/
|
*/
|
||||||
public enum GameType {
|
public enum GameType {
|
||||||
|
|
||||||
|
/** The Constructed. */
|
||||||
Constructed(false),
|
Constructed(false),
|
||||||
Sealed(true),
|
/** The Sealed. */
|
||||||
Draft(true),
|
Sealed(true),
|
||||||
Commander(false),
|
/** The Draft. */
|
||||||
Quest(true);
|
Draft(true),
|
||||||
|
/** The Commander. */
|
||||||
|
Commander(false),
|
||||||
|
/** The Quest. */
|
||||||
|
Quest(true);
|
||||||
|
|
||||||
private final boolean bLimited;
|
private final boolean bLimited;
|
||||||
public final boolean isLimited() { return bLimited; }
|
|
||||||
|
|
||||||
GameType(final boolean isLimited) {
|
/**
|
||||||
bLimited = isLimited;
|
* Checks if is limited.
|
||||||
|
*
|
||||||
|
* @return true, if is limited
|
||||||
|
*/
|
||||||
|
public final boolean isLimited() {
|
||||||
|
return this.bLimited;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new game type.
|
||||||
|
*
|
||||||
|
* @param isLimited the is limited
|
||||||
|
*/
|
||||||
|
GameType(final boolean isLimited) {
|
||||||
|
this.bLimited = isLimited;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smart value of.
|
||||||
|
*
|
||||||
|
* @param value the value
|
||||||
|
* @return the game type
|
||||||
|
*/
|
||||||
public static GameType smartValueOf(final String value) {
|
public static GameType smartValueOf(final String value) {
|
||||||
String valToCompate = value.trim();
|
final String valToCompate = value.trim();
|
||||||
for (GameType v : GameType.values()) {
|
for (final GameType v : GameType.values()) {
|
||||||
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
|
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,42 +5,53 @@ import forge.item.CardPrinted;
|
|||||||
import forge.item.ItemPoolView;
|
import forge.item.ItemPoolView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>BoosterDraft interface.</p>
|
* <p>
|
||||||
|
* BoosterDraft interface.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public interface BoosterDraft {
|
public interface BoosterDraft {
|
||||||
/**
|
/**
|
||||||
* <p>nextChoice.</p>
|
* <p>
|
||||||
|
* nextChoice.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
ItemPoolView<CardPrinted> nextChoice();
|
ItemPoolView<CardPrinted> nextChoice();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>setChoice.</p>
|
* <p>
|
||||||
|
* setChoice.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param c a {@link forge.Card} object.
|
* @param c
|
||||||
|
* a {@link forge.Card} object.
|
||||||
*/
|
*/
|
||||||
void setChoice(CardPrinted c);
|
void setChoice(CardPrinted c);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>hasNextChoice.</p>
|
* <p>
|
||||||
|
* hasNextChoice.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
boolean hasNextChoice();
|
boolean hasNextChoice();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getDecks.</p>
|
* <p>
|
||||||
|
* getDecks.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return an array of {@link forge.deck.Deck} objects.
|
* @return an array of {@link forge.deck.Deck} objects.
|
||||||
*/
|
*/
|
||||||
Deck[] getDecks(); //size 7, all the computers decks
|
Deck[] getDecks(); // size 7, all the computers decks
|
||||||
|
|
||||||
/** Constant <code>LandSetCode="{}"</code>. */
|
/** Constant <code>LandSetCode="{}"</code>. */
|
||||||
public String LandSetCode[] = {""};
|
String[] LAND_SET_CODE = { "" };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when drafting is over - to upload picks.
|
* Called when drafting is over - to upload picks.
|
||||||
@@ -48,9 +59,3 @@ public interface BoosterDraft {
|
|||||||
void finishedDrafting();
|
void finishedDrafting();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,19 @@
|
|||||||
package forge.game.limited;
|
package forge.game.limited;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||||
|
import net.slightlymagic.maxmtg.Closure1;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import forge.AllZone;
|
import forge.AllZone;
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardList;
|
import forge.CardList;
|
||||||
@@ -18,20 +32,6 @@ import forge.item.CardPrinted;
|
|||||||
import forge.item.ItemPool;
|
import forge.item.ItemPool;
|
||||||
import forge.item.ItemPoolView;
|
import forge.item.ItemPoolView;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
|
|
||||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
|
||||||
import net.slightlymagic.maxmtg.Closure1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* TODO Write javadoc for this type.
|
* TODO Write javadoc for this type.
|
||||||
@@ -39,135 +39,147 @@ import net.slightlymagic.maxmtg.Closure1;
|
|||||||
*/
|
*/
|
||||||
public final class BoosterDraft_1 implements BoosterDraft {
|
public final class BoosterDraft_1 implements BoosterDraft {
|
||||||
private final BoosterDraftAI draftAI = new BoosterDraftAI();
|
private final BoosterDraftAI draftAI = new BoosterDraftAI();
|
||||||
private static final int nPlayers = 8;
|
private static final int N_PLAYERS = 8;
|
||||||
|
|
||||||
private int nextBoosterGroup = 0;
|
private int nextBoosterGroup = 0;
|
||||||
private int currentBoosterSize = 0;
|
private int currentBoosterSize = 0;
|
||||||
private int currentBoosterPick = 0;
|
private int currentBoosterPick = 0;
|
||||||
private List<List<CardPrinted>> pack; //size 8
|
private List<List<CardPrinted>> pack; // size 8
|
||||||
|
|
||||||
public Map<String,Float> draftPicks = new TreeMap<String,Float>();
|
/** The draft picks. */
|
||||||
private CardPoolLimitation draftFormat;
|
private Map<String, Float> draftPicks = new TreeMap<String, Float>();
|
||||||
|
private final CardPoolLimitation draftFormat;
|
||||||
|
|
||||||
private ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>> packs = new ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>>();
|
private final ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>> packs = new ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Constructor for BoosterDraft_1.</p>
|
* <p>
|
||||||
|
* Constructor for BoosterDraft_1.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param draftType a {@link java.lang.String} object.
|
* @param draftType
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public BoosterDraft_1(CardPoolLimitation draftType) {
|
public BoosterDraft_1(final CardPoolLimitation draftType) {
|
||||||
draftAI.bd = this;
|
this.draftAI.setBd(this);
|
||||||
draftFormat = draftType;
|
this.draftFormat = draftType;
|
||||||
|
|
||||||
switch (draftType) {
|
switch (draftType) {
|
||||||
case Full: // Draft from all cards in Forge
|
case Full: // Draft from all cards in Forge
|
||||||
BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
|
final BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
|
||||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull);
|
final Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull);
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
packs.add(picker);
|
this.packs.add(picker);
|
||||||
|
}
|
||||||
|
|
||||||
|
BoosterDraft.LAND_SET_CODE[0] = CardDb.instance().getCard("Plains").getSet();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Block: // Draft from cards by block or set
|
||||||
|
final List<CardBlock> blocks = SetUtils.getBlocks();
|
||||||
|
|
||||||
|
final Object o = GuiUtils.getChoice("Choose Block", blocks.toArray());
|
||||||
|
final CardBlock block = (CardBlock) o;
|
||||||
|
|
||||||
|
final CardSet[] cardSets = block.getSets();
|
||||||
|
final String[] sets = new String[cardSets.length];
|
||||||
|
for (int k = cardSets.length - 1; k >= 0; --k) {
|
||||||
|
sets[k] = cardSets[k].getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
final int nPacks = block.getCntBoostersDraft();
|
||||||
|
|
||||||
|
final ArrayList<String> setCombos = new ArrayList<String>();
|
||||||
|
if (sets.length >= 2) {
|
||||||
|
setCombos.add(String.format("%s/%s/%s", sets[0], sets[0], sets[0]));
|
||||||
|
setCombos.add(String.format("%s/%s/%s", sets[1], sets[0], sets[0]));
|
||||||
|
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[0]));
|
||||||
|
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[1]));
|
||||||
|
}
|
||||||
|
if (sets.length >= 3) {
|
||||||
|
setCombos.add(String.format("%s/%s/%s", sets[2], sets[1], sets[0]));
|
||||||
|
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[0]));
|
||||||
|
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[1]));
|
||||||
|
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sets.length > 1) {
|
||||||
|
final Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
||||||
|
final String[] pp = p.toString().split("/");
|
||||||
|
for (int i = 0; i < nPacks; i++) {
|
||||||
|
final BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
||||||
|
this.packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
||||||
}
|
}
|
||||||
|
|
||||||
LandSetCode[0] = CardDb.instance().getCard("Plains").getSet();
|
} else {
|
||||||
break;
|
final BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
||||||
|
final Closure1<List<CardPrinted>, BoosterGenerator> pick1 = BoosterGenerator.getSimplePicker(bpOne);
|
||||||
case Block: // Draft from cards by block or set
|
for (int i = 0; i < nPacks; i++) {
|
||||||
List<CardBlock> blocks = SetUtils.getBlocks();
|
this.packs.add(pick1);
|
||||||
|
|
||||||
Object o = GuiUtils.getChoice("Choose Block", blocks.toArray());
|
|
||||||
CardBlock block = (CardBlock) o;
|
|
||||||
|
|
||||||
CardSet[] cardSets = block.getSets();
|
|
||||||
String[] sets = new String[cardSets.length];
|
|
||||||
for (int k = cardSets.length - 1; k >= 0 ; --k) { sets[k] = cardSets[k].getCode();}
|
|
||||||
|
|
||||||
int nPacks = block.getCntBoostersDraft();
|
|
||||||
|
|
||||||
ArrayList<String> setCombos = new ArrayList<String>();
|
|
||||||
if (sets.length >= 2) {
|
|
||||||
setCombos.add(String.format("%s/%s/%s", sets[0], sets[0], sets[0]));
|
|
||||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[0], sets[0]));
|
|
||||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[0]));
|
|
||||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[1]));
|
|
||||||
}
|
|
||||||
if (sets.length >= 3) {
|
|
||||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[1], sets[0]));
|
|
||||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[0]));
|
|
||||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[1]));
|
|
||||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[2]));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BoosterDraft.LAND_SET_CODE[0] = block.getLandSet().getCode();
|
||||||
|
break;
|
||||||
|
|
||||||
if (sets.length > 1) {
|
case Custom:
|
||||||
Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
final List<CustomLimited> myDrafts = this.loadCustomDrafts("res/draft/", ".draft");
|
||||||
String[] pp = p.toString().split("/");
|
|
||||||
for (int i = 0; i < nPacks; i++) {
|
|
||||||
BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
|
||||||
packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
if (myDrafts.size() < 1) {
|
||||||
BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
JOptionPane
|
||||||
Closure1<List<CardPrinted>, BoosterGenerator> pick1 = BoosterGenerator.getSimplePicker(bpOne);
|
.showMessageDialog(null, "No custom draft files found.", "", JOptionPane.INFORMATION_MESSAGE);
|
||||||
for (int i = 0; i < nPacks; i++) { packs.add(pick1); }
|
} else {
|
||||||
}
|
final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Draft",
|
||||||
|
myDrafts.toArray());
|
||||||
LandSetCode[0] = block.getLandSet().getCode();
|
this.setupCustomDraft(draft);
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
case Custom:
|
default:
|
||||||
List<CustomLimited> myDrafts = loadCustomDrafts("res/draft/", ".draft");
|
throw new NoSuchElementException("Draft for mode " + draftType + " has not been set up!");
|
||||||
|
|
||||||
if (myDrafts.size() < 1) {
|
|
||||||
JOptionPane.showMessageDialog(null, "No custom draft files found.", "", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} else {
|
|
||||||
CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Draft", myDrafts.toArray());
|
|
||||||
setupCustomDraft(draft);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new NoSuchElementException("Draft for mode " + draftType + " has not been set up!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pack = get8BoosterPack();
|
this.pack = this.get8BoosterPack();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupCustomDraft(final CustomLimited draft)
|
private void setupCustomDraft(final CustomLimited draft) {
|
||||||
{
|
final DeckManager dio = AllZone.getDeckManager();
|
||||||
DeckManager dio = AllZone.getDeckManager();
|
final Deck dPool = dio.getDeck(draft.DeckFile);
|
||||||
Deck dPool = dio.getDeck(draft.DeckFile);
|
|
||||||
if (dPool == null) {
|
if (dPool == null) {
|
||||||
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.DeckFile);
|
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.DeckFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
final BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
||||||
Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
final Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||||
@Override public List<CardPrinted> apply(BoosterGenerator pack) {
|
@Override
|
||||||
if ( draft.IgnoreRarity ) {
|
public List<CardPrinted> apply(final BoosterGenerator pack) {
|
||||||
|
if (draft.IgnoreRarity) {
|
||||||
if (!draft.Singleton) {
|
if (!draft.Singleton) {
|
||||||
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0);
|
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0);
|
||||||
} else {
|
} else {
|
||||||
return pack.getSingletonBoosterPack(draft.NumCards);
|
return pack.getSingletonBoosterPack(draft.NumCards);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, 0, 0, 0);
|
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics,
|
||||||
|
draft.NumSpecials, 0, 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = new Closure1<List<CardPrinted>, BoosterGenerator>(fnPick, bpCustom);
|
final Closure1<List<CardPrinted>, BoosterGenerator> picker = new Closure1<List<CardPrinted>, BoosterGenerator>(
|
||||||
for (int i = 0; i < draft.NumPacks; i++) { packs.add(picker); }
|
fnPick, bpCustom);
|
||||||
|
for (int i = 0; i < draft.NumPacks; i++) {
|
||||||
|
this.packs.add(picker);
|
||||||
|
}
|
||||||
|
|
||||||
LandSetCode[0] = draft.LandSetCode;
|
BoosterDraft.LAND_SET_CODE[0] = draft.LandSetCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Looks for res/draft/*.draft files, reads them, returns a list */
|
/** Looks for res/draft/*.draft files, reads them, returns a list. */
|
||||||
private List<CustomLimited> loadCustomDrafts(String lookupFolder, String fileExtension)
|
private List<CustomLimited> loadCustomDrafts(final String lookupFolder, final String fileExtension) {
|
||||||
{
|
|
||||||
String[] dList;
|
String[] dList;
|
||||||
ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();
|
final ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();
|
||||||
|
|
||||||
// get list of custom draft files
|
// get list of custom draft files
|
||||||
File dFolder = new File(lookupFolder);
|
final File dFolder = new File(lookupFolder);
|
||||||
if (!dFolder.exists()) {
|
if (!dFolder.exists()) {
|
||||||
throw new RuntimeException("BoosterDraft : folder not found -- folder is " + dFolder.getAbsolutePath());
|
throw new RuntimeException("BoosterDraft : folder not found -- folder is " + dFolder.getAbsolutePath());
|
||||||
}
|
}
|
||||||
@@ -178,151 +190,172 @@ public final class BoosterDraft_1 implements BoosterDraft {
|
|||||||
|
|
||||||
dList = dFolder.list();
|
dList = dFolder.list();
|
||||||
|
|
||||||
for (int i = 0; i < dList.length; i++) {
|
for (final String element : dList) {
|
||||||
if (dList[i].endsWith(fileExtension)) {
|
if (element.endsWith(fileExtension)) {
|
||||||
List<String> dfData = FileUtil.readFile(lookupFolder + dList[i]);
|
final List<String> dfData = FileUtil.readFile(lookupFolder + element);
|
||||||
customs.add(CustomLimited.parse(dfData));
|
customs.add(CustomLimited.parse(dfData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return customs;
|
return customs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>nextChoice.</p>
|
* <p>
|
||||||
|
* nextChoice.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public ItemPoolView<CardPrinted> nextChoice() {
|
public ItemPoolView<CardPrinted> nextChoice() {
|
||||||
if (pack.get(getCurrentBoosterIndex()).size() == 0) {
|
if (this.pack.get(this.getCurrentBoosterIndex()).size() == 0) {
|
||||||
pack = get8BoosterPack();
|
this.pack = this.get8BoosterPack();
|
||||||
}
|
}
|
||||||
|
|
||||||
computerChoose();
|
this.computerChoose();
|
||||||
return ItemPool.createFrom(pack.get(getCurrentBoosterIndex()), CardPrinted.class);
|
return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>get8BoosterPack.</p>
|
* <p>
|
||||||
|
* get8BoosterPack.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return an array of {@link forge.CardList} objects.
|
* @return an array of {@link forge.CardList} objects.
|
||||||
*/
|
*/
|
||||||
public List<List<CardPrinted>> get8BoosterPack() {
|
public List<List<CardPrinted>> get8BoosterPack() {
|
||||||
if (nextBoosterGroup >= packs.size()) { return null; }
|
if (this.nextBoosterGroup >= this.packs.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
List<List<CardPrinted>> list = new ArrayList<List<CardPrinted>>();
|
final List<List<CardPrinted>> list = new ArrayList<List<CardPrinted>>();
|
||||||
for (int i = 0; i < 8; i++) { list.add(packs.get(nextBoosterGroup).apply()); }
|
for (int i = 0; i < 8; i++) {
|
||||||
|
list.add(this.packs.get(this.nextBoosterGroup).apply());
|
||||||
|
}
|
||||||
|
|
||||||
nextBoosterGroup++;
|
this.nextBoosterGroup++;
|
||||||
currentBoosterSize = list.get(0).size();
|
this.currentBoosterSize = list.get(0).size();
|
||||||
currentBoosterPick = 0;
|
this.currentBoosterPick = 0;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
//size 7, all the computers decks
|
// size 7, all the computers decks
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getDecks.</p>
|
* <p>
|
||||||
|
* getDecks.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return an array of {@link forge.deck.Deck} objects.
|
* @return an array of {@link forge.deck.Deck} objects.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Deck[] getDecks() {
|
public Deck[] getDecks() {
|
||||||
return draftAI.getDecks();
|
return this.draftAI.getDecks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void computerChoose() {
|
private void computerChoose() {
|
||||||
|
|
||||||
int iHumansBooster = getCurrentBoosterIndex();
|
final int iHumansBooster = this.getCurrentBoosterIndex();
|
||||||
int iPlayer = 0;
|
int iPlayer = 0;
|
||||||
for (int i = 0; i < pack.size(); i++) {
|
for (int i = 0; i < this.pack.size(); i++) {
|
||||||
if (iHumansBooster == i) { continue; } // don't touch player's booster
|
if (iHumansBooster == i) {
|
||||||
|
continue;
|
||||||
|
} // don't touch player's booster
|
||||||
|
|
||||||
CardList forAi = new CardList();
|
final CardList forAi = new CardList();
|
||||||
List<CardPrinted> booster = pack.get(i);
|
final List<CardPrinted> booster = this.pack.get(i);
|
||||||
for (CardPrinted cr : booster) {
|
for (final CardPrinted cr : booster) {
|
||||||
forAi.add(cr.toForgeCard());
|
forAi.add(cr.toForgeCard());
|
||||||
}
|
}
|
||||||
// TODO: Please write this drafting code to work without heavy card objects
|
// TODO: Please write this drafting code to work without heavy card
|
||||||
Card aiPick = draftAI.choose(forAi, iPlayer++);
|
// objects
|
||||||
String pickedName = aiPick.getName();
|
final Card aiPick = this.draftAI.choose(forAi, iPlayer++);
|
||||||
|
final String pickedName = aiPick.getName();
|
||||||
|
|
||||||
for (int pick = booster.size() - 1; pick >= 0; pick--) {
|
for (int pick = booster.size() - 1; pick >= 0; pick--) {
|
||||||
CardPrinted cp = booster.get(pick);
|
final CardPrinted cp = booster.get(pick);
|
||||||
if (cp.getName().equalsIgnoreCase(pickedName)) {
|
if (cp.getName().equalsIgnoreCase(pickedName)) {
|
||||||
booster.remove(pick);
|
booster.remove(pick);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //computerChoose()
|
} // computerChoose()
|
||||||
|
|
||||||
private int getCurrentBoosterIndex() {
|
private int getCurrentBoosterIndex() {
|
||||||
return currentBoosterPick % nPlayers;
|
return this.currentBoosterPick % BoosterDraft_1.N_PLAYERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>hasNextChoice.</p>
|
* <p>
|
||||||
|
* hasNextChoice.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean hasNextChoice() {
|
public boolean hasNextChoice() {
|
||||||
boolean isLastGroup = nextBoosterGroup >= packs.size();
|
final boolean isLastGroup = this.nextBoosterGroup >= this.packs.size();
|
||||||
boolean isBoosterDepleted = currentBoosterPick >= currentBoosterSize;
|
final boolean isBoosterDepleted = this.currentBoosterPick >= this.currentBoosterSize;
|
||||||
boolean noMoreCards = isLastGroup && isBoosterDepleted;
|
final boolean noMoreCards = isLastGroup && isBoosterDepleted;
|
||||||
return !noMoreCards;
|
return !noMoreCards;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
public void setChoice(final CardPrinted c) {
|
public void setChoice(final CardPrinted c) {
|
||||||
List<CardPrinted> thisBooster = pack.get(getCurrentBoosterIndex());
|
final List<CardPrinted> thisBooster = this.pack.get(this.getCurrentBoosterIndex());
|
||||||
|
|
||||||
if (!thisBooster.contains(c)) {
|
if (!thisBooster.contains(c)) {
|
||||||
throw new RuntimeException("BoosterDraft : setChoice() error - card not found - " + c + " - booster pack = " + thisBooster);
|
throw new RuntimeException("BoosterDraft : setChoice() error - card not found - " + c
|
||||||
|
+ " - booster pack = " + thisBooster);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Constant.Runtime.UPLOAD_DRAFT[0]) {
|
if (Constant.Runtime.UPLOAD_DRAFT[0]) {
|
||||||
for (int i = 0; i < thisBooster.size(); i++) {
|
for (int i = 0; i < thisBooster.size(); i++) {
|
||||||
CardPrinted cc = thisBooster.get(i);
|
final CardPrinted cc = thisBooster.get(i);
|
||||||
String cnBk = cc.getName() + "|" + cc.getSet();
|
final String cnBk = cc.getName() + "|" + cc.getSet();
|
||||||
|
|
||||||
float pickValue = 0;
|
float pickValue = 0;
|
||||||
if (cc.equals(c)) {
|
if (cc.equals(c)) {
|
||||||
pickValue = thisBooster.size() * (1f - ((float) currentBoosterPick / currentBoosterSize) * 2f);
|
pickValue = thisBooster.size()
|
||||||
|
* (1f - (((float) this.currentBoosterPick / this.currentBoosterSize) * 2f));
|
||||||
} else {
|
} else {
|
||||||
pickValue = 0;
|
pickValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!draftPicks.containsKey(cnBk)) {
|
if (!this.draftPicks.containsKey(cnBk)) {
|
||||||
draftPicks.put(cnBk, pickValue);
|
this.draftPicks.put(cnBk, pickValue);
|
||||||
} else {
|
} else {
|
||||||
float curValue = draftPicks.get(cnBk);
|
final float curValue = this.draftPicks.get(cnBk);
|
||||||
float newValue = (curValue + pickValue) / 2;
|
final float newValue = (curValue + pickValue) / 2;
|
||||||
draftPicks.put(cnBk, newValue);
|
this.draftPicks.put(cnBk, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thisBooster.remove(c);
|
thisBooster.remove(c);
|
||||||
currentBoosterPick++;
|
this.currentBoosterPick++;
|
||||||
} //setChoice()
|
} // setChoice()
|
||||||
|
|
||||||
/** This will upload drafting picks to cardforge HQ. */
|
/** This will upload drafting picks to cardforge HQ. */
|
||||||
|
@Override
|
||||||
public void finishedDrafting() {
|
public void finishedDrafting() {
|
||||||
if (Constant.Runtime.UPLOAD_DRAFT[0]) {
|
if (Constant.Runtime.UPLOAD_DRAFT[0]) {
|
||||||
if (draftPicks.size() > 1) {
|
if (this.draftPicks.size() > 1) {
|
||||||
ArrayList<String> outDraftData = new ArrayList<String>();
|
final ArrayList<String> outDraftData = new ArrayList<String>();
|
||||||
|
|
||||||
String[] keys = draftPicks.keySet().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
final String[] keys = this.draftPicks.keySet().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
||||||
|
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (final String key : keys) {
|
||||||
outDraftData.add(keys[i] + "|" + draftPicks.get(keys[i]));
|
outDraftData.add(key + "|" + this.draftPicks.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil.writeFile("res/draft/tmpDraftData.txt", outDraftData);
|
FileUtil.writeFile("res/draft/tmpDraftData.txt", outDraftData);
|
||||||
|
|
||||||
HttpUtil poster = new HttpUtil();
|
final HttpUtil poster = new HttpUtil();
|
||||||
poster.upload("http://cardforge.org/draftAI/submitDraftData.php?fmt="
|
poster.upload("http://cardforge.org/draftAI/submitDraftData.php?fmt=" + this.draftFormat,
|
||||||
+ draftFormat, "res/draft/tmpDraftData.txt");
|
"res/draft/tmpDraftData.txt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,73 @@
|
|||||||
package forge.game.limited;
|
package forge.game.limited;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>CCnt class.</p>
|
* <p>
|
||||||
|
* CCnt class.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
class CCnt {
|
class CCnt {
|
||||||
public String Color;
|
|
||||||
public int Count;
|
/** The Color. */
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
/** The Count. */
|
||||||
|
private int count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Constructor for CCnt.</p>
|
* <p>
|
||||||
|
* Constructor for CCnt.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param clr a {@link java.lang.String} object.
|
* @param clr
|
||||||
* @param cnt a int.
|
* a {@link java.lang.String} object.
|
||||||
|
* @param cnt
|
||||||
|
* a int.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* <p>deckColors class.</p>
|
* <p>
|
||||||
|
* deckColors class.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param clr a {@link java.lang.String} object.
|
* @param clr
|
||||||
* @param cnt a int.
|
* a {@link java.lang.String} object.
|
||||||
|
* @param cnt
|
||||||
|
* a int.
|
||||||
*/
|
*/
|
||||||
public CCnt(final String clr, final int cnt) {
|
public CCnt(final String clr, final int cnt) {
|
||||||
Color = clr;
|
this.setColor(clr);
|
||||||
Count = cnt;
|
this.setCount(cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the color
|
||||||
|
*/
|
||||||
|
public String getColor() {
|
||||||
|
return this.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param color
|
||||||
|
* the color to set
|
||||||
|
*/
|
||||||
|
public void setColor(final String color) {
|
||||||
|
this.color = color; // TODO: Add 0 to parameter's name.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the count
|
||||||
|
*/
|
||||||
|
public int getCount() {
|
||||||
|
return this.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param count
|
||||||
|
* the count to set
|
||||||
|
*/
|
||||||
|
public void setCount(final int count) {
|
||||||
|
this.count = count; // TODO: Add 0 to parameter's name.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ package forge.game.limited;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public enum CardPoolLimitation {
|
public enum CardPoolLimitation {
|
||||||
|
|
||||||
|
/** The Full. */
|
||||||
Full,
|
Full,
|
||||||
Block,
|
/** The Block. */
|
||||||
Custom
|
Block,
|
||||||
|
/** The Custom. */
|
||||||
|
Custom
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,53 +5,125 @@ import java.util.List;
|
|||||||
import forge.AllZone;
|
import forge.AllZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>CustomDraft class.</p>
|
* <p>
|
||||||
|
* CustomDraft class.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
class CustomLimited {
|
class CustomLimited {
|
||||||
|
|
||||||
|
/** The Name. */
|
||||||
public String Name;
|
public String Name;
|
||||||
|
|
||||||
|
/** The Type. */
|
||||||
public String Type;
|
public String Type;
|
||||||
|
|
||||||
|
/** The Deck file. */
|
||||||
public String DeckFile;
|
public String DeckFile;
|
||||||
|
|
||||||
|
/** The Ignore rarity. */
|
||||||
public Boolean IgnoreRarity;
|
public Boolean IgnoreRarity;
|
||||||
|
|
||||||
|
/** The Singleton. */
|
||||||
public Boolean Singleton = false;
|
public Boolean Singleton = false;
|
||||||
|
|
||||||
|
/** The Num cards. */
|
||||||
public int NumCards = 15;
|
public int NumCards = 15;
|
||||||
|
|
||||||
|
/** The Num specials. */
|
||||||
public int NumSpecials = 0;
|
public int NumSpecials = 0;
|
||||||
|
|
||||||
|
/** The Num mythics. */
|
||||||
public int NumMythics = 1;
|
public int NumMythics = 1;
|
||||||
|
|
||||||
|
/** The Num rares. */
|
||||||
public int NumRares = 1;
|
public int NumRares = 1;
|
||||||
|
|
||||||
|
/** The Num uncommons. */
|
||||||
public int NumUncommons = 3;
|
public int NumUncommons = 3;
|
||||||
|
|
||||||
|
/** The Num commons. */
|
||||||
public int NumCommons = 11;
|
public int NumCommons = 11;
|
||||||
|
|
||||||
|
/** The Num double faced. */
|
||||||
public int NumDoubleFaced = 0;
|
public int NumDoubleFaced = 0;
|
||||||
|
|
||||||
|
/** The Num packs. */
|
||||||
public int NumPacks = 3;
|
public int NumPacks = 3;
|
||||||
|
|
||||||
|
/** The Land set code. */
|
||||||
public String LandSetCode = AllZone.getCardFactory().getCard("Plains", AllZone.getHumanPlayer()).getMostRecentSet();
|
public String LandSetCode = AllZone.getCardFactory().getCard("Plains", AllZone.getHumanPlayer()).getMostRecentSet();
|
||||||
|
|
||||||
@Override public String toString() { return Name; }
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.Name;
|
||||||
|
}
|
||||||
|
|
||||||
public static CustomLimited parse(List<String> dfData)
|
/**
|
||||||
{
|
* Parses the.
|
||||||
CustomLimited cd = new CustomLimited();
|
*
|
||||||
|
* @param dfData
|
||||||
|
* the df data
|
||||||
|
* @return the custom limited
|
||||||
|
*/
|
||||||
|
public static CustomLimited parse(final List<String> dfData) {
|
||||||
|
final CustomLimited cd = new CustomLimited();
|
||||||
|
|
||||||
for (String dd : dfData) {
|
for (final String dd : dfData) {
|
||||||
String[] v = dd.split(":", 2);
|
final String[] v = dd.split(":", 2);
|
||||||
String key = v[0];
|
final String key = v[0];
|
||||||
String value = v.length > 1 ? v[1].trim() : "";
|
final String value = v.length > 1 ? v[1].trim() : "";
|
||||||
|
|
||||||
if (key.equalsIgnoreCase("Name")) { cd.Name = value; }
|
if (key.equalsIgnoreCase("Name")) {
|
||||||
if (key.equalsIgnoreCase("Type")) { cd.Type = value; }
|
cd.Name = value;
|
||||||
if (key.equalsIgnoreCase("DeckFile")) { cd.DeckFile = value; }
|
}
|
||||||
if (key.equalsIgnoreCase("IgnoreRarity")) { cd.IgnoreRarity = value.equals("True"); }
|
if (key.equalsIgnoreCase("Type")) {
|
||||||
if (key.equalsIgnoreCase("Singleton")) { cd.Singleton = value.equals("True"); }
|
cd.Type = value;
|
||||||
if (key.equalsIgnoreCase("LandSetCode")) { cd.LandSetCode = value; }
|
}
|
||||||
|
if (key.equalsIgnoreCase("DeckFile")) {
|
||||||
|
cd.DeckFile = value;
|
||||||
|
}
|
||||||
|
if (key.equalsIgnoreCase("IgnoreRarity")) {
|
||||||
|
cd.IgnoreRarity = value.equals("True");
|
||||||
|
}
|
||||||
|
if (key.equalsIgnoreCase("Singleton")) {
|
||||||
|
cd.Singleton = value.equals("True");
|
||||||
|
}
|
||||||
|
if (key.equalsIgnoreCase("LandSetCode")) {
|
||||||
|
cd.LandSetCode = value;
|
||||||
|
}
|
||||||
|
|
||||||
if (key.equalsIgnoreCase("NumCards")) { cd.NumCards = Integer.parseInt(value); }
|
if (key.equalsIgnoreCase("NumCards")) {
|
||||||
if (key.equalsIgnoreCase("NumDoubleFaced")) { cd.NumDoubleFaced = Integer.parseInt(value); }
|
cd.NumCards = Integer.parseInt(value);
|
||||||
if (key.equalsIgnoreCase("NumSpecials")) { cd.NumSpecials = Integer.parseInt(value); }
|
}
|
||||||
if (key.equalsIgnoreCase("NumMythics")) { cd.NumMythics = Integer.parseInt(value); }
|
if (key.equalsIgnoreCase("NumDoubleFaced")) {
|
||||||
if (key.equalsIgnoreCase("NumRares")) { cd.NumRares = Integer.parseInt(value); }
|
cd.NumDoubleFaced = Integer.parseInt(value);
|
||||||
if (key.equalsIgnoreCase("NumUncommons")) { cd.NumUncommons = Integer.parseInt(value); }
|
}
|
||||||
if (key.equalsIgnoreCase("NumCommons")) { cd.NumCommons = Integer.parseInt(value); }
|
if (key.equalsIgnoreCase("NumSpecials")) {
|
||||||
if (key.equalsIgnoreCase("NumPacks")) { cd.NumPacks = Integer.parseInt(value); }
|
cd.NumSpecials = Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
if (key.equalsIgnoreCase("NumMythics")) {
|
||||||
|
cd.NumMythics = Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
if (key.equalsIgnoreCase("NumRares")) {
|
||||||
|
cd.NumRares = Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
if (key.equalsIgnoreCase("NumUncommons")) {
|
||||||
|
cd.NumUncommons = Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
if (key.equalsIgnoreCase("NumCommons")) {
|
||||||
|
cd.NumCommons = Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
if (key.equalsIgnoreCase("NumPacks")) {
|
||||||
|
cd.NumPacks = Integer.parseInt(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cd;
|
return cd;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,56 +3,71 @@ package forge.game.limited;
|
|||||||
import forge.Constant;
|
import forge.Constant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA. User: dhudson Date: 6/24/11 Time: 8:42 PM To change
|
||||||
* User: dhudson
|
* this template use File | Settings | File Templates.
|
||||||
* Date: 6/24/11
|
|
||||||
* Time: 8:42 PM
|
|
||||||
* To change this template use File | Settings | File Templates.
|
|
||||||
*/
|
*/
|
||||||
class DeckColors {
|
class DeckColors {
|
||||||
|
|
||||||
|
/** The Color1. */
|
||||||
public String Color1 = "none";
|
public String Color1 = "none";
|
||||||
|
|
||||||
|
/** The Color2. */
|
||||||
public String Color2 = "none";
|
public String Color2 = "none";
|
||||||
//public String Splash = "none";
|
// public String Splash = "none";
|
||||||
|
/** The Mana1. */
|
||||||
public String Mana1 = "";
|
public String Mana1 = "";
|
||||||
|
|
||||||
|
/** The Mana2. */
|
||||||
public String Mana2 = "";
|
public String Mana2 = "";
|
||||||
//public String ManaS = "";
|
|
||||||
|
// public String ManaS = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Constructor for deckColors.</p>
|
* <p>
|
||||||
|
* Constructor for deckColors.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param c1 a {@link java.lang.String} object.
|
* @param c1
|
||||||
* @param c2 a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
* @param sp a {@link java.lang.String} object.
|
* @param c2
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
|
* @param sp
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public DeckColors(String c1, String c2, String sp) {
|
public DeckColors(final String c1, final String c2, final String sp) {
|
||||||
Color1 = c1;
|
this.Color1 = c1;
|
||||||
Color2 = c2;
|
this.Color2 = c2;
|
||||||
//Splash = sp;
|
// Splash = sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Constructor for DeckColors.</p>
|
* <p>
|
||||||
|
* Constructor for DeckColors.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public DeckColors() {
|
public DeckColors() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>ColorToMana.</p>
|
* <p>
|
||||||
|
* ColorToMana.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param color a {@link java.lang.String} object.
|
* @param color
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public String ColorToMana(String color) {
|
public String ColorToMana(final String color) {
|
||||||
String Mana[] = {"W", "U", "B", "R", "G"};
|
final String Mana[] = { "W", "U", "B", "R", "G" };
|
||||||
|
|
||||||
for (int i = 0; i < Constant.Color.ONLY_COLORS.length; i++) {
|
for (int i = 0; i < Constant.Color.ONLY_COLORS.length; i++) {
|
||||||
if (Constant.Color.ONLY_COLORS[i].equals(color))
|
if (Constant.Color.ONLY_COLORS[i].equals(color)) {
|
||||||
return Mana[i];
|
return Mana[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
package forge.game.limited;
|
package forge.game.limited;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||||
|
import net.slightlymagic.maxmtg.Closure1;
|
||||||
import forge.AllZone;
|
import forge.AllZone;
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardList;
|
import forge.CardList;
|
||||||
@@ -21,164 +29,180 @@ import forge.item.CardDb;
|
|||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
import forge.item.ItemPool;
|
import forge.item.ItemPool;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
|
||||||
import net.slightlymagic.maxmtg.Closure1;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>SealedDeck class.</p>
|
* <p>
|
||||||
|
* SealedDeck class.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
* @since 1.0.15
|
* @since 1.0.15
|
||||||
*/
|
*/
|
||||||
public class SealedDeck {
|
public class SealedDeck {
|
||||||
private List<Closure1<List<CardPrinted>, BoosterGenerator>> packs = new ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>>();
|
private final List<Closure1<List<CardPrinted>, BoosterGenerator>> packs = new ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>>();
|
||||||
public String LandSetCode[] = {""};
|
|
||||||
|
/** The Land set code. */
|
||||||
|
public String LandSetCode[] = { "" };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Constructor for SealedDeck.</p>
|
* <p>
|
||||||
|
* Constructor for SealedDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param sealedType a {@link java.lang.String} object.
|
* @param sealedType
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public SealedDeck(String sealedType) {
|
public SealedDeck(final String sealedType) {
|
||||||
|
|
||||||
if (sealedType.equals("Full")) {
|
if (sealedType.equals("Full")) {
|
||||||
BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
|
final BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
|
||||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull);
|
final Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull);
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++) {
|
||||||
packs.add(picker);
|
this.packs.add(picker);
|
||||||
|
}
|
||||||
|
|
||||||
LandSetCode[0] = CardDb.instance().getCard("Plains").getSet();
|
this.LandSetCode[0] = CardDb.instance().getCard("Plains").getSet();
|
||||||
} else if (sealedType.equals("Block")) {
|
} else if (sealedType.equals("Block")) {
|
||||||
|
|
||||||
Object o = GuiUtils.getChoice("Choose Block", SetUtils.getBlocks().toArray());
|
final Object o = GuiUtils.getChoice("Choose Block", SetUtils.getBlocks().toArray());
|
||||||
CardBlock block = (CardBlock) o;
|
final CardBlock block = (CardBlock) o;
|
||||||
|
|
||||||
CardSet[] cardSets = block.getSets();
|
final CardSet[] cardSets = block.getSets();
|
||||||
String[] sets = new String[cardSets.length];
|
final String[] sets = new String[cardSets.length];
|
||||||
for (int k = cardSets.length - 1; k >= 0 ; --k) { sets[k] = cardSets[k].getCode();}
|
for (int k = cardSets.length - 1; k >= 0; --k) {
|
||||||
|
sets[k] = cardSets[k].getCode();
|
||||||
|
}
|
||||||
|
|
||||||
int nPacks = block.getCntBoostersSealed();
|
final int nPacks = block.getCntBoostersSealed();
|
||||||
|
|
||||||
List<String> setCombos = new ArrayList<String>();
|
final List<String> setCombos = new ArrayList<String>();
|
||||||
if (sets.length >= 2) {
|
if (sets.length >= 2) {
|
||||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[0], sets[0], sets[0], sets[0], sets[0], sets[0]));
|
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[0], sets[0], sets[0], sets[0], sets[0], sets[0]));
|
||||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[0], sets[0], sets[0], sets[0]));
|
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[0], sets[0], sets[0], sets[0]));
|
||||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[1], sets[0], sets[0], sets[0]));
|
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[1], sets[0], sets[0], sets[0]));
|
||||||
}
|
}
|
||||||
if (sets.length >= 3) {
|
if (sets.length >= 3) {
|
||||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[2], sets[0], sets[0], sets[0]));
|
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[2], sets[0], sets[0], sets[0]));
|
||||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[1], sets[1], sets[0], sets[0]));
|
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[1], sets[1], sets[0], sets[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (sets.length > 1) {
|
if (sets.length > 1) {
|
||||||
Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
final Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
||||||
|
|
||||||
String[] pp = p.toString().split("/");
|
final String[] pp = p.toString().split("/");
|
||||||
for (int i = 0; i < nPacks; i++) {
|
for (int i = 0; i < nPacks; i++) {
|
||||||
BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
final BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
||||||
packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
this.packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
final BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
||||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpOne);
|
final Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpOne);
|
||||||
for (int i = 0; i < nPacks; i++) { packs.add(picker); }
|
for (int i = 0; i < nPacks; i++) {
|
||||||
|
this.packs.add(picker);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LandSetCode[0] = block.getLandSet().getCode();
|
this.LandSetCode[0] = block.getLandSet().getCode();
|
||||||
|
|
||||||
} else if (sealedType.equals("Custom")) {
|
} else if (sealedType.equals("Custom")) {
|
||||||
String dList[];
|
String dList[];
|
||||||
ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();
|
final ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();
|
||||||
|
|
||||||
// get list of custom draft files
|
// get list of custom draft files
|
||||||
File dFolder = new File("res/sealed/");
|
final File dFolder = new File("res/sealed/");
|
||||||
if (!dFolder.exists())
|
if (!dFolder.exists()) {
|
||||||
throw new RuntimeException("GenerateSealed : folder not found -- folder is " + dFolder.getAbsolutePath());
|
throw new RuntimeException("GenerateSealed : folder not found -- folder is "
|
||||||
|
+ dFolder.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
if (!dFolder.isDirectory())
|
if (!dFolder.isDirectory()) {
|
||||||
throw new RuntimeException("GenerateSealed : not a folder -- " + dFolder.getAbsolutePath());
|
throw new RuntimeException("GenerateSealed : not a folder -- " + dFolder.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
dList = dFolder.list();
|
dList = dFolder.list();
|
||||||
|
|
||||||
for (int i = 0; i < dList.length; i++) {
|
for (final String element : dList) {
|
||||||
if (dList[i].endsWith(".sealed")) {
|
if (element.endsWith(".sealed")) {
|
||||||
ArrayList<String> dfData = FileUtil.readFile("res/sealed/" + dList[i]);
|
final ArrayList<String> dfData = FileUtil.readFile("res/sealed/" + element);
|
||||||
CustomLimited cs = CustomLimited.parse(dfData);
|
final CustomLimited cs = CustomLimited.parse(dfData);
|
||||||
customs.add(cs);
|
customs.add(cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// present list to user
|
// present list to user
|
||||||
if (customs.size() < 1)
|
if (customs.size() < 1) {
|
||||||
JOptionPane.showMessageDialog(null, "No custom sealed files found.", "", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "No custom sealed files found.", "",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} else {
|
||||||
|
final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Sealed Pool",
|
||||||
|
customs.toArray());
|
||||||
|
|
||||||
else {
|
final DeckManager dio = AllZone.getDeckManager();
|
||||||
final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Sealed Pool", customs.toArray());
|
final Deck dPool = dio.getDeck(draft.DeckFile);
|
||||||
|
|
||||||
DeckManager dio = AllZone.getDeckManager();
|
|
||||||
Deck dPool = dio.getDeck(draft.DeckFile);
|
|
||||||
if (dPool == null) {
|
if (dPool == null) {
|
||||||
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.DeckFile);
|
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.DeckFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
final BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
||||||
Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
final Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||||
@Override public List<CardPrinted> apply(BoosterGenerator pack) {
|
@Override
|
||||||
if ( draft.IgnoreRarity ) {
|
public List<CardPrinted> apply(final BoosterGenerator pack) {
|
||||||
|
if (draft.IgnoreRarity) {
|
||||||
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0);
|
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0);
|
||||||
}
|
}
|
||||||
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, draft.NumDoubleFaced, 0, 0);
|
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares,
|
||||||
|
draft.NumMythics, draft.NumSpecials, draft.NumDoubleFaced, 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = new Closure1<List<CardPrinted>, BoosterGenerator>(fnPick, bpCustom);
|
final Closure1<List<CardPrinted>, BoosterGenerator> picker = new Closure1<List<CardPrinted>, BoosterGenerator>(
|
||||||
|
fnPick, bpCustom);
|
||||||
|
|
||||||
for (int i = 0; i < draft.NumPacks; i++) {
|
for (int i = 0; i < draft.NumPacks; i++) {
|
||||||
packs.add(picker);
|
this.packs.add(picker);
|
||||||
}
|
}
|
||||||
|
|
||||||
LandSetCode[0] = draft.LandSetCode;
|
this.LandSetCode[0] = draft.LandSetCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getCardpool.</p>
|
* <p>
|
||||||
|
* getCardpool.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
public ItemPool<CardPrinted> getCardpool() {
|
public ItemPool<CardPrinted> getCardpool() {
|
||||||
ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class);
|
final ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||||
|
|
||||||
for (int i = 0; i < packs.size(); i++)
|
for (int i = 0; i < this.packs.size(); i++) {
|
||||||
pool.addAllCards(packs.get(i).apply());
|
pool.addAllCards(this.packs.get(i).apply());
|
||||||
|
}
|
||||||
|
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>buildAIDeck.</p>
|
* <p>
|
||||||
|
* buildAIDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param aiCardpool a {@link forge.CardList} object.
|
* @param aiCardpool
|
||||||
|
* a {@link forge.CardList} object.
|
||||||
* @return a {@link forge.deck.Deck} object.
|
* @return a {@link forge.deck.Deck} object.
|
||||||
*/
|
*/
|
||||||
public Deck buildAIDeck(CardList aiCardpool) {
|
public Deck buildAIDeck(final CardList aiCardpool) {
|
||||||
CardList deck = new CardList();
|
final CardList deck = new CardList();
|
||||||
|
|
||||||
int cardsNeeded = 22;
|
int cardsNeeded = 22;
|
||||||
int landsNeeded = 18;
|
int landsNeeded = 18;
|
||||||
int nCreatures = 15;
|
int nCreatures = 15;
|
||||||
|
|
||||||
CardList AIPlayables = aiCardpool.filter(new CardListFilter() {
|
final CardList AIPlayables = aiCardpool.filter(new CardListFilter() {
|
||||||
public boolean addCard(Card c) {
|
@Override
|
||||||
|
public boolean addCard(final Card c) {
|
||||||
return !(c.getSVar("RemAIDeck").equals("True"));
|
return !(c.getSVar("RemAIDeck").equals("True"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -186,28 +210,32 @@ public class SealedDeck {
|
|||||||
CardList creatures = AIPlayables.getType("Creature");
|
CardList creatures = AIPlayables.getType("Creature");
|
||||||
CardListUtil.sortByEvaluateCreature(creatures);
|
CardListUtil.sortByEvaluateCreature(creatures);
|
||||||
|
|
||||||
CardList colorChooserList = new CardList(); // choose colors based on top 33% of creatures
|
final CardList colorChooserList = new CardList(); // choose colors based
|
||||||
for (int i = 0; i < (creatures.size() * .33); i++)
|
// on top 33% of
|
||||||
|
// creatures
|
||||||
|
for (int i = 0; i < (creatures.size() * .33); i++) {
|
||||||
colorChooserList.add(creatures.get(i));
|
colorChooserList.add(creatures.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
int colorCounts[] = {0, 0, 0, 0, 0};
|
final int colorCounts[] = { 0, 0, 0, 0, 0 };
|
||||||
String colors[] = Constant.Color.ONLY_COLORS;
|
final String colors[] = Constant.Color.ONLY_COLORS;
|
||||||
for (int i = 0; i < colors.length; i++)
|
for (int i = 0; i < colors.length; i++) {
|
||||||
colorCounts[i] = colorChooserList.getColor(colors[i]).size();
|
colorCounts[i] = colorChooserList.getColor(colors[i]).size();
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (colorCounts[i + 1] < colorCounts[i]) {
|
if (colorCounts[i + 1] < colorCounts[i]) {
|
||||||
int t = colorCounts[i];
|
final int t = colorCounts[i];
|
||||||
colorCounts[i] = colorCounts[i + 1];
|
colorCounts[i] = colorCounts[i + 1];
|
||||||
colorCounts[i + 1] = t;
|
colorCounts[i + 1] = t;
|
||||||
|
|
||||||
String s = colors[i];
|
final String s = colors[i];
|
||||||
colors[i] = colors[i + 1];
|
colors[i] = colors[i + 1];
|
||||||
colors[i + 1] = s;
|
colors[i + 1] = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckColors dcAI = new DeckColors();
|
final DeckColors dcAI = new DeckColors();
|
||||||
dcAI.Color1 = colors[0];
|
dcAI.Color1 = colors[0];
|
||||||
dcAI.Color2 = colors[1];
|
dcAI.Color2 = colors[1];
|
||||||
dcAI.Splash = colors[2];
|
dcAI.Splash = colors[2];
|
||||||
@@ -220,8 +248,8 @@ public class SealedDeck {
|
|||||||
|
|
||||||
CardListUtil.sortByEvaluateCreature(creatures);
|
CardListUtil.sortByEvaluateCreature(creatures);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (nCreatures > 0 && i < creatures.size()) {
|
while ((nCreatures > 0) && (i < creatures.size())) {
|
||||||
Card c = creatures.get(i);
|
final Card c = creatures.get(i);
|
||||||
|
|
||||||
deck.add(c);
|
deck.add(c);
|
||||||
aiCardpool.remove(c);
|
aiCardpool.remove(c);
|
||||||
@@ -231,9 +259,9 @@ public class SealedDeck {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardList splashCreatures = AIPlayables.getType("Creature").getColor(dcAI.Splash);
|
final CardList splashCreatures = AIPlayables.getType("Creature").getColor(dcAI.Splash);
|
||||||
while (nCreatures > 1 && splashCreatures.size() > 1) {
|
while ((nCreatures > 1) && (splashCreatures.size() > 1)) {
|
||||||
Card c = splashCreatures.get(MyRandom.getRandom().nextInt(splashCreatures.size() - 1));
|
final Card c = splashCreatures.get(MyRandom.getRandom().nextInt(splashCreatures.size() - 1));
|
||||||
|
|
||||||
deck.add(c);
|
deck.add(c);
|
||||||
aiCardpool.remove(c);
|
aiCardpool.remove(c);
|
||||||
@@ -243,7 +271,7 @@ public class SealedDeck {
|
|||||||
nCreatures--;
|
nCreatures--;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardList walkers = AIPlayables.getType("Planeswalker").getOnly2Colors(dcAI.Color1, dcAI.Color2);
|
final CardList walkers = AIPlayables.getType("Planeswalker").getOnly2Colors(dcAI.Color1, dcAI.Color2);
|
||||||
if (walkers.size() > 0) {
|
if (walkers.size() > 0) {
|
||||||
deck.add(walkers.get(0));
|
deck.add(walkers.get(0));
|
||||||
AIPlayables.remove(walkers.get(0));
|
AIPlayables.remove(walkers.get(0));
|
||||||
@@ -251,12 +279,12 @@ public class SealedDeck {
|
|||||||
cardsNeeded--;
|
cardsNeeded--;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardList spells = AIPlayables.getType("Instant").getOnly2Colors(dcAI.Color1, dcAI.Color2);
|
final CardList spells = AIPlayables.getType("Instant").getOnly2Colors(dcAI.Color1, dcAI.Color2);
|
||||||
spells.addAll(AIPlayables.getType("Sorcery").getOnly2Colors(dcAI.Color1, dcAI.Color2));
|
spells.addAll(AIPlayables.getType("Sorcery").getOnly2Colors(dcAI.Color1, dcAI.Color2));
|
||||||
spells.addAll(AIPlayables.getType("Enchantment").getOnly2Colors(dcAI.Color1, dcAI.Color2));
|
spells.addAll(AIPlayables.getType("Enchantment").getOnly2Colors(dcAI.Color1, dcAI.Color2));
|
||||||
|
|
||||||
while (cardsNeeded > 0 && spells.size() > 1) {
|
while ((cardsNeeded > 0) && (spells.size() > 1)) {
|
||||||
Card c = spells.get(MyRandom.getRandom().nextInt(spells.size() - 1));
|
final Card c = spells.get(MyRandom.getRandom().nextInt(spells.size() - 1));
|
||||||
deck.add(c);
|
deck.add(c);
|
||||||
spells.remove(c);
|
spells.remove(c);
|
||||||
AIPlayables.remove(c);
|
AIPlayables.remove(c);
|
||||||
@@ -264,11 +292,11 @@ public class SealedDeck {
|
|||||||
cardsNeeded--;
|
cardsNeeded--;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardList splashSpells = AIPlayables.getType("Instant").getColor(dcAI.Splash);
|
final CardList splashSpells = AIPlayables.getType("Instant").getColor(dcAI.Splash);
|
||||||
splashSpells.addAll(AIPlayables.getType("Sorcery").getColor(dcAI.Splash));
|
splashSpells.addAll(AIPlayables.getType("Sorcery").getColor(dcAI.Splash));
|
||||||
|
|
||||||
while (cardsNeeded > 0 && splashSpells.size() > 1) {
|
while ((cardsNeeded > 0) && (splashSpells.size() > 1)) {
|
||||||
Card c = splashSpells.get(MyRandom.getRandom().nextInt(splashSpells.size() - 1));
|
final Card c = splashSpells.get(MyRandom.getRandom().nextInt(splashSpells.size() - 1));
|
||||||
deck.add(c);
|
deck.add(c);
|
||||||
splashSpells.remove(c);
|
splashSpells.remove(c);
|
||||||
AIPlayables.remove(c);
|
AIPlayables.remove(c);
|
||||||
@@ -276,16 +304,18 @@ public class SealedDeck {
|
|||||||
cardsNeeded--;
|
cardsNeeded--;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardList lands = AIPlayables.getType("Land");
|
final CardList lands = AIPlayables.getType("Land");
|
||||||
if (lands.size() > 0) {
|
if (lands.size() > 0) {
|
||||||
final DeckColors AIdc = dcAI; // just for the filter
|
final DeckColors AIdc = dcAI; // just for the filter
|
||||||
|
|
||||||
lands.filter(new CardListFilter() {
|
lands.filter(new CardListFilter() {
|
||||||
public boolean addCard(Card c) {
|
@Override
|
||||||
ArrayList<Ability_Mana> maList = c.getManaAbility();
|
public boolean addCard(final Card c) {
|
||||||
|
final ArrayList<Ability_Mana> maList = c.getManaAbility();
|
||||||
for (int j = 0; j < maList.size(); j++) {
|
for (int j = 0; j < maList.size(); j++) {
|
||||||
if (maList.get(j).canProduce(AIdc.Mana1) || maList.get(j).canProduce(AIdc.Mana2))
|
if (maList.get(j).canProduce(AIdc.Mana1) || maList.get(j).canProduce(AIdc.Mana2)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -294,7 +324,7 @@ public class SealedDeck {
|
|||||||
|
|
||||||
if (lands.size() > 0) {
|
if (lands.size() > 0) {
|
||||||
for (i = 0; i < lands.size(); i++) {
|
for (i = 0; i < lands.size(); i++) {
|
||||||
Card c = lands.get(i);
|
final Card c = lands.get(i);
|
||||||
|
|
||||||
deck.add(c);
|
deck.add(c);
|
||||||
aiCardpool.remove(c);
|
aiCardpool.remove(c);
|
||||||
@@ -304,52 +334,56 @@ public class SealedDeck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (landsNeeded > 0) // attempt to optimize basic land counts according to color representation
|
if (landsNeeded > 0) // attempt to optimize basic land counts
|
||||||
|
// according to color representation
|
||||||
{
|
{
|
||||||
CCnt ClrCnts[] = {new CCnt("Plains", 0),
|
final CCnt ClrCnts[] = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
|
||||||
new CCnt("Island", 0),
|
new CCnt("Mountain", 0), new CCnt("Forest", 0) };
|
||||||
new CCnt("Swamp", 0),
|
|
||||||
new CCnt("Mountain", 0),
|
|
||||||
new CCnt("Forest", 0)};
|
|
||||||
|
|
||||||
// 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 (i = 0; i < deck.size(); i++) {
|
for (i = 0; i < deck.size(); i++) {
|
||||||
String mc = deck.get(i).getManaCost();
|
final String mc = deck.get(i).getManaCost();
|
||||||
|
|
||||||
// count each mana symbol in the mana cost
|
// count each mana symbol in the mana cost
|
||||||
for (int j = 0; j < mc.length(); j++) {
|
for (int j = 0; j < mc.length(); j++) {
|
||||||
char c = mc.charAt(j);
|
final char c = mc.charAt(j);
|
||||||
|
|
||||||
if (c == 'W')
|
if (c == 'W') {
|
||||||
ClrCnts[0].Count++;
|
ClrCnts[0].setCount(ClrCnts[0].getCount() + 1);
|
||||||
else if (c == 'U')
|
} else if (c == 'U') {
|
||||||
ClrCnts[1].Count++;
|
ClrCnts[1].setCount(ClrCnts[1].getCount() + 1);
|
||||||
else if (c == 'B')
|
} else if (c == 'B') {
|
||||||
ClrCnts[2].Count++;
|
ClrCnts[2].setCount(ClrCnts[2].getCount() + 1);
|
||||||
else if (c == 'R')
|
} else if (c == 'R') {
|
||||||
ClrCnts[3].Count++;
|
ClrCnts[3].setCount(ClrCnts[3].getCount() + 1);
|
||||||
else if (c == 'G')
|
} else if (c == 'G') {
|
||||||
ClrCnts[4].Count++;
|
ClrCnts[4].setCount(ClrCnts[4].getCount() + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// total of all ClrCnts
|
// total of all ClrCnts
|
||||||
int totalColor = 0;
|
int totalColor = 0;
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
totalColor += ClrCnts[i].Count;
|
totalColor += ClrCnts[i].getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
if (ClrCnts[i].Count > 0) { // calculate number of lands for each color
|
if (ClrCnts[i].getCount() > 0) { // calculate number of
|
||||||
float p = (float) ClrCnts[i].Count / (float) totalColor;
|
// lands for
|
||||||
int nLand = (int) ((float) landsNeeded * p) + 1;
|
// each color
|
||||||
//tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n";
|
final float p = (float) ClrCnts[i].getCount() / (float) totalColor;
|
||||||
if (Constant.Runtime.DEV_MODE[0])
|
final int nLand = (int) (landsNeeded * p) + 1;
|
||||||
System.out.println("Basics[" + ClrCnts[i].Color + "]:" + nLand);
|
// tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand
|
||||||
|
// + "\n";
|
||||||
|
if (Constant.Runtime.DEV_MODE[0]) {
|
||||||
|
System.out.println("Basics[" + ClrCnts[i].getColor() + "]:" + nLand);
|
||||||
|
}
|
||||||
|
|
||||||
for (int j = 0; j <= nLand; j++) {
|
for (int j = 0; j <= nLand; j++) {
|
||||||
Card c = AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer());
|
final Card c = AllZone.getCardFactory().getCard(ClrCnts[i].getColor(),
|
||||||
|
AllZone.getComputerPlayer());
|
||||||
c.setCurSetCode(this.LandSetCode[0]);
|
c.setCurSetCode(this.LandSetCode[0]);
|
||||||
deck.add(c);
|
deck.add(c);
|
||||||
landsNeeded--;
|
landsNeeded--;
|
||||||
@@ -358,63 +392,103 @@ public class SealedDeck {
|
|||||||
}
|
}
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (landsNeeded > 0) {
|
while (landsNeeded > 0) {
|
||||||
if (ClrCnts[n].Count > 0) {
|
if (ClrCnts[n].getCount() > 0) {
|
||||||
Card c = AllZone.getCardFactory().getCard(ClrCnts[n].Color, AllZone.getComputerPlayer());
|
final Card c = AllZone.getCardFactory().getCard(ClrCnts[n].getColor(),
|
||||||
|
AllZone.getComputerPlayer());
|
||||||
c.setCurSetCode(this.LandSetCode[0]);
|
c.setCurSetCode(this.LandSetCode[0]);
|
||||||
deck.add(c);
|
deck.add(c);
|
||||||
landsNeeded--;
|
landsNeeded--;
|
||||||
|
|
||||||
if (Constant.Runtime.DEV_MODE[0])
|
if (Constant.Runtime.DEV_MODE[0]) {
|
||||||
System.out.println("AddBasics: " + c.getName());
|
System.out.println("AddBasics: " + c.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (++n > 4)
|
if (++n > 4) {
|
||||||
n = 0;
|
n = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Deck aiDeck = new Deck(GameType.Sealed);
|
final Deck aiDeck = new Deck(GameType.Sealed);
|
||||||
|
|
||||||
for (i = 0; i < deck.size(); i++)
|
for (i = 0; i < deck.size(); i++) {
|
||||||
aiDeck.addMain(deck.get(i).getName() + "|" + deck.get(i).getCurSetCode());
|
aiDeck.addMain(deck.get(i).getName() + "|" + deck.get(i).getCurSetCode());
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < aiCardpool.size(); i++)
|
for (i = 0; i < aiCardpool.size(); i++) {
|
||||||
aiDeck.addSideboard(aiCardpool.get(i).getName() + "|" + aiCardpool.get(i).getCurSetCode());
|
aiDeck.addSideboard(aiCardpool.get(i).getName() + "|" + aiCardpool.get(i).getCurSetCode());
|
||||||
|
}
|
||||||
|
|
||||||
return aiDeck;
|
return aiDeck;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class DeckColors.
|
||||||
|
*/
|
||||||
class DeckColors {
|
class DeckColors {
|
||||||
|
|
||||||
|
/** The Color1. */
|
||||||
public String Color1 = "none";
|
public String Color1 = "none";
|
||||||
|
|
||||||
|
/** The Color2. */
|
||||||
public String Color2 = "none";
|
public String Color2 = "none";
|
||||||
|
|
||||||
|
/** The Splash. */
|
||||||
public String Splash = "none";
|
public String Splash = "none";
|
||||||
|
|
||||||
|
/** The Mana1. */
|
||||||
public String Mana1 = "";
|
public String Mana1 = "";
|
||||||
|
|
||||||
|
/** The Mana2. */
|
||||||
public String Mana2 = "";
|
public String Mana2 = "";
|
||||||
|
|
||||||
|
/** The Mana s. */
|
||||||
public String ManaS = "";
|
public String ManaS = "";
|
||||||
|
|
||||||
public DeckColors(String c1, String c2, String sp) {
|
/**
|
||||||
Color1 = c1;
|
* Instantiates a new deck colors.
|
||||||
Color2 = c2;
|
*
|
||||||
//Splash = sp;
|
* @param c1
|
||||||
|
* the c1
|
||||||
|
* @param c2
|
||||||
|
* the c2
|
||||||
|
* @param sp
|
||||||
|
* the sp
|
||||||
|
*/
|
||||||
|
public DeckColors(final String c1, final String c2, final String sp) {
|
||||||
|
this.Color1 = c1;
|
||||||
|
this.Color2 = c2;
|
||||||
|
// Splash = sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new deck colors.
|
||||||
|
*/
|
||||||
public DeckColors() {
|
public DeckColors() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String ColorToMana(String color) {
|
/**
|
||||||
String Mana[] = {"W", "U", "B", "R", "G"};
|
* Color to mana.
|
||||||
String Clrs[] = {"white", "blue", "black", "red", "green"};
|
*
|
||||||
|
* @param color
|
||||||
|
* the color
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public String ColorToMana(final String color) {
|
||||||
|
final String Mana[] = { "W", "U", "B", "R", "G" };
|
||||||
|
final String Clrs[] = { "white", "blue", "black", "red", "green" };
|
||||||
|
|
||||||
for (int i = 0; i < Constant.Color.ONLY_COLORS.length; i++) {
|
for (int i = 0; i < Constant.Color.ONLY_COLORS.length; i++) {
|
||||||
if (Clrs[i].equals(color))
|
if (Clrs[i].equals(color)) {
|
||||||
return Mana[i];
|
return Mana[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
/** Forge Card Game */
|
/** Forge Card Game */
|
||||||
package forge.game.limited;
|
package forge.game.limited;
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
/** Forge Card Game */
|
/** Forge Card Game. */
|
||||||
package forge.game;
|
package forge.game;
|
||||||
|
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
|||||||
ItemPoolView<CardPrinted> list = ItemPool.createFrom(bottom.getCards(), CardPrinted.class);
|
ItemPoolView<CardPrinted> list = ItemPool.createFrom(bottom.getCards(), CardPrinted.class);
|
||||||
deck.addSideboard(list);
|
deck.addSideboard(list);
|
||||||
|
|
||||||
String landSet = BoosterDraft.LandSetCode[0];
|
String landSet = BoosterDraft.LAND_SET_CODE[0];
|
||||||
final int LANDS_COUNT = 20;
|
final int LANDS_COUNT = 20;
|
||||||
deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT);
|
deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT);
|
||||||
deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), LANDS_COUNT);
|
deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), LANDS_COUNT);
|
||||||
|
|||||||
Reference in New Issue
Block a user