remove unused instance members in HeadlessGameController

master
melvinzhang 2015-02-18 10:30:40 +08:00
parent 2b110ea7f8
commit 75cf2868c3
1 changed files with 7 additions and 42 deletions

View File

@ -26,17 +26,11 @@ import magic.model.choice.MagicPlayChoiceResult;
public class HeadlessGameController implements IGameController, ILogBookListener { public class HeadlessGameController implements IGameController, ILogBookListener {
private long MAX_TEST_MODE_DURATION=10000; private long MAX_TEST_MODE_DURATION=10000;
private final MagicGame game; private final MagicGame game;
// isDeckStrMode is true when game is run via DeckStrengthViewer or DeckStrCal.
private final boolean isDeckStrMode;
private final AtomicBoolean running = new AtomicBoolean(false);
private final AtomicBoolean isPaused = new AtomicBoolean(false);
/** Fully artificial test game. */ /** Fully artificial test game. */
public HeadlessGameController(final MagicGame aGame) { public HeadlessGameController(final MagicGame aGame) {
game = aGame; game = aGame;
isDeckStrMode = true;
} }
public void setMaxTestGameDuration(final long duration) { public void setMaxTestGameDuration(final long duration) {
@ -49,11 +43,6 @@ public class HeadlessGameController implements IGameController, ILogBookListener
} }
private Object[] getArtificialNextEventChoiceResults(final MagicEvent event) { private Object[] getArtificialNextEventChoiceResults(final MagicEvent event) {
if (!isDeckStrMode) {
disableActionButton(true);
showMessage(event.getSource(),event.getChoiceDescription());
}
//dynamically get the AI based on the player's index //dynamically get the AI based on the player's index
final MagicPlayer player = event.getPlayer(); final MagicPlayer player = event.getPlayer();
final MagicAI ai = game.getDuel().getAIs()[player.getIndex()]; final MagicAI ai = game.getDuel().getAIs()[player.getIndex()];
@ -69,44 +58,20 @@ public class HeadlessGameController implements IGameController, ILogBookListener
*/ */
public void runGame() { public void runGame() {
final long startTime=System.currentTimeMillis(); final long startTime=System.currentTimeMillis();
running.set(true); while (true) {
while (running.get()) { if (game.isFinished()) {
if (isPaused.get()) { game.advanceDuel(false);
pause(100); break;
} else if (game.isFinished()) {
doNextActionOnGameFinished();
} else { } else {
executeNextEventOrPhase(); executeNextEventOrPhase();
if (isDeckStrMode) { if (System.currentTimeMillis() - startTime > MAX_TEST_MODE_DURATION) {
if (System.currentTimeMillis() - startTime > MAX_TEST_MODE_DURATION) { System.err.println("WARNING. Max time for AI game exceeded");
System.err.println("WARNING. Max time for AI game exceeded"); break;
running.set(false);
}
} else {
updateGameView();
} }
} }
} }
} }
/**
* Once a game has finished determine what happens next.
* <p>
* If running an automated game then automatically start next game/duel.
* If an interactive game then wait for input from user.
*/
private void doNextActionOnGameFinished() {
if (isDeckStrMode) {
game.advanceDuel(false);
running.set(false);
} else {
game.logMessages();
clearValidChoices();
game.advanceDuel(false);
running.set(false);
}
}
private void executeNextEventOrPhase() { private void executeNextEventOrPhase() {
if (game.hasNextEvent()) { if (game.hasNextEvent()) {
executeNextEvent(); executeNextEvent();