add method Game.isActivePlayer(UUID playerId)

This commit is contained in:
igoudt 2018-06-29 14:59:11 +02:00
parent 2b78716a1b
commit ca1ebeb55e
16 changed files with 33 additions and 31 deletions

View file

@ -254,7 +254,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
} else if (stepFinished) { } else if (stepFinished) {
logger.debug("Step finished"); logger.debug("Step finished");
int testScore = GameStateEvaluator2.evaluate(playerId, game); int testScore = GameStateEvaluator2.evaluate(playerId, game);
if (game.getActivePlayerId().equals(playerId)) { if (game.isActivePlayer(playerId)) {
if (testScore < currentScore) { if (testScore < currentScore) {
// if score at end of step is worse than original score don't check further // if score at end of step is worse than original score don't check further
//logger.debug("Add Action -- abandoning check, no immediate benefit"); //logger.debug("Add Action -- abandoning check, no immediate benefit");

View file

@ -54,7 +54,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
pass(game); pass(game);
return false; return false;
case PRECOMBAT_MAIN: case PRECOMBAT_MAIN:
if (game.getActivePlayerId().equals(playerId)) { if (game.isActivePlayer(playerId)) {
printOutState(game); printOutState(game);
if (actions.isEmpty()) { if (actions.isEmpty()) {
logger.info("Sim Calculate pre combat actions ----------------------------------------------------- "); logger.info("Sim Calculate pre combat actions ----------------------------------------------------- ");

View file

@ -987,7 +987,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
private boolean priorityPlay(Game game) { private boolean priorityPlay(Game game) {
UUID opponentId = game.getOpponents(playerId).iterator().next(); UUID opponentId = game.getOpponents(playerId).iterator().next();
if (game.getActivePlayerId().equals(playerId)) { if (game.isActivePlayer(playerId)) {
if (game.isMainPhase() && game.getStack().isEmpty()) { if (game.isMainPhase() && game.getStack().isEmpty()) {
playLand(game); playLand(game);
} }

View file

@ -348,7 +348,7 @@ public class ComputerPlayerMCTS extends ComputerPlayer implements Player {
thinkTime = maxThinkTime / 2; thinkTime = maxThinkTime / 2;
} }
} }
else if (game.getActivePlayerId().equals(playerId) && (curStep == PhaseStep.PRECOMBAT_MAIN || curStep == PhaseStep.POSTCOMBAT_MAIN) && game.getStack().isEmpty()) { else if (game.isActivePlayer(playerId) && (curStep == PhaseStep.PRECOMBAT_MAIN || curStep == PhaseStep.POSTCOMBAT_MAIN) && game.getStack().isEmpty()) {
if (nodeSizeRatio < THINK_MIN_RATIO) { if (nodeSizeRatio < THINK_MIN_RATIO) {
thinkTime = maxThinkTime; thinkTime = maxThinkTime;
} }

View file

@ -50,7 +50,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
pass(game); pass(game);
return false; return false;
case PRECOMBAT_MAIN: case PRECOMBAT_MAIN:
if (game.getActivePlayerId().equals(playerId)) { if (game.isActivePlayer(playerId)) {
if (actions.isEmpty()) { if (actions.isEmpty()) {
calculatePreCombatActions(game); calculatePreCombatActions(game);
} }
@ -64,7 +64,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
pass(game); pass(game);
return false; return false;
case DECLARE_ATTACKERS: case DECLARE_ATTACKERS:
if (!game.getActivePlayerId().equals(playerId)) { if (!game.isActivePlayer(playerId)) {
if (actions.isEmpty()) { if (actions.isEmpty()) {
calculatePreCombatActions(game); calculatePreCombatActions(game);
} }
@ -81,7 +81,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
pass(game); pass(game);
return false; return false;
case POSTCOMBAT_MAIN: case POSTCOMBAT_MAIN:
if (game.getActivePlayerId().equals(playerId)) { if (game.isActivePlayer(playerId)) {
if (actions.isEmpty()) { if (actions.isEmpty()) {
calculatePostCombatActions(game); calculatePostCombatActions(game);
} }
@ -184,7 +184,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
else if (stepFinished) { else if (stepFinished) {
logger.debug(indent(node.depth) + "step finished"); logger.debug(indent(node.depth) + "step finished");
int testScore = GameStateEvaluator.evaluate(playerId, game); int testScore = GameStateEvaluator.evaluate(playerId, game);
if (game.getActivePlayerId().equals(playerId)) { if (game.isActivePlayer(playerId)) {
if (testScore < currentScore) { if (testScore < currentScore) {
// if score at end of step is worse than original score don't check further // if score at end of step is worse than original score don't check further
logger.debug(indent(node.depth) + "simulating -- abandoning check, no immediate benefit"); logger.debug(indent(node.depth) + "simulating -- abandoning check, no immediate benefit");

View file

@ -1943,7 +1943,7 @@ public class HumanPlayer extends PlayerImpl {
if (userData.confirmEmptyManaPool() if (userData.confirmEmptyManaPool()
&& game.getStack().isEmpty() && getManaPool().count() > 0) { && game.getStack().isEmpty() && getManaPool().count() > 0) {
String activePlayerText; String activePlayerText;
if (game.getActivePlayerId().equals(playerId)) { if (game.isActivePlayer(playerId)) {
activePlayerText = "Your turn"; activePlayerText = "Your turn";
} else { } else {
activePlayerText = game.getPlayer(game.getActivePlayerId()).getName() + "'s turn"; activePlayerText = game.getPlayer(game.getActivePlayerId()).getName() + "'s turn";

View file

@ -40,7 +40,7 @@ public enum TournamentFactory {
Map<String,Integer> setInfo = new LinkedHashMap<>(); Map<String,Integer> setInfo = new LinkedHashMap<>();
for (String setCode: options.getLimitedOptions().getSetCodes()) { for (String setCode: options.getLimitedOptions().getSetCodes()) {
tournament.getSets().add(Sets.findSet(setCode)); tournament.getSets().add(Sets.findSet(setCode));
int count = setInfo.containsKey(setCode) ? setInfo.get(setCode) : 0; int count = setInfo.getOrDefault(setCode, 0);
setInfo.put(setCode, count + 1); setInfo.put(setCode, count + 1);
} }
tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters()); tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters());

View file

@ -97,7 +97,7 @@ class ElkinBottleCastFromExileEffect extends AsThoughEffectImpl {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
if (game.getPhase().getStep().getType() == PhaseStep.UPKEEP) { if (game.getPhase().getStep().getType() == PhaseStep.UPKEEP) {
if (!sameStep && game.getActivePlayerId().equals(source.getControllerId()) || game.getPlayer(source.getControllerId()).hasReachedNextTurnAfterLeaving()) { if (!sameStep && game.isActivePlayer(source.getControllerId()) || game.getPlayer(source.getControllerId()).hasReachedNextTurnAfterLeaving()) {
return true; return true;
} }
} else { } else {

View file

@ -66,7 +66,7 @@ class WellOfKnowledgeConditionalActivatedAbility extends ActivatedAbilityImpl {
public ActivationStatus canActivate(UUID playerId, Game game) { public ActivationStatus canActivate(UUID playerId, Game game) {
if (condition.apply(game, this) if (condition.apply(game, this)
&& costs.canPay(this, sourceId, playerId, game) && costs.canPay(this, sourceId, playerId, game)
&& game.getActivePlayerId().equals(playerId)) { && game.isActivePlayer(playerId)) {
this.activatorId = playerId; this.activatorId = playerId;
return ActivationStatus.getTrue(); return ActivationStatus.getTrue();
} }

View file

@ -31,7 +31,7 @@ public class PlayLandAbility extends ActivatedAbilityImpl {
return ActivationStatus.getFalse(); return ActivationStatus.getFalse();
} }
//20091005 - 114.2a //20091005 - 114.2a
return new ActivationStatus(game.getActivePlayerId().equals(playerId) && game.getPlayer(playerId).canPlayLand() && game.canPlaySorcery(playerId), permittingObject); return new ActivationStatus(game.isActivePlayer(playerId) && game.getPlayer(playerId).canPlayLand() && game.canPlaySorcery(playerId), permittingObject);
} }
@Override @Override

View file

@ -51,7 +51,7 @@ public class HideawayPlayEffect extends OneShotEffect {
*/ */
if (card.isLand()) { if (card.isLand()) {
UUID playerId = controller.getId(); UUID playerId = controller.getId();
if (!game.getActivePlayerId().equals(playerId) || !game.getPlayer(playerId).canPlayLand()) { if (!game.isActivePlayer(playerId) || !game.getPlayer(playerId).canPlayLand()) {
return false; return false;
} }
} }

View file

@ -154,7 +154,7 @@ public class ManaOptions extends ArrayList<Mana> {
} }
} }
} }
} else if (abilities.size() > 1) { } else {
//perform a union of all existing options and the new options //perform a union of all existing options and the new options
List<Mana> copy = copy(); List<Mana> copy = copy();
this.clear(); this.clear();
@ -227,7 +227,7 @@ public class ManaOptions extends ArrayList<Mana> {
if (options.size() == 1) { if (options.size() == 1) {
//if there is only one mana option available add it to all the existing options //if there is only one mana option available add it to all the existing options
addMana(options.get(0)); addMana(options.get(0));
} else if (options.size() > 1) { } else {
//perform a union of all existing options and the new options //perform a union of all existing options and the new options
List<Mana> copy = copy(); List<Mana> copy = copy();
this.clear(); this.clear();

View file

@ -3,6 +3,8 @@ package mage.game;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import mage.MageItem; import mage.MageItem;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -119,15 +121,17 @@ public interface Game extends MageItem, Serializable {
* @param playerId * @param playerId
* @return * @return
*/ */
default public Set<UUID> getOpponents(UUID playerId) { default Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
Player player = getPlayer(playerId); Player player = getPlayer(playerId);
for (UUID opponentId : player.getInRange()) { return player.getInRange().stream()
if (!opponentId.equals(playerId)) { .filter(opponentId -> !opponentId.equals(playerId))
opponents.add(opponentId); .collect(Collectors.toSet());
}
} }
return opponents;
default boolean isActivePlayer(UUID playerId){
return getActivePlayerId().equals(playerId);
} }
/** /**
@ -141,7 +145,7 @@ public interface Game extends MageItem, Serializable {
* @param playerToCheckId * @param playerToCheckId
* @return * @return
*/ */
default public boolean isOpponent(Player player, UUID playerToCheckId) { default boolean isOpponent(Player player, UUID playerToCheckId) {
return !player.getId().equals(playerToCheckId); return !player.getId().equals(playerToCheckId);
} }

View file

@ -2450,7 +2450,7 @@ public abstract class GameImpl implements Game, Serializable {
@Override @Override
public boolean canPlaySorcery(UUID playerId) { public boolean canPlaySorcery(UUID playerId) {
return isMainPhase() && getActivePlayerId().equals(playerId) && getStack().isEmpty(); return isMainPhase() && isActivePlayer(playerId) && getStack().isEmpty();
} }
/** /**
@ -2594,7 +2594,7 @@ public abstract class GameImpl implements Game, Serializable {
// If the current monarch leaves the game. When that happens, the player whose turn it is becomes the monarch. // If the current monarch leaves the game. When that happens, the player whose turn it is becomes the monarch.
// If the monarch leaves the game on their turn, the next player in turn order becomes the monarch. // If the monarch leaves the game on their turn, the next player in turn order becomes the monarch.
if (playerId.equals(getMonarchId())) { if (playerId.equals(getMonarchId())) {
if (!getActivePlayerId().equals(playerId)) { if (!isActivePlayer(playerId)) {
setMonarchId(null, getActivePlayerId()); setMonarchId(null, getActivePlayerId());
} else { } else {
Player nextPlayer = getPlayerList().getNext(this); Player nextPlayer = getPlayerList().getNext(this);

View file

@ -2956,9 +2956,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// Other activated abilities // Other activated abilities
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>(); LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
getOtherUseableActivatedAbilities(card, Zone.GRAVEYARD, game, useable); getOtherUseableActivatedAbilities(card, Zone.GRAVEYARD, game, useable);
for (Ability ability : useable.values()) { playable.addAll(useable.values());
playable.add(ability);
}
} }
for (ExileZone exile : game.getExile().getExileZones()) { for (ExileZone exile : game.getExile().getExileZones()) {
for (Card card : exile.getCards(game)) { for (Card card : exile.getCards(game)) {

View file

@ -76,7 +76,7 @@ public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher {
} }
public List<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) { public List<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) {
if (game.getActivePlayerId().equals(playerId)) { if (game.isActivePlayer(playerId)) {
return enteringBattlefield.get(playerId); return enteringBattlefield.get(playerId);
} }
return enteringBattlefieldLastTurn.get(playerId); return enteringBattlefieldLastTurn.get(playerId);