mirror of
https://github.com/correl/mage.git
synced 2024-11-24 19:19:56 +00:00
Fixed player leaving/conceding handling.
This commit is contained in:
parent
79d4c07d20
commit
58d3fc2328
21 changed files with 553 additions and 463 deletions
|
@ -519,7 +519,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
|
|||
logger.trace("interrupted - " + val);
|
||||
return val;
|
||||
}
|
||||
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.gameOver(null)) {
|
||||
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.checkIfGameIsOver()) {
|
||||
logger.trace("Add actions -- reached end state, node count=" + SimulationNode2.nodeCount + ", depth=" + depth);
|
||||
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||
UUID currentPlayerId = node.getGame().getPlayerList().get();
|
||||
|
@ -540,7 +540,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
|
|||
}
|
||||
}
|
||||
|
||||
if (game.gameOver(null)) {
|
||||
if (game.checkIfGameIsOver()) {
|
||||
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||
} else if (!node.getChildren().isEmpty()) {
|
||||
//declared attackers or blockers or triggered abilities
|
||||
|
@ -588,7 +588,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
|
|||
logger.debug("Sim Prio [" + depth + "] -- repeated action: " + action.toString());
|
||||
continue;
|
||||
}
|
||||
if (!sim.gameOver(null) && action.isUsesStack()) {
|
||||
if (!sim.checkIfGameIsOver() && action.isUsesStack()) {
|
||||
// only pass if the last action uses the stack
|
||||
UUID nextPlayerId = sim.getPlayerList().get();
|
||||
do {
|
||||
|
@ -864,7 +864,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
|
|||
break;
|
||||
case CLEANUP:
|
||||
game.getPhase().getStep().beginStep(game, activePlayerId);
|
||||
if (!game.checkStateAndTriggered() && !game.gameOver(null)) {
|
||||
if (!game.checkStateAndTriggered() && !game.checkIfGameIsOver()) {
|
||||
game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext());
|
||||
game.getTurn().setPhase(new BeginningPhase());
|
||||
game.getPhase().setStep(new UntapStep());
|
||||
|
|
|
@ -233,7 +233,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
|||
return GameStateEvaluator2.evaluate(playerId, game);
|
||||
}
|
||||
// Condition to stop deeper simulation
|
||||
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.gameOver(null)) {
|
||||
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.checkIfGameIsOver()) {
|
||||
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||
if (logger.isTraceEnabled()) {
|
||||
StringBuilder sb = new StringBuilder("Add Actions -- reached end state <").append(val).append('>');
|
||||
|
@ -267,7 +267,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
|||
}
|
||||
}
|
||||
|
||||
if (game.gameOver(null)) {
|
||||
if (game.checkIfGameIsOver()) {
|
||||
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||
} else if (stepFinished) {
|
||||
logger.debug("Step finished");
|
||||
|
@ -481,7 +481,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
|||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
||||
Combat simCombat = sim.getCombat().copy();
|
||||
finishCombat(sim);
|
||||
if (sim.gameOver(null)) {
|
||||
if (sim.checkIfGameIsOver()) {
|
||||
val = GameStateEvaluator2.evaluate(playerId, sim);
|
||||
} else if (!counter) {
|
||||
val = simulatePostCombatMain(sim, newNode, depth - 1, alpha, beta);
|
||||
|
@ -549,7 +549,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
|||
logger.debug("interrupted");
|
||||
return;
|
||||
}
|
||||
if (!game.gameOver(null)) {
|
||||
if (!game.checkIfGameIsOver()) {
|
||||
game.getPhase().setStep(step);
|
||||
if (!step.skipStep(game, game.getActivePlayerId())) {
|
||||
step.beginStep(game, game.getActivePlayerId());
|
||||
|
@ -598,7 +598,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
|||
logger.debug("interrupted");
|
||||
return;
|
||||
}
|
||||
if (!game.gameOver(null)) {
|
||||
if (!game.checkIfGameIsOver()) {
|
||||
game.getTurn().getPhase().endPhase(game, game.getActivePlayerId());
|
||||
game.getTurn().setPhase(new EndPhase());
|
||||
if (game.getTurn().getPhase().beginPhase(game, game.getActivePlayerId())) {
|
||||
|
|
|
@ -33,7 +33,7 @@ public final class GameStateEvaluator2 {
|
|||
public static int evaluate(UUID playerId, Game game) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next());
|
||||
if (game.gameOver(null)) {
|
||||
if (game.checkIfGameIsOver()) {
|
||||
if (player.hasLost() || opponent.hasWon()) {
|
||||
return LOSE_GAME_SCORE;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ActionSimulator {
|
|||
|
||||
public int evaluateState() {
|
||||
Player opponent = game.getPlayer(game.getOpponents(player.getId()).iterator().next());
|
||||
if (game.gameOver(null)) {
|
||||
if (game.checkIfGameIsOver()) {
|
||||
if (player.hasLost() || opponent.hasWon()) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class MCTSNode {
|
|||
this.game = game;
|
||||
this.stateValue = game.getState().getValue(game, targetPlayer);
|
||||
this.fullStateValue = game.getState().getValue(true, game);
|
||||
this.terminal = game.gameOver(null);
|
||||
this.terminal = game.checkIfGameIsOver();
|
||||
setPlayer();
|
||||
nodeCount = 1;
|
||||
// logger.info(this.stateValue);
|
||||
|
@ -90,7 +90,7 @@ public class MCTSNode {
|
|||
this.game = game;
|
||||
this.stateValue = game.getState().getValue(game, targetPlayer);
|
||||
this.fullStateValue = game.getState().getValue(true, game);
|
||||
this.terminal = game.gameOver(null);
|
||||
this.terminal = game.checkIfGameIsOver();
|
||||
this.parent = parent;
|
||||
this.action = action;
|
||||
setPlayer();
|
||||
|
@ -104,7 +104,7 @@ public class MCTSNode {
|
|||
this.combat = combat;
|
||||
this.stateValue = game.getState().getValue(game, targetPlayer);
|
||||
this.fullStateValue = game.getState().getValue(true, game);
|
||||
this.terminal = game.gameOver(null);
|
||||
this.terminal = game.checkIfGameIsOver();
|
||||
this.parent = parent;
|
||||
setPlayer();
|
||||
nodeCount++;
|
||||
|
|
|
@ -330,7 +330,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements Player {
|
|||
return GameStateEvaluator.evaluate(playerId, game);
|
||||
}
|
||||
int val;
|
||||
if (node.depth > maxDepth || game.gameOver(null)) {
|
||||
if (node.depth > maxDepth || game.checkIfGameIsOver()) {
|
||||
logger.debug(indent(node.depth) + "simulating -- reached end state");
|
||||
val = GameStateEvaluator.evaluate(playerId, game);
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements Player {
|
|||
}
|
||||
}
|
||||
|
||||
if (game.gameOver(null)) {
|
||||
if (game.checkIfGameIsOver()) {
|
||||
val = GameStateEvaluator.evaluate(playerId, game);
|
||||
}
|
||||
else if (!node.getChildren().isEmpty()) {
|
||||
|
@ -403,7 +403,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements Player {
|
|||
logger.debug(indent(node.depth) + "found useless action: " + action);
|
||||
continue;
|
||||
}
|
||||
if (!sim.gameOver(null) && action.isUsesStack()) {
|
||||
if (!sim.checkIfGameIsOver() && action.isUsesStack()) {
|
||||
// only pass if the last action uses the stack
|
||||
sim.getPlayer(currentPlayer.getId()).pass(game);
|
||||
sim.getPlayerList().getNext();
|
||||
|
@ -588,7 +588,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements Player {
|
|||
break;
|
||||
case CLEANUP:
|
||||
game.getPhase().getStep().beginStep(game, activePlayerId);
|
||||
if (!game.checkStateAndTriggered() && !game.gameOver(null)) {
|
||||
if (!game.checkStateAndTriggered() && !game.checkIfGameIsOver()) {
|
||||
game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext());
|
||||
game.getTurn().setPhase(new BeginningPhase());
|
||||
game.getPhase().setStep(new UntapStep());
|
||||
|
|
|
@ -184,7 +184,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
logger.debug(indent(node.depth) + "interrupted");
|
||||
return GameStateEvaluator.evaluate(playerId, game);
|
||||
}
|
||||
if (node.depth > maxDepth || game.gameOver(null)) {
|
||||
if (node.depth > maxDepth || game.checkIfGameIsOver()) {
|
||||
logger.debug(indent(node.depth) + "simulating -- reached end state");
|
||||
val = GameStateEvaluator.evaluate(playerId, game);
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
}
|
||||
}
|
||||
|
||||
if (game.gameOver(null)) {
|
||||
if (game.checkIfGameIsOver()) {
|
||||
val = GameStateEvaluator.evaluate(playerId, game);
|
||||
}
|
||||
else if (stepFinished) {
|
||||
|
@ -408,7 +408,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
||||
Combat simCombat = sim.getCombat().copy();
|
||||
finishCombat(sim);
|
||||
if (sim.gameOver(null)) {
|
||||
if (sim.checkIfGameIsOver()) {
|
||||
val = GameStateEvaluator.evaluate(playerId, sim);
|
||||
}
|
||||
else if (!counter) {
|
||||
|
@ -450,7 +450,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
return GameStateEvaluator.evaluate(playerId, game);
|
||||
}
|
||||
Integer val = null;
|
||||
if (!game.gameOver(null)) {
|
||||
if (!game.checkIfGameIsOver()) {
|
||||
logger.debug(indent(node.depth) + "simulating -- ending turn");
|
||||
simulateToEnd(game);
|
||||
game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext());
|
||||
|
@ -478,7 +478,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
logger.debug("interrupted");
|
||||
return;
|
||||
}
|
||||
if (!game.gameOver(null)) {
|
||||
if (!game.checkIfGameIsOver()) {
|
||||
game.getPhase().setStep(step);
|
||||
if (!step.skipStep(game, game.getActivePlayerId())) {
|
||||
step.beginStep(game, game.getActivePlayerId());
|
||||
|
@ -526,7 +526,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
logger.debug("interrupted");
|
||||
return;
|
||||
}
|
||||
if (!game.gameOver(null)) {
|
||||
if (!game.checkIfGameIsOver()) {
|
||||
game.getTurn().getPhase().endPhase(game, game.getActivePlayerId());
|
||||
game.getTurn().setPhase(new EndPhase());
|
||||
if (game.getTurn().getPhase().beginPhase(game, game.getActivePlayerId())) {
|
||||
|
|
|
@ -70,7 +70,7 @@ public final class GameStateEvaluator {
|
|||
public static int evaluate(UUID playerId, Game game, boolean ignoreTapped) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next());
|
||||
if (game.gameOver(null)) {
|
||||
if (game.checkIfGameIsOver()) {
|
||||
if (player.hasLost() || opponent.hasWon())
|
||||
return LOSE_SCORE;
|
||||
if (opponent.hasLost() || player.hasWon())
|
||||
|
|
|
@ -53,6 +53,7 @@ import mage.filter.common.FilterCreatureForCombat;
|
|||
import mage.filter.common.FilterCreatureForCombatBlock;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameImpl;
|
||||
import mage.game.combat.CombatGroup;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.events.GameEvent;
|
||||
|
@ -186,6 +187,9 @@ public class HumanPlayer extends PlayerImpl {
|
|||
response.clear();
|
||||
logger.debug("Waiting response from player: " + getId());
|
||||
game.resumeTimer(getTurnControlledBy());
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
loop = false;
|
||||
synchronized (response) {
|
||||
try {
|
||||
response.wait();
|
||||
|
@ -195,6 +199,15 @@ public class HumanPlayer extends PlayerImpl {
|
|||
game.pauseTimer(getTurnControlledBy());
|
||||
}
|
||||
}
|
||||
if (response.getResponseConcedeCheck()) {
|
||||
((GameImpl) game).checkConcede();
|
||||
if (game.hasEnded()) {
|
||||
return;
|
||||
}
|
||||
response.clear();
|
||||
loop = true;
|
||||
}
|
||||
}
|
||||
if (recordingMacro && !macroTriggeredSelectionFlag) {
|
||||
// logger.info("Adding an action " + response);
|
||||
actionQueueSaved.add(new PlayerResponse(response));
|
||||
|
@ -1706,6 +1719,15 @@ public class HumanPlayer extends PlayerImpl {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signalPlayerConcede() {
|
||||
synchronized (response) {
|
||||
response.setResponseConcedeCheck();
|
||||
response.notifyAll();
|
||||
logger.debug("Set check concede for waiting player: " + getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skip() {
|
||||
synchronized (response) {
|
||||
|
|
|
@ -43,6 +43,7 @@ public class PlayerResponse implements Serializable {
|
|||
private Integer responseInteger;
|
||||
private ManaType responseManaType;
|
||||
private UUID responseManaTypePlayerId;
|
||||
private Boolean responseConcedeCheck;
|
||||
|
||||
public PlayerResponse() {
|
||||
clear();
|
||||
|
@ -55,7 +56,8 @@ public class PlayerResponse implements Serializable {
|
|||
+ ',' + responseBoolean
|
||||
+ ',' + responseInteger
|
||||
+ ',' + responseManaType
|
||||
+ ',' + responseManaTypePlayerId;
|
||||
+ ',' + responseManaTypePlayerId
|
||||
+ ',' + responseConcedeCheck;
|
||||
}
|
||||
|
||||
public PlayerResponse(PlayerResponse other) {
|
||||
|
@ -69,6 +71,7 @@ public class PlayerResponse implements Serializable {
|
|||
responseInteger = other.responseInteger;
|
||||
responseManaType = other.responseManaType;
|
||||
responseManaTypePlayerId = other.responseManaTypePlayerId;
|
||||
responseConcedeCheck = other.responseConcedeCheck;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
@ -78,6 +81,7 @@ public class PlayerResponse implements Serializable {
|
|||
responseInteger = null;
|
||||
responseManaType = null;
|
||||
responseManaTypePlayerId = null;
|
||||
responseConcedeCheck = null;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
|
@ -104,6 +108,17 @@ public class PlayerResponse implements Serializable {
|
|||
this.responseBoolean = responseBoolean;
|
||||
}
|
||||
|
||||
public Boolean getResponseConcedeCheck() {
|
||||
if (responseConcedeCheck == null) {
|
||||
return false;
|
||||
}
|
||||
return responseConcedeCheck;
|
||||
}
|
||||
|
||||
public void setResponseConcedeCheck() {
|
||||
this.responseConcedeCheck = true;
|
||||
}
|
||||
|
||||
public Integer getInteger() {
|
||||
return responseInteger;
|
||||
}
|
||||
|
|
|
@ -349,11 +349,11 @@ public class PlayerLeftGameRange1Test extends CardTestMultiPlayerBase {
|
|||
setStopAt(4, PhaseStep.POSTCOMBAT_MAIN);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerA, 0);
|
||||
|
||||
assertLife(playerA, 2);
|
||||
Assert.assertFalse("Player A is no longer in the game", playerA.isInGame());
|
||||
|
||||
assertPermanentCount(playerA, 0);
|
||||
|
||||
Permanent staffPlayerD = getPermanent("Proteus Staff", playerD);
|
||||
Assert.assertFalse("Staff of player D could not be used", staffPlayerD.isTapped());
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ import mage.filter.predicate.Predicates;
|
|||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.filter.predicate.permanent.SummoningSicknessPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameImpl;
|
||||
import mage.game.Graveyard;
|
||||
import mage.game.Table;
|
||||
import mage.game.combat.CombatGroup;
|
||||
|
@ -519,6 +520,7 @@ public class TestPlayer implements Player {
|
|||
}
|
||||
if (groups[0].equals("Concede")) {
|
||||
game.concede(getId());
|
||||
((GameImpl) game).checkConcede();
|
||||
actions.remove(action);
|
||||
}
|
||||
}
|
||||
|
@ -1182,6 +1184,11 @@ public class TestPlayer implements Player {
|
|||
computerPlayer.abort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signalPlayerConcede() {
|
||||
computerPlayer.signalPlayerConcede();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abortReset() {
|
||||
computerPlayer.abortReset();
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
*/
|
||||
package org.mage.test.stub;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.*;
|
||||
import mage.abilities.costs.AlternativeSourceCosts;
|
||||
|
@ -62,9 +64,6 @@ import mage.target.TargetAmount;
|
|||
import mage.target.TargetCard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Quercitron
|
||||
|
@ -702,6 +701,11 @@ public class PlayerStub implements Player {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signalPlayerConcede() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abortReset() {
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ public interface Game extends MageItem, Serializable {
|
|||
|
||||
UUID getPriorityPlayerId();
|
||||
|
||||
boolean gameOver(UUID playerId);
|
||||
boolean checkIfGameIsOver();
|
||||
|
||||
boolean hasEnded();
|
||||
|
||||
|
@ -347,6 +347,8 @@ public interface Game extends MageItem, Serializable {
|
|||
|
||||
void concede(UUID playerId);
|
||||
|
||||
void setConcedingPlayer(UUID playerId);
|
||||
|
||||
void setManaPaymentMode(UUID playerId, boolean autoPayment);
|
||||
|
||||
void setManaPaymentModeRestricted(UUID playerId, boolean autoPaymentRestricted);
|
||||
|
|
|
@ -161,6 +161,8 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
private final LinkedList<UUID> stackObjectsCheck = new LinkedList<>(); // used to check if different sources used the stack
|
||||
// used to set the counters a permanent adds the battlefield (if no replacement effect is used e.g. Persist)
|
||||
protected Map<UUID, Counters> enterWithCounters = new HashMap<>();
|
||||
// used to proceed player conceding requests
|
||||
private final LinkedList<UUID> concedingPlayers = new LinkedList<>(); // used to handle asynchronous request of a player to leave the game
|
||||
|
||||
public GameImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) {
|
||||
this.id = UUID.randomUUID();
|
||||
|
@ -535,26 +537,58 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts check if game is over or if playerId is given let the player
|
||||
* concede.
|
||||
*
|
||||
* @param playerId
|
||||
* @return
|
||||
*/
|
||||
// /**
|
||||
// * Starts check if game is over or if playerId is given let the player
|
||||
// * concede.
|
||||
// *
|
||||
// * @param playerId
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// public synchronized boolean gameOver(UUID playerId) {
|
||||
// if (playerId == null) {
|
||||
// boolean result = checkIfGameIsOver();
|
||||
// return result;
|
||||
// } else {
|
||||
// logger.debug("Game over for player Id: " + playerId + " gameId " + getId());
|
||||
// concedingPlayers.add(playerId);
|
||||
// Player player = getPlayer(state.getPriorityPlayerId());
|
||||
// if (player != null && player.isHuman()) {
|
||||
// player.signalPlayerConcede();
|
||||
// } else {
|
||||
// checkConcede();
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
@Override
|
||||
public synchronized boolean gameOver(UUID playerId) {
|
||||
if (playerId == null) {
|
||||
boolean result = checkIfGameIsOver();
|
||||
return result;
|
||||
} else {
|
||||
public void setConcedingPlayer(UUID playerId) {
|
||||
Player player = getPlayer(state.getPriorityPlayerId());
|
||||
if (player != null) {
|
||||
if (!player.hasLeft() && player.isHuman()) {
|
||||
if (!concedingPlayers.contains(playerId)) {
|
||||
logger.debug("Game over for player Id: " + playerId + " gameId " + getId());
|
||||
leave(playerId);
|
||||
return true;
|
||||
concedingPlayers.add(playerId);
|
||||
player.signalPlayerConcede();
|
||||
}
|
||||
} else {
|
||||
// no asynchronous action so check directly
|
||||
checkConcede();
|
||||
}
|
||||
} else {
|
||||
checkConcede();
|
||||
checkIfGameIsOver();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIfGameIsOver() {
|
||||
public void checkConcede() {
|
||||
while (!concedingPlayers.isEmpty()) {
|
||||
leave(concedingPlayers.removeFirst());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkIfGameIsOver() {
|
||||
if (state.isGameOver()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -578,7 +612,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
for (Player player : state.getPlayers().values()) {
|
||||
if (!player.hasLeft() && !player.hasLost()) {
|
||||
logger.debug(new StringBuilder("Player ").append(player.getName()).append(" has won gameId: ").append(this.getId()));
|
||||
logger.debug("Player " + player.getName() + " has won gameId: " + this.getId());
|
||||
player.won(this);
|
||||
}
|
||||
}
|
||||
|
@ -696,13 +730,13 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
Player player = getPlayer(playerList.get());
|
||||
boolean wasPaused = state.isPaused();
|
||||
state.resume();
|
||||
if (!gameOver(null)) {
|
||||
if (!checkIfGameIsOver()) {
|
||||
fireInformEvent("Turn " + state.getTurnNum());
|
||||
if (checkStopOnTurnOption()) {
|
||||
return;
|
||||
}
|
||||
state.getTurn().resumePlay(this, wasPaused);
|
||||
if (!isPaused() && !gameOver(null)) {
|
||||
if (!isPaused() && !checkIfGameIsOver()) {
|
||||
endOfTurn();
|
||||
player = playerList.getNext(this);
|
||||
state.setTurnNum(state.getTurnNum() + 1);
|
||||
|
@ -712,11 +746,11 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
|
||||
protected void play(UUID nextPlayerId) {
|
||||
if (!isPaused() && !gameOver(null)) {
|
||||
if (!isPaused() && !checkIfGameIsOver()) {
|
||||
playerList = state.getPlayerList(nextPlayerId);
|
||||
Player playerByOrder = getPlayer(playerList.get());
|
||||
state.setPlayerByOrderId(playerByOrder.getId());
|
||||
while (!isPaused() && !gameOver(null)) {
|
||||
while (!isPaused() && !checkIfGameIsOver()) {
|
||||
if (!playExtraTurns()) {
|
||||
break;
|
||||
}
|
||||
|
@ -733,7 +767,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
state.setPlayerByOrderId(playerByOrder.getId());
|
||||
}
|
||||
}
|
||||
if (gameOver(null) && !isSimulation()) {
|
||||
if (checkIfGameIsOver() && !isSimulation()) {
|
||||
winnerId = findWinnersAndLosers();
|
||||
StringBuilder sb = new StringBuilder("GAME END gameId: ").append(this.getId()).append(' ');
|
||||
int count = 0;
|
||||
|
@ -816,7 +850,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
skipTurn = state.getTurn().play(this, player);
|
||||
} while (executingRollback);
|
||||
|
||||
if (isPaused() || gameOver(null)) {
|
||||
if (isPaused() || checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
if (!skipTurn) {
|
||||
|
@ -854,7 +888,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
|
||||
saveState(false);
|
||||
|
||||
if (gameOver(null)) {
|
||||
if (checkIfGameIsOver()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1245,7 +1279,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
clearAllBookmarks();
|
||||
try {
|
||||
applyEffects();
|
||||
while (!isPaused() && !gameOver(null) && !this.getTurn().isEndTurnRequested()) {
|
||||
while (!isPaused() && !checkIfGameIsOver() && !this.getTurn().isEndTurnRequested()) {
|
||||
if (!resuming) {
|
||||
state.getPlayers().resetPassed();
|
||||
state.getPlayerList().setCurrent(activePlayerId);
|
||||
|
@ -1254,14 +1288,14 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
fireUpdatePlayersEvent();
|
||||
Player player;
|
||||
while (!isPaused() && !gameOver(null)) {
|
||||
while (!isPaused() && !checkIfGameIsOver()) {
|
||||
try {
|
||||
if (bookmark == 0) {
|
||||
bookmark = bookmarkState();
|
||||
}
|
||||
player = getPlayer(state.getPlayerList().get());
|
||||
state.setPriorityPlayerId(player.getId());
|
||||
while (!player.isPassed() && player.canRespond() && !isPaused() && !gameOver(null)) {
|
||||
while (!player.isPassed() && player.canRespond() && !isPaused() && !checkIfGameIsOver()) {
|
||||
if (!resuming) {
|
||||
// 603.3. Once an ability has triggered, its controller puts it on the stack as an object that's not a card the next time a player would receive priority
|
||||
checkStateAndTriggered();
|
||||
|
@ -1270,7 +1304,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
resetLKI();
|
||||
}
|
||||
saveState(false);
|
||||
if (isPaused() || gameOver(null)) {
|
||||
if (isPaused() || checkIfGameIsOver()) {
|
||||
return;
|
||||
}
|
||||
// resetPassed should be called if player performs any action
|
||||
|
@ -1289,13 +1323,14 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
resetShortLivingLKI();
|
||||
resuming = false;
|
||||
if (isPaused() || gameOver(null)) {
|
||||
if (isPaused() || checkIfGameIsOver()) {
|
||||
return;
|
||||
}
|
||||
if (allPassed()) {
|
||||
if (!state.getStack().isEmpty()) {
|
||||
//20091005 - 115.4
|
||||
resolve();
|
||||
checkConcede();
|
||||
applyEffects();
|
||||
state.getPlayers().resetPassed();
|
||||
fireUpdatePlayersEvent();
|
||||
|
@ -1609,11 +1644,11 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
public boolean checkStateAndTriggered() {
|
||||
boolean somethingHappened = false;
|
||||
//20091005 - 115.5
|
||||
while (!isPaused() && !gameOver(null)) {
|
||||
while (!isPaused() && !checkIfGameIsOver()) {
|
||||
if (!checkStateBasedActions()) {
|
||||
// nothing happened so check triggers
|
||||
state.handleSimultaneousEvent(this);
|
||||
if (isPaused() || gameOver(null) || getTurn().isEndTurnRequested() || !checkTriggered()) {
|
||||
if (isPaused() || checkIfGameIsOver() || getTurn().isEndTurnRequested() || !checkTriggered()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1621,6 +1656,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
applyEffects(); // needed e.g if boost effects end and cause creatures to die
|
||||
somethingHappened = true;
|
||||
}
|
||||
checkConcede();
|
||||
return somethingHappened;
|
||||
}
|
||||
|
||||
|
@ -1734,7 +1770,6 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
List<Permanent> planeswalkers = new ArrayList<>();
|
||||
List<Permanent> legendary = new ArrayList<>();
|
||||
List<Permanent> worldEnchantment = new ArrayList<>();
|
||||
for (Permanent perm : getBattlefield().getAllActivePermanents()) {
|
||||
|
@ -1781,7 +1816,6 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
planeswalkers.add(perm);
|
||||
}
|
||||
if (perm.isWorld()) {
|
||||
worldEnchantment.add(perm);
|
||||
|
@ -2288,7 +2322,6 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
* @param playerId
|
||||
*/
|
||||
protected void leave(UUID playerId) { // needs to be executed from the game thread, not from the concede thread of conceding player!
|
||||
|
||||
Player player = getPlayer(playerId);
|
||||
if (player == null || player.hasLeft()) {
|
||||
logger.debug("Player already left " + (player != null ? player.getName() : playerId));
|
||||
|
|
|
@ -264,7 +264,7 @@ public class Combat implements Serializable, Copyable<Combat> {
|
|||
player.selectAttackers(game, attackingPlayerId);
|
||||
}
|
||||
firstTime = false;
|
||||
if (game.isPaused() || game.gameOver(null) || game.executingRollback()) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver() || game.executingRollback()) {
|
||||
return;
|
||||
}
|
||||
// because of possible undo during declare attackers it's neccassary to call here the methods with "game.getCombat()." to get the current combat object!!!
|
||||
|
@ -461,7 +461,7 @@ public class Combat implements Serializable, Copyable<Combat> {
|
|||
}
|
||||
while (choose) {
|
||||
controller.selectBlockers(game, defenderId);
|
||||
if (game.isPaused() || game.gameOver(null) || game.executingRollback()) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver() || game.executingRollback()) {
|
||||
return;
|
||||
}
|
||||
if (!game.getCombat().checkBlockRestrictions(defender, game)) {
|
||||
|
|
|
@ -95,7 +95,7 @@ public abstract class Phase implements Serializable {
|
|||
}
|
||||
|
||||
public boolean play(Game game, UUID activePlayerId) {
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ public abstract class Phase implements Serializable {
|
|||
if (beginPhase(game, activePlayerId)) {
|
||||
|
||||
for (Step step : steps) {
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
if (game.getTurn().isEndTurnRequested() && step.getType()!=PhaseStep.CLEANUP) {
|
||||
|
@ -122,7 +122,7 @@ public abstract class Phase implements Serializable {
|
|||
}
|
||||
|
||||
}
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
count++;
|
||||
|
@ -143,7 +143,7 @@ public abstract class Phase implements Serializable {
|
|||
}
|
||||
|
||||
public boolean resumePlay(Game game, PhaseStep stepType, boolean wasPaused) {
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ public abstract class Phase implements Serializable {
|
|||
resumeStep(game, wasPaused);
|
||||
while (it.hasNext()) {
|
||||
step = it.next();
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
currentStep = step;
|
||||
|
@ -169,7 +169,7 @@ public abstract class Phase implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
count++;
|
||||
|
@ -206,13 +206,13 @@ public abstract class Phase implements Serializable {
|
|||
if (!currentStep.skipStep(game, activePlayerId)) {
|
||||
game.getState().increaseStepNum();
|
||||
prePriority(game, activePlayerId);
|
||||
if (!game.isPaused() && !game.gameOver(null) && !game.executingRollback()) {
|
||||
if (!game.isPaused() && !game.checkIfGameIsOver() && !game.executingRollback()) {
|
||||
currentStep.priority(game, activePlayerId, false);
|
||||
if (game.executingRollback()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!game.isPaused() && !game.gameOver(null) && !game.executingRollback()) {
|
||||
if (!game.isPaused() && !game.checkIfGameIsOver() && !game.executingRollback()) {
|
||||
postPriority(game, activePlayerId);
|
||||
}
|
||||
}
|
||||
|
@ -233,11 +233,11 @@ public abstract class Phase implements Serializable {
|
|||
prePriority(game, activePlayerId);
|
||||
}
|
||||
case PRIORITY:
|
||||
if (!game.isPaused() && !game.gameOver(null)) {
|
||||
if (!game.isPaused() && !game.checkIfGameIsOver()) {
|
||||
currentStep.priority(game, activePlayerId, resuming);
|
||||
}
|
||||
case POST:
|
||||
if (!game.isPaused() && !game.gameOver(null)) {
|
||||
if (!game.isPaused() && !game.checkIfGameIsOver()) {
|
||||
postPriority(game, activePlayerId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public class Turn implements Serializable {
|
|||
public boolean play(Game game, Player activePlayer) {
|
||||
activePlayer.becomesActivePlayer();
|
||||
this.setDeclareAttackersStepStarted(false);
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public class Turn implements Serializable {
|
|||
resetCounts();
|
||||
game.getPlayer(activePlayer.getId()).beginTurn(game);
|
||||
for (Phase phase : phases) {
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return false;
|
||||
}
|
||||
if (!isEndTurnRequested() || phase.getType() == TurnPhase.END) {
|
||||
|
@ -189,7 +189,7 @@ public class Turn implements Serializable {
|
|||
}
|
||||
while (it.hasNext()) {
|
||||
phase = it.next();
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
if (game.isPaused() || game.checkIfGameIsOver()) {
|
||||
return;
|
||||
}
|
||||
currentPhase = phase;
|
||||
|
|
|
@ -444,6 +444,8 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
|
||||
void abortReset();
|
||||
|
||||
void signalPlayerConcede();
|
||||
|
||||
void skip();
|
||||
|
||||
// priority, undo, ...
|
||||
|
|
|
@ -2039,9 +2039,9 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
@Override
|
||||
public void concede(Game game) {
|
||||
game.gameOver(playerId);
|
||||
game.setConcedingPlayer(playerId);
|
||||
lost(game);
|
||||
this.left = true;
|
||||
// this.left = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2136,7 +2136,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
// for draw - first all players that have lost have to be set to lost
|
||||
if (!hasLeft()) {
|
||||
logger.debug("Game over playerId: " + playerId);
|
||||
game.gameOver(playerId);
|
||||
game.setConcedingPlayer(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2197,7 +2197,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
this.draws = true;
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DRAW_PLAYER, null, null, playerId));
|
||||
game.informPlayers("For " + this.getLogName() + " the game is a draw.");
|
||||
game.gameOver(playerId);
|
||||
game.setConcedingPlayer(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3578,6 +3578,11 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
abort = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signalPlayerConcede() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scry(int value, Ability source,
|
||||
Game game
|
||||
|
|
Loading…
Reference in a new issue