merge helper methods into runGame loop
parent
fe81862272
commit
2a6416d6a4
|
@ -46,7 +46,13 @@ public class HeadlessGameController implements IGameController {
|
||||||
|
|
||||||
running = true;
|
running = true;
|
||||||
while (running && game.isFinished() == false && System.currentTimeMillis() - startTime <= maxDuration) {
|
while (running && game.isFinished() == false && System.currentTimeMillis() - startTime <= maxDuration) {
|
||||||
executeNextEventOrPhase();
|
if (game.hasNextEvent()) {
|
||||||
|
final MagicEvent event = game.getNextEvent();
|
||||||
|
final Object[] result = event.hasChoice() ? getAIChoiceResults(event) : MagicEvent.NO_CHOICE_RESULTS;
|
||||||
|
game.executeNextEvent(result);
|
||||||
|
} else {
|
||||||
|
game.executePhase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.isFinished()) {
|
if (game.isFinished()) {
|
||||||
|
@ -58,31 +64,7 @@ public class HeadlessGameController implements IGameController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeNextEventOrPhase() {
|
private Object[] getAIChoiceResults(final MagicEvent event) {
|
||||||
if (game.hasNextEvent()) {
|
|
||||||
executeNextEvent();
|
|
||||||
} else {
|
|
||||||
game.executePhase();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void executeNextEvent() {
|
|
||||||
final MagicEvent event=game.getNextEvent();
|
|
||||||
if (event instanceof MagicPriorityEvent) {
|
|
||||||
game.logMessages();
|
|
||||||
}
|
|
||||||
if (event.hasChoice()) {
|
|
||||||
executeNextEventWithChoices(event);
|
|
||||||
} else {
|
|
||||||
game.executeNextEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void executeNextEventWithChoices(final MagicEvent event) {
|
|
||||||
game.executeNextEvent(getArtificialNextEventChoiceResults(event));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object[] getArtificialNextEventChoiceResults(final MagicEvent event) {
|
|
||||||
//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()];
|
||||||
|
|
Loading…
Reference in New Issue