diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer2.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer4.java similarity index 98% rename from Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer2.java rename to Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer4.java index a3c3008bb0..5d52139360 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer2.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer4.java @@ -49,7 +49,6 @@ import mage.abilities.ActivatedAbility; import mage.abilities.effects.Effect; import mage.abilities.effects.SearchEffect; import mage.cards.Cards; -import mage.cards.decks.Deck; import mage.choices.Choice; import mage.filter.FilterAbility; import mage.game.Game; @@ -85,9 +84,9 @@ import mage.util.Logging; * * @author BetaSteward_at_googlemail.com */ -public class ComputerPlayer2 extends ComputerPlayer implements Player { +public class ComputerPlayer4 extends ComputerPlayer implements Player { - private static final transient Logger logger = Logging.getLogger(ComputerPlayer2.class.getName()); + private static final transient Logger logger = Logging.getLogger(ComputerPlayer4.class.getName()); private static final ExecutorService pool = Executors.newFixedThreadPool(1); protected int maxDepth; @@ -99,13 +98,13 @@ public class ComputerPlayer2 extends ComputerPlayer implements protected int currentScore; protected SimulationNode root; - public ComputerPlayer2(String name, RangeOfInfluence range) { + public ComputerPlayer4(String name, RangeOfInfluence range) { super(name, range); maxDepth = Config.maxDepth; maxNodes = Config.maxNodes; } - public ComputerPlayer2(final ComputerPlayer2 player) { + public ComputerPlayer4(final ComputerPlayer4 player) { super(player); this.maxDepth = player.maxDepth; this.currentScore = player.currentScore; @@ -123,8 +122,8 @@ public class ComputerPlayer2 extends ComputerPlayer implements } @Override - public ComputerPlayer2 copy() { - return new ComputerPlayer2(this); + public ComputerPlayer4 copy() { + return new ComputerPlayer4(this); } @Override @@ -162,6 +161,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements boolean usedStack = false; while (actions.peek() != null) { Ability ability = actions.poll(); + System.out.println("[" + game.getPlayer(playerId).getName() + "] Action: " + ability.toString()); this.activateAbility((ActivatedAbility) ability, game); if (ability.isUsesStack()) usedStack = true; diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer3.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer5.java similarity index 97% rename from Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer3.java rename to Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer5.java index b3f4134527..d4bfe29dfb 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer3.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer5.java @@ -37,7 +37,6 @@ import mage.Constants.PhaseStep; import mage.Constants.RangeOfInfluence; import mage.Constants.Zone; import mage.abilities.Ability; -import mage.cards.decks.Deck; import mage.filter.FilterAbility; import mage.game.Game; import mage.game.combat.Combat; @@ -66,9 +65,9 @@ import mage.util.Logging; * * @author BetaSteward_at_googlemail.com */ -public class ComputerPlayer3 extends ComputerPlayer2 implements Player { +public class ComputerPlayer5 extends ComputerPlayer4 implements Player { - private static final transient Logger logger = Logging.getLogger(ComputerPlayer3.class.getName()); + private static final transient Logger logger = Logging.getLogger(ComputerPlayer5.class.getName()); private static FilterAbility filterLand = new FilterAbility(); private static FilterAbility filterNotLand = new FilterAbility(); @@ -83,19 +82,19 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player { } - public ComputerPlayer3(String name, RangeOfInfluence range) { + public ComputerPlayer5(String name, RangeOfInfluence range) { super(name, range); maxDepth = Config.maxDepth; maxNodes = Config.maxNodes; } - public ComputerPlayer3(final ComputerPlayer3 player) { + public ComputerPlayer5(final ComputerPlayer5 player) { super(player); } @Override - public ComputerPlayer3 copy() { - return new ComputerPlayer3(this); + public ComputerPlayer5 copy() { + return new ComputerPlayer5(this); } @Override @@ -109,6 +108,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player { break; case PRECOMBAT_MAIN: if (game.getActivePlayerId().equals(playerId)) { + System.out.println("["+ game.getPlayer(playerId).getName() + "] Precombat Main, life=" + game.getPlayer(playerId).getLife()); if (actions.size() == 0) { calculatePreCombatActions(game); } diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulateBlockWorker.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulateBlockWorker.java index 66a27c3c1c..77fbc41225 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulateBlockWorker.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulateBlockWorker.java @@ -31,7 +31,7 @@ package mage.player.ai; import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.logging.Logger; -import mage.game.Game; + import mage.util.Logging; /** @@ -43,9 +43,9 @@ public class SimulateBlockWorker implements Callable { private final static Logger logger = Logging.getLogger(SimulationWorker.class.getName()); private SimulationNode node; - private ComputerPlayer3 player; + private ComputerPlayer5 player; - public SimulateBlockWorker(ComputerPlayer3 player, SimulationNode node) { + public SimulateBlockWorker(ComputerPlayer5 player, SimulationNode node) { this.player = player; this.node = node; } diff --git a/Mage.Server/config/config.xml b/Mage.Server/config/config.xml index 08f9d514c5..4e9c75581f 100644 --- a/Mage.Server/config/config.xml +++ b/Mage.Server/config/config.xml @@ -7,7 +7,7 @@ - + diff --git a/Mage.Server/plugins/mage-player-ai-ma.jar b/Mage.Server/plugins/mage-player-ai-ma.jar index 0d1597136c..2bf8e7c4aa 100644 Binary files a/Mage.Server/plugins/mage-player-ai-ma.jar and b/Mage.Server/plugins/mage-player-ai-ma.jar differ diff --git a/Mage.Tests/RB Aggro.dck b/Mage.Tests/RB Aggro.dck new file mode 100644 index 0000000000..604fc32923 --- /dev/null +++ b/Mage.Tests/RB Aggro.dck @@ -0,0 +1,19 @@ +NAME:RB Aggro +4 [ALA:156] Blightning +2 [ZEN:245] Mountain +2 [ZEN:244] Mountain +2 [ZEN:243] Mountain +2 [ZEN:242] Mountain +4 [ZEN:223] Scalding Tarn +4 [M10:146] Lightning Bolt +4 [WWK:139] Lavaclaw Reaches +3 [M10:134] Earthquake +4 [ZEN:126] Goblin Guide +4 [CON:65] Hellspark Elemental +4 [M10:125] Ball Lightning +4 [ALA:103] Hell's Thunder +2 [CON:70] Quenchable Fire +3 [ZEN:119] Burst Lightning +4 [ZEN:211] Arid Mesa +4 [M10:223] Dragonskull Summit +4 [WWK:90] Searing Blaze diff --git a/Mage.Tests/config/config.xml b/Mage.Tests/config/config.xml index 62c7d6854f..b3ae1e8072 100644 --- a/Mage.Tests/config/config.xml +++ b/Mage.Tests/config/config.xml @@ -3,17 +3,14 @@ - - - + - - + diff --git a/Mage.Tests/plugins/AIMinimax.properties b/Mage.Tests/plugins/AIMinimax.properties new file mode 100644 index 0000000000..96b5480294 --- /dev/null +++ b/Mage.Tests/plugins/AIMinimax.properties @@ -0,0 +1,7 @@ +maxDepth=10 +maxNodes=5000 +evaluatorLifeFactor=2 +evaluatorPermanentFactor=1 +evaluatorCreatureFactor=1 +evaluatorHandFactor=1 +maxThinkSeconds=30 \ No newline at end of file diff --git a/Mage.Tests/plugins/mage-deck-constructed.jar b/Mage.Tests/plugins/mage-deck-constructed.jar new file mode 100644 index 0000000000..3647989d7d Binary files /dev/null and b/Mage.Tests/plugins/mage-deck-constructed.jar differ diff --git a/Mage.Tests/plugins/mage-deck-limited.jar b/Mage.Tests/plugins/mage-deck-limited.jar new file mode 100644 index 0000000000..b4ca904cc5 Binary files /dev/null and b/Mage.Tests/plugins/mage-deck-limited.jar differ diff --git a/Mage.Tests/plugins/mage-game-twoplayerduel.jar b/Mage.Tests/plugins/mage-game-twoplayerduel.jar new file mode 100644 index 0000000000..5136d69d1e Binary files /dev/null and b/Mage.Tests/plugins/mage-game-twoplayerduel.jar differ diff --git a/Mage.Tests/plugins/mage-player-ai-ma.jar b/Mage.Tests/plugins/mage-player-ai-ma.jar new file mode 100644 index 0000000000..2bf8e7c4aa Binary files /dev/null and b/Mage.Tests/plugins/mage-player-ai-ma.jar differ diff --git a/Mage.Tests/plugins/mage-player-aiminimax.jar b/Mage.Tests/plugins/mage-player-aiminimax.jar new file mode 100644 index 0000000000..9ddd1b6941 Binary files /dev/null and b/Mage.Tests/plugins/mage-player-aiminimax.jar differ diff --git a/Mage.Tests/plugins/mage-tournament-booster-draft.jar b/Mage.Tests/plugins/mage-tournament-booster-draft.jar new file mode 100644 index 0000000000..e48a8b75ad Binary files /dev/null and b/Mage.Tests/plugins/mage-tournament-booster-draft.jar differ diff --git a/Mage.Tests/pom.xml b/Mage.Tests/pom.xml index f3956fea0a..c451f8e773 100644 --- a/Mage.Tests/pom.xml +++ b/Mage.Tests/pom.xml @@ -39,6 +39,12 @@ junit 4.8.2 + + ${project.groupId} + Mage-Game-TwoPlayerDuel + ${project.version} + compile + log4j diff --git a/Mage.Tests/src/frozen/org/mage/test/clientside/LandTest.java b/Mage.Tests/src/frozen/org/mage/test/clientside/LandTest.java new file mode 100644 index 0000000000..e3d51f7a39 --- /dev/null +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/LandTest.java @@ -0,0 +1,22 @@ +package org.mage.test.clientside; + +import org.junit.Test; +import org.mage.test.clientside.base.MageAPI; +import org.mage.test.clientside.bdd.and.And; +import org.mage.test.clientside.bdd.given.Given; +import org.mage.test.clientside.bdd.then.Then; +import org.mage.test.clientside.bdd.when.When; + +import static org.mage.test.clientside.base.MageAPI.Owner.*; + +public class LandTest extends MageAPI { + + @Test + public void testPlayingLandInMainPhase() throws Exception { + Given.I.have.a.card("Mountain"); + And.phase.is("Precombat Main", mine); + When.I.play("Mountain"); + Then.battlefield.has("Mountain"); + And.graveyards.empty(); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/LandTestExtended.java b/Mage.Tests/src/frozen/org/mage/test/clientside/LandTestExtended.java similarity index 68% rename from Mage.Tests/src/test/java/org/mage/test/LandTestExtended.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/LandTestExtended.java index 0003969e6c..4dee8a596d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/LandTestExtended.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/LandTestExtended.java @@ -1,10 +1,10 @@ -package org.mage.test; +package org.mage.test.clientside; import mage.Constants; import org.junit.Test; -import org.mage.test.base.MageAPIExtended; +import org.mage.test.clientside.base.MageAPIExtended; -import static org.mage.test.base.MageAPI.Owner.mine; +import static org.mage.test.clientside.base.MageAPI.Owner.mine; public class LandTestExtended extends MageAPIExtended { diff --git a/Mage.Tests/src/test/java/org/mage/test/LightningHelixTest.java b/Mage.Tests/src/frozen/org/mage/test/clientside/LightningHelixTest.java similarity index 65% rename from Mage.Tests/src/test/java/org/mage/test/LightningHelixTest.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/LightningHelixTest.java index 26cb7af199..19e9a3d83c 100644 --- a/Mage.Tests/src/test/java/org/mage/test/LightningHelixTest.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/LightningHelixTest.java @@ -1,14 +1,7 @@ -package org.mage.test; +package org.mage.test.clientside; -import mage.Constants; import org.junit.Test; -import org.mage.test.base.MageAPI; -import org.mage.test.bdd.and.And; -import org.mage.test.bdd.given.Given; -import org.mage.test.bdd.then.Then; -import org.mage.test.bdd.when.When; - -import static org.mage.test.base.MageAPI.Owner.mine; +import org.mage.test.clientside.base.MageAPI; public class LightningHelixTest extends MageAPI { diff --git a/Mage.Tests/src/test/java/org/mage/test/base/Command.java b/Mage.Tests/src/frozen/org/mage/test/clientside/base/Command.java similarity index 73% rename from Mage.Tests/src/test/java/org/mage/test/base/Command.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/base/Command.java index 09deeb3b4b..078c2451ea 100644 --- a/Mage.Tests/src/test/java/org/mage/test/base/Command.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/base/Command.java @@ -1,4 +1,4 @@ -package org.mage.test.base; +package org.mage.test.clientside.base; /** * Command pattern. diff --git a/Mage.Tests/src/test/java/org/mage/test/base/MageAPI.java b/Mage.Tests/src/frozen/org/mage/test/clientside/base/MageAPI.java similarity index 80% rename from Mage.Tests/src/test/java/org/mage/test/base/MageAPI.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/base/MageAPI.java index ca3251e95f..308b63d90d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/base/MageAPI.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/base/MageAPI.java @@ -1,9 +1,8 @@ -package org.mage.test.base; +package org.mage.test.clientside.base; import org.junit.BeforeClass; -import org.mage.test.bdd.StepController; -import org.mage.test.bdd.StepState; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import org.mage.test.clientside.bdd.StepController; +import org.mage.test.clientside.bdd.StepState; /** * Parent class for all Mage tests. diff --git a/Mage.Tests/src/test/java/org/mage/test/base/MageAPIExtended.java b/Mage.Tests/src/frozen/org/mage/test/clientside/base/MageAPIExtended.java similarity index 65% rename from Mage.Tests/src/test/java/org/mage/test/base/MageAPIExtended.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/base/MageAPIExtended.java index 52c4f5cadc..cef5ce49af 100644 --- a/Mage.Tests/src/test/java/org/mage/test/base/MageAPIExtended.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/base/MageAPIExtended.java @@ -1,15 +1,12 @@ -package org.mage.test.base; +package org.mage.test.clientside.base; import mage.Constants; -import org.junit.BeforeClass; -import org.mage.test.bdd.StepController; -import org.mage.test.bdd.StepState; -import org.mage.test.bdd.and.And; -import org.mage.test.bdd.given.Given; -import org.mage.test.bdd.then.Then; -import org.mage.test.bdd.when.When; +import org.mage.test.clientside.bdd.and.And; +import org.mage.test.clientside.bdd.given.Given; +import org.mage.test.clientside.bdd.then.Then; +import org.mage.test.clientside.bdd.when.When; -import static org.mage.test.base.MageAPI.Owner.mine; +import static org.mage.test.clientside.base.MageAPI.Owner.mine; /** * Contains wrappers for bdd calls. diff --git a/Mage.Tests/src/test/java/org/mage/test/base/MageBase.java b/Mage.Tests/src/frozen/org/mage/test/clientside/base/MageBase.java similarity index 97% rename from Mage.Tests/src/test/java/org/mage/test/base/MageBase.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/base/MageBase.java index e7a855c7d0..c1ac149db1 100644 --- a/Mage.Tests/src/test/java/org/mage/test/base/MageBase.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/base/MageBase.java @@ -1,4 +1,4 @@ -package org.mage.test.base; +package org.mage.test.clientside.base; import mage.interfaces.MageException; import mage.interfaces.Server; diff --git a/Mage.Tests/src/test/java/org/mage/test/base/exception/CardNotFoundException.java b/Mage.Tests/src/frozen/org/mage/test/clientside/base/exception/CardNotFoundException.java similarity index 78% rename from Mage.Tests/src/test/java/org/mage/test/base/exception/CardNotFoundException.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/base/exception/CardNotFoundException.java index a911c36544..0da2793ee5 100644 --- a/Mage.Tests/src/test/java/org/mage/test/base/exception/CardNotFoundException.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/base/exception/CardNotFoundException.java @@ -1,4 +1,4 @@ -package org.mage.test.base.exception; +package org.mage.test.clientside.base.exception; /** * Thrown when server couldn't create card with given name. diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/BDDTests.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/BDDTests.java similarity index 54% rename from Mage.Tests/src/test/java/org/mage/test/bdd/BDDTests.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/BDDTests.java index f5a2d3d8a4..6f4f3dd174 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/BDDTests.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/BDDTests.java @@ -1,15 +1,15 @@ -package org.mage.test.bdd; +package org.mage.test.clientside.bdd; import org.junit.Test; -import org.mage.test.base.Command; -import org.mage.test.base.MageAPI; -import org.mage.test.base.exception.CardNotFoundException; -import org.mage.test.bdd.and.And; -import org.mage.test.bdd.given.Given; -import org.mage.test.bdd.then.Then; -import org.mage.test.bdd.when.When; +import org.mage.test.clientside.base.Command; +import org.mage.test.clientside.base.MageAPI; +import org.mage.test.clientside.base.exception.CardNotFoundException; +import org.mage.test.clientside.bdd.and.And; +import org.mage.test.clientside.bdd.given.Given; +import org.mage.test.clientside.bdd.then.Then; +import org.mage.test.clientside.bdd.when.When; -import static org.mage.test.base.MageAPI.Owner.mine; +import static org.mage.test.clientside.base.MageAPI.Owner.mine; /** * Tests BDD classes. diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/Expect.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/Expect.java similarity index 82% rename from Mage.Tests/src/test/java/org/mage/test/bdd/Expect.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/Expect.java index cf794b9124..49d3669d1f 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/Expect.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/Expect.java @@ -1,7 +1,7 @@ -package org.mage.test.bdd; +package org.mage.test.clientside.bdd; import org.junit.Assert; -import org.mage.test.base.Command; +import org.mage.test.clientside.base.Command; import static org.hamcrest.CoreMatchers.is; diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/StepController.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/StepController.java similarity index 91% rename from Mage.Tests/src/test/java/org/mage/test/bdd/StepController.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/StepController.java index d9821bb1c1..60ef062e0e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/StepController.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/StepController.java @@ -1,4 +1,4 @@ -package org.mage.test.bdd; +package org.mage.test.clientside.bdd; /** * Controls steps of bdd calls. diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/StepState.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/StepState.java similarity index 65% rename from Mage.Tests/src/test/java/org/mage/test/bdd/StepState.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/StepState.java index cc264748ea..b1f62f2973 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/StepState.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/StepState.java @@ -1,4 +1,4 @@ -package org.mage.test.bdd; +package org.mage.test.clientside.bdd; public enum StepState { GIVEN, diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/and/And.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/And.java similarity index 59% rename from Mage.Tests/src/test/java/org/mage/test/bdd/and/And.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/And.java index 21e57e3bff..2fca595954 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/and/And.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/And.java @@ -1,7 +1,7 @@ -package org.mage.test.bdd.and; +package org.mage.test.clientside.bdd.and; -import org.mage.test.bdd.StepState; -import org.mage.test.bdd.given.I; +import org.mage.test.clientside.bdd.StepState; +import org.mage.test.clientside.bdd.given.I; public class And { public static Phase phase = new Phase(StepState.UNKNOWN); diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/and/Graveyards.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/Graveyards.java similarity index 74% rename from Mage.Tests/src/test/java/org/mage/test/bdd/and/Graveyards.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/Graveyards.java index 967cc578bb..1972c10a6a 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/and/Graveyards.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/Graveyards.java @@ -1,9 +1,9 @@ -package org.mage.test.bdd.and; +package org.mage.test.clientside.bdd.and; import org.junit.Assert; -import org.mage.test.base.MageAPI; -import org.mage.test.base.MageBase; -import org.mage.test.bdd.StepState; +import org.mage.test.clientside.base.MageAPI; +import org.mage.test.clientside.base.MageBase; +import org.mage.test.clientside.bdd.StepState; import static org.hamcrest.core.Is.is; diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/and/Phase.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/Phase.java similarity index 68% rename from Mage.Tests/src/test/java/org/mage/test/bdd/and/Phase.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/Phase.java index 3854f52b8b..47dde060e0 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/and/Phase.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/and/Phase.java @@ -1,13 +1,10 @@ -package org.mage.test.bdd.and; +package org.mage.test.clientside.bdd.and; -import org.mage.test.base.MageAPI; -import org.mage.test.base.MageBase; -import org.mage.test.bdd.StepState; -import org.mage.test.bdd.given.Have; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import org.mage.test.clientside.base.MageAPI; +import org.mage.test.clientside.base.MageBase; +import org.mage.test.clientside.bdd.StepState; -import static org.mage.test.base.MageAPI.*; -import static org.mage.test.base.MageAPI.Owner.*; +import static org.mage.test.clientside.base.MageAPI.Owner.*; public class Phase { private StepState step; diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/given/A.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/A.java similarity index 71% rename from Mage.Tests/src/test/java/org/mage/test/bdd/given/A.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/A.java index ca4b959809..ff7e0539de 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/given/A.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/A.java @@ -1,10 +1,9 @@ -package org.mage.test.bdd.given; +package org.mage.test.clientside.bdd.given; -import org.mage.test.base.MageAPI; -import org.mage.test.base.MageBase; -import org.mage.test.base.exception.CardNotFoundException; -import org.mage.test.bdd.StepController; -import org.mage.test.bdd.StepState; +import org.mage.test.clientside.base.MageAPI; +import org.mage.test.clientside.base.MageBase; +import org.mage.test.clientside.base.exception.CardNotFoundException; +import org.mage.test.clientside.bdd.StepState; public class A { private StepState step; diff --git a/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/Given.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/Given.java new file mode 100644 index 0000000000..45a6710a41 --- /dev/null +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/Given.java @@ -0,0 +1,9 @@ +package org.mage.test.clientside.bdd.given; + +import org.mage.test.clientside.bdd.StepState; +import org.mage.test.clientside.bdd.and.Phase; + +public class Given { + public static I I = new I(StepState.GIVEN); + public static Phase phase = new Phase(StepState.GIVEN); +} diff --git a/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/Have.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/Have.java new file mode 100644 index 0000000000..a28035efa5 --- /dev/null +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/Have.java @@ -0,0 +1,10 @@ +package org.mage.test.clientside.bdd.given; + +import org.mage.test.clientside.bdd.StepState; + +public class Have { + public Have(StepState step) { + a = new A(step); + } + public A a; +} \ No newline at end of file diff --git a/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/I.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/I.java new file mode 100644 index 0000000000..148fbeae2e --- /dev/null +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/given/I.java @@ -0,0 +1,10 @@ +package org.mage.test.clientside.bdd.given; + +import org.mage.test.clientside.bdd.StepState; + +public class I { + public I(StepState step) { + have = new Have(step); + } + public Have have; +} \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/then/Battlefield.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/then/Battlefield.java similarity index 70% rename from Mage.Tests/src/test/java/org/mage/test/bdd/then/Battlefield.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/then/Battlefield.java index 65b1c77841..abaa744075 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/then/Battlefield.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/then/Battlefield.java @@ -1,8 +1,8 @@ -package org.mage.test.bdd.then; +package org.mage.test.clientside.bdd.then; -import org.mage.test.base.MageAPI; -import org.mage.test.base.MageBase; -import org.mage.test.bdd.StepState; +import org.mage.test.clientside.base.MageAPI; +import org.mage.test.clientside.base.MageBase; +import org.mage.test.clientside.bdd.StepState; public class Battlefield { private StepState step; diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/then/Then.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/then/Then.java similarity index 53% rename from Mage.Tests/src/test/java/org/mage/test/bdd/then/Then.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/then/Then.java index bab0ba4bc9..6e759337dc 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/then/Then.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/then/Then.java @@ -1,7 +1,7 @@ -package org.mage.test.bdd.then; +package org.mage.test.clientside.bdd.then; -import org.mage.test.bdd.StepState; -import org.mage.test.bdd.and.Graveyards; +import org.mage.test.clientside.bdd.StepState; +import org.mage.test.clientside.bdd.and.Graveyards; public class Then { public static Battlefield battlefield = new Battlefield(StepState.THEN); diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/when/I.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/when/I.java similarity index 57% rename from Mage.Tests/src/test/java/org/mage/test/bdd/when/I.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/when/I.java index 606b21257a..4d84aa2c98 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/when/I.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/when/I.java @@ -1,6 +1,6 @@ -package org.mage.test.bdd.when; +package org.mage.test.clientside.bdd.when; -import org.mage.test.base.MageBase; +import org.mage.test.clientside.base.MageBase; public class I { public void play(String cardName) throws Exception { diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/when/When.java b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/when/When.java similarity index 53% rename from Mage.Tests/src/test/java/org/mage/test/bdd/when/When.java rename to Mage.Tests/src/frozen/org/mage/test/clientside/bdd/when/When.java index 41cb10a937..97efc9d6ab 100644 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/when/When.java +++ b/Mage.Tests/src/frozen/org/mage/test/clientside/bdd/when/When.java @@ -1,4 +1,4 @@ -package org.mage.test.bdd.when; +package org.mage.test.clientside.bdd.when; public class When { public static I I = new I(); diff --git a/Mage.Tests/src/test/java/org/mage/test/LandTest.java b/Mage.Tests/src/test/java/org/mage/test/LandTest.java deleted file mode 100644 index a2235509d0..0000000000 --- a/Mage.Tests/src/test/java/org/mage/test/LandTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.mage.test; - -import org.junit.Test; -import org.mage.test.base.MageAPI; -import org.mage.test.bdd.and.And; -import org.mage.test.bdd.given.Given; -import org.mage.test.bdd.then.Then; -import org.mage.test.bdd.when.When; - -import static org.mage.test.base.MageAPI.Owner.*; - -public class LandTest extends MageAPI { - - @Test - public void testPlayingLandInMainPhase() throws Exception { - Given.I.have.a.card("Mountain"); - And.phase.is("Precombat Main", mine); - When.I.play("Mountain"); - Then.battlefield.has("Mountain"); - And.graveyards.empty(); - } -} diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/given/Given.java b/Mage.Tests/src/test/java/org/mage/test/bdd/given/Given.java deleted file mode 100644 index d80bd10d2b..0000000000 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/given/Given.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.mage.test.bdd.given; - -import org.mage.test.bdd.StepState; -import org.mage.test.bdd.and.Phase; - -public class Given { - public static I I = new I(StepState.GIVEN); - public static Phase phase = new Phase(StepState.GIVEN); -} diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/given/Have.java b/Mage.Tests/src/test/java/org/mage/test/bdd/given/Have.java deleted file mode 100644 index 85f46168b3..0000000000 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/given/Have.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.mage.test.bdd.given; - -import org.mage.test.bdd.StepController; -import org.mage.test.bdd.StepState; - -public class Have { - public Have(StepState step) { - a = new A(step); - } - public A a; -} \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/bdd/given/I.java b/Mage.Tests/src/test/java/org/mage/test/bdd/given/I.java deleted file mode 100644 index 5a5160ee5e..0000000000 --- a/Mage.Tests/src/test/java/org/mage/test/bdd/given/I.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.mage.test.bdd.given; - -import org.mage.test.bdd.StepController; -import org.mage.test.bdd.StepState; - -public class I { - public I(StepState step) { - have = new Have(step); - } - public Have have; -} \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/PlayGameTest.java b/Mage.Tests/src/test/java/org/mage/test/serverside/PlayGameTest.java new file mode 100644 index 0000000000..1c1cc4b119 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/PlayGameTest.java @@ -0,0 +1,53 @@ +package org.mage.test.serverside; + +import mage.Constants; +import mage.cards.decks.Deck; +import mage.game.Game; +import mage.game.GameException; +import mage.game.TwoPlayerDuel; +import mage.players.Player; +import mage.server.game.PlayerFactory; +import mage.sets.Sets; +import org.junit.Test; +import org.mage.test.serverside.base.MageTestBase; + +import java.io.FileNotFoundException; + +/** + * @author ayratn + */ +public class PlayGameTest extends MageTestBase { + + @Test + public void playOneGame() throws GameException, FileNotFoundException, IllegalArgumentException { + Game game = new TwoPlayerDuel(Constants.MultiplayerAttackOption.LEFT, Constants.RangeOfInfluence.ALL); + + Player player = createPlayer("computer1", "Computer - mad"); + Deck deck = Deck.load(Sets.loadDeck("RB Aggro.dck")); + + if (deck.getCards().size() < 40) { + throw new IllegalArgumentException("Couldn't load deck, deck side=" + deck.getCards().size()); + } + game.addPlayer(player, deck); + game.loadCards(deck.getCards(), player.getId()); + + Player player2 = createPlayer("computer2", "Computer - mad"); + Deck deck2 = Deck.load(Sets.loadDeck("UW Control.dck")); + if (deck2.getCards().size() < 40) { + throw new IllegalArgumentException("Couldn't load deck, deck side=" + deck2.getCards().size()); + } + game.addPlayer(player2, deck2); + game.loadCards(deck2.getCards(), player2.getId()); + + long t1 = System.nanoTime(); + game.start(player.getId()); + long t2 = System.nanoTime(); + + logger.info("Winner: " + game.getWinner()); + logger.info("Time: " + (t2 - t1) / 1000000 + " ms"); + } + + private Player createPlayer(String name, String playerType) { + return PlayerFactory.getInstance().createPlayer(playerType, name, Constants.RangeOfInfluence.ALL); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/MageTestBase.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/MageTestBase.java new file mode 100644 index 0000000000..56e319cb6c --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/MageTestBase.java @@ -0,0 +1,108 @@ +package org.mage.test.serverside.base; + +import mage.game.match.MatchType; +import mage.game.tournament.TournamentType; +import mage.server.game.DeckValidatorFactory; +import mage.server.game.GameFactory; +import mage.server.game.PlayerFactory; +import mage.server.tournament.TournamentFactory; +import mage.server.util.ConfigSettings; +import mage.server.util.PluginClassLoader; +import mage.server.util.config.GamePlugin; +import mage.server.util.config.Plugin; +import mage.util.Copier; +import mage.util.Logging; +import org.junit.BeforeClass; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * @author ayratn + */ +public class MageTestBase { + protected static Logger logger = Logging.getLogger(MageTestBase.class.getName()); + + public static PluginClassLoader classLoader = new PluginClassLoader(); + + private final static String pluginFolder = "plugins"; + + @BeforeClass + public static void init() { + logger.info("Starting MAGE tests"); + logger.info("Logging level: " + Logging.getLevel(logger)); + deleteSavedGames(); + ConfigSettings config = ConfigSettings.getInstance(); + for (GamePlugin plugin : config.getGameTypes()) { + GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin)); + } + for (GamePlugin plugin : config.getTournamentTypes()) { + TournamentFactory.getInstance().addTournamentType(plugin.getName(), loadTournamentType(plugin), loadPlugin(plugin)); + } + for (Plugin plugin : config.getPlayerTypes()) { + PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin)); + } + for (Plugin plugin : config.getDeckTypes()) { + DeckValidatorFactory.getInstance().addDeckType(plugin.getName(), loadPlugin(plugin)); + } + Copier.setLoader(classLoader); + } + + private static Class loadPlugin(Plugin plugin) { + try { + classLoader.addURL(new File(pluginFolder + "/" + plugin.getJar()).toURI().toURL()); + logger.info("Loading plugin: " + plugin.getClassName()); + return Class.forName(plugin.getClassName(), true, classLoader); + } catch (ClassNotFoundException ex) { + logger.log(Level.SEVERE, "Plugin not Found:" + plugin.getJar() + " - check plugin folder"); + } catch (Exception ex) { + logger.log(Level.SEVERE, "Error loading plugin " + plugin.getJar(), ex); + } + return null; + } + + private static MatchType loadGameType(GamePlugin plugin) { + try { + classLoader.addURL(new File(pluginFolder + "/" + plugin.getJar()).toURI().toURL()); + logger.info("Loading game type: " + plugin.getClassName()); + return (MatchType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance(); + } catch (ClassNotFoundException ex) { + logger.log(Level.SEVERE, "Game type not found:" + plugin.getJar() + " - check plugin folder"); + } catch (Exception ex) { + logger.log(Level.SEVERE, "Error loading game type " + plugin.getJar(), ex); + } + return null; + } + + private static TournamentType loadTournamentType(GamePlugin plugin) { + try { + classLoader.addURL(new File(pluginFolder + "/" + plugin.getJar()).toURI().toURL()); + logger.info("Loading tournament type: " + plugin.getClassName()); + return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance(); + } catch (ClassNotFoundException ex) { + logger.log(Level.SEVERE, "Tournament type not found:" + plugin.getJar() + " - check plugin folder"); + } catch (Exception ex) { + logger.log(Level.SEVERE, "Error loading game type " + plugin.getJar(), ex); + } + return null; + } + + private static void deleteSavedGames() { + File directory = new File("saved/"); + if (!directory.exists()) + directory.mkdirs(); + File[] files = directory.listFiles( + new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.endsWith(".game"); + } + } + ); + for (File file : files) { + file.delete(); + } + } +} diff --git a/Mage/src/mage/cards/decks/Deck.java b/Mage/src/mage/cards/decks/Deck.java index 5ebba4cfb8..d7234af042 100644 --- a/Mage/src/mage/cards/decks/Deck.java +++ b/Mage/src/mage/cards/decks/Deck.java @@ -41,6 +41,7 @@ public class Deck implements Serializable { private Set sideboard = new LinkedHashSet(); public static Deck load(DeckCardLists deckCardLists) throws GameException { + return Deck.load(deckCardLists, false); }