diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/Attackers.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/Attackers.java index a20c15f41da..d64d08900b7 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/Attackers.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/Attackers.java @@ -1,16 +1,16 @@ /* * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR @@ -20,12 +20,11 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.player.ai; import java.util.ArrayList; @@ -40,9 +39,9 @@ import mage.game.permanent.Permanent; public class Attackers extends TreeMap> { public List getAttackers() { - List attackers = new ArrayList(); - for (List l: this.values()) { - for (Permanent permanent: l) { + List attackers = new ArrayList<>(); + for (List l : this.values()) { + for (Permanent permanent : l) { attackers.add(permanent); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/AI/basic/CombatTest.java b/Mage.Tests/src/test/java/org/mage/test/AI/basic/CombatTest.java new file mode 100644 index 00000000000..f95d8e9aabd --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/AI/basic/CombatTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package org.mage.test.AI.basic; + +import org.mage.test.serverside.base.CardTestPlayerBaseAI; + +/** + * + * @author LevelX2 + */ +public class CombatTest extends CardTestPlayerBaseAI { + + /* + * Combat is not integrated yet in the CardTestPlayerBaseAI + * + * TODO: Modify CardTestPlayerBaseAI to use the AI combat acting + * + * Tests to create: + * AI is not attacking if opponent has a creature that can't block + * AI is not blocking also if able if the damage the attacker will do will kill the AI + * AI is not able to block with two or more creatures one attacking creature to kill it. Even if none of the AI creatures will die + * AI attacks with a flyer even if opponent has a bigger flyer that kills AI + */ +} diff --git a/Mage.Tests/src/test/java/org/mage/test/utils/ManaUtilTest.java b/Mage.Tests/src/test/java/org/mage/test/utils/ManaUtilTest.java index 49ee45f089f..888bd5fa924 100644 --- a/Mage.Tests/src/test/java/org/mage/test/utils/ManaUtilTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/utils/ManaUtilTest.java @@ -1,9 +1,16 @@ package org.mage.test.utils; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.UUID; import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.mana.*; +import mage.abilities.mana.BasicManaAbility; +import mage.abilities.mana.BlackManaAbility; +import mage.abilities.mana.ManaAbility; +import mage.abilities.mana.RedManaAbility; +import mage.abilities.mana.WhiteManaAbility; import mage.cards.Card; import mage.cards.repository.CardRepository; import mage.util.ManaUtil; @@ -11,10 +18,6 @@ import org.junit.Assert; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.UUID; - /** * @author noxx */ @@ -47,7 +50,7 @@ public class ManaUtilTest extends CardTestPlayerBase { testManaToPayVsLand("{2}", "Cavern of Souls", 2, 2); // can't auto choose to pay testManaToPayVsLand("{2}", "Eldrazi Temple", 2, 2); // can't auto choose to pay - + // hybrid mana testManaToPayVsLand("{W/R}{W/R}{W/R}", "Sacred Foundry", 2, 1); // auto choose for hybrid mana: choose any testManaToPayVsLand("{R}{W/R}", "Sacred Foundry", 2, RedManaAbility.class); // auto choose for hybrid mana: we should choose {R} @@ -79,18 +82,20 @@ public class ManaUtilTest extends CardTestPlayerBase { Assert.assertEquals("{R}{R}", ManaUtil.condenseManaCostString("{R}{R}")); Assert.assertEquals("{U}", ManaUtil.condenseManaCostString("{U}")); Assert.assertEquals("{2}", ManaUtil.condenseManaCostString("{2}")); - Assert.assertEquals("", ManaUtil.condenseManaCostString("")); + Assert.assertEquals("", ManaUtil.condenseManaCostString("{}")); } /** * Common way to test ManaUtil.tryToAutoPay * - * We get all mana abilities, then try to auto pay and compare to expected1 and expected2 params. + * We get all mana abilities, then try to auto pay and compare to expected1 + * and expected2 params. * * @param manaToPay Mana that should be paid using land. * @param landName Land to use as mana producer. * @param expected1 The amount of mana abilities the land should have. - * @param expected2 The amount of mana abilities that ManaUtil.tryToAutoPay should be returned after optimization. + * @param expected2 The amount of mana abilities that ManaUtil.tryToAutoPay + * should be returned after optimization. */ private void testManaToPayVsLand(String manaToPay, String landName, int expected1, int expected2) { ManaCost unpaid = new ManaCostsImpl(manaToPay); @@ -100,19 +105,20 @@ public class ManaUtilTest extends CardTestPlayerBase { HashMap useableAbilities = getManaAbilities(card); Assert.assertEquals(expected1, useableAbilities.size()); - useableAbilities = ManaUtil.tryToAutoPay(unpaid, (LinkedHashMap)useableAbilities); + useableAbilities = ManaUtil.tryToAutoPay(unpaid, (LinkedHashMap) useableAbilities); Assert.assertEquals(expected2, useableAbilities.size()); } /** - * Another way to test ManaUtil.tryToAutoPay - * Here we also check what ability was auto chosen + * Another way to test ManaUtil.tryToAutoPay Here we also check what ability + * was auto chosen * - * N.B. This method can be used ONLY if we have one ability left that auto choose mode! - * That's why we assert the following: - * Assert.assertEquals(1, useableAbilities.size()); + * N.B. This method can be used ONLY if we have one ability left that auto + * choose mode! That's why we assert the following: Assert.assertEquals(1, + * useableAbilities.size()); * - * We get all mana abilities, then try to auto pay and compare to expected1 and expected2 params. + * We get all mana abilities, then try to auto pay and compare to expected1 + * and expected2 params. * * @param manaToPay Mana that should be paid using land. * @param landName Land to use as mana producer. @@ -127,7 +133,7 @@ public class ManaUtilTest extends CardTestPlayerBase { HashMap useableAbilities = getManaAbilities(card); Assert.assertEquals(expected1, useableAbilities.size()); - useableAbilities = ManaUtil.tryToAutoPay(unpaid, (LinkedHashMap)useableAbilities); + useableAbilities = ManaUtil.tryToAutoPay(unpaid, (LinkedHashMap) useableAbilities); Assert.assertEquals(1, useableAbilities.size()); ManaAbility ability = useableAbilities.values().iterator().next(); Assert.assertTrue("Wrong mana ability has been chosen", expectedChosen.isInstance(ability)); @@ -141,13 +147,13 @@ public class ManaUtilTest extends CardTestPlayerBase { */ private HashMap getManaAbilities(Card card) { HashMap useableAbilities = new LinkedHashMap<>(); - for (Ability ability: card.getAbilities()) { + for (Ability ability : card.getAbilities()) { if (ability instanceof ManaAbility) { ability.newId(); // we need to assign id manually as we are not in game - useableAbilities.put(ability.getId(), (ManaAbility)ability); + useableAbilities.put(ability.getId(), (ManaAbility) ability); } } return useableAbilities; } - + }