Refactoring (#1543)
* Fix typos. * Remove unnecessary boxing/unboxing. * Replace traditional 'for' loops with 'foreach' loops. * Replace explicit types with <> (diamonds) where they can be inferred. * Collapse identical catch branches. * Replace statement lambda with expression lambda for short statements. * Remove unnecessary imports. * Replace some lambdas with Comparator.comparing * Replace Runnables with lambdas. * Use addAll instead of adding whole collection manually. * Simplify boolean expressions. * Remove redundant 'else'. * Simplify some boolean conditions that are always true or false. * Inline redundant local variables. * Remove extraneous semicolons. * Fix Javadoc errors. * Replace anonymous classes with lambdas. * Replace chain of 'if's with switch. * Remove delaration of exception that is never thrown. * Use String/StringBuilder properly.master
parent
66ffd3f1d1
commit
bd5ae5fd7a
|
@ -74,7 +74,7 @@ class CommandLineArgs {
|
|||
case "--headless":
|
||||
headless = true;
|
||||
break;
|
||||
case "--duels": // the number of duels to playe [--duels 1].
|
||||
case "--duels": // the number of duels to play [--duels 1].
|
||||
duels = Integer.parseInt(args[i + 1].trim());
|
||||
break;
|
||||
|
||||
|
|
|
@ -35,71 +35,84 @@ public class DeckStrCal {
|
|||
for (int i = 0; i < args.length; i += 2) {
|
||||
final String curr = args[i];
|
||||
final String next = args[i+1];
|
||||
if ("--games".equals(curr)) {
|
||||
try { //parse CLI option
|
||||
games = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! number of games not an integer");
|
||||
switch (curr) {
|
||||
case "--games":
|
||||
try { //parse CLI option
|
||||
games = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! number of games not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
break;
|
||||
case "--str1":
|
||||
try { //parse CLI option
|
||||
str[0] = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! AI strength not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
break;
|
||||
case "--str2":
|
||||
try { //parse CLI option
|
||||
str[1] = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! AI strength not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
break;
|
||||
case "--deck1":
|
||||
deck[0] = next;
|
||||
break;
|
||||
case "--deck2":
|
||||
deck[1] = next;
|
||||
break;
|
||||
case "--profile":
|
||||
profile = next;
|
||||
break;
|
||||
case "--ai1":
|
||||
try { //parse CLI option
|
||||
ai[0] = MagicAIImpl.valueOf(next);
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
System.err.println("Error: " + next + " is not valid AI");
|
||||
validArgs = false;
|
||||
}
|
||||
break;
|
||||
case "--ai2":
|
||||
try { //parse CLI option
|
||||
ai[1] = MagicAIImpl.valueOf(next);
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
System.err.println("Error: " + next + " is not valid AI");
|
||||
validArgs = false;
|
||||
}
|
||||
break;
|
||||
case "--life":
|
||||
try { //parse CLI option
|
||||
life = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! starting life is not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
break;
|
||||
case "--repeat":
|
||||
try { //parse CLI option
|
||||
repeat = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! repeat is not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
break;
|
||||
case "--seed":
|
||||
try { //parse CLI option
|
||||
seed = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! seed is not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.err.println("Error: unknown option " + curr);
|
||||
validArgs = false;
|
||||
}
|
||||
} else if ("--str1".equals(curr)) {
|
||||
try { //parse CLI option
|
||||
str[0] = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! AI strength not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
} else if ("--str2".equals(curr)) {
|
||||
try { //parse CLI option
|
||||
str[1] = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! AI strength not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
} else if ("--deck1".equals(curr)) {
|
||||
deck[0] = next;
|
||||
} else if ("--deck2".equals(curr)) {
|
||||
deck[1] = next;
|
||||
} else if ("--profile".equals(curr)) {
|
||||
profile = next;
|
||||
} else if ("--ai1".equals(curr)) {
|
||||
try { //parse CLI option
|
||||
ai[0] = MagicAIImpl.valueOf(next);
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
System.err.println("Error: " + next + " is not valid AI");
|
||||
validArgs = false;
|
||||
}
|
||||
} else if ("--ai2".equals(curr)) {
|
||||
try { //parse CLI option
|
||||
ai[1] = MagicAIImpl.valueOf(next);
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
System.err.println("Error: " + next + " is not valid AI");
|
||||
validArgs = false;
|
||||
}
|
||||
} else if ("--life".equals(curr)) {
|
||||
try { //parse CLI option
|
||||
life = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! starting life is not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
} else if ("--repeat".equals(curr)) {
|
||||
try { //parse CLI option
|
||||
repeat = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! repeat is not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
} else if ("--seed".equals(curr)) {
|
||||
try { //parse CLI option
|
||||
seed = Integer.parseInt(next);
|
||||
} catch (final NumberFormatException ex) {
|
||||
System.err.println("ERROR! seed is not an integer");
|
||||
validArgs = false;
|
||||
}
|
||||
} else {
|
||||
System.err.println("Error: unknown option " + curr);
|
||||
validArgs = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,7 @@ public class FiremindQueueWorker {
|
|||
p.waitFor();
|
||||
reader.close();
|
||||
lastExitStatus = p.exitValue();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -50,8 +47,7 @@ public class FiremindQueueWorker {
|
|||
|
||||
private static boolean parseArguments(final String[] args) {
|
||||
boolean validArgs = true;
|
||||
for (int i = 0; i < args.length; i += 1) {
|
||||
final String curr = args[i];
|
||||
for (final String curr : args) {
|
||||
if ("--self-terminate".equals(curr)) {
|
||||
shutDownOnEmptyQueue = true;
|
||||
}
|
||||
|
|
|
@ -66,13 +66,13 @@ public class MagicMain {
|
|||
MagicSystem.initialize(reporter);
|
||||
if (MagicSystem.showStartupStats()) {
|
||||
final double duration = (double)(System.currentTimeMillis() - start_time) / 1000;
|
||||
System.err.println("Initalization of engine took " + duration + "s");
|
||||
System.err.println("Initialization of engine took " + duration + "s");
|
||||
}
|
||||
|
||||
LaFHelper.setDefaultLookAndFeel();
|
||||
|
||||
reporter.setMessage("Starting UI...");
|
||||
SwingUtilities.invokeLater(() -> { startUI(cmdline); });
|
||||
SwingUtilities.invokeLater(() -> startUI(cmdline));
|
||||
}
|
||||
|
||||
|
||||
|
@ -195,7 +195,7 @@ public class MagicMain {
|
|||
DeckGenerators.setRandomDeck(player);
|
||||
return;
|
||||
|
||||
} else if (!deckArg.isEmpty()) { // search for deck file.
|
||||
} else { // search for deck file.
|
||||
File deckFile = DeckUtils.findDeckFile(deckArg);
|
||||
if (deckFile != null) {
|
||||
MagicDeck deck = DeckUtils.loadDeckFromFile(deckFile.toPath());
|
||||
|
|
|
@ -50,9 +50,7 @@ public class ArtificialScore {
|
|||
if (this==INVALID_SCORE) {
|
||||
return "none";
|
||||
}
|
||||
final StringBuilder buffer=new StringBuilder();
|
||||
buffer.append(score).append(" at ").append(depth);
|
||||
return buffer.toString();
|
||||
return String.valueOf(score) + " at " + depth;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,7 +7,7 @@ public class ArtificialScoreBoard {
|
|||
private final LRUCache<Long,ArtificialScore> gameScoresMap;
|
||||
|
||||
ArtificialScoreBoard() {
|
||||
gameScoresMap=new LRUCache<Long,ArtificialScore>(100000);
|
||||
gameScoresMap= new LRUCache<>(100000);
|
||||
}
|
||||
|
||||
synchronized void setGameScore(final long gameId,final ArtificialScore aiScore) {
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ArtificialScoringSystem {
|
|||
final int score=(int)(cardDefinition.getValue()*100) - costFactor * cardDefinition.getConvertedCost() * 20;
|
||||
if (cardDefinition.isCreature()) {
|
||||
return score+(cardDefinition.getCardPower()+cardDefinition.getCardToughness())*10;
|
||||
} else if (cardDefinition.isToken() == false) {
|
||||
} else if (!cardDefinition.isToken()) {
|
||||
return score+cardDefinition.getRemoval()*50+cardDefinition.getRarity()*30;
|
||||
} else {
|
||||
return score;
|
||||
|
|
|
@ -29,7 +29,7 @@ Classical MCTS (UCT)
|
|||
- uniform random simulated playout
|
||||
- score = XX% (25000 matches against MMAB-1)
|
||||
|
||||
Enchancements to basic UCT
|
||||
Enhancements to basic UCT
|
||||
- use ratio selection (v + 10)/(n + 10)
|
||||
- UCB1 with C = 1.0
|
||||
- UCB1 with C = 2.0
|
||||
|
@ -44,16 +44,16 @@ UCT algorithm from Kocsis and Sezepesvari 2006
|
|||
Consistency Modifications for Automatically Tuned Monte-Carlo Tree Search
|
||||
consistent -> child of root with greatest number of simulations is optimal
|
||||
frugal -> do not need to visit the whole tree
|
||||
eps-greedy is not consisteny for fixed eps (with prob eps select randomly, else use score)
|
||||
eps-greedy is not consistent for fixed eps (with prob eps select randomly, else use score)
|
||||
eps-greedy is consistent but not frugal if eps dynamically decreases to 0
|
||||
UCB1 is consistent but not frugal
|
||||
score = average is not consistent
|
||||
score = (total reward + K)/(total simulation + 2K) is consistent and frugal!
|
||||
using v_t threshold ensures consistency for case of reward in {0,1} using any score function
|
||||
v(s) < v_t (0.3), randomy pick a child, else pick child that maximize score
|
||||
v(s) < v_t (0.3), randomly pick a child, else pick child that maximize score
|
||||
|
||||
Monte-Carlo Tree Search in Lines of Action
|
||||
1-ply lookahread to detect direct win for player to move
|
||||
1-ply lookahead to detect direct win for player to move
|
||||
secure child formula for decision v + A/sqrt(n)
|
||||
evaluation cut-off: use score function to stop simulation early
|
||||
use evaluation score to remove "bad" moves during simulation
|
||||
|
@ -94,7 +94,7 @@ public class MCTSAI extends MagicAI {
|
|||
private final boolean CHEAT;
|
||||
|
||||
//cache nodes to reuse them in later decision
|
||||
private final LRUCache<Long, MCTSGameTree> CACHE = new LRUCache<Long, MCTSGameTree>(1000);
|
||||
private final LRUCache<Long, MCTSGameTree> CACHE = new LRUCache<>(1000);
|
||||
|
||||
public MCTSAI(final boolean cheat) {
|
||||
CHEAT = cheat;
|
||||
|
@ -178,30 +178,24 @@ public class MCTSAI extends MagicAI {
|
|||
}
|
||||
|
||||
private Runnable genSimulationTask(final MagicGame rootGame, final LinkedList<MCTSGameTree> path, final BlockingQueue<Runnable> queue) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// propagate result of random play up the path
|
||||
final double score = randomPlay(path.getLast(), rootGame);
|
||||
queue.offer(genBackpropagationTask(score, path));
|
||||
}
|
||||
return () -> {
|
||||
// propagate result of random play up the path
|
||||
final double score = randomPlay(path.getLast(), rootGame);
|
||||
queue.offer(genBackpropagationTask(score, path));
|
||||
};
|
||||
}
|
||||
|
||||
private Runnable genBackpropagationTask(final double score, final LinkedList<MCTSGameTree> path) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Iterator<MCTSGameTree> iter = path.descendingIterator();
|
||||
MCTSGameTree child = null;
|
||||
MCTSGameTree parent = null;
|
||||
while (iter.hasNext()) {
|
||||
child = parent;
|
||||
parent = iter.next();
|
||||
return () -> {
|
||||
final Iterator<MCTSGameTree> iter = path.descendingIterator();
|
||||
MCTSGameTree child = null;
|
||||
MCTSGameTree parent = null;
|
||||
while (iter.hasNext()) {
|
||||
child = parent;
|
||||
parent = iter.next();
|
||||
|
||||
parent.removeVirtualLoss();
|
||||
parent.updateScore(child, score);
|
||||
}
|
||||
parent.removeVirtualLoss();
|
||||
parent.updateScore(child, score);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -217,7 +211,7 @@ public class MCTSAI extends MagicAI {
|
|||
) {
|
||||
|
||||
//prioritize backpropagation tasks
|
||||
while (queue.isEmpty() == false) {
|
||||
while (!queue.isEmpty()) {
|
||||
try {
|
||||
queue.take().run();
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -278,7 +272,7 @@ public class MCTSAI extends MagicAI {
|
|||
}
|
||||
|
||||
// end simulations once root is AI win or time is up
|
||||
if (running && root.isAIWin() == false) {
|
||||
if (running && !root.isAIWin()) {
|
||||
try {
|
||||
executor.execute(updateTask);
|
||||
} catch (RejectedExecutionException e) {
|
||||
|
@ -302,14 +296,13 @@ public class MCTSAI extends MagicAI {
|
|||
final StringBuilder out = new StringBuilder();
|
||||
final long duration = System.currentTimeMillis() - START_TIME;
|
||||
|
||||
out.append("MCTS" +
|
||||
" cheat=" + CHEAT +
|
||||
" index=" + scorePlayer.getIndex() +
|
||||
" life=" + scorePlayer.getLife() +
|
||||
" turn=" + scorePlayer.getGame().getTurn() +
|
||||
" phase=" + scorePlayer.getGame().getPhase().getType() +
|
||||
" sims=" + sims +
|
||||
" time=" + duration);
|
||||
out.append("MCTS cheat=").append(CHEAT)
|
||||
.append(" index=").append(scorePlayer.getIndex())
|
||||
.append(" life=").append(scorePlayer.getLife())
|
||||
.append(" turn=").append(scorePlayer.getGame().getTurn())
|
||||
.append(" phase=").append(scorePlayer.getGame().getPhase().getType())
|
||||
.append(" sims=").append(sims)
|
||||
.append(" time=").append(duration);
|
||||
out.append('\n');
|
||||
|
||||
for (final MCTSGameTree node : root) {
|
||||
|
@ -342,7 +335,7 @@ public class MCTSAI extends MagicAI {
|
|||
}
|
||||
|
||||
private LinkedList<MCTSGameTree> growTree(final MCTSGameTree root, final MagicGame game, final List<Object[]> RCHOICES) {
|
||||
final LinkedList<MCTSGameTree> path = new LinkedList<MCTSGameTree>();
|
||||
final LinkedList<MCTSGameTree> path = new LinkedList<>();
|
||||
boolean found = false;
|
||||
MCTSGameTree curr = root;
|
||||
path.add(curr);
|
||||
|
@ -509,7 +502,7 @@ public class MCTSAI extends MagicAI {
|
|||
List<Object[]> choices = null;
|
||||
if (game.getNumActions() == 0) {
|
||||
//map the RCHOICES to the current game instead of recomputing the choices
|
||||
choices = new ArrayList<Object[]>(RCHOICES.size());
|
||||
choices = new ArrayList<>(RCHOICES.size());
|
||||
for (final Object[] choice : RCHOICES) {
|
||||
choices.add(game.map(choice));
|
||||
}
|
||||
|
@ -566,7 +559,7 @@ public class MCTSAI extends MagicAI {
|
|||
class MCTSGameTree implements Iterable<MCTSGameTree> {
|
||||
|
||||
private final MCTSGameTree parent;
|
||||
private final LinkedList<MCTSGameTree> children = new LinkedList<MCTSGameTree>();
|
||||
private final LinkedList<MCTSGameTree> children = new LinkedList<>();
|
||||
private final int choice;
|
||||
private boolean isAI;
|
||||
private boolean isCached;
|
||||
|
|
|
@ -57,7 +57,7 @@ public class MMAB extends MagicAI {
|
|||
final ArtificialPruneScoreRef scoreRef = new ArtificialPruneScoreRef(new ArtificialMultiPruneScore());
|
||||
final ArtificialScoreBoard scoreBoard = new ArtificialScoreBoard();
|
||||
final ExecutorService executor = Executors.newFixedThreadPool(getMaxThreads());
|
||||
final List<ArtificialChoiceResults> achoices=new ArrayList<ArtificialChoiceResults>();
|
||||
final List<ArtificialChoiceResults> achoices= new ArrayList<>();
|
||||
final int artificialLevel = scorePlayer.getAiProfile().getAiLevel();
|
||||
final int rounds = (size + getMaxThreads() - 1) / getMaxThreads();
|
||||
final long slice = artificialLevel * SEC_TO_NANO / rounds;
|
||||
|
@ -75,18 +75,15 @@ public class MMAB extends MagicAI {
|
|||
}
|
||||
workerGame.setFastChoices(true);
|
||||
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final MMABWorker worker=new MMABWorker(
|
||||
Thread.currentThread().getId(),
|
||||
workerGame,
|
||||
scoreBoard,
|
||||
CHEAT
|
||||
);
|
||||
worker.evaluateGame(achoice, scoreRef.get(), System.nanoTime() + slice);
|
||||
scoreRef.update(achoice.aiScore.getScore());
|
||||
}
|
||||
executor.execute(() -> {
|
||||
final MMABWorker worker=new MMABWorker(
|
||||
Thread.currentThread().getId(),
|
||||
workerGame,
|
||||
scoreBoard,
|
||||
CHEAT
|
||||
);
|
||||
worker.evaluateGame(achoice, scoreRef.get(), System.nanoTime() + slice);
|
||||
scoreRef.update(achoice.aiScore.getScore());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -106,7 +103,7 @@ public class MMAB extends MagicAI {
|
|||
ArtificialChoiceResults bestAchoice = achoices.get(0);
|
||||
for (final ArtificialChoiceResults achoice : achoices) {
|
||||
if (bestScore.isBetter(achoice.aiScore, true) &&
|
||||
MovesBlackList.isBlackListed(choiceGame, event, achoice.choiceResults) == false) {
|
||||
!MovesBlackList.isBlackListed(choiceGame, event, achoice.choiceResults)) {
|
||||
bestScore = achoice.aiScore;
|
||||
bestAchoice = achoice;
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ public class MTDF extends MagicAI {
|
|||
table.put(id, entry);
|
||||
}
|
||||
|
||||
if (d == 0 || game.isFinished() || hasTime() == false) {
|
||||
if (d == 0 || game.isFinished() || !hasTime()) {
|
||||
/* leaf node */
|
||||
int g = game.getScore();
|
||||
entry.update(g, alpha, beta);
|
||||
|
|
|
@ -48,7 +48,7 @@ public class VegasAI extends MagicAI {
|
|||
|
||||
// Multiple choices
|
||||
final ExecutorService executor = Executors.newFixedThreadPool(getMaxThreads());
|
||||
final List<VegasScore> scores=new ArrayList<VegasScore>();
|
||||
final List<VegasScore> scores= new ArrayList<>();
|
||||
final int artificialLevel = scorePlayer.getAiProfile().getAiLevel();
|
||||
final int rounds = (size + getMaxThreads() - 1) / getMaxThreads();
|
||||
final long slice = artificialLevel * SEC_TO_NANO / rounds;
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.stream.Stream;
|
|||
import magic.model.MagicCardDefinition;
|
||||
import magic.model.MagicChangeCardDefinition;
|
||||
import magic.model.MagicColor;
|
||||
import magic.model.event.MagicHandCastActivation;
|
||||
import magic.ui.MagicCardImages;
|
||||
import magic.ui.screen.images.download.CardImageDisplayMode;
|
||||
import magic.utility.FileIO;
|
||||
|
@ -69,7 +68,7 @@ public class CardDefinitions {
|
|||
CompilerConfiguration.DEFAULT.getOptimizationOptions().put(CompilerConfiguration.INVOKEDYNAMIC, Boolean.TRUE);
|
||||
}
|
||||
|
||||
// groovy shell for evaluating groovy card scripts with autmatic imports
|
||||
// groovy shell for evaluating groovy card scripts with automatic imports
|
||||
private static final GroovyShell shell = new GroovyShell(
|
||||
new CompilerConfiguration().addCompilationCustomizers(
|
||||
new ImportCustomizer()
|
||||
|
@ -287,16 +286,17 @@ public class CardDefinitions {
|
|||
}
|
||||
|
||||
public static MagicCardDefinition getBasicLand(final MagicColor color) {
|
||||
if (color == MagicColor.Black) {
|
||||
return getCard("Swamp");
|
||||
} else if (color == MagicColor.Blue) {
|
||||
return getCard("Island");
|
||||
} else if (color == MagicColor.Green) {
|
||||
return getCard("Forest");
|
||||
} else if (color == MagicColor.Red) {
|
||||
return getCard("Mountain");
|
||||
} else if (color == MagicColor.White) {
|
||||
return getCard("Plains");
|
||||
switch (color) {
|
||||
case Black:
|
||||
return getCard("Swamp");
|
||||
case Blue:
|
||||
return getCard("Island");
|
||||
case Green:
|
||||
return getCard("Forest");
|
||||
case Red:
|
||||
return getCard("Mountain");
|
||||
case White:
|
||||
return getCard("Plains");
|
||||
}
|
||||
throw new RuntimeException("No matching basic land for MagicColor " + color);
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ public class CardDefinitions {
|
|||
private static void printStatistics() {
|
||||
if (MagicSystem.showStartupStats()) {
|
||||
final CardStatistics statistics=new CardStatistics(getDefaultPlayableCardDefs());
|
||||
statistics.printStatictics(System.err);
|
||||
statistics.printStatistics(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -436,7 +436,7 @@ public class CardDefinitions {
|
|||
}
|
||||
|
||||
public static List<String> getMissingCardNames() {
|
||||
List<String> names = new ArrayList<String>(getMissingCards().size());
|
||||
List<String> names = new ArrayList<>(getMissingCards().size());
|
||||
for (final MagicCardDefinition cdef : getMissingCards()) {
|
||||
names.add(cdef.getName());
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ public class CardStatistics {
|
|||
}
|
||||
}
|
||||
|
||||
void printStatictics(final PrintStream stream) {
|
||||
void printStatistics(final PrintStream stream) {
|
||||
|
||||
stream.print("Cards : "+totalCards);
|
||||
for (int index=0;index<NR_OF_TYPES;index++) {
|
||||
|
|
|
@ -57,14 +57,15 @@ public class DeckGenerator {
|
|||
}
|
||||
|
||||
private String getColorText() {
|
||||
if (maxColors == 1) {
|
||||
return MagicDeckProfile.ANY_ONE;
|
||||
} else if (maxColors == 2) {
|
||||
return MagicDeckProfile.ANY_TWO;
|
||||
} else if (maxColors == 3) {
|
||||
return MagicDeckProfile.ANY_THREE;
|
||||
} else {
|
||||
throw new IndexOutOfBoundsException("maxColors = " + maxColors);
|
||||
switch (maxColors) {
|
||||
case 1:
|
||||
return MagicDeckProfile.ANY_ONE;
|
||||
case 2:
|
||||
return MagicDeckProfile.ANY_TWO;
|
||||
case 3:
|
||||
return MagicDeckProfile.ANY_THREE;
|
||||
default:
|
||||
throw new IndexOutOfBoundsException("maxColors = " + maxColors);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ public class DeckGenerators {
|
|||
private final Map<String, RandomDeckGenerator> generatorsMap;
|
||||
|
||||
private DeckGenerators() {
|
||||
generatorsClass = new TreeMap<String, Class<? extends RandomDeckGenerator>>();
|
||||
generatorsMap = new TreeMap<String, RandomDeckGenerator>();
|
||||
generatorsClass = new TreeMap<>();
|
||||
generatorsMap = new TreeMap<>();
|
||||
}
|
||||
|
||||
public Set<String> getGeneratorNames() {
|
||||
|
@ -57,12 +57,10 @@ public class DeckGenerators {
|
|||
}
|
||||
|
||||
public RandomDeckGenerator getDeckGenerator(final String name) {
|
||||
if (generatorsClass.containsKey(name) && generatorsMap.containsKey(name) == false) {
|
||||
if (generatorsClass.containsKey(name) && !generatorsMap.containsKey(name)) {
|
||||
try {
|
||||
generatorsMap.put(name, generatorsClass.get(name).newInstance());
|
||||
} catch (final InstantiationException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (final IllegalAccessException ex) {
|
||||
} catch (final InstantiationException | IllegalAccessException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,18 +223,17 @@ public class GeneralConfig {
|
|||
public void setProxy(final Proxy proxy) {
|
||||
final String DELIM = "|";
|
||||
if (proxy != Proxy.NO_PROXY && proxy.type() != Proxy.Type.DIRECT) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(proxy.type().toString()).append(DELIM);
|
||||
sb.append(Integer.toString(((InetSocketAddress)proxy.address()).getPort())).append(DELIM);
|
||||
sb.append(proxy.address().toString());
|
||||
setProperty(PROXY_SETTINGS, sb.toString());
|
||||
String sb = proxy.type().toString() + DELIM
|
||||
+ Integer.toString(((InetSocketAddress) proxy.address()).getPort()) + DELIM
|
||||
+ proxy.address().toString();
|
||||
setProperty(PROXY_SETTINGS, sb);
|
||||
} else {
|
||||
setProperty(PROXY_SETTINGS, "");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCustomCardImagesPath() {
|
||||
return getProperty(CARD_IMAGES_PATH, "").isEmpty() == false;
|
||||
return !getProperty(CARD_IMAGES_PATH, "").isEmpty();
|
||||
}
|
||||
|
||||
public Path getCardImagesPath() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package magic.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import magic.model.MagicCardDefinition;
|
||||
|
@ -25,9 +25,7 @@ public class ImagesDownloadList extends ArrayList<DownloadableFile> {
|
|||
}
|
||||
|
||||
private void sortListByFilename() {
|
||||
Collections.sort(this, (o1, o2) ->
|
||||
o1.getFilename().compareTo(o2.getFilename())
|
||||
);
|
||||
this.sort(Comparator.comparing(DownloadableFile::getFilename));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,12 +80,7 @@ public class MagicCustomFormat extends MagicFormat {
|
|||
//
|
||||
|
||||
private static final String CUBE_FILE_EXTENSION = "_cube.txt";
|
||||
private static final FileFilter CUBE_FILE_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File file) {
|
||||
return file.isFile() && file.getName().endsWith(CUBE_FILE_EXTENSION);
|
||||
}
|
||||
};
|
||||
private static final FileFilter CUBE_FILE_FILTER = file -> file.isFile() && file.getName().endsWith(CUBE_FILE_EXTENSION);
|
||||
|
||||
private static List<MagicFormat> customFormats;
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public class OSXAdapter implements InvocationHandler {
|
|||
// com.apple.eawt.Application reflectively
|
||||
try {
|
||||
final Method enableAboutMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledAboutMenu", new Class<?>[] { boolean.class });
|
||||
enableAboutMethod.invoke(macOSXApplication, Boolean.valueOf(enableAboutMenu));
|
||||
enableAboutMethod.invoke(macOSXApplication, enableAboutMenu);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("OSXAdapter could not access the About Menu");
|
||||
ex.printStackTrace();
|
||||
|
@ -106,7 +106,7 @@ public class OSXAdapter implements InvocationHandler {
|
|||
// com.apple.eawt.Application reflectively
|
||||
try {
|
||||
final Method enablePrefsMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledPreferencesMenu", new Class<?>[] { boolean.class });
|
||||
enablePrefsMethod.invoke(macOSXApplication, Boolean.valueOf(enablePrefsMenu));
|
||||
enablePrefsMethod.invoke(macOSXApplication, enablePrefsMenu);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("OSXAdapter could not access the About Menu");
|
||||
ex.printStackTrace();
|
||||
|
@ -172,7 +172,7 @@ public class OSXAdapter implements InvocationHandler {
|
|||
if (result == null) {
|
||||
return true;
|
||||
}
|
||||
return Boolean.valueOf(result.toString()).booleanValue();
|
||||
return Boolean.valueOf(result.toString());
|
||||
}
|
||||
|
||||
// InvocationHandler implementation
|
||||
|
@ -200,7 +200,7 @@ public class OSXAdapter implements InvocationHandler {
|
|||
try {
|
||||
final Method setHandledMethod = event.getClass().getDeclaredMethod("setHandled", new Class<?>[] { boolean.class });
|
||||
// If the target method returns a boolean, use that as a hint
|
||||
setHandledMethod.invoke(event, Boolean.valueOf(handled));
|
||||
setHandledMethod.invoke(event, handled);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("OSXAdapter was unable to handle an ApplicationEvent: " + event);
|
||||
ex.printStackTrace();
|
||||
|
|
|
@ -166,12 +166,12 @@ public class TextImages {
|
|||
}
|
||||
|
||||
private static void add(final String text, final MagicIcon icon) {
|
||||
assert TEXT_ICONS.containsKey(text) == false : "Duplicate key in TextImages: " + text;
|
||||
assert !TEXT_ICONS.containsKey(text) : "Duplicate key in TextImages: " + text;
|
||||
TEXT_ICONS.put(text, icon);
|
||||
}
|
||||
|
||||
public static MagicIcon getIcon(final String text) {
|
||||
if (TEXT_ICONS.containsKey(text) == false) {
|
||||
if (!TEXT_ICONS.containsKey(text)) {
|
||||
throw new RuntimeException("No corresponding icon for " + text);
|
||||
}
|
||||
return TEXT_ICONS.get(text);
|
||||
|
|
|
@ -27,7 +27,7 @@ enum H2Schema {
|
|||
String SQL = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'GAMESTATS_SETTINGS'";
|
||||
try (PreparedStatement ps = conn.prepareStatement(SQL)) {
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next() == false) {
|
||||
if (!rs.next()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.io.PrintWriter;
|
|||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -56,7 +55,7 @@ public class FiremindClient {
|
|||
d.ai2 = obj.getString("ai2");
|
||||
|
||||
JSONArray scripts = obj.getJSONArray("card_scripts");
|
||||
addedScripts = new ArrayList<String>();
|
||||
addedScripts = new ArrayList<>();
|
||||
if(scripts != null){
|
||||
for (int i = 0; i < scripts.length(); i++) {
|
||||
JSONObject script = scripts.getJSONObject(i);
|
||||
|
@ -108,9 +107,7 @@ public class FiremindClient {
|
|||
writer.println(content);
|
||||
writer.close();
|
||||
System.out.println(f.getAbsolutePath());
|
||||
}catch (FileNotFoundException e){
|
||||
System.err.println("Couldn't save script file");
|
||||
}catch (UnsupportedEncodingException e){
|
||||
}catch (FileNotFoundException | UnsupportedEncodingException e){
|
||||
System.err.println("Couldn't save script file");
|
||||
}
|
||||
}
|
||||
|
@ -172,9 +169,6 @@ public class FiremindClient {
|
|||
} else {
|
||||
System.err.println(con.getResponseMessage());
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -210,9 +204,6 @@ public class FiremindClient {
|
|||
} else {
|
||||
System.err.println(con.getResponseMessage());
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -241,9 +232,6 @@ public class FiremindClient {
|
|||
} else {
|
||||
System.err.println(con.getResponseMessage());
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -266,8 +254,7 @@ public class FiremindClient {
|
|||
BufferedReader rd = new BufferedReader(new InputStreamReader(
|
||||
con.getInputStream(), Charset.forName("UTF-8")));
|
||||
String jsonText = readAll(rd);
|
||||
JSONObject json = new JSONObject(jsonText);
|
||||
return json;
|
||||
return new JSONObject(jsonText);
|
||||
}
|
||||
|
||||
private static String readAll(Reader rd) throws IOException {
|
||||
|
|
|
@ -127,17 +127,15 @@ public class FiremindGameReport implements Thread.UncaughtExceptionHandler {
|
|||
|
||||
public void buildReport(final MagicGame game, final Thread th, final Throwable ex) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("CRASH REPORT FOR MAGARENA THREAD " + th);
|
||||
sb.append("CRASH REPORT FOR MAGARENA THREAD ").append(th);
|
||||
sb.append('\n');
|
||||
sb.append("CREATED ON "
|
||||
+ (new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"))
|
||||
.format(new Date()));
|
||||
sb.append("CREATED ON ").append((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")).format(new Date()));
|
||||
sb.append('\n');
|
||||
sb.append("MAGARENA VERSION " + MagicSystem.VERSION);
|
||||
sb.append(", JRE " + System.getProperty("java.version"));
|
||||
sb.append(", OS " + System.getProperty("os.name"));
|
||||
sb.append("_" + System.getProperty("os.version"));
|
||||
sb.append(" " + System.getProperty("os.arch"));
|
||||
sb.append(", JRE ").append(System.getProperty("java.version"));
|
||||
sb.append(", OS ").append(System.getProperty("os.name"));
|
||||
sb.append("_").append(System.getProperty("os.version"));
|
||||
sb.append(" ").append(System.getProperty("os.arch"));
|
||||
sb.append("\n\n");
|
||||
try {
|
||||
// buildReport might throw an exception
|
||||
|
@ -146,8 +144,7 @@ public class FiremindGameReport implements Thread.UncaughtExceptionHandler {
|
|||
sb.append('\n');
|
||||
}
|
||||
} catch (final Throwable ex2) {
|
||||
sb.append("Exception from MagicGameReport.buildReport: "
|
||||
+ ex2.getMessage());
|
||||
sb.append("Exception from MagicGameReport.buildReport: ").append(ex2.getMessage());
|
||||
sb.append('\n');
|
||||
final StringWriter result = new StringWriter();
|
||||
final PrintWriter printWriter = new PrintWriter(result);
|
||||
|
@ -155,7 +152,7 @@ public class FiremindGameReport implements Thread.UncaughtExceptionHandler {
|
|||
sb.append(result.toString());
|
||||
sb.append('\n');
|
||||
}
|
||||
sb.append("Exception from controller.runGame: " + ex.getMessage());
|
||||
sb.append("Exception from controller.runGame: ").append(ex.getMessage());
|
||||
sb.append('\n');
|
||||
final StringWriter result = new StringWriter();
|
||||
final PrintWriter printWriter = new PrintWriter(result);
|
||||
|
|
|
@ -20,8 +20,7 @@ public final class GameLoader {
|
|||
public static MagicGame loadSavedGame(final File gameFile) {
|
||||
final GameState gameState = GameStateFileReader.loadGameStateFromFile(gameFile);
|
||||
final MagicDuel duel = getDuelState(gameState);
|
||||
final MagicGame game = getGameState(gameState, duel);
|
||||
return game;
|
||||
return getGameState(gameState, duel);
|
||||
}
|
||||
|
||||
private static MagicGame getGameState(final GameState gameState, final MagicDuel duel) {
|
||||
|
|
|
@ -15,8 +15,8 @@ public class Ability_Mono_DeckGenerator extends RandomDeckGenerator {
|
|||
private static final int MIN_NUM_CARDS_WITH_SUBTYPE = 30;
|
||||
|
||||
// all possible tribes - calculated once
|
||||
private static final ArrayList<MagicAbility> possibleAbilities = new ArrayList<MagicAbility>();
|
||||
private static final ArrayList<ArrayList<String>> possibleColors = new ArrayList<ArrayList<String>>();
|
||||
private static final ArrayList<MagicAbility> possibleAbilities = new ArrayList<>();
|
||||
private static final ArrayList<ArrayList<String>> possibleColors = new ArrayList<>();
|
||||
|
||||
// random tribe from all possible for each instance
|
||||
private final MagicAbility ability;
|
||||
|
@ -45,7 +45,7 @@ public class Ability_Mono_DeckGenerator extends RandomDeckGenerator {
|
|||
|
||||
private void getPossibleTribes() {
|
||||
for (final MagicAbility ab : MagicAbility.values()) {
|
||||
final HashMap<MagicColor, Integer> countColors = new HashMap<MagicColor, Integer>();
|
||||
final HashMap<MagicColor, Integer> countColors = new HashMap<>();
|
||||
countColors.put(MagicColor.Black, 0);
|
||||
countColors.put(MagicColor.White, 0);
|
||||
countColors.put(MagicColor.Green, 0);
|
||||
|
@ -75,10 +75,10 @@ public class Ability_Mono_DeckGenerator extends RandomDeckGenerator {
|
|||
|
||||
private ArrayList<String> getPossibleColors(final HashMap<MagicColor, Integer> countColors) {
|
||||
// monocolor
|
||||
final ArrayList<String> a = new ArrayList<String>();
|
||||
final ArrayList<String> a = new ArrayList<>();
|
||||
|
||||
for (final MagicColor c : countColors.keySet()) {
|
||||
if (countColors.get(c).intValue() > MIN_NUM_CARDS_WITH_SUBTYPE) {
|
||||
if (countColors.get(c) > MIN_NUM_CARDS_WITH_SUBTYPE) {
|
||||
a.add("" + c.getSymbol());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ public class Tribal_Mono_DeckGenerator extends RandomDeckGenerator {
|
|||
private static final int MIN_NUM_CARDS_WITH_SUBTYPE = 30;
|
||||
|
||||
// all possible tribes - calculated once
|
||||
private static final ArrayList<MagicSubType> possibleTribes = new ArrayList<MagicSubType>();
|
||||
private static final ArrayList<ArrayList<String>> possibleColors = new ArrayList<ArrayList<String>>();
|
||||
private static final ArrayList<MagicSubType> possibleTribes = new ArrayList<>();
|
||||
private static final ArrayList<ArrayList<String>> possibleColors = new ArrayList<>();
|
||||
|
||||
// random tribe from all possible for each instance
|
||||
private final MagicSubType tribe;
|
||||
|
@ -45,7 +45,7 @@ public class Tribal_Mono_DeckGenerator extends RandomDeckGenerator {
|
|||
|
||||
private void getPossibleTribes() {
|
||||
for (final MagicSubType s : MagicSubType.ALL_CREATURES) {
|
||||
final HashMap<MagicColor, Integer> countColors = new HashMap<MagicColor, Integer>();
|
||||
final HashMap<MagicColor, Integer> countColors = new HashMap<>();
|
||||
countColors.put(MagicColor.Black, 0);
|
||||
countColors.put(MagicColor.White, 0);
|
||||
countColors.put(MagicColor.Green, 0);
|
||||
|
@ -76,10 +76,10 @@ public class Tribal_Mono_DeckGenerator extends RandomDeckGenerator {
|
|||
|
||||
private ArrayList<String> getPossibleColors(final HashMap<MagicColor, Integer> countColors) {
|
||||
// monocolor
|
||||
final ArrayList<String> a = new ArrayList<String>();
|
||||
final ArrayList<String> a = new ArrayList<>();
|
||||
|
||||
for (final MagicColor c : countColors.keySet()) {
|
||||
if (countColors.get(c).intValue() > MIN_NUM_CARDS_WITH_SUBTYPE) {
|
||||
if (countColors.get(c) > MIN_NUM_CARDS_WITH_SUBTYPE) {
|
||||
a.add("" + c.getSymbol());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public interface IRenderableCard {
|
|||
}
|
||||
|
||||
default Set<MagicType> getTypes() {
|
||||
Set<MagicType> types = new HashSet<MagicType>();
|
||||
Set<MagicType> types = new HashSet<>();
|
||||
for (MagicType type : MagicType.values()) {
|
||||
if (hasType(type)) {
|
||||
types.add(type);
|
||||
|
|
|
@ -750,7 +750,7 @@ public enum MagicAbility {
|
|||
card.add(FromGraveyardIntoLibraryTrigger.create());
|
||||
}
|
||||
},
|
||||
LibraryInteadOfGraveyard("If SN would be put into a graveyard from anywhere, reveal SN and shuffle it into its owner's library instead\\.",10) {
|
||||
LibraryInsteadOfGraveyard("If SN would be put into a graveyard from anywhere, reveal SN and shuffle it into its owner's library instead\\.",10) {
|
||||
@Override
|
||||
protected void addAbilityImpl(final MagicAbilityStore card, final Matcher arg) {
|
||||
card.add(ThisPutIntoGraveyardTrigger.LibraryInsteadOfGraveyard);
|
||||
|
@ -1119,7 +1119,7 @@ public enum MagicAbility {
|
|||
protected void addAbilityImpl(final MagicAbilityStore card, final Matcher arg) {
|
||||
//Does nothing but allows text to be part of ability property
|
||||
//HauntAbility contains actual effects
|
||||
//Not currently compatable with Instants or Sorceries
|
||||
//Not currently compatible with Instants or Sorceries
|
||||
}
|
||||
},
|
||||
HauntAbility("When SN enters the battlefield or the creature it haunts dies, " + ARG.EFFECT, 0) {
|
||||
|
|
|
@ -101,7 +101,7 @@ public class MagicCard
|
|||
private MagicCard(final MagicCardDefinition aCardDefinition,final MagicPlayer aOwner,final long aId, final boolean aToken) {
|
||||
aCardDefinition.loadAbilities();
|
||||
cardDefinition = aCardDefinition;
|
||||
counters = new EnumMap<MagicCounterType, Integer>(MagicCounterType.class);
|
||||
counters = new EnumMap<>(MagicCounterType.class);
|
||||
owner = aOwner;
|
||||
id = aId;
|
||||
token = aToken;
|
||||
|
@ -111,7 +111,7 @@ public class MagicCard
|
|||
copyMap.put(sourceCard, this);
|
||||
|
||||
cardDefinition = sourceCard.cardDefinition;
|
||||
counters = new EnumMap<MagicCounterType,Integer>(sourceCard.counters);
|
||||
counters = new EnumMap<>(sourceCard.counters);
|
||||
owner = copyMap.copy(sourceCard.owner);
|
||||
id = sourceCard.id;
|
||||
token = sourceCard.token;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package magic.model;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import magic.ai.ArtificialScoringSystem;
|
||||
import magic.data.CardDefinitions;
|
||||
import magic.data.CardProperty;
|
||||
|
@ -24,7 +24,7 @@ public class MagicCardDefinition implements MagicAbilityStore, IRenderableCard {
|
|||
* Comparator for sorting instances of {@code MagicCardDefinition} by distinct name.
|
||||
*/
|
||||
public static final Comparator<MagicCardDefinition> SORT_BY_NAME =
|
||||
(o1, o2) -> o1.getDistinctName().compareTo(o2.getDistinctName());
|
||||
Comparator.comparing(MagicCardDefinition::getDistinctName);
|
||||
|
||||
private static final List<String> unsupportedStatuses = new ArrayList<>();
|
||||
private static boolean isSorted = false;
|
||||
|
@ -81,20 +81,20 @@ public class MagicCardDefinition implements MagicAbilityStore, IRenderableCard {
|
|||
private MagicStaticType staticType=MagicStaticType.None;
|
||||
private MagicTiming timing=MagicTiming.None;
|
||||
private MagicCardEvent cardEvent=MagicPlayCardEvent.create();
|
||||
private final Collection<MagicActivation<MagicPermanent>> permActivations=new ArrayList<MagicActivation<MagicPermanent>>();
|
||||
private final Collection<MagicActivation<MagicPermanent>> morphActivations=new ArrayList<MagicActivation<MagicPermanent>>();
|
||||
private final LinkedList<MagicActivation<MagicCard>> handActivations = new LinkedList<MagicActivation<MagicCard>>();
|
||||
private final LinkedList<MagicActivation<MagicCard>> graveyardActivations = new LinkedList<MagicActivation<MagicCard>>();
|
||||
private final Collection<MagicCDA> CDAs = new ArrayList<MagicCDA>();
|
||||
private final Collection<MagicTrigger<?>> triggers = new ArrayList<MagicTrigger<?>>();
|
||||
private final Collection<MagicStatic> statics=new ArrayList<MagicStatic>();
|
||||
private final LinkedList<EntersBattlefieldTrigger> etbTriggers = new LinkedList<EntersBattlefieldTrigger>();
|
||||
private final Collection<ThisSpellIsCastTrigger> spellIsCastTriggers = new ArrayList<ThisSpellIsCastTrigger>();
|
||||
private final Collection<ThisCycleTrigger> cycleTriggers = new ArrayList<ThisCycleTrigger>();
|
||||
private final Collection<ThisDrawnTrigger> drawnTriggers = new ArrayList<ThisDrawnTrigger>();
|
||||
private final Collection<ThisPutIntoGraveyardTrigger> putIntoGraveyardTriggers = new ArrayList<ThisPutIntoGraveyardTrigger>();
|
||||
private final Collection<MagicManaActivation> manaActivations=new ArrayList<MagicManaActivation>();
|
||||
private final Collection<MagicEventSource> costEventSources=new ArrayList<MagicEventSource>();
|
||||
private final Collection<MagicActivation<MagicPermanent>> permActivations= new ArrayList<>();
|
||||
private final Collection<MagicActivation<MagicPermanent>> morphActivations= new ArrayList<>();
|
||||
private final LinkedList<MagicActivation<MagicCard>> handActivations = new LinkedList<>();
|
||||
private final LinkedList<MagicActivation<MagicCard>> graveyardActivations = new LinkedList<>();
|
||||
private final Collection<MagicCDA> CDAs = new ArrayList<>();
|
||||
private final Collection<MagicTrigger<?>> triggers = new ArrayList<>();
|
||||
private final Collection<MagicStatic> statics= new ArrayList<>();
|
||||
private final LinkedList<EntersBattlefieldTrigger> etbTriggers = new LinkedList<>();
|
||||
private final Collection<ThisSpellIsCastTrigger> spellIsCastTriggers = new ArrayList<>();
|
||||
private final Collection<ThisCycleTrigger> cycleTriggers = new ArrayList<>();
|
||||
private final Collection<ThisDrawnTrigger> drawnTriggers = new ArrayList<>();
|
||||
private final Collection<ThisPutIntoGraveyardTrigger> putIntoGraveyardTriggers = new ArrayList<>();
|
||||
private final Collection<MagicManaActivation> manaActivations= new ArrayList<>();
|
||||
private final Collection<MagicEventSource> costEventSources= new ArrayList<>();
|
||||
|
||||
private MagicCardDefinition flipCardDefinition;
|
||||
private MagicCardDefinition transformCardDefinition;
|
||||
|
@ -714,7 +714,7 @@ public class MagicCardDefinition implements MagicAbilityStore, IRenderableCard {
|
|||
}
|
||||
|
||||
private List<MagicEvent> getCostEvent(final MagicCard source, final MagicManaCost manaCost) {
|
||||
final List<MagicEvent> costEvent = new ArrayList<MagicEvent>();
|
||||
final List<MagicEvent> costEvent = new ArrayList<>();
|
||||
if (manaCost != MagicManaCost.NONE) {
|
||||
costEvent.add(MagicPayManaCostEvent.Cast(
|
||||
source,
|
||||
|
@ -1010,7 +1010,7 @@ public class MagicCardDefinition implements MagicAbilityStore, IRenderableCard {
|
|||
}
|
||||
|
||||
public static final Comparator<MagicCardDefinition> NAME_COMPARATOR_ASC =
|
||||
(cd1, cd2) -> cd1.getName().compareTo(cd2.getName());
|
||||
Comparator.comparing(MagicCardDefinition::getName);
|
||||
|
||||
public static final Comparator<MagicCardDefinition> NAME_COMPARATOR_DESC =
|
||||
(cd1, cd2) -> cd2.getName().compareTo(cd1.getName());
|
||||
|
@ -1029,11 +1029,11 @@ public class MagicCardDefinition implements MagicAbilityStore, IRenderableCard {
|
|||
|
||||
public static final Comparator<MagicCardDefinition> TYPE_COMPARATOR_ASC = (cd1, cd2) -> TYPE_COMPARATOR_DESC.compare(cd2, cd1);
|
||||
|
||||
public static final Comparator<MagicCardDefinition> SUBTYPE_COMPARATOR_DESC = (cd1, cd2) -> cd1.getSubTypeString().compareTo(cd2.getSubTypeString());
|
||||
public static final Comparator<MagicCardDefinition> SUBTYPE_COMPARATOR_DESC = Comparator.comparing(MagicCardDefinition::getSubTypeString);
|
||||
|
||||
public static final Comparator<MagicCardDefinition> SUBTYPE_COMPARATOR_ASC = (cd1, cd2) -> SUBTYPE_COMPARATOR_DESC.compare(cd2, cd1);
|
||||
|
||||
public static final Comparator<MagicCardDefinition> RARITY_COMPARATOR_DESC = (cd1, cd2) -> cd1.getRarity() - cd2.getRarity();
|
||||
public static final Comparator<MagicCardDefinition> RARITY_COMPARATOR_DESC = Comparator.comparingInt(MagicCardDefinition::getRarity);
|
||||
|
||||
public static final Comparator<MagicCardDefinition> RARITY_COMPARATOR_ASC = (cd1, cd2) -> RARITY_COMPARATOR_DESC.compare(cd2, cd1);
|
||||
|
||||
|
|
|
@ -200,8 +200,8 @@ public class MagicCardList extends ArrayList<MagicCard> implements MagicCopyable
|
|||
private void smartShuffle(final long seed) {
|
||||
final MagicRandom rng = new MagicRandom(seed);
|
||||
final int size=size();
|
||||
final List<MagicCard> lands=new ArrayList<MagicCard>();
|
||||
final List<MagicCard> spells=new ArrayList<MagicCard>();
|
||||
final List<MagicCard> lands= new ArrayList<>();
|
||||
final List<MagicCard> spells= new ArrayList<>();
|
||||
int lowLeft=0;
|
||||
for (final MagicCard card : this) {
|
||||
final MagicCardDefinition cardDefinition=card.getCardDefinition();
|
||||
|
|
|
@ -139,7 +139,7 @@ public enum MagicColor {
|
|||
}
|
||||
|
||||
public static String getRandomColors(final int count) {
|
||||
final List<MagicColor> colors = new ArrayList<MagicColor>(Arrays.asList(values()));
|
||||
final List<MagicColor> colors = new ArrayList<>(Arrays.asList(values()));
|
||||
final StringBuilder colorText=new StringBuilder();
|
||||
for (int c=count;c>0;c--) {
|
||||
final int index=MagicRandom.nextRNGInt(colors.size());
|
||||
|
|
|
@ -34,127 +34,73 @@ public class MagicCondensedCardDefinition {
|
|||
return copies;
|
||||
}
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> RATING_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return Double.compare(cardDefinition1.getCard().getValue(), cardDefinition2.getCard().getValue());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> RATING_COMPARATOR_DESC =
|
||||
Comparator.comparingDouble(cardDefinition -> cardDefinition.getCard().getValue());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> RATING_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCondensedCardDefinition.RATING_COMPARATOR_DESC.compare(cardDefinition2, cardDefinition1);
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> RATING_COMPARATOR_ASC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCondensedCardDefinition.RATING_COMPARATOR_DESC.compare(cardDefinition2, cardDefinition1);
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> NUM_COPIES_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return cardDefinition1.getNumCopies() - cardDefinition2.getNumCopies();
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> NUM_COPIES_COMPARATOR_DESC =
|
||||
Comparator.comparingInt(MagicCondensedCardDefinition::getNumCopies);
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> NUM_COPIES_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCondensedCardDefinition.NUM_COPIES_COMPARATOR_DESC.compare(cardDefinition2, cardDefinition1);
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> NUM_COPIES_COMPARATOR_ASC=
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCondensedCardDefinition.NUM_COPIES_COMPARATOR_DESC.compare(cardDefinition2, cardDefinition1);
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> NAME_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.NAME_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> NAME_COMPARATOR_DESC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.NAME_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> NAME_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.NAME_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> NAME_COMPARATOR_ASC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.NAME_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> CONVERTED_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.CONVERTED_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> CONVERTED_COMPARATOR_DESC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.CONVERTED_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> CONVERTED_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.CONVERTED_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> SUBTYPE_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.SUBTYPE_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> SUBTYPE_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.SUBTYPE_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> TYPE_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.TYPE_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> CONVERTED_COMPARATOR_ASC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.CONVERTED_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> SUBTYPE_COMPARATOR_ASC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.SUBTYPE_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> TYPE_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.TYPE_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> SUBTYPE_COMPARATOR_DESC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.SUBTYPE_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> RARITY_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.RARITY_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> TYPE_COMPARATOR_DESC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.TYPE_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> RARITY_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.RARITY_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> TYPE_COMPARATOR_ASC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.TYPE_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> POWER_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.POWER_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> RARITY_COMPARATOR_DESC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.RARITY_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> POWER_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.POWER_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> RARITY_COMPARATOR_ASC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.RARITY_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> TOUGHNESS_COMPARATOR_DESC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.TOUGHNESS_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> POWER_COMPARATOR_DESC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.POWER_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> TOUGHNESS_COMPARATOR_ASC=new Comparator<MagicCondensedCardDefinition>() {
|
||||
@Override
|
||||
public int compare(final MagicCondensedCardDefinition cardDefinition1,final MagicCondensedCardDefinition cardDefinition2) {
|
||||
return MagicCardDefinition.TOUGHNESS_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
};
|
||||
public static final Comparator<MagicCondensedCardDefinition> POWER_COMPARATOR_ASC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.POWER_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> TOUGHNESS_COMPARATOR_DESC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.TOUGHNESS_COMPARATOR_DESC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
|
||||
public static final Comparator<MagicCondensedCardDefinition> TOUGHNESS_COMPARATOR_ASC =
|
||||
(cardDefinition1, cardDefinition2) ->
|
||||
MagicCardDefinition.TOUGHNESS_COMPARATOR_ASC.compare(cardDefinition1.getCard(), cardDefinition2.getCard());
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class MagicCondensedDeck extends ArrayList<MagicCondensedCardDefinition>
|
|||
|
||||
private String name = "Unsaved Deck";
|
||||
|
||||
private final HashMap<String, MagicCondensedCardDefinition> map = new HashMap<String, MagicCondensedCardDefinition>();
|
||||
private final HashMap<String, MagicCondensedCardDefinition> map = new HashMap<>();
|
||||
|
||||
public MagicCondensedDeck() {}
|
||||
|
||||
|
|
|
@ -149,8 +149,8 @@ public class MagicDeck extends ArrayList<MagicCardDefinition> {
|
|||
if (this.size() != other.size()) {
|
||||
return false;
|
||||
}
|
||||
Collections.sort(this, MagicCardDefinition.NAME_COMPARATOR_ASC);
|
||||
Collections.sort(other, MagicCardDefinition.NAME_COMPARATOR_ASC);
|
||||
this.sort(MagicCardDefinition.NAME_COMPARATOR_ASC);
|
||||
other.sort(MagicCardDefinition.NAME_COMPARATOR_ASC);
|
||||
return super.equals(other);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -23,7 +23,7 @@ public enum MagicDeckConstructionRule {
|
|||
}
|
||||
|
||||
public static List<MagicDeckConstructionRule> checkDeck(final MagicDeck deck) {
|
||||
final ArrayList<MagicDeckConstructionRule> brokenRules = new ArrayList<MagicDeckConstructionRule>();
|
||||
final ArrayList<MagicDeckConstructionRule> brokenRules = new ArrayList<>();
|
||||
|
||||
if (deck.size() < MIN_DECK_SIZE) {
|
||||
brokenRules.add(MinDeckSize);
|
||||
|
|
|
@ -555,7 +555,7 @@ public class MagicGame {
|
|||
}
|
||||
|
||||
public void doAction(final MagicAction action) {
|
||||
if (action.isLegal(this) == false) {
|
||||
if (!action.isLegal(this)) {
|
||||
return;
|
||||
}
|
||||
actions.add(action);
|
||||
|
@ -652,14 +652,14 @@ public class MagicGame {
|
|||
public void snapshot() {
|
||||
final MagicAction markerAction=new MarkerAction();
|
||||
doAction(markerAction);
|
||||
if (artificial == false) {
|
||||
if (!artificial) {
|
||||
doAction(new LogMarkerAction());
|
||||
undoPoints.addLast(markerAction);
|
||||
}
|
||||
}
|
||||
|
||||
public void restore() {
|
||||
if (artificial == false) {
|
||||
if (!artificial) {
|
||||
undoPoints.removeLast();
|
||||
}
|
||||
//undo each action up to and including the first MagicMarkerAction
|
||||
|
@ -746,7 +746,7 @@ public class MagicGame {
|
|||
if (disableLog || result.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final SortedSet<String> names=new TreeSet<String>();
|
||||
final SortedSet<String> names= new TreeSet<>();
|
||||
for (final MagicPermanent attacker : result) {
|
||||
names.add(MagicMessage.getCardToken(attacker));
|
||||
}
|
||||
|
@ -760,7 +760,7 @@ public class MagicGame {
|
|||
if (disableLog) {
|
||||
return;
|
||||
}
|
||||
final SortedSet<String> names = new TreeSet<String>();
|
||||
final SortedSet<String> names = new TreeSet<>();
|
||||
for (final MagicCombatCreature[] creatures : result) {
|
||||
for (int index = 1; index < creatures.length; index++) {
|
||||
names.add(MagicMessage.getCardToken(creatures[index].permanent));
|
||||
|
@ -812,10 +812,10 @@ public class MagicGame {
|
|||
}
|
||||
|
||||
public boolean advanceToNextEventWithChoice() {
|
||||
while (isFinished() == false) {
|
||||
if (hasNextEvent() == false) {
|
||||
while (!isFinished()) {
|
||||
if (!hasNextEvent()) {
|
||||
executePhase();
|
||||
} else if (getNextEvent().hasChoice() == false) {
|
||||
} else if (!getNextEvent().hasChoice()) {
|
||||
executeNextEvent();
|
||||
} else {
|
||||
return true;
|
||||
|
@ -825,10 +825,10 @@ public class MagicGame {
|
|||
}
|
||||
|
||||
public List<Object[]> advanceToNextEventWithChoices() {
|
||||
while (isFinished() == false) {
|
||||
if (hasNextEvent() == false) {
|
||||
while (!isFinished()) {
|
||||
if (!hasNextEvent()) {
|
||||
executePhase();
|
||||
} else if (getNextEvent().hasChoice() == false) {
|
||||
} else if (!getNextEvent().hasChoice()) {
|
||||
executeNextEvent();
|
||||
} else {
|
||||
final MagicEvent event = getNextEvent();
|
||||
|
@ -1126,7 +1126,7 @@ public class MagicGame {
|
|||
|
||||
// put pending triggers on stack in APNAP order
|
||||
pendingStack.sortAPNAP(getTurnPlayer());
|
||||
while (pendingStack.isEmpty() == false) {
|
||||
while (!pendingStack.isEmpty()) {
|
||||
doAction(new PutItemOnStackAction(pendingStack.peek()));
|
||||
doAction(new DequeueTriggerAction());
|
||||
}
|
||||
|
@ -1215,14 +1215,14 @@ public class MagicGame {
|
|||
|
||||
final List<MagicTarget> options;
|
||||
if (targetChoice.isTargeted()) {
|
||||
options=new ArrayList<MagicTarget>();
|
||||
options= new ArrayList<>();
|
||||
for (final MagicTarget target : targets) {
|
||||
if (target.isValidTarget(source)) {
|
||||
options.add(target);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
options=new ArrayList<MagicTarget>(targets);
|
||||
options= new ArrayList<>(targets);
|
||||
}
|
||||
|
||||
if (options.isEmpty()) {
|
||||
|
@ -1357,13 +1357,13 @@ public class MagicGame {
|
|||
|
||||
public <T> void executeTrigger(final MagicTrigger<T> trigger, final MagicPermanent permanent, final MagicSource source, final T data) {
|
||||
|
||||
if (trigger.accept(permanent, data) == false) {
|
||||
if (!trigger.accept(permanent, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final MagicEvent event=trigger.executeTrigger(this,permanent,data);
|
||||
|
||||
if (event.isValid() == false) {
|
||||
if (!event.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1388,7 +1388,7 @@ public class MagicGame {
|
|||
return;
|
||||
}
|
||||
|
||||
final Collection<MagicPermanentTrigger> copiedTriggers=new ArrayList<MagicPermanentTrigger>(typeTriggers);
|
||||
final Collection<MagicPermanentTrigger> copiedTriggers= new ArrayList<>(typeTriggers);
|
||||
for (final MagicPermanentTrigger permanentTrigger : copiedTriggers) {
|
||||
final MagicPermanent permanent = permanentTrigger.getPermanent();
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -12,7 +12,7 @@ public class MagicLogMessageBuilder {
|
|||
MagicLogMessageBuilder(final MagicGame aGame) {
|
||||
game = aGame;
|
||||
messageBuilders=new StringBuilder[]{new StringBuilder(),new StringBuilder()};
|
||||
order = new ArrayList<MagicPlayer>(2);
|
||||
order = new ArrayList<>(2);
|
||||
}
|
||||
|
||||
void appendMessage(final MagicPlayer player,final String message) {
|
||||
|
@ -22,7 +22,7 @@ public class MagicLogMessageBuilder {
|
|||
}
|
||||
messageBuilder.append(message);
|
||||
|
||||
if (order.contains(player) == false) {
|
||||
if (!order.contains(player)) {
|
||||
order.add(player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public class MagicMessage {
|
|||
private static final String CARD_TOKEN = "<%s" + CARD_ID_DELIMITER + "%d>";
|
||||
|
||||
private static String getXCost(final String sourceText, final Object obj) {
|
||||
if (obj != null && obj instanceof MagicPayedCost && sourceText.contains("where X") == false) {
|
||||
if (obj != null && obj instanceof MagicPayedCost && !sourceText.contains("where X")) {
|
||||
return "X (" + ((MagicPayedCost)obj).getX() + ")";
|
||||
} else {
|
||||
return "X";
|
||||
|
|
|
@ -92,7 +92,7 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
cardDefinition = aCardDef;
|
||||
firstController = aController;
|
||||
|
||||
counters = new EnumMap<MagicCounterType, Integer>(MagicCounterType.class);
|
||||
counters = new EnumMap<>(MagicCounterType.class);
|
||||
equipmentPermanents = new MagicPermanentSet();
|
||||
auraPermanents = new MagicPermanentSet();
|
||||
blockingCreatures = new MagicPermanentList();
|
||||
|
@ -104,10 +104,10 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
cachedColorFlags = getCardDefinition().getColorFlags();
|
||||
cachedAbilityFlags = getCardDefinition().genAbilityFlags();
|
||||
cachedPowerToughness = getCardDefinition().genPowerToughness();
|
||||
cachedActivations = new LinkedList<MagicActivation<MagicPermanent>>();
|
||||
cachedManaActivations = new LinkedList<MagicManaActivation>();
|
||||
cachedTriggers = new LinkedList<MagicTrigger<?>>();
|
||||
etbTriggers = new LinkedList<EntersBattlefieldTrigger>();
|
||||
cachedActivations = new LinkedList<>();
|
||||
cachedManaActivations = new LinkedList<>();
|
||||
cachedTriggers = new LinkedList<>();
|
||||
etbTriggers = new LinkedList<>();
|
||||
}
|
||||
|
||||
private MagicPermanent(final MagicCopyMap copyMap, final MagicPermanent sourcePermanent) {
|
||||
|
@ -119,7 +119,7 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
card = copyMap.copy(sourcePermanent.card);
|
||||
firstController = copyMap.copy(sourcePermanent.firstController);
|
||||
stateFlags = sourcePermanent.stateFlags;
|
||||
counters = new EnumMap<MagicCounterType, Integer>(sourcePermanent.counters);
|
||||
counters = new EnumMap<>(sourcePermanent.counters);
|
||||
abilityPlayedThisTurn = sourcePermanent.abilityPlayedThisTurn;
|
||||
equippedCreature = copyMap.copy(sourcePermanent.equippedCreature);
|
||||
equipmentPermanents = new MagicPermanentSet(copyMap, sourcePermanent.equipmentPermanents);
|
||||
|
@ -142,10 +142,10 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
cachedColorFlags = sourcePermanent.cachedColorFlags;
|
||||
cachedAbilityFlags = sourcePermanent.cachedAbilityFlags;
|
||||
cachedPowerToughness = sourcePermanent.cachedPowerToughness;
|
||||
cachedActivations = new LinkedList<MagicActivation<MagicPermanent>>(sourcePermanent.cachedActivations);
|
||||
cachedManaActivations = new LinkedList<MagicManaActivation>(sourcePermanent.cachedManaActivations);
|
||||
cachedTriggers = new LinkedList<MagicTrigger<?>>(sourcePermanent.cachedTriggers);
|
||||
etbTriggers = new LinkedList<EntersBattlefieldTrigger>(sourcePermanent.etbTriggers);
|
||||
cachedActivations = new LinkedList<>(sourcePermanent.cachedActivations);
|
||||
cachedManaActivations = new LinkedList<>(sourcePermanent.cachedManaActivations);
|
||||
cachedTriggers = new LinkedList<>(sourcePermanent.cachedTriggers);
|
||||
etbTriggers = new LinkedList<>(sourcePermanent.etbTriggers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -383,7 +383,7 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
|
||||
public boolean isName(final String other) {
|
||||
final String name = getName();
|
||||
return name.isEmpty() == false && name.equalsIgnoreCase(other);
|
||||
return !name.isEmpty() && name.equalsIgnoreCase(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -481,11 +481,11 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
cachedColorFlags = getCardDefinition().getColorFlags();
|
||||
cachedAbilityFlags = getCardDefinition().genAbilityFlags();
|
||||
cachedPowerToughness = getCardDefinition().genPowerToughness();
|
||||
cachedActivations = new LinkedList<MagicActivation<MagicPermanent>>(getCardDefinition().getActivations());
|
||||
cachedActivations = new LinkedList<>(getCardDefinition().getActivations());
|
||||
cachedActivations.addAll(cardDefinition.getMorphActivations());
|
||||
cachedManaActivations = new LinkedList<MagicManaActivation>(getCardDefinition().getManaActivations());
|
||||
cachedTriggers = new LinkedList<MagicTrigger<?>>(getCardDefinition().getTriggers());
|
||||
etbTriggers = new LinkedList<EntersBattlefieldTrigger>(getCardDefinition().getETBTriggers());
|
||||
cachedManaActivations = new LinkedList<>(getCardDefinition().getManaActivations());
|
||||
cachedTriggers = new LinkedList<>(getCardDefinition().getTriggers());
|
||||
etbTriggers = new LinkedList<>(getCardDefinition().getETBTriggers());
|
||||
appliedStatics = new HashSet<>();
|
||||
break;
|
||||
case CDASubtype:
|
||||
|
@ -814,7 +814,7 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
}
|
||||
|
||||
// Soulbond
|
||||
if (pairedCreature.isValid() && pairedCreature.isCreature() == false) {
|
||||
if (pairedCreature.isValid() && !pairedCreature.isCreature()) {
|
||||
game.logAppendMessage(
|
||||
getController(),
|
||||
MagicMessage.format("%s becomes unpaired as %s is no longer a creature.", this, pairedCreature)
|
||||
|
@ -829,14 +829,14 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
String reason = "";
|
||||
if (isCreature()) {
|
||||
reason = "it is a creature.";
|
||||
} else if (enchantedPermanent.isValid() == false
|
||||
|| game.isLegalTarget(getController(), this, tchoice, enchantedPermanent) == false) {
|
||||
} else if (!enchantedPermanent.isValid()
|
||||
|| !game.isLegalTarget(getController(), this, tchoice, enchantedPermanent)) {
|
||||
reason = "it no longer enchants a valid permanent.";
|
||||
} else if (enchantedPermanent.hasProtectionFrom(this)) {
|
||||
reason = MagicMessage.format("%s has protection.", enchantedPermanent);
|
||||
}
|
||||
|
||||
if (reason.isEmpty() == false) {
|
||||
if (!reason.isEmpty()) {
|
||||
// 702.102e If an Aura with bestow is attached to an illegal object or player, it becomes unattached.
|
||||
// This is an exception to rule 704.5n.
|
||||
if (hasAbility(MagicAbility.Bestow)) {
|
||||
|
@ -860,12 +860,12 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
String reason = "";
|
||||
if (isCreature()) {
|
||||
reason = "it is a creature.";
|
||||
} else if (equippedCreature.isCreature() == false) {
|
||||
} else if (!equippedCreature.isCreature()) {
|
||||
reason = MagicMessage.format("%s is no longer a creature.", equippedCreature);
|
||||
} else if (equippedCreature.hasProtectionFrom(this)) {
|
||||
reason = MagicMessage.format("%s has protection.", equippedCreature);
|
||||
}
|
||||
if (reason.isEmpty() == false) {
|
||||
if (!reason.isEmpty()) {
|
||||
game.logAppendMessage(
|
||||
getController(),
|
||||
MagicMessage.format("%s becomes unattached as %s", this, reason)
|
||||
|
@ -1234,7 +1234,7 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource, Magi
|
|||
}
|
||||
|
||||
// Can't be the target of nongreen spells or abilities from nongreen sources
|
||||
if (hasAbility(MagicAbility.CannotBeTheTargetOfNonGreen) && source.hasColor(MagicColor.Green) == false) {
|
||||
if (hasAbility(MagicAbility.CannotBeTheTargetOfNonGreen) && !source.hasColor(MagicColor.Green)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ public class MagicPlayer extends MagicObjectImpl implements MagicSource, MagicTa
|
|||
|
||||
@Override
|
||||
public Set<MagicSourceActivation<? extends MagicSource>> getSourceActivations() {
|
||||
Set<MagicSourceActivation<? extends MagicSource>> set = new TreeSet<MagicSourceActivation<? extends MagicSource>>();
|
||||
Set<MagicSourceActivation<? extends MagicSource>> set = new TreeSet<>();
|
||||
for (final MagicCard card : hand) {
|
||||
set.addAll(card.getSourceActivations());
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ public class MagicPlayer extends MagicObjectImpl implements MagicSource, MagicTa
|
|||
startingHandSize = handSize;
|
||||
final MagicDeck deck = playerConfig.getDeck();
|
||||
Thread thread = Thread.currentThread();
|
||||
for (int i = 0; i < deck.size() && thread.isInterrupted() == false; i++) {
|
||||
for (int i = 0; i < deck.size() && !thread.isInterrupted(); i++) {
|
||||
final MagicCardDefinition cardDefinition = deck.get(i);
|
||||
if (cardDefinition.isValid()) {
|
||||
final long id = currGame.getUniqueId();
|
||||
|
@ -504,7 +504,7 @@ public class MagicPlayer extends MagicObjectImpl implements MagicSource, MagicTa
|
|||
}
|
||||
|
||||
public List<MagicCard> filterCards(final MagicTargetFilter<MagicCard> filter) {
|
||||
final List<MagicCard> targets = new ArrayList<MagicCard>();
|
||||
final List<MagicCard> targets = new ArrayList<>();
|
||||
|
||||
// Cards in graveyard
|
||||
if (filter.acceptType(MagicTargetType.Graveyard)) {
|
||||
|
@ -540,16 +540,16 @@ public class MagicPlayer extends MagicObjectImpl implements MagicSource, MagicTa
|
|||
|
||||
public void addPermanent(final MagicPermanent permanent) {
|
||||
final boolean added = permanents.add(permanent);
|
||||
assert added == true : permanent + " cannot be added to " + this;
|
||||
assert added : permanent + " cannot be added to " + this;
|
||||
}
|
||||
|
||||
public void removePermanent(final MagicPermanent permanent) {
|
||||
final boolean removed = permanents.remove(permanent);
|
||||
assert removed == true : permanent + " cannot be removed from " + this;
|
||||
assert removed : permanent + " cannot be removed from " + this;
|
||||
}
|
||||
|
||||
public List<MagicSourceManaActivation> getManaActivations(final MagicGame game) {
|
||||
final List<MagicSourceManaActivation> activations=new ArrayList<MagicSourceManaActivation>();
|
||||
final List<MagicSourceManaActivation> activations= new ArrayList<>();
|
||||
for (final MagicPermanent permanent : permanents) {
|
||||
if (!permanent.producesMana()) {
|
||||
continue;
|
||||
|
@ -928,14 +928,18 @@ public class MagicPlayer extends MagicObjectImpl implements MagicSource, MagicTa
|
|||
|
||||
@Override
|
||||
public void changeCounters(final MagicCounterType counterType,final int amount) {
|
||||
if (counterType == MagicCounterType.Poison) {
|
||||
poison += amount;
|
||||
} else if (counterType == MagicCounterType.Experience) {
|
||||
experience += amount;
|
||||
} else if (counterType == MagicCounterType.Energy) {
|
||||
energy += amount;
|
||||
} else {
|
||||
throw new RuntimeException(counterType + " cannot be modified on player");
|
||||
switch (counterType) {
|
||||
case Poison:
|
||||
poison += amount;
|
||||
break;
|
||||
case Experience:
|
||||
experience += amount;
|
||||
break;
|
||||
case Energy:
|
||||
energy += amount;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(counterType + " cannot be modified on player");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import magic.model.action.MagicPermanentAction;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MagicTuple implements MagicCopyable {
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ import java.util.Arrays;
|
|||
|
||||
public class AIRevealAction extends MagicAction {
|
||||
|
||||
private final List<MagicCard> cards = new ArrayList<MagicCard>();
|
||||
private final List<Boolean> known = new ArrayList<Boolean>();
|
||||
private final List<MagicCard> cards = new ArrayList<>();
|
||||
private final List<Boolean> known = new ArrayList<>();
|
||||
private final boolean newValue;
|
||||
|
||||
public AIRevealAction(final MagicCard... aCards) {
|
||||
|
|
|
@ -2,7 +2,6 @@ package magic.model.action;
|
|||
|
||||
import magic.model.MagicGame;
|
||||
import magic.model.MagicPermanent;
|
||||
import magic.model.trigger.MagicPermanentTrigger;
|
||||
import magic.model.trigger.MagicTrigger;
|
||||
|
||||
public class AddTriggerAction extends MagicAction {
|
||||
|
|
|
@ -2,7 +2,6 @@ package magic.model.action;
|
|||
|
||||
import magic.model.MagicGame;
|
||||
import magic.model.MagicPermanent;
|
||||
import magic.model.trigger.MagicPermanentTrigger;
|
||||
import magic.model.trigger.MagicTrigger;
|
||||
|
||||
public class AddTurnTriggerAction extends MagicAction {
|
||||
|
|
|
@ -52,7 +52,7 @@ public class AttachAction extends MagicAction {
|
|||
|
||||
@Override
|
||||
public boolean isLegal(final MagicGame game) {
|
||||
if (attachable.isValid() == false) {
|
||||
if (!attachable.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class AttachAction extends MagicAction {
|
|||
|
||||
if (attachable.isAura() && creature.isValid()) {
|
||||
final MagicTargetChoice tchoice = new MagicTargetChoice(attachable.getAuraTargetChoice(), false);
|
||||
if (game.isLegalTarget(attachable.getController(),attachable,tchoice,creature) == false) {
|
||||
if (!game.isLegalTarget(attachable.getController(), attachable, tchoice, creature)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class BecomesAction extends MagicAction {
|
|||
};
|
||||
game.doAction(new AddStaticAction(permanent, PT));
|
||||
}
|
||||
if (color.isEmpty() == false) {
|
||||
if (!color.isEmpty()) {
|
||||
int _mask = 0;
|
||||
for (final MagicColor element : color) {
|
||||
_mask |= element.getMask();
|
||||
|
@ -90,7 +90,7 @@ public class BecomesAction extends MagicAction {
|
|||
};
|
||||
game.doAction(new AddStaticAction(permanent, C));
|
||||
}
|
||||
if (type.isEmpty() == false) {
|
||||
if (!type.isEmpty()) {
|
||||
int _mask = 0;
|
||||
for (final MagicType element : type) {
|
||||
_mask |= element.getMask();
|
||||
|
@ -109,7 +109,7 @@ public class BecomesAction extends MagicAction {
|
|||
};
|
||||
game.doAction(new AddStaticAction(permanent, T));
|
||||
}
|
||||
if (subType.isEmpty() == false) {
|
||||
if (!subType.isEmpty()) {
|
||||
final MagicStatic ST = new MagicStatic(MagicLayer.Type, duration) {
|
||||
@Override
|
||||
public void modSubTypeFlags(final MagicPermanent permanent, final Set<MagicSubType> flags) {
|
||||
|
|
|
@ -40,7 +40,7 @@ public class CastCardAction extends MagicAction {
|
|||
@Override
|
||||
public void doAction(final MagicGame game) {
|
||||
for (final MagicEvent event : withoutManaCost ? card.getWithoutManaCostEvent() : card.getCostEvent()) {
|
||||
if (event.isSatisfied() == false) {
|
||||
if (!event.isSatisfied()) {
|
||||
game.logAppendMessage(player, "Casting failed as " + player + " is unable to pay casting costs.");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class ChangeControlAction extends MagicAction {
|
|||
game.doAction(new RemoveFromCombatAction(perm));
|
||||
game.doAction(ChangeStateAction.Clear(perm,MagicPermanentState.ExcludeFromCombat));
|
||||
|
||||
if (perm.getPairedCreature().isValid()) {;
|
||||
if (perm.getPairedCreature().isValid()) {
|
||||
game.doAction(new SoulbondAction(perm,perm.getPairedCreature(),false));
|
||||
}
|
||||
|
||||
|
|
|
@ -34,13 +34,13 @@ public class CombatDamageAction extends MagicAction {
|
|||
creature.hasAbility(MagicAbility.FirstStrike) ||
|
||||
creature.hasAbility(MagicAbility.DoubleStrike)
|
||||
:
|
||||
creature.hasState(MagicPermanentState.DealtFirstStrike) == false ||
|
||||
!creature.hasState(MagicPermanentState.DealtFirstStrike) ||
|
||||
creature.hasAbility(MagicAbility.DoubleStrike);
|
||||
}
|
||||
|
||||
private void combatDamage(final MagicGame game, final MagicPlayer aAttackingPlayer, final MagicPlayer aDefendingPlayer) {
|
||||
|
||||
final Collection<MagicDamage> combatDamage=new ArrayList<MagicDamage>();
|
||||
final Collection<MagicDamage> combatDamage= new ArrayList<>();
|
||||
|
||||
// Determine all combat damage that must be dealt.
|
||||
for (final MagicPermanent attacker : aAttackingPlayer.getPermanents()) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class DealDamageAction extends MagicAction {
|
|||
*/
|
||||
|
||||
// in immediate mode, always deal damage to player
|
||||
if (game.isImmediate() == false &&
|
||||
if (!game.isImmediate() &&
|
||||
target == null &&
|
||||
damage.getTarget().isPlayer() &&
|
||||
damage.getSource().getController() != damage.getTarget() &&
|
||||
|
|
|
@ -12,7 +12,7 @@ import magic.model.MagicMessage;
|
|||
|
||||
public class DestroyAction extends MagicAction {
|
||||
|
||||
private final Collection<MagicPermanent> targets = new ArrayList<MagicPermanent>();
|
||||
private final Collection<MagicPermanent> targets = new ArrayList<>();
|
||||
private int numDestroyed = 0;
|
||||
|
||||
public DestroyAction(final MagicPermanent permanent) {
|
||||
|
@ -25,7 +25,7 @@ public class DestroyAction extends MagicAction {
|
|||
|
||||
@Override
|
||||
public void doAction(final MagicGame game) {
|
||||
final Collection<MagicPermanent> toBeDestroyed = new ArrayList<MagicPermanent>();
|
||||
final Collection<MagicPermanent> toBeDestroyed = new ArrayList<>();
|
||||
for (final MagicPermanent permanent : targets) {
|
||||
boolean destroy = true;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public class DrawAction extends MagicAction {
|
|||
|
||||
@Override
|
||||
public void doAction(final MagicGame game) {
|
||||
drawnCards=new ArrayList<MagicCard>();
|
||||
drawnCards= new ArrayList<>();
|
||||
final MagicCardList library=player.getLibrary();
|
||||
int score=0;
|
||||
for (int count=amount;count>0;count--) {
|
||||
|
|
|
@ -20,7 +20,7 @@ public class FlipAction extends MagicAction {
|
|||
|
||||
@Override
|
||||
public void doAction(final MagicGame game) {
|
||||
if (permanent.isFlipCard() && permanent.isFlipped() == false) {
|
||||
if (permanent.isFlipCard() && !permanent.isFlipped()) {
|
||||
oldStatics = permanent.getStatics();
|
||||
|
||||
game.doAction(ChangeStateAction.Set(permanent, MagicPermanentState.Flipped));
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
|
||||
public class LookAction extends MagicAction {
|
||||
|
||||
private final List<MagicCard> cards = new ArrayList<MagicCard>();
|
||||
private final List<MagicCard> cards = new ArrayList<>();
|
||||
private final MagicPlayer player;
|
||||
private final String desc;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ public class PutStateTriggerOnStackAction extends MagicAction {
|
|||
|
||||
@Override
|
||||
public boolean isLegal(final MagicGame game) {
|
||||
return game.hasItem(event.getSource(), event.getChoiceDescription()) == false;
|
||||
return !game.hasItem(event.getSource(), event.getChoiceDescription());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.ArrayList;
|
|||
|
||||
public class RemoveAllFromPlayAction extends MagicAction {
|
||||
|
||||
private final Collection<MagicPermanent> perms = new ArrayList<MagicPermanent>();
|
||||
private final Collection<MagicPermanent> perms = new ArrayList<>();
|
||||
private final MagicLocationType toLocation;
|
||||
|
||||
public RemoveAllFromPlayAction(final Collection<MagicPermanent> aPerms, final MagicLocationType aToLocation) {
|
||||
|
|
|
@ -15,7 +15,7 @@ public class ReturnLinkedExileAction extends MagicAction {
|
|||
private final MagicPermanent source;
|
||||
private final MagicLocationType location;
|
||||
private final MagicPlayer controller;
|
||||
private final List<MagicPermanentAction> modifications = new LinkedList<MagicPermanentAction>();;
|
||||
private final List<MagicPermanentAction> modifications = new LinkedList<>();
|
||||
private MagicCardList exiledList;
|
||||
|
||||
public ReturnLinkedExileAction(final MagicPermanent aSource, final MagicLocationType aLocation, final MagicPlayer aController) {
|
||||
|
|
|
@ -24,7 +24,7 @@ public class SetBlockerAction extends MagicAction {
|
|||
attacker.addBlockingCreature(blocker);
|
||||
blocker.setBlockedCreature(attacker);
|
||||
blocker.setState(MagicPermanentState.Blocking);
|
||||
if (attacker.hasState(MagicPermanentState.Blocked) == false) {
|
||||
if (!attacker.hasState(MagicPermanentState.Blocked)) {
|
||||
game.doAction(ChangeStateAction.Set(attacker, MagicPermanentState.Blocked));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class TurnFaceDownAction extends MagicAction {
|
|||
|
||||
@Override
|
||||
public void doAction(final MagicGame game) {
|
||||
if (permanent.isFaceDown() == false && permanent.isDoubleFaced() == false) {
|
||||
if (!permanent.isFaceDown() && !permanent.isDoubleFaced()) {
|
||||
oldStatics = permanent.getStatics();
|
||||
|
||||
game.doAction(ChangeStateAction.Set(permanent, MagicPermanentState.FaceDown));
|
||||
|
|
|
@ -82,7 +82,7 @@ public class MagicCardChoice extends MagicChoice {
|
|||
final MagicSource source = event.getSource();
|
||||
|
||||
final MagicCardChoiceResult result = new MagicCardChoiceResult();
|
||||
final Set<Object> validCards = new HashSet<Object>(player.getHand());
|
||||
final Set<Object> validCards = new HashSet<>(player.getHand());
|
||||
validCards.remove(source);
|
||||
int actualAmount = Math.min(amount, validCards.size());
|
||||
for (; actualAmount > 0; actualAmount--) {
|
||||
|
|
|
@ -97,16 +97,17 @@ public abstract class MagicChoice {
|
|||
public List<Object[]> getArtificialChoiceResults(final MagicGame game, final MagicEvent event) {
|
||||
final Collection<?> options=getArtificialOptions(game,event);
|
||||
final int size=options.size();
|
||||
if (size == 0) {
|
||||
return Collections.singletonList(new Object[]{MagicTargetNone.getInstance()});
|
||||
} else if (size == 1) {
|
||||
return Collections.singletonList(new Object[]{options.iterator().next()});
|
||||
} else {
|
||||
final List<Object[]> choiceResultsList=new ArrayList<Object[]>(size);
|
||||
for (final Object option : options) {
|
||||
choiceResultsList.add(new Object[]{option});
|
||||
}
|
||||
return choiceResultsList;
|
||||
switch (size) {
|
||||
case 0:
|
||||
return Collections.singletonList(new Object[]{MagicTargetNone.getInstance()});
|
||||
case 1:
|
||||
return Collections.singletonList(new Object[]{options.iterator().next()});
|
||||
default:
|
||||
final List<Object[]> choiceResultsList = new ArrayList<>(size);
|
||||
for (final Object option : options) {
|
||||
choiceResultsList.add(new Object[]{option});
|
||||
}
|
||||
return choiceResultsList;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public class MagicCombatCreature {
|
|||
|
||||
void setAttacker(final MagicGame game,final Set<MagicCombatCreature> blockers) {
|
||||
final SortedSet<MagicCombatCreature> candidateBlockersSet =
|
||||
new TreeSet<MagicCombatCreature>(new BlockerComparator(this));
|
||||
new TreeSet<>(new BlockerComparator(this));
|
||||
for (final MagicCombatCreature blocker : blockers) {
|
||||
if (blocker.permanent.canBlock(permanent)) {
|
||||
candidateBlockersSet.add(blocker);
|
||||
|
@ -116,5 +116,5 @@ public class MagicCombatCreature {
|
|||
}
|
||||
return blocker1.permanent.compareTo(blocker2.permanent);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,19 +11,16 @@ import magic.model.MagicPlayer;
|
|||
|
||||
public class MagicCombatCreatureBuilder {
|
||||
|
||||
private static final Comparator<MagicCombatCreature> ATTACKER_COMPARATOR=new Comparator<MagicCombatCreature>() {
|
||||
@Override
|
||||
public int compare(final MagicCombatCreature attacker1,final MagicCombatCreature attacker2) {
|
||||
final int adif=attacker1.attackerScore-attacker2.attackerScore;
|
||||
if (adif!=0) {
|
||||
return adif;
|
||||
}
|
||||
final int sdif=attacker1.score-attacker2.score;
|
||||
if (sdif!=0) {
|
||||
return sdif;
|
||||
}
|
||||
return attacker1.permanent.compareTo(attacker2.permanent);
|
||||
private static final Comparator<MagicCombatCreature> ATTACKER_COMPARATOR= (attacker1, attacker2) -> {
|
||||
final int adif = attacker1.attackerScore - attacker2.attackerScore;
|
||||
if (adif != 0) {
|
||||
return adif;
|
||||
}
|
||||
final int sdif = attacker1.score - attacker2.score;
|
||||
if (sdif != 0) {
|
||||
return sdif;
|
||||
}
|
||||
return attacker1.permanent.compareTo(attacker2.permanent);
|
||||
};
|
||||
|
||||
private final MagicGame game;
|
||||
|
@ -40,7 +37,7 @@ public class MagicCombatCreatureBuilder {
|
|||
|
||||
/** Must be called before building attackers. */
|
||||
boolean buildBlockers() {
|
||||
blockers=new HashSet<MagicCombatCreature>();
|
||||
blockers= new HashSet<>();
|
||||
for (final MagicPermanent permanent : defendingPlayer.getPermanents()) {
|
||||
if (permanent.canBlock()) {
|
||||
blockers.add(new MagicCombatCreature(permanent));
|
||||
|
@ -56,7 +53,7 @@ public class MagicCombatCreatureBuilder {
|
|||
}
|
||||
|
||||
boolean buildAttackers() {
|
||||
attackers=new TreeSet<MagicCombatCreature>(ATTACKER_COMPARATOR);
|
||||
attackers= new TreeSet<>(ATTACKER_COMPARATOR);
|
||||
for (final MagicPermanent permanent : attackingPlayer.getPermanents()) {
|
||||
if (permanent.canAttack()) {
|
||||
attackers.add(createAttacker(permanent));
|
||||
|
@ -66,7 +63,7 @@ public class MagicCombatCreatureBuilder {
|
|||
}
|
||||
|
||||
boolean buildBlockableAttackers() {
|
||||
attackers=new TreeSet<MagicCombatCreature>(ATTACKER_COMPARATOR);
|
||||
attackers= new TreeSet<>(ATTACKER_COMPARATOR);
|
||||
for (final MagicPermanent permanent : attackingPlayer.getPermanents()) {
|
||||
if (permanent.isAttacking()&&permanent.canBeBlocked(defendingPlayer)) {
|
||||
final MagicCombatCreature attacker=createAttacker(permanent);
|
||||
|
@ -87,7 +84,7 @@ public class MagicCombatCreatureBuilder {
|
|||
}
|
||||
|
||||
Set<MagicPermanent> getCandidateBlockers() {
|
||||
final Set<MagicPermanent> candidateBlockers=new HashSet<MagicPermanent>();
|
||||
final Set<MagicPermanent> candidateBlockers= new HashSet<>();
|
||||
for (final MagicCombatCreature attacker : attackers) {
|
||||
for (final MagicCombatCreature blocker : attacker.candidateBlockers) {
|
||||
candidateBlockers.add(blocker.permanent);
|
||||
|
@ -97,7 +94,7 @@ public class MagicCombatCreatureBuilder {
|
|||
}
|
||||
|
||||
Set<MagicPermanent> getBlockableAttackers(final MagicPermanent blocker) {
|
||||
final Set<MagicPermanent> blockableAttackers=new HashSet<MagicPermanent>();
|
||||
final Set<MagicPermanent> blockableAttackers= new HashSet<>();
|
||||
for (final MagicCombatCreature attacker : attackers) {
|
||||
for (final MagicCombatCreature candidateBlocker : attacker.candidateBlockers) {
|
||||
if (candidateBlocker.permanent==blocker) {
|
||||
|
|
|
@ -64,7 +64,7 @@ public class MagicDeclareAttackersChoice extends MagicChoice {
|
|||
final MagicCombatCreatureBuilder builder=new MagicCombatCreatureBuilder(game,player,player.getOpponent());
|
||||
builder.buildBlockers();
|
||||
|
||||
final Set<Object> validChoices=new HashSet<Object>();
|
||||
final Set<Object> validChoices= new HashSet<>();
|
||||
if (builder.buildAttackers()) {
|
||||
for (final MagicCombatCreature attacker : builder.getAttackers()) {
|
||||
if (attacker.hasAbility(MagicAbility.AttacksEachTurnIfAble)) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class MagicDeclareAttackersResultBuilder {
|
|||
}
|
||||
|
||||
// Build results.
|
||||
final Collection<Object> results=new ArrayList<Object>();
|
||||
final Collection<Object> results= new ArrayList<>();
|
||||
|
||||
// Get the best remaining optional attackers.
|
||||
while (size>maxAttackers) {
|
||||
|
|
|
@ -41,7 +41,7 @@ public class MagicDeclareBlockersChoice extends MagicChoice {
|
|||
for (final MagicCombatCreature attacker : builder.getAttackers()) {
|
||||
final MagicPermanentList blockers=attacker.permanent.getBlockingCreatures();
|
||||
if (!blockers.isEmpty()) {
|
||||
final List<MagicCombatCreature> creatures=new ArrayList<MagicCombatCreature>();
|
||||
final List<MagicCombatCreature> creatures= new ArrayList<>();
|
||||
creatures.add(attacker);
|
||||
for (final MagicPermanent blocker : blockers) {
|
||||
for (final MagicCombatCreature candidateBlocker : attacker.candidateBlockers) {
|
||||
|
|
|
@ -62,14 +62,14 @@ public class MagicDeclareBlockersResultBuilder {
|
|||
final MagicRandom rng = new MagicRandom(attackers.length + blockers.size());
|
||||
for (int i = 0; i < NUM_SAMPLES; i++) {
|
||||
final Map<Integer, List<MagicCombatCreature>> block =
|
||||
new HashMap<Integer, List<MagicCombatCreature>>();
|
||||
new HashMap<>();
|
||||
for (int j = 0; j < attackers.length; j++) {
|
||||
block.put(j, new ArrayList<MagicCombatCreature>(5));
|
||||
block.put(j, new ArrayList<>(5));
|
||||
block.get(j).add(attackers[j]);
|
||||
}
|
||||
for (final MagicCombatCreature blocker : blockers) {
|
||||
//determine attackers it can block
|
||||
final List<Integer> choices = new ArrayList<Integer>();
|
||||
final List<Integer> choices = new ArrayList<>();
|
||||
for (int j = 0; j < attackers.length; j++) {
|
||||
if (Arrays.asList(attackers[j].candidateBlockers).contains(blocker)) {
|
||||
choices.add(j);
|
||||
|
|
|
@ -27,7 +27,7 @@ public class MagicExcludeChoice extends MagicChoice {
|
|||
Collection<Object> getArtificialOptions(final MagicGame game, final MagicEvent event) {
|
||||
final MagicPlayer player = event.getPlayer();
|
||||
|
||||
final List<MagicPermanent> excludePermanents=new ArrayList<MagicPermanent>();
|
||||
final List<MagicPermanent> excludePermanents= new ArrayList<>();
|
||||
for (final MagicPermanent permanent : player.getPermanents()) {
|
||||
if (permanent.hasExcludeManaOrCombat()) {
|
||||
excludePermanents.add(permanent);
|
||||
|
@ -48,7 +48,7 @@ public class MagicExcludeChoice extends MagicChoice {
|
|||
return Collections.<Object>singleton(new MagicExcludeResult(excludePermanents,0));
|
||||
}
|
||||
|
||||
final List<Object> excludeOptions = new ArrayList<Object>(numOptions);
|
||||
final List<Object> excludeOptions = new ArrayList<>(numOptions);
|
||||
for (int flags = excludeAllFlags; flags >= 0; flags--) {
|
||||
excludeOptions.add(new MagicExcludeResult(excludePermanents,flags));
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class MagicExcludeResult implements MagicMappable<MagicExcludeResult> {
|
|||
|
||||
@Override
|
||||
public MagicExcludeResult map(final MagicGame game) {
|
||||
final List<MagicPermanent> mappedExcludePermanents=new ArrayList<MagicPermanent>();
|
||||
final List<MagicPermanent> mappedExcludePermanents= new ArrayList<>();
|
||||
for (final MagicPermanent excludePermanent : excludePermanents) {
|
||||
mappedExcludePermanents.add(excludePermanent.map(game));
|
||||
}
|
||||
|
|
|
@ -123,11 +123,11 @@ public class MagicMayChoice extends MagicChoice {
|
|||
noChoiceResults[0]=NO_CHOICE;
|
||||
|
||||
final List<Collection<?>> optionsList=new ArrayList<>(nrOfChoices);
|
||||
for (int index=0;index<nrOfChoices;index++) {
|
||||
if (!choices[index].hasOptions(game,player,source,true)) {
|
||||
for (MagicChoice choice : choices) {
|
||||
if (!choice.hasOptions(game, player, source, true)) {
|
||||
return Collections.singletonList(noChoiceResults);
|
||||
}
|
||||
optionsList.add(choices[index].getArtificialOptions(game,event));
|
||||
optionsList.add(choice.getArtificialOptions(game, event));
|
||||
}
|
||||
|
||||
final List<Object[]> choiceResultsList=new ArrayList<>();
|
||||
|
|
|
@ -68,7 +68,7 @@ public class MagicMulliganChoice extends MagicChoice {
|
|||
|
||||
int playable = 0;
|
||||
for (final MagicCard card : assumedPlayer.getHand()) {
|
||||
if (card.hasType(MagicType.Land) == false &&
|
||||
if (!card.hasType(MagicType.Land) &&
|
||||
card.getCost().getCondition().accept(card)) {
|
||||
playable++;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class MagicOrChoice extends MagicChoice {
|
|||
obj
|
||||
});
|
||||
}
|
||||
if (choices[i].isValid() == false) {
|
||||
if (!choices[i].isValid()) {
|
||||
choiceResultsList.add(new Object[] {
|
||||
i + 1
|
||||
});
|
||||
|
|
|
@ -61,7 +61,7 @@ public class MagicPayManaCostChoice extends MagicChoice {
|
|||
} else if (maxX == 1) {
|
||||
return Collections.<Object>singletonList(new MagicDelayedPayManaCostResult(cost,1));
|
||||
} else {
|
||||
final List<Object> choices=new ArrayList<Object>();
|
||||
final List<Object> choices= new ArrayList<>();
|
||||
for (int x=1;x<=maxX;x++) {
|
||||
choices.add(new MagicDelayedPayManaCostResult(cost,x));
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public class MagicPayManaCostChoice extends MagicChoice {
|
|||
|
||||
controller.disableActionButton(false);
|
||||
|
||||
if (event.isSatisfied() == false) {
|
||||
if (!event.isSatisfied()) {
|
||||
controller.showMessage(source, MText.get(_S_NO_OPTIONS, cost.getText()));
|
||||
controller.waitForInput();
|
||||
return MagicEvent.NO_CHOICE_RESULTS;
|
||||
|
|
|
@ -81,7 +81,7 @@ public class MagicPayManaCostResultBuilder {
|
|||
final boolean hasX = costManaType == MagicCostManaType.Generic && cost.hasX();
|
||||
|
||||
// Fast implementation when minimum amount is 1 without X.
|
||||
if (minAmount == 1 && hasX == false) {
|
||||
if (minAmount == 1 && !hasX) {
|
||||
for (int i = 0; i < typeActivationSize; i++) {
|
||||
final MagicSourceManaActivation typeActivation = typeActivations[i];
|
||||
typeActivation.available = false;
|
||||
|
@ -123,7 +123,7 @@ public class MagicPayManaCostResultBuilder {
|
|||
typeActivations[i].available = false;
|
||||
typeActivations[i].manaType = producedTypes[i];
|
||||
count++;
|
||||
if (count >= minAmount && (hasX == false || cost.validX(count)) && build(index + 1, single) && single) {
|
||||
if (count >= minAmount && (!hasX || cost.validX(count)) && build(index + 1, single) && single) {
|
||||
return true;
|
||||
}
|
||||
if (count < minAmount || (hasX && i + 1 != typeActivationSize)) {
|
||||
|
@ -161,9 +161,9 @@ public class MagicPayManaCostResultBuilder {
|
|||
for (final MagicSourceManaActivation activation : activations) {
|
||||
activation.available = true;
|
||||
}
|
||||
results = new HashMap<MagicBuilderPayManaCostResult,MagicBuilderPayManaCostResult>();
|
||||
results = new HashMap<>();
|
||||
build(0, false);
|
||||
return new TreeSet<Object>(results.values());
|
||||
return new TreeSet<>(results.values());
|
||||
}
|
||||
|
||||
/** Find all possible mana sources to pay one mana of given type for the player. */
|
||||
|
@ -173,8 +173,8 @@ public class MagicPayManaCostResultBuilder {
|
|||
types = cost.getTypes();
|
||||
amounts = cost.getAmounts();
|
||||
|
||||
final Set<MagicPermanent> manaSources = new HashSet<MagicPermanent>();
|
||||
final Set<Integer> manaIds = new HashSet<Integer>();
|
||||
final Set<MagicPermanent> manaSources = new HashSet<>();
|
||||
final Set<Integer> manaIds = new HashSet<>();
|
||||
for (final MagicSourceManaActivation currentActivation : activations) {
|
||||
currentActivation.available = true;
|
||||
if (currentActivation.canProduce(type).isValid()) {
|
||||
|
@ -187,7 +187,7 @@ public class MagicPayManaCostResultBuilder {
|
|||
manaSources.add(permanent);
|
||||
} else {
|
||||
final int manaId = permanent.getManaId();
|
||||
if (manaIds.contains(manaId) == false) {
|
||||
if (!manaIds.contains(manaId)) {
|
||||
manaSources.add(permanent);
|
||||
manaIds.add(manaId);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import magic.model.target.MagicTargetHint;
|
|||
import magic.model.target.MagicTargetNone;
|
||||
import magic.model.target.MagicTargetPicker;
|
||||
import magic.model.target.MagicTargetType;
|
||||
import magic.translate.MText;
|
||||
|
||||
public class MagicTargetChoice extends MagicChoice {
|
||||
|
||||
|
@ -463,7 +462,7 @@ public class MagicTargetChoice extends MagicChoice {
|
|||
controller.focusViewers(4);
|
||||
}
|
||||
final MagicTargetHint usedTargetHint=getTargetHint(GeneralConfig.getInstance().getSmartTarget());
|
||||
final Set<Object> validChoices=new HashSet<Object>(game.getLegalTargets(player,source,this,usedTargetHint));
|
||||
final Set<Object> validChoices= new HashSet<>(game.getLegalTargets(player, source, this, usedTargetHint));
|
||||
if (validChoices.size()==1) {
|
||||
// There are no valid choices.
|
||||
if (validChoices.contains(MagicTargetNone.getInstance())) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public abstract class MagicCondition implements MagicMatchedCostEvent {
|
|||
game.doAction(new PlayAbilityAction(event.getPermanent()));
|
||||
|
||||
public static List<MagicMatchedCostEvent> build(final String costs) {
|
||||
final List<MagicMatchedCostEvent> matched = new LinkedList<MagicMatchedCostEvent>();
|
||||
final List<MagicMatchedCostEvent> matched = new LinkedList<>();
|
||||
final String[] splitCosts = costs.split("(,)? and ");
|
||||
for (String cost : splitCosts) {
|
||||
matched.add(MagicConditionParser.build(cost));
|
||||
|
@ -689,7 +689,7 @@ public abstract class MagicCondition implements MagicMatchedCostEvent {
|
|||
}
|
||||
};
|
||||
|
||||
public static MagicCondition YOU_30_OR_MORE_OPPPONENT_10_OR_LESS_LIFE = new MagicCondition() {
|
||||
public static MagicCondition YOU_30_OR_MORE_OPPONENT_10_OR_LESS_LIFE = new MagicCondition() {
|
||||
@Override
|
||||
public boolean accept(MagicSource source) {
|
||||
return YOU_30_OR_MORE_LIFE.accept(source) &&
|
||||
|
|
|
@ -10,7 +10,6 @@ import magic.model.MagicPermanent;
|
|||
import magic.model.MagicPlayer;
|
||||
import magic.model.MagicSource;
|
||||
import magic.model.MagicSubType;
|
||||
import magic.model.MagicType;
|
||||
import magic.model.event.MagicEvent;
|
||||
import magic.model.event.MagicPermanentActivation;
|
||||
import magic.model.target.MagicOtherCardTargetFilter;
|
||||
|
|
|
@ -11,7 +11,6 @@ import magic.model.MagicColor;
|
|||
import magic.model.MagicCounterType;
|
||||
import magic.model.MagicPermanent;
|
||||
import magic.model.MagicSubType;
|
||||
import magic.model.MagicType;
|
||||
import magic.model.MagicCard;
|
||||
import magic.model.event.MagicMatchedCostEvent;
|
||||
import magic.model.target.MagicTargetFilter;
|
||||
|
@ -454,7 +453,7 @@ public enum MagicConditionParser {
|
|||
You30LifeOrMoreOpponent10LifeOrLess("you have 30 or more life and an opponent has 10 or less life") {
|
||||
@Override
|
||||
public MagicCondition toCondition(final Matcher arg) {
|
||||
return MagicCondition.YOU_30_OR_MORE_OPPPONENT_10_OR_LESS_LIFE;
|
||||
return MagicCondition.YOU_30_OR_MORE_OPPONENT_10_OR_LESS_LIFE;
|
||||
}
|
||||
},
|
||||
OpponentTenLifeOrLess("an opponent has 10 or less life") {
|
||||
|
@ -856,7 +855,7 @@ public enum MagicConditionParser {
|
|||
|
||||
public static List<MagicMatchedCostEvent> buildCost(final String costs) {
|
||||
final String[] splitCosts = costs.split(" and ");
|
||||
final List<MagicMatchedCostEvent> matched = new LinkedList<MagicMatchedCostEvent>();
|
||||
final List<MagicMatchedCostEvent> matched = new LinkedList<>();
|
||||
for (String cost : splitCosts) {
|
||||
matched.add(build(cost));
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public abstract class MagicActivation<T extends MagicSource> implements MagicEve
|
|||
|
||||
// Check conditions for activation
|
||||
for (final MagicCondition condition : conditions) {
|
||||
if (condition.accept(source) == false) {
|
||||
if (!condition.accept(source)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public abstract class MagicActivation<T extends MagicSource> implements MagicEve
|
|||
// * execute pay mana cost event
|
||||
//
|
||||
for (final MagicEvent event : getCostEvent(source)) {
|
||||
if (event.isSatisfied() == false) {
|
||||
if (!event.isSatisfied()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import magic.model.MagicCounterType;
|
|||
import magic.model.MagicGame;
|
||||
import magic.model.MagicPermanent;
|
||||
import magic.model.MagicSource;
|
||||
import magic.model.MagicCopyMap;
|
||||
import magic.model.action.ChangeCountersAction;
|
||||
import magic.model.choice.MagicTargetChoice;
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import magic.model.condition.MagicCondition;
|
|||
import magic.model.stack.MagicAbilityOnStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public abstract class MagicCardAbilityActivation extends MagicHandCastActivation {
|
||||
|
||||
|
@ -99,12 +98,15 @@ public abstract class MagicCardAbilityActivation extends MagicHandCastActivation
|
|||
|
||||
@Override
|
||||
public void change(final MagicCardDefinition cdef) {
|
||||
if (loc == MagicLocationType.OwnersHand) {
|
||||
cdef.addHandAct(this);
|
||||
} else if (loc == MagicLocationType.Graveyard) {
|
||||
cdef.addGraveyardAct(this);
|
||||
} else {
|
||||
throw new RuntimeException("unknown location: \"" + loc + "\"");
|
||||
switch (loc) {
|
||||
case OwnersHand:
|
||||
cdef.addHandAct(this);
|
||||
break;
|
||||
case Graveyard:
|
||||
cdef.addGraveyardAct(this);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("unknown location: \"" + loc + "\"");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -27,7 +27,7 @@ public class MagicClashEvent extends MagicEvent {
|
|||
final MagicPlayer winner = executeClash(game, event);
|
||||
if (winner == event.getPlayer()) {
|
||||
clashAction.executeEvent(game, event);
|
||||
};
|
||||
}
|
||||
game.executeTrigger(MagicTriggerType.WhenClash, winner);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import magic.model.MagicGame;
|
|||
import magic.model.MagicManaCost;
|
||||
import magic.model.MagicPermanent;
|
||||
import magic.model.MagicSource;
|
||||
import magic.model.MagicCopyMap;
|
||||
import magic.model.action.SacrificeAction;
|
||||
import magic.model.choice.MagicTargetChoice;
|
||||
import magic.model.target.MagicSacrificeTargetPicker;
|
||||
|
|
|
@ -45,7 +45,7 @@ public class MagicEquipActivation extends MagicPermanentActivation {
|
|||
|
||||
@Override
|
||||
public Iterable<? extends MagicEvent> getCostEvent(final MagicPermanent source) {
|
||||
final List<MagicEvent> costEvents = new LinkedList<MagicEvent>();
|
||||
final List<MagicEvent> costEvents = new LinkedList<>();
|
||||
for (final MagicMatchedCostEvent matched : costs) {
|
||||
costEvents.add(matched.getEvent(source));
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import magic.model.MagicCardDefinition;
|
|||
import magic.model.MagicCardDefinitionInit;
|
||||
import magic.model.MagicSubType;
|
||||
import magic.model.MagicGame;
|
||||
import magic.model.MagicLocationType;
|
||||
import magic.model.MagicManaCost;
|
||||
import magic.model.MagicPayedCost;
|
||||
import magic.model.action.PlayTokenAction;
|
||||
|
|
|
@ -577,7 +577,7 @@ public class MagicEvent implements MagicCopyable {
|
|||
chosenTarget == MagicTargetNone.getInstance();
|
||||
chosen = null;
|
||||
chosenTarget = null;
|
||||
return countered == false;
|
||||
return !countered;
|
||||
}
|
||||
|
||||
public final boolean processTarget(final MagicGame game, final MagicTargetAction effect) {
|
||||
|
@ -730,8 +730,8 @@ public class MagicEvent implements MagicCopyable {
|
|||
}
|
||||
|
||||
public final void executeAllEvents(final MagicGame game, final MagicSourceEvent... sourceEvents) {
|
||||
for (int i = 0; i < sourceEvents.length; i++) {
|
||||
sourceEvents[i].getAction().executeEvent(game, this);
|
||||
for (MagicSourceEvent sourceEvent : sourceEvents) {
|
||||
sourceEvent.getAction().executeEvent(game, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package magic.model.event;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import magic.model.MagicCard;
|
||||
import magic.model.MagicCardDefinition;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package magic.model.event;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import magic.model.MagicAmount;
|
||||
import magic.model.MagicCard;
|
||||
|
|
|
@ -5,7 +5,6 @@ import magic.model.MagicGame;
|
|||
import magic.model.MagicLocationType;
|
||||
import magic.model.MagicPermanent;
|
||||
import magic.model.MagicPlayer;
|
||||
import magic.model.MagicCopyMap;
|
||||
import magic.model.action.AddTriggerAction;
|
||||
import magic.model.action.MoveCardAction;
|
||||
import magic.model.action.RemoveCardAction;
|
||||
|
|
|
@ -64,5 +64,5 @@ public class MagicLevelUpActivation extends MagicPermanentActivation {
|
|||
public boolean accept(final MagicSource source) {
|
||||
return ((MagicPermanent)source).getCounters(MagicCounterType.Level)<maximum;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import magic.model.MagicPlayerState;
|
|||
import magic.model.condition.MagicCondition;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public abstract class MagicManaActivation implements MagicChangeCardDefinition {
|
||||
|
||||
|
@ -58,7 +57,7 @@ public abstract class MagicManaActivation implements MagicChangeCardDefinition {
|
|||
|
||||
// Check able to pay costs
|
||||
for (final MagicEvent event : getCostEvent(source)) {
|
||||
if (event.isSatisfied() == false) {
|
||||
if (!event.isSatisfied()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class MagicMorphActivation extends MagicPermanentActivation {
|
|||
|
||||
@Override
|
||||
public Iterable<? extends MagicEvent> getCostEvent(final MagicPermanent source) {
|
||||
final List<MagicEvent> costEvents = new LinkedList<MagicEvent>();
|
||||
final List<MagicEvent> costEvents = new LinkedList<>();
|
||||
for (final MagicMatchedCostEvent matched : matchedCostEvents) {
|
||||
costEvents.add(matched.getEvent(source));
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class MagicMorphCastActivation extends MagicHandCastActivation {
|
|||
}
|
||||
@Override
|
||||
public boolean canBeCountered() {
|
||||
return hasAbility(MagicAbility.CannotBeCountered) == false;
|
||||
return !hasAbility(MagicAbility.CannotBeCountered);
|
||||
}
|
||||
@Override
|
||||
public int getConvertedCost() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package magic.model.event;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import magic.model.MagicCounterType;
|
||||
|
|
|
@ -2,7 +2,6 @@ package magic.model.event;
|
|||
|
||||
import magic.model.MagicCardDefinition;
|
||||
import magic.model.MagicChangeCardDefinition;
|
||||
import magic.model.MagicCopyMap;
|
||||
import magic.model.MagicGame;
|
||||
import magic.model.MagicManaCost;
|
||||
import magic.model.MagicPayedCost;
|
||||
|
@ -18,7 +17,6 @@ import magic.model.mstatic.MagicStatic;
|
|||
import magic.model.stack.MagicAbilityOnStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MagicPermanentActivation extends MagicActivation<MagicPermanent> implements MagicChangeCardDefinition {
|
||||
|
@ -47,8 +45,8 @@ public abstract class MagicPermanentActivation extends MagicActivation<MagicPerm
|
|||
|
||||
private final boolean canPayCosts(final MagicGame game, final MagicPermanent source) {
|
||||
for (final MagicEvent event : getCostEvent(source)) {
|
||||
if (event.hasChoice() == false) {
|
||||
if (event.isSatisfied() == false) {
|
||||
if (!event.hasChoice()) {
|
||||
if (!event.isSatisfied()) {
|
||||
return false;
|
||||
} else {
|
||||
game.executeEvent(event, MagicEvent.NO_CHOICE_RESULTS);
|
||||
|
@ -56,8 +54,8 @@ public abstract class MagicPermanentActivation extends MagicActivation<MagicPerm
|
|||
}
|
||||
}
|
||||
for (final MagicEvent event : getCostEvent(source)) {
|
||||
if (event.hasChoice() == true) {
|
||||
if (event.isSatisfied() == false) {
|
||||
if (event.hasChoice()) {
|
||||
if (!event.isSatisfied()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,14 +50,14 @@ public class MagicPriorityEvent extends MagicEvent {
|
|||
|
||||
// pay costs without choices first, eg {T}
|
||||
for (final MagicEvent costEvent : sourceActivation.getCostEvent()) {
|
||||
if (costEvent.hasChoice() == false) {
|
||||
if (!costEvent.hasChoice()) {
|
||||
game.executeEvent(costEvent, MagicEvent.NO_CHOICE_RESULTS);
|
||||
}
|
||||
}
|
||||
|
||||
// then pay costs with choices. eg mana cost
|
||||
for (final MagicEvent costEvent : sourceActivation.getCostEvent()) {
|
||||
if (costEvent.hasChoice() == true) {
|
||||
if (costEvent.hasChoice()) {
|
||||
game.addCostEvent(costEvent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package magic.model.event;
|
|||
|
||||
import magic.model.MagicCard;
|
||||
import magic.model.MagicGame;
|
||||
import magic.model.MagicPlayer;
|
||||
import magic.model.MagicSource;
|
||||
import magic.model.MagicLocationType;
|
||||
import magic.model.choice.MagicTargetChoice;
|
||||
|
|
|
@ -36,7 +36,7 @@ public class MagicPutCardOnStackEvent extends MagicEvent {
|
|||
cardOnStack.setFromLocation(from);
|
||||
cardOnStack.setMoveLocation(to);
|
||||
final MagicCard card = event.getCard();
|
||||
if (card.isToken() == false) {
|
||||
if (!card.isToken()) {
|
||||
game.doAction(new RemoveCardAction(card, from));
|
||||
}
|
||||
game.doAction(new PutItemOnStackAction(cardOnStack));
|
||||
|
|
|
@ -4,7 +4,6 @@ import magic.model.MagicCounterType;
|
|||
import magic.model.MagicGame;
|
||||
import magic.model.MagicPermanent;
|
||||
import magic.model.MagicSource;
|
||||
import magic.model.MagicCopyMap;
|
||||
import magic.model.MagicTuple;
|
||||
import magic.model.action.ChangeCountersAction;
|
||||
import magic.model.choice.MagicTargetChoice;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue