refined game flow by adjusting situations where game with automatically pass, added test case for game flow

master
melvin 2011-06-20 12:49:52 +08:00
parent f39f6dad01
commit 394f68bede
3 changed files with 67 additions and 12 deletions

View File

@ -253,13 +253,7 @@ public class MagicGame {
} }
public boolean canSkipSingleChoice() { public boolean canSkipSingleChoice() {
//human is attacking, AI is blocking, return GeneralConfig.getInstance().getSkipSingle();
//pass priority during declare blockers if AI is not blocking and nothing else to do
return GeneralConfig.getInstance().getSkipSingle() &&
!(isPhase(MagicPhaseType.DeclareBlockers) &&
turnPlayer.getIndex() == 0 &&
getOpponent(turnPlayer).getNrOfBlockers() > 0 &&
stack.isEmpty());
} }
public boolean canSkipSingleManaChoice() { public boolean canSkipSingleManaChoice() {
@ -273,7 +267,8 @@ public class MagicGame {
public boolean canAlwaysPass() { public boolean canAlwaysPass() {
if (GeneralConfig.getInstance().getAlwaysPass()) { if (GeneralConfig.getInstance().getAlwaysPass()) {
return phase.getType()==MagicPhaseType.Draw||phase.getType()==MagicPhaseType.BeginOfCombat; return phase.getType() == MagicPhaseType.Draw ||
phase.getType() == MagicPhaseType.BeginOfCombat;
} }
return false; return false;
} }

View File

@ -90,10 +90,12 @@ public class MagicPlayChoice extends MagicChoice {
final MagicPlayer player, final MagicPlayer player,
final MagicSource source) { final MagicSource source) {
//always pass draw and begin combat option
if (game.canAlwaysPass()) { if (game.canAlwaysPass()) {
return PASS_CHOICE_RESULTS; return PASS_CHOICE_RESULTS;
} }
//skip all combat phases if nobody is attacking
if ((game.isPhase(MagicPhaseType.DeclareAttackers) || if ((game.isPhase(MagicPhaseType.DeclareAttackers) ||
game.isPhase(MagicPhaseType.DeclareBlockers) || game.isPhase(MagicPhaseType.DeclareBlockers) ||
game.isPhase(MagicPhaseType.CombatDamage) || game.isPhase(MagicPhaseType.CombatDamage) ||
@ -103,11 +105,28 @@ public class MagicPlayChoice extends MagicChoice {
return PASS_CHOICE_RESULTS; return PASS_CHOICE_RESULTS;
} }
//skip is phase is combat damage, not supposed to be able to do
//anything but resolve triggers
if (game.isPhase(MagicPhaseType.CombatDamage)) {
if (!game.getStack().isEmpty()) {
try {
Thread.sleep(1000);
} catch (final Exception err) {
}
}
return PASS_CHOICE_RESULTS;
}
final Set<Object> validChoices; final Set<Object> validChoices;
validChoices=getValidChoices(game,player); validChoices=getValidChoices(game,player);
if ((game.isPhase(MagicPhaseType.CombatDamage)) || //skip single choice except during declare blockers phase and stack is empty so that
(validChoices.isEmpty() && game.canSkipSingleChoice())) { //user can observe the final combat sitation before damage is delt
if (validChoices.isEmpty() &&
game.canSkipSingleChoice() &&
!(game.isPhase(MagicPhaseType.DeclareBlockers) && game.getStack().isEmpty())) {
if (!game.getStack().isEmpty()) { if (!game.getStack().isEmpty()) {
try { try {
Thread.sleep(1000); Thread.sleep(1000);

View File

@ -0,0 +1,41 @@
package magic.test;
import magic.model.*;
import magic.model.phase.MagicMainPhase;
class TestFlow extends TestGameBuilder {
public MagicGame getGame() {
final MagicTournament tournament=new MagicTournament();
tournament.setDifficulty(6);
final MagicPlayerProfile profile=new MagicPlayerProfile("bgruw");
final MagicPlayerDefinition player1=new MagicPlayerDefinition("Player",false,profile,15);
final MagicPlayerDefinition player2=new MagicPlayerDefinition("Computer",true,profile,14);
tournament.setPlayers(new MagicPlayerDefinition[]{player1,player2});
tournament.setStartPlayer(0);
final MagicGame game=tournament.nextGame(true);
game.setPhase(MagicMainPhase.getFirstInstance());
final MagicPlayer player=game.getPlayer(0);
final MagicPlayer opponent=game.getPlayer(1);
MagicPlayer P = player;
P.setLife(4);
P.setPoison(0);
addToLibrary(P,"Plains",10);
createPermanent(game,P,"Rupture Spire",false,8);
createPermanent(game,P,"Chameleon Colossus",false,1);
P = opponent;
P.setLife(8);
P.setPoison(0);
addToLibrary(P,"Island",10);
createPermanent(game,P,"Rupture Spire",false,5);
createPermanent(game,P,"Tectonic Edge",false,3);
return game;
}
}