mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
AI, combat: fixed that computer safely blocks the weakest creature instead most powerfull
This commit is contained in:
parent
89b2509fa5
commit
138788659a
3 changed files with 175 additions and 4 deletions
|
|
@ -898,7 +898,7 @@ public class ComputerPlayer6 extends ComputerPlayer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CombatUtil.sortByPower(attackers, false);
|
CombatUtil.sortByPower(attackers, false); // most powerfull go to first
|
||||||
|
|
||||||
CombatInfo combatInfo = CombatUtil.blockWithGoodTrade2(game, attackers, possibleBlockers);
|
CombatInfo combatInfo = CombatUtil.blockWithGoodTrade2(game, attackers, possibleBlockers);
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public final class CombatUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortByPower(blockableAttackers, true);
|
sortByPower(blockableAttackers, false); // most powerfull go to first
|
||||||
|
|
||||||
// imagine that most powerful will be blocked as 1-vs-1
|
// imagine that most powerful will be blocked as 1-vs-1
|
||||||
List<Permanent> attackersThatWontBeBlocked = new ArrayList<>(blockableAttackers);
|
List<Permanent> attackersThatWontBeBlocked = new ArrayList<>(blockableAttackers);
|
||||||
|
|
@ -87,9 +87,9 @@ public final class CombatUtil {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Permanent o1, Permanent o2) {
|
public int compare(Permanent o1, Permanent o2) {
|
||||||
if (ascending) {
|
if (ascending) {
|
||||||
return o2.getPower().getValue() - o1.getPower().getValue();
|
|
||||||
} else {
|
|
||||||
return o1.getPower().getValue() - o2.getPower().getValue();
|
return o1.getPower().getValue() - o2.getPower().getValue();
|
||||||
|
} else {
|
||||||
|
return o2.getPower().getValue() - o1.getPower().getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
package org.mage.test.AI.basic;
|
||||||
|
|
||||||
|
import mage.constants.PhaseStep;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mage.test.serverside.base.CardTestPlayerBaseWithAIHelps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author JayDi85
|
||||||
|
*/
|
||||||
|
public class BlockSimulationAITest extends CardTestPlayerBaseWithAIHelps {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Block_1_small_attacker_vs_1_big_blocker() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Arbor Elf", 1); // 1/1
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); // 2/2
|
||||||
|
|
||||||
|
attack(1, playerA, "Arbor Elf");
|
||||||
|
|
||||||
|
// ai must block
|
||||||
|
aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB);
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20);
|
||||||
|
assertGraveyardCount(playerA, "Arbor Elf", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Block_1_small_attacker_vs_2_big_blockers() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Arbor Elf", 1); // 1/1
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 2); // 2/2
|
||||||
|
|
||||||
|
attack(1, playerA, "Arbor Elf");
|
||||||
|
|
||||||
|
// ai must block
|
||||||
|
aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB);
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20);
|
||||||
|
assertGraveyardCount(playerA, "Arbor Elf", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Block_1_small_attacker_vs_1_small_blocker() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Arbor Elf", 1); // 1/1
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Arbor Elf", 1); // 1/1
|
||||||
|
|
||||||
|
attack(1, playerA, "Arbor Elf");
|
||||||
|
|
||||||
|
// ai must block
|
||||||
|
aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB);
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20);
|
||||||
|
assertGraveyardCount(playerA, "Arbor Elf", 1);
|
||||||
|
assertGraveyardCount(playerB, "Arbor Elf", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Block_1_big_attacker_vs_1_small_blocker() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); // 2/2
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Arbor Elf", 1); // 1/1
|
||||||
|
|
||||||
|
attack(1, playerA, "Balduvian Bears");
|
||||||
|
|
||||||
|
// ai must not block
|
||||||
|
aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB);
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20 - 2);
|
||||||
|
assertGraveyardCount(playerA, "Balduvian Bears", 0);
|
||||||
|
assertGraveyardCount(playerB, "Arbor Elf", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Block_2_big_attackers_vs_1_small_blocker() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); // 2/2
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Deadbridge Goliath", 1); // 5/5
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Arbor Elf", 1); // 1/1
|
||||||
|
|
||||||
|
attack(1, playerA, "Balduvian Bears");
|
||||||
|
attack(1, playerA, "Deadbridge Goliath");
|
||||||
|
|
||||||
|
// ai must not block
|
||||||
|
aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB);
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20 - 2 - 5);
|
||||||
|
assertGraveyardCount(playerA, "Balduvian Bears", 0);
|
||||||
|
assertGraveyardCount(playerA, "Deadbridge Goliath", 0);
|
||||||
|
assertGraveyardCount(playerB, "Arbor Elf", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Block_2_big_attackers_vs_1_big_blocker_a() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); // 2/2
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Deadbridge Goliath", 1); // 5/5
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Colossal Dreadmaw", 1); // 6/6
|
||||||
|
|
||||||
|
attack(1, playerA, "Balduvian Bears");
|
||||||
|
attack(1, playerA, "Deadbridge Goliath");
|
||||||
|
|
||||||
|
// ai must block bigger attacker and survive (6/6 must block 5/5)
|
||||||
|
aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB);
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20 - 2);
|
||||||
|
assertGraveyardCount(playerA, "Balduvian Bears", 0);
|
||||||
|
assertGraveyardCount(playerA, "Deadbridge Goliath", 1);
|
||||||
|
assertGraveyardCount(playerB, "Colossal Dreadmaw", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Block_2_big_attackers_vs_1_big_blocker_b() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Arbor Elf", 1); // 1/1
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); // 2/2
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Deadbridge Goliath", 1); // 5/5
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Colossal Dreadmaw", 1); // 6/6
|
||||||
|
//
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Spectral Bears", 1); // 3/3
|
||||||
|
|
||||||
|
attack(1, playerA, "Arbor Elf");
|
||||||
|
attack(1, playerA, "Balduvian Bears");
|
||||||
|
attack(1, playerA, "Deadbridge Goliath");
|
||||||
|
attack(1, playerA, "Colossal Dreadmaw");
|
||||||
|
|
||||||
|
// ai must block bigger attacker and survive (3/3 must block 2/2)
|
||||||
|
aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB);
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20 - 1 - 5 - 6);
|
||||||
|
assertGraveyardCount(playerA, "Balduvian Bears", 1);
|
||||||
|
assertPermanentCount(playerB, "Spectral Bears", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add tests for DeathtouchAbility
|
||||||
|
// TODO: add tests for FirstStrikeAbility
|
||||||
|
// TODO: add tests for DoubleStrikeAbility
|
||||||
|
// TODO: add tests for IndestructibleAbility
|
||||||
|
// TODO: add tests for FlyingAbility
|
||||||
|
// TODO: add tests for ReachAbility
|
||||||
|
// TODO: add tests for ExaltedAbility???
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue