Added "AI vs AI" test. Removed clientside tests.

This commit is contained in:
magenoxx 2011-02-10 18:38:44 +03:00
parent d17fd869c3
commit 3521b7d89f
45 changed files with 322 additions and 148 deletions

View file

@ -49,7 +49,6 @@ import mage.abilities.ActivatedAbility;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.SearchEffect; import mage.abilities.effects.SearchEffect;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.choices.Choice; import mage.choices.Choice;
import mage.filter.FilterAbility; import mage.filter.FilterAbility;
import mage.game.Game; import mage.game.Game;
@ -85,9 +84,9 @@ import mage.util.Logging;
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements Player { public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> 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); private static final ExecutorService pool = Executors.newFixedThreadPool(1);
protected int maxDepth; protected int maxDepth;
@ -99,13 +98,13 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
protected int currentScore; protected int currentScore;
protected SimulationNode root; protected SimulationNode root;
public ComputerPlayer2(String name, RangeOfInfluence range) { public ComputerPlayer4(String name, RangeOfInfluence range) {
super(name, range); super(name, range);
maxDepth = Config.maxDepth; maxDepth = Config.maxDepth;
maxNodes = Config.maxNodes; maxNodes = Config.maxNodes;
} }
public ComputerPlayer2(final ComputerPlayer2 player) { public ComputerPlayer4(final ComputerPlayer4 player) {
super(player); super(player);
this.maxDepth = player.maxDepth; this.maxDepth = player.maxDepth;
this.currentScore = player.currentScore; this.currentScore = player.currentScore;
@ -123,8 +122,8 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
} }
@Override @Override
public ComputerPlayer2 copy() { public ComputerPlayer4 copy() {
return new ComputerPlayer2(this); return new ComputerPlayer4(this);
} }
@Override @Override
@ -162,6 +161,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
boolean usedStack = false; boolean usedStack = false;
while (actions.peek() != null) { while (actions.peek() != null) {
Ability ability = actions.poll(); Ability ability = actions.poll();
System.out.println("[" + game.getPlayer(playerId).getName() + "] Action: " + ability.toString());
this.activateAbility((ActivatedAbility) ability, game); this.activateAbility((ActivatedAbility) ability, game);
if (ability.isUsesStack()) if (ability.isUsesStack())
usedStack = true; usedStack = true;

View file

@ -37,7 +37,6 @@ import mage.Constants.PhaseStep;
import mage.Constants.RangeOfInfluence; import mage.Constants.RangeOfInfluence;
import mage.Constants.Zone; import mage.Constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.cards.decks.Deck;
import mage.filter.FilterAbility; import mage.filter.FilterAbility;
import mage.game.Game; import mage.game.Game;
import mage.game.combat.Combat; import mage.game.combat.Combat;
@ -66,9 +65,9 @@ import mage.util.Logging;
* *
* @author BetaSteward_at_googlemail.com * @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 filterLand = new FilterAbility();
private static FilterAbility filterNotLand = 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); super(name, range);
maxDepth = Config.maxDepth; maxDepth = Config.maxDepth;
maxNodes = Config.maxNodes; maxNodes = Config.maxNodes;
} }
public ComputerPlayer3(final ComputerPlayer3 player) { public ComputerPlayer5(final ComputerPlayer5 player) {
super(player); super(player);
} }
@Override @Override
public ComputerPlayer3 copy() { public ComputerPlayer5 copy() {
return new ComputerPlayer3(this); return new ComputerPlayer5(this);
} }
@Override @Override
@ -109,6 +108,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
break; break;
case PRECOMBAT_MAIN: case PRECOMBAT_MAIN:
if (game.getActivePlayerId().equals(playerId)) { if (game.getActivePlayerId().equals(playerId)) {
System.out.println("["+ game.getPlayer(playerId).getName() + "] Precombat Main, life=" + game.getPlayer(playerId).getLife());
if (actions.size() == 0) { if (actions.size() == 0) {
calculatePreCombatActions(game); calculatePreCombatActions(game);
} }

View file

@ -31,7 +31,7 @@ package mage.player.ai;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import mage.game.Game;
import mage.util.Logging; import mage.util.Logging;
/** /**
@ -43,9 +43,9 @@ public class SimulateBlockWorker implements Callable {
private final static Logger logger = Logging.getLogger(SimulationWorker.class.getName()); private final static Logger logger = Logging.getLogger(SimulationWorker.class.getName());
private SimulationNode node; 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.player = player;
this.node = node; this.node = node;
} }

View file

@ -7,7 +7,7 @@
<playerType name="Computer - default" jar="mage-player-ai.jar" className="mage.player.ai.ComputerPlayer"/> <playerType name="Computer - default" jar="mage-player-ai.jar" className="mage.player.ai.ComputerPlayer"/>
<playerType name="Computer - minimax" jar="mage-player-aiminimax.jar" className="mage.player.ai.ComputerPlayer2"/> <playerType name="Computer - minimax" jar="mage-player-aiminimax.jar" className="mage.player.ai.ComputerPlayer2"/>
<playerType name="Computer - minimax hybrid" jar="mage-player-aiminimax.jar" className="mage.player.ai.ComputerPlayer3"/> <playerType name="Computer - minimax hybrid" jar="mage-player-aiminimax.jar" className="mage.player.ai.ComputerPlayer3"/>
<playerType name="Computer - mad" jar="mage-player-ai-ma.jar" className="mage.player.ai.ComputerPlayer3"/> <playerType name="Computer - mad" jar="mage-player-ai-ma.jar" className="mage.player.ai.ComputerPlayer5"/>
</playerTypes> </playerTypes>
<gameTypes> <gameTypes>
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/> <gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>

19
Mage.Tests/RB Aggro.dck Normal file
View file

@ -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

View file

@ -3,17 +3,14 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<server serverAddress="localhost" serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/> <server serverAddress="localhost" serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/>
<playerTypes> <playerTypes>
<playerType name="Human" jar="mage-player-human.jar" className="mage.player.human.HumanPlayer"/>
<playerType name="Computer - default" jar="mage-player-ai.jar" className="mage.player.ai.ComputerPlayer"/>
<playerType name="Computer - minimax" jar="mage-player-aiminimax.jar" className="mage.player.ai.ComputerPlayer2"/>
<playerType name="Computer - minimax hybrid" jar="mage-player-aiminimax.jar" className="mage.player.ai.ComputerPlayer3"/> <playerType name="Computer - minimax hybrid" jar="mage-player-aiminimax.jar" className="mage.player.ai.ComputerPlayer3"/>
<playerType name="Computer - mad" jar="mage-player-ai-ma.jar" className="mage.player.ai.ComputerPlayer5"/>
</playerTypes> </playerTypes>
<gameTypes> <gameTypes>
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/> <gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>
<gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/>
</gameTypes> </gameTypes>
<tournamentTypes> <tournamentTypes>
<tournamentType name="Booster Draft" jar="mage-tournament-booster-draft.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/> <tournamentType name="Elimination Booster Draft" jar="mage-tournament-booster-draft.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/>
</tournamentTypes> </tournamentTypes>
<deckTypes> <deckTypes>
<deckType name="Constructed" jar="mage-deck-constructed.jar" className="mage.deck.Constructed"/> <deckType name="Constructed" jar="mage-deck-constructed.jar" className="mage.deck.Constructed"/>

View file

@ -0,0 +1,7 @@
maxDepth=10
maxNodes=5000
evaluatorLifeFactor=2
evaluatorPermanentFactor=1
evaluatorCreatureFactor=1
evaluatorHandFactor=1
maxThinkSeconds=30

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -39,6 +39,12 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.8.2</version> <version>4.8.2</version>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Mage-Game-TwoPlayerDuel</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>log4j</groupId>

View file

@ -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();
}
}

View file

@ -1,10 +1,10 @@
package org.mage.test; package org.mage.test.clientside;
import mage.Constants; import mage.Constants;
import org.junit.Test; 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 { public class LandTestExtended extends MageAPIExtended {

View file

@ -1,14 +1,7 @@
package org.mage.test; package org.mage.test.clientside;
import mage.Constants;
import org.junit.Test; import org.junit.Test;
import org.mage.test.base.MageAPI; import org.mage.test.clientside.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;
public class LightningHelixTest extends MageAPI { public class LightningHelixTest extends MageAPI {

View file

@ -1,4 +1,4 @@
package org.mage.test.base; package org.mage.test.clientside.base;
/** /**
* Command pattern. * Command pattern.

View file

@ -1,9 +1,8 @@
package org.mage.test.base; package org.mage.test.clientside.base;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.mage.test.bdd.StepController; import org.mage.test.clientside.bdd.StepController;
import org.mage.test.bdd.StepState; import org.mage.test.clientside.bdd.StepState;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
/** /**
* Parent class for all Mage tests. * Parent class for all Mage tests.

View file

@ -1,15 +1,12 @@
package org.mage.test.base; package org.mage.test.clientside.base;
import mage.Constants; import mage.Constants;
import org.junit.BeforeClass; import org.mage.test.clientside.bdd.and.And;
import org.mage.test.bdd.StepController; import org.mage.test.clientside.bdd.given.Given;
import org.mage.test.bdd.StepState; import org.mage.test.clientside.bdd.then.Then;
import org.mage.test.bdd.and.And; import org.mage.test.clientside.bdd.when.When;
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 static org.mage.test.clientside.base.MageAPI.Owner.mine;
/** /**
* Contains wrappers for bdd calls. * Contains wrappers for bdd calls.

View file

@ -1,4 +1,4 @@
package org.mage.test.base; package org.mage.test.clientside.base;
import mage.interfaces.MageException; import mage.interfaces.MageException;
import mage.interfaces.Server; import mage.interfaces.Server;

View file

@ -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. * Thrown when server couldn't create card with given name.

View file

@ -1,15 +1,15 @@
package org.mage.test.bdd; package org.mage.test.clientside.bdd;
import org.junit.Test; import org.junit.Test;
import org.mage.test.base.Command; import org.mage.test.clientside.base.Command;
import org.mage.test.base.MageAPI; import org.mage.test.clientside.base.MageAPI;
import org.mage.test.base.exception.CardNotFoundException; import org.mage.test.clientside.base.exception.CardNotFoundException;
import org.mage.test.bdd.and.And; import org.mage.test.clientside.bdd.and.And;
import org.mage.test.bdd.given.Given; import org.mage.test.clientside.bdd.given.Given;
import org.mage.test.bdd.then.Then; import org.mage.test.clientside.bdd.then.Then;
import org.mage.test.bdd.when.When; 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. * Tests BDD classes.

View file

@ -1,7 +1,7 @@
package org.mage.test.bdd; package org.mage.test.clientside.bdd;
import org.junit.Assert; import org.junit.Assert;
import org.mage.test.base.Command; import org.mage.test.clientside.base.Command;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;

View file

@ -1,4 +1,4 @@
package org.mage.test.bdd; package org.mage.test.clientside.bdd;
/** /**
* Controls steps of bdd calls. * Controls steps of bdd calls.

View file

@ -1,4 +1,4 @@
package org.mage.test.bdd; package org.mage.test.clientside.bdd;
public enum StepState { public enum StepState {
GIVEN, GIVEN,

View file

@ -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.clientside.bdd.StepState;
import org.mage.test.bdd.given.I; import org.mage.test.clientside.bdd.given.I;
public class And { public class And {
public static Phase phase = new Phase(StepState.UNKNOWN); public static Phase phase = new Phase(StepState.UNKNOWN);

View file

@ -1,9 +1,9 @@
package org.mage.test.bdd.and; package org.mage.test.clientside.bdd.and;
import org.junit.Assert; import org.junit.Assert;
import org.mage.test.base.MageAPI; import org.mage.test.clientside.base.MageAPI;
import org.mage.test.base.MageBase; import org.mage.test.clientside.base.MageBase;
import org.mage.test.bdd.StepState; import org.mage.test.clientside.bdd.StepState;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;

View file

@ -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.clientside.base.MageAPI;
import org.mage.test.base.MageBase; import org.mage.test.clientside.base.MageBase;
import org.mage.test.bdd.StepState; import org.mage.test.clientside.bdd.StepState;
import org.mage.test.bdd.given.Have;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import static org.mage.test.base.MageAPI.*; import static org.mage.test.clientside.base.MageAPI.Owner.*;
import static org.mage.test.base.MageAPI.Owner.*;
public class Phase { public class Phase {
private StepState step; private StepState step;

View file

@ -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.clientside.base.MageAPI;
import org.mage.test.base.MageBase; import org.mage.test.clientside.base.MageBase;
import org.mage.test.base.exception.CardNotFoundException; import org.mage.test.clientside.base.exception.CardNotFoundException;
import org.mage.test.bdd.StepController; import org.mage.test.clientside.bdd.StepState;
import org.mage.test.bdd.StepState;
public class A { public class A {
private StepState step; private StepState step;

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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.clientside.base.MageAPI;
import org.mage.test.base.MageBase; import org.mage.test.clientside.base.MageBase;
import org.mage.test.bdd.StepState; import org.mage.test.clientside.bdd.StepState;
public class Battlefield { public class Battlefield {
private StepState step; private StepState step;

View file

@ -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.clientside.bdd.StepState;
import org.mage.test.bdd.and.Graveyards; import org.mage.test.clientside.bdd.and.Graveyards;
public class Then { public class Then {
public static Battlefield battlefield = new Battlefield(StepState.THEN); public static Battlefield battlefield = new Battlefield(StepState.THEN);

View file

@ -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 class I {
public void play(String cardName) throws Exception { public void play(String cardName) throws Exception {

View file

@ -1,4 +1,4 @@
package org.mage.test.bdd.when; package org.mage.test.clientside.bdd.when;
public class When { public class When {
public static I I = new I(); public static I I = new I();

View file

@ -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();
}
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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();
}
}
}

View file

@ -41,6 +41,7 @@ public class Deck implements Serializable {
private Set<Card> sideboard = new LinkedHashSet<Card>(); private Set<Card> sideboard = new LinkedHashSet<Card>();
public static Deck load(DeckCardLists deckCardLists) throws GameException { public static Deck load(DeckCardLists deckCardLists) throws GameException {
return Deck.load(deckCardLists, false); return Deck.load(deckCardLists, false);
} }