* Added Celestial Convergence and some changes to game draw handling.

This commit is contained in:
LevelX2 2017-04-21 15:18:04 +02:00
parent 274e0f9052
commit e284922017
8 changed files with 278 additions and 31 deletions

View file

@ -0,0 +1,80 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.mage.test.game.ends;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class GameIsADrawTest extends CardTestPlayerBase {
@Test
public void GameDrawByDamage() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
// Flame Rift deals 4 damage to each player.
addCard(Zone.HAND, playerA, "Flame Rift", 3); // Sorcery {1}{R}
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 4);
// Flame Rift deals 4 damage to each player.
addCard(Zone.HAND, playerB, "Flame Rift", 2); // Sorcery
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flame Rift");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flame Rift");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flame Rift");
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Flame Rift");
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Flame Rift");
setStopAt(2, PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 0);
assertLife(playerB, 0);
Assert.assertFalse("Player A has not won.", playerA.hasWon());
Assert.assertFalse("Player B has not won.", playerB.hasWon());
Assert.assertTrue("Game has ended.", currentGame.hasEnded());
Assert.assertTrue("Both players had 0 life, game has be de a draw.", currentGame.isADraw());
}
@Test
public void GameDrawByDivineIntervention() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 8);
// Divine Intervention enters the battlefield with two intervention counters on it.
// At the beginning of your upkeep, remove an intervention counter from Divine Intervention.
// When you remove the last intervention counter from Divine Intervention, the game is a draw.
addCard(Zone.HAND, playerA, "Divine Intervention", 1); // Enchantment {6}{W}{W}
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Divine Intervention");
setStopAt(5, PhaseStep.PRECOMBAT_MAIN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
Assert.assertFalse("Player A has not won.", playerA.hasWon());
Assert.assertFalse("Player B has not won.", playerB.hasWon());
Assert.assertTrue("Game has ended.", currentGame.hasEnded());
Assert.assertTrue("Both players had 0 life, game has be de a draw.", currentGame.isADraw());
}
}

View file

@ -29,7 +29,6 @@ package org.mage.test.player;
import java.io.Serializable;
import java.util.*;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Abilities;
@ -574,16 +573,16 @@ public class TestPlayer implements Player {
List<Permanent> possibleBlockers = findPermanents(filterPermanent, computerPlayer.getId(), game);
if (!possibleBlockers.isEmpty() && attacker != null) {
boolean blockerFound = false;
for(Permanent blocker: possibleBlockers) {
for (Permanent blocker : possibleBlockers) {
// See if it can block this creature
if(canBlockAnother(game, blocker, attacker, blockedCreaturesByCreature)) {
if (canBlockAnother(game, blocker, attacker, blockedCreaturesByCreature)) {
computerPlayer.declareBlocker(defendingPlayerId, blocker.getId(), attacker.getId(), game);
blockerFound = true;
break;
}
}
// If we haven't found a blocker then an illegal block has been made in the test
if(!blockerFound) {
if (!blockerFound) {
throw new UnsupportedOperationException(groups[0] + " cannot block " + groups[1]);
}
}
@ -596,8 +595,8 @@ public class TestPlayer implements Player {
private boolean canBlockAnother(Game game, Permanent blocker, Permanent attacker, Map<MageObjectReference, List<MageObjectReference>> blockedCreaturesByCreature) {
MageObjectReference blockerRef = new MageObjectReference(blocker, game);
// See if we already reference this blocker
for(MageObjectReference r: blockedCreaturesByCreature.keySet()) {
if(r.equals(blockerRef)) {
for (MageObjectReference r : blockedCreaturesByCreature.keySet()) {
if (r.equals(blockerRef)) {
// Use the existing reference if we do
blockerRef = r;
}
@ -605,7 +604,7 @@ public class TestPlayer implements Player {
List<MageObjectReference> blocked = blockedCreaturesByCreature.getOrDefault(blockerRef, new ArrayList<>());
int numBlocked = blocked.size();
// Can't block any more creatures
if(++numBlocked > blocker.getMaxBlocks()) {
if (++numBlocked > blocker.getMaxBlocks()) {
return false;
}
// Add the attacker reference to the list of creatures this creature is blocking
@ -619,21 +618,20 @@ public class TestPlayer implements Player {
// Stores the total number of blockers for each attacker
Map<MageObjectReference, Integer> blockersForAttacker = new HashMap<>();
// Calculate the number of blockers each attacker has
for(List<MageObjectReference> attackers : blockedCreaturesByCreature.values()) {
for(MageObjectReference mr: attackers) {
for (List<MageObjectReference> attackers : blockedCreaturesByCreature.values()) {
for (MageObjectReference mr : attackers) {
Integer blockers = blockersForAttacker.getOrDefault(mr, 0);
blockersForAttacker.put(mr, blockers+1);
blockersForAttacker.put(mr, blockers + 1);
}
}
// Check each attacker is blocked by an allowed amount of creatures
for(Map.Entry<MageObjectReference, Integer> entry: blockersForAttacker.entrySet()) {
for (Map.Entry<MageObjectReference, Integer> entry : blockersForAttacker.entrySet()) {
Permanent attacker = entry.getKey().getPermanent(game);
Integer blockers = entry.getValue();
// If getMaxBlockedBy() == 0 it means any number of creatures can block this creature
if(attacker.getMaxBlockedBy() != 0 && blockers > attacker.getMaxBlockedBy()) {
if (attacker.getMaxBlockedBy() != 0 && blockers > attacker.getMaxBlockedBy()) {
throw new UnsupportedOperationException(attacker.getName() + " is blocked by " + blockers + " creature(s). It can only be blocked by " + attacker.getMaxBlockedBy() + " or less.");
}
else if(blockers < attacker.getMinBlockedBy()) {
} else if (blockers < attacker.getMinBlockedBy()) {
throw new UnsupportedOperationException(attacker.getName() + " is blocked by " + blockers + " creature(s). It has to be blocked by " + attacker.getMinBlockedBy() + " or more.");
}
}
@ -1676,6 +1674,16 @@ public class TestPlayer implements Player {
computerPlayer.lost(game);
}
@Override
public boolean hasDrew() {
return computerPlayer.hasDrew();
}
@Override
public void drew(Game game) {
computerPlayer.drew(game);
}
@Override
public void lostForced(Game game) {
computerPlayer.lostForced(game);