mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
AI fix - better time out support
This commit is contained in:
parent
bab866fcd9
commit
7e00b5cc25
7 changed files with 30 additions and 23 deletions
|
@ -394,6 +394,11 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
|||
if (logger.isDebugEnabled())
|
||||
logger.debug("simulating -- adding " + allActions.size() + " children:" + allActions);
|
||||
for (Ability action: allActions) {
|
||||
if (Thread.interrupted()) {
|
||||
Thread.currentThread().interrupt();
|
||||
logger.debug("interrupted");
|
||||
break;
|
||||
}
|
||||
Game sim = game.copy();
|
||||
if (sim.getPlayer(currentPlayer.getId()).activateAbility((ActivatedAbility) action.copy(), sim)) {
|
||||
sim.applyEffects();
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -2,14 +2,11 @@ package org.mage.test.serverside;
|
|||
|
||||
import mage.Constants;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameException;
|
||||
import mage.game.TwoPlayerDuel;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.permanent.PermanentImpl;
|
||||
import mage.players.Player;
|
||||
import mage.server.game.PlayerFactory;
|
||||
import mage.sets.Sets;
|
||||
|
@ -28,8 +25,8 @@ public class PlayGameTest extends MageTestBase {
|
|||
|
||||
private List<Card> handCardsA = new ArrayList<Card>();
|
||||
private List<Card> handCardsB = new ArrayList<Card>();
|
||||
private List<Card> battlefieldCardsA = new ArrayList<Card>();
|
||||
private List<Card> battlefieldCardsB = new ArrayList<Card>();
|
||||
private List<PermanentCard> battlefieldCardsA = new ArrayList<PermanentCard>();
|
||||
private List<PermanentCard> battlefieldCardsB = new ArrayList<PermanentCard>();
|
||||
private List<Card> graveyardCardsA = new ArrayList<Card>();
|
||||
private List<Card> graveyardCardsB = new ArrayList<Card>();
|
||||
private List<Card> libraryCardsA = new ArrayList<Card>();
|
||||
|
@ -42,8 +39,8 @@ public class PlayGameTest extends MageTestBase {
|
|||
public void playOneGame() throws GameException, FileNotFoundException, IllegalArgumentException {
|
||||
Game game = new TwoPlayerDuel(Constants.MultiplayerAttackOption.LEFT, Constants.RangeOfInfluence.ALL);
|
||||
|
||||
//Player computerA = createPlayer("ComputerA", "Computer - minimax hybrid");
|
||||
Player computerA = createPlayer("ComputerA", "Computer - mad");
|
||||
Player computerA = createPlayer("ComputerA", "Computer - minimax hybrid");
|
||||
// Player computerA = createPlayer("ComputerA", "Computer - mad");
|
||||
Deck deck = Deck.load(Sets.loadDeck("RB Aggro.dck"));
|
||||
|
||||
if (deck.getCards().size() < 40) {
|
||||
|
@ -52,8 +49,8 @@ public class PlayGameTest extends MageTestBase {
|
|||
game.addPlayer(computerA, deck);
|
||||
game.loadCards(deck.getCards(), computerA.getId());
|
||||
|
||||
//Player computerB = createPlayer("ComputerB", "Computer - minimax hybrid");
|
||||
Player computerB = createPlayer("ComputerB", "Computer - mad");
|
||||
Player computerB = createPlayer("ComputerB", "Computer - minimax hybrid");
|
||||
// Player computerB = createPlayer("ComputerB", "Computer - mad");
|
||||
Deck deck2 = Deck.load(Sets.loadDeck("RB Aggro.dck"));
|
||||
if (deck2.getCards().size() < 40) {
|
||||
throw new IllegalArgumentException("Couldn't load deck, deck size=" + deck2.getCards().size());
|
||||
|
@ -61,7 +58,7 @@ public class PlayGameTest extends MageTestBase {
|
|||
game.addPlayer(computerB, deck2);
|
||||
game.loadCards(deck2.getCards(), computerB.getId());
|
||||
|
||||
parseScenario("tests/Burn the Impure.test");
|
||||
parseScenario("scenario8.txt");
|
||||
game.cheat(computerA.getId(), commandsA);
|
||||
game.cheat(computerA.getId(), libraryCardsA, handCardsA, battlefieldCardsA, graveyardCardsA);
|
||||
game.cheat(computerB.getId(), commandsB);
|
||||
|
@ -105,14 +102,15 @@ public class PlayGameTest extends MageTestBase {
|
|||
String nickname = m.group(2);
|
||||
|
||||
if (nickname.equals("ComputerA") || nickname.equals("ComputerB")) {
|
||||
List<Card> cards;
|
||||
List<Card> cards = null;
|
||||
List<PermanentCard> perms = null;
|
||||
Constants.Zone gameZone;
|
||||
if ("hand".equalsIgnoreCase(zone)) {
|
||||
gameZone = Constants.Zone.HAND;
|
||||
cards = nickname.equals("ComputerA") ? handCardsA : handCardsB;
|
||||
} else if ("battlefield".equalsIgnoreCase(zone)) {
|
||||
gameZone = Constants.Zone.BATTLEFIELD;
|
||||
cards = nickname.equals("ComputerA") ? battlefieldCardsA : battlefieldCardsB;
|
||||
perms = nickname.equals("ComputerA") ? battlefieldCardsA : battlefieldCardsB;
|
||||
} else if ("graveyard".equalsIgnoreCase(zone)) {
|
||||
gameZone = Constants.Zone.GRAVEYARD;
|
||||
cards = nickname.equals("ComputerA") ? graveyardCardsA : graveyardCardsB;
|
||||
|
@ -150,7 +148,7 @@ public class PlayGameTest extends MageTestBase {
|
|||
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
||||
PermanentCard p = new PermanentCard(card, null);
|
||||
p.setTapped(tapped);
|
||||
cards.add(p);
|
||||
perms.add(p);
|
||||
} else {
|
||||
cards.add(card);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#default levels
|
||||
log4j.rootLogger=info, console, file, watchdog
|
||||
log4j.rootLogger=debug, console, file, watchdog
|
||||
|
||||
#console log
|
||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.console.layout.ConversionPattern=%-5p [%d{yyyy-MM-dd HH:mm [ss:SSS]}] %C{1}[%t]: %m%n
|
||||
log4j.appender.console.Threshold=INFO
|
||||
log4j.appender.console.Threshold=DEBUG
|
||||
|
||||
#file log
|
||||
log4j.appender.file=org.apache.log4j.FileAppender
|
||||
|
|
|
@ -57,6 +57,7 @@ import mage.game.events.Listener;
|
|||
import mage.game.events.PlayerQueryEvent;
|
||||
import mage.game.permanent.Battlefield;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.turn.Phase;
|
||||
import mage.game.turn.Step;
|
||||
import mage.game.turn.Turn;
|
||||
|
@ -159,5 +160,5 @@ public interface Game extends MageItem, Serializable {
|
|||
|
||||
// game cheats (for tests only)
|
||||
public void cheat(UUID ownerId, Map<Zone, String> commands);
|
||||
public void cheat(UUID ownerId, List<Card> library, List<Card> hand, List<Card> battlefield, List<Card> graveyard);
|
||||
public void cheat(UUID ownerId, List<Card> library, List<Card> hand, List<PermanentCard> battlefield, List<Card> graveyard);
|
||||
}
|
||||
|
|
|
@ -911,6 +911,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
* @param zone
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Card getLastKnownInformation(UUID objectId, Zone zone) {
|
||||
return lki.get(objectId);
|
||||
}
|
||||
|
@ -922,6 +923,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
* @param zone
|
||||
* @param card
|
||||
*/
|
||||
@Override
|
||||
public void rememberLKI(UUID objectId, Zone zone, Card card) {
|
||||
Card copy = card.copy();
|
||||
lki.put(objectId, copy);
|
||||
|
@ -930,10 +932,12 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
/**
|
||||
* Reset objects stored for Last Known Information.
|
||||
*/
|
||||
@Override
|
||||
public void resetLKI() {
|
||||
lki.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cheat(UUID ownerId, Map<Zone, String> commands) {
|
||||
if (commands != null) {
|
||||
Player player = getPlayer(ownerId);
|
||||
|
@ -982,7 +986,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
cards.clear();
|
||||
}
|
||||
|
||||
public void cheat(UUID ownerId, List<Card> library, List<Card> hand, List<Card> battlefield, List<Card> graveyard) {
|
||||
@Override
|
||||
public void cheat(UUID ownerId, List<Card> library, List<Card> hand, List<PermanentCard> battlefield, List<Card> graveyard) {
|
||||
Player player = getPlayer(ownerId);
|
||||
if (player != null) {
|
||||
loadCards(ownerId, library);
|
||||
|
@ -1002,23 +1007,21 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
setZone(card.getId(), Zone.GRAVEYARD);
|
||||
player.getGraveyard().add(card);
|
||||
}
|
||||
for (Card card : battlefield) {
|
||||
for (PermanentCard card : battlefield) {
|
||||
card.setOwnerId(ownerId);
|
||||
PermanentCard permanent = new PermanentCard(card, ownerId);
|
||||
permanent.setTapped(card.isTapped());
|
||||
getBattlefield().addPermanent(permanent);
|
||||
}
|
||||
applyEffects();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCards(UUID ownerId, List<Card> cards) {
|
||||
private void loadCards(UUID ownerId, List<? extends Card> cards) {
|
||||
if (cards == null) {
|
||||
return;
|
||||
}
|
||||
Set<Card> set = new HashSet<Card>();
|
||||
for (Card card : cards) {
|
||||
set.add(card);
|
||||
}
|
||||
Set<Card> set = new HashSet<Card>(cards);
|
||||
loadCards(set, ownerId);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue