mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
add method Game.isActivePlayer(UUID playerId)
This commit is contained in:
parent
2b78716a1b
commit
ca1ebeb55e
16 changed files with 33 additions and 31 deletions
|
@ -254,7 +254,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
|
|||
} else if (stepFinished) {
|
||||
logger.debug("Step finished");
|
||||
int testScore = GameStateEvaluator2.evaluate(playerId, game);
|
||||
if (game.getActivePlayerId().equals(playerId)) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
if (testScore < currentScore) {
|
||||
// if score at end of step is worse than original score don't check further
|
||||
//logger.debug("Add Action -- abandoning check, no immediate benefit");
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
|||
pass(game);
|
||||
return false;
|
||||
case PRECOMBAT_MAIN:
|
||||
if (game.getActivePlayerId().equals(playerId)) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
printOutState(game);
|
||||
if (actions.isEmpty()) {
|
||||
logger.info("Sim Calculate pre combat actions ----------------------------------------------------- ");
|
||||
|
|
|
@ -987,7 +987,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
|
||||
private boolean priorityPlay(Game game) {
|
||||
UUID opponentId = game.getOpponents(playerId).iterator().next();
|
||||
if (game.getActivePlayerId().equals(playerId)) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
if (game.isMainPhase() && game.getStack().isEmpty()) {
|
||||
playLand(game);
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ public class ComputerPlayerMCTS extends ComputerPlayer implements Player {
|
|||
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) {
|
||||
thinkTime = maxThinkTime;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
pass(game);
|
||||
return false;
|
||||
case PRECOMBAT_MAIN:
|
||||
if (game.getActivePlayerId().equals(playerId)) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
if (actions.isEmpty()) {
|
||||
calculatePreCombatActions(game);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
pass(game);
|
||||
return false;
|
||||
case DECLARE_ATTACKERS:
|
||||
if (!game.getActivePlayerId().equals(playerId)) {
|
||||
if (!game.isActivePlayer(playerId)) {
|
||||
if (actions.isEmpty()) {
|
||||
calculatePreCombatActions(game);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
pass(game);
|
||||
return false;
|
||||
case POSTCOMBAT_MAIN:
|
||||
if (game.getActivePlayerId().equals(playerId)) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
if (actions.isEmpty()) {
|
||||
calculatePostCombatActions(game);
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
|||
else if (stepFinished) {
|
||||
logger.debug(indent(node.depth) + "step finished");
|
||||
int testScore = GameStateEvaluator.evaluate(playerId, game);
|
||||
if (game.getActivePlayerId().equals(playerId)) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
if (testScore < currentScore) {
|
||||
// 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");
|
||||
|
|
|
@ -1943,7 +1943,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
if (userData.confirmEmptyManaPool()
|
||||
&& game.getStack().isEmpty() && getManaPool().count() > 0) {
|
||||
String activePlayerText;
|
||||
if (game.getActivePlayerId().equals(playerId)) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
activePlayerText = "Your turn";
|
||||
} else {
|
||||
activePlayerText = game.getPlayer(game.getActivePlayerId()).getName() + "'s turn";
|
||||
|
|
|
@ -40,7 +40,7 @@ public enum TournamentFactory {
|
|||
Map<String,Integer> setInfo = new LinkedHashMap<>();
|
||||
for (String setCode: options.getLimitedOptions().getSetCodes()) {
|
||||
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);
|
||||
}
|
||||
tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters());
|
||||
|
|
|
@ -97,7 +97,7 @@ class ElkinBottleCastFromExileEffect extends AsThoughEffectImpl {
|
|||
@Override
|
||||
public boolean isInactive(Ability source, Game game) {
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -66,7 +66,7 @@ class WellOfKnowledgeConditionalActivatedAbility extends ActivatedAbilityImpl {
|
|||
public ActivationStatus canActivate(UUID playerId, Game game) {
|
||||
if (condition.apply(game, this)
|
||||
&& costs.canPay(this, sourceId, playerId, game)
|
||||
&& game.getActivePlayerId().equals(playerId)) {
|
||||
&& game.isActivePlayer(playerId)) {
|
||||
this.activatorId = playerId;
|
||||
return ActivationStatus.getTrue();
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PlayLandAbility extends ActivatedAbilityImpl {
|
|||
return ActivationStatus.getFalse();
|
||||
}
|
||||
//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
|
||||
|
|
|
@ -51,7 +51,7 @@ public class HideawayPlayEffect extends OneShotEffect {
|
|||
*/
|
||||
if (card.isLand()) {
|
||||
UUID playerId = controller.getId();
|
||||
if (!game.getActivePlayerId().equals(playerId) || !game.getPlayer(playerId).canPlayLand()) {
|
||||
if (!game.isActivePlayer(playerId) || !game.getPlayer(playerId).canPlayLand()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
List<Mana> copy = copy();
|
||||
this.clear();
|
||||
|
@ -227,7 +227,7 @@ public class ManaOptions extends ArrayList<Mana> {
|
|||
if (options.size() == 1) {
|
||||
//if there is only one mana option available add it to all the existing options
|
||||
addMana(options.get(0));
|
||||
} else if (options.size() > 1) {
|
||||
} else {
|
||||
//perform a union of all existing options and the new options
|
||||
List<Mana> copy = copy();
|
||||
this.clear();
|
||||
|
|
|
@ -3,6 +3,8 @@ package mage.game;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import mage.MageItem;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
|
@ -119,15 +121,17 @@ public interface Game extends MageItem, Serializable {
|
|||
* @param playerId
|
||||
* @return
|
||||
*/
|
||||
default public Set<UUID> getOpponents(UUID playerId) {
|
||||
Set<UUID> opponents = new HashSet<>();
|
||||
default Set<UUID> getOpponents(UUID playerId) {
|
||||
Player player = getPlayer(playerId);
|
||||
for (UUID opponentId : player.getInRange()) {
|
||||
if (!opponentId.equals(playerId)) {
|
||||
opponents.add(opponentId);
|
||||
}
|
||||
}
|
||||
return opponents;
|
||||
return player.getInRange().stream()
|
||||
.filter(opponentId -> !opponentId.equals(playerId))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
}
|
||||
|
||||
|
||||
default boolean isActivePlayer(UUID playerId){
|
||||
return getActivePlayerId().equals(playerId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,7 +145,7 @@ public interface Game extends MageItem, Serializable {
|
|||
* @param playerToCheckId
|
||||
* @return
|
||||
*/
|
||||
default public boolean isOpponent(Player player, UUID playerToCheckId) {
|
||||
default boolean isOpponent(Player player, UUID playerToCheckId) {
|
||||
return !player.getId().equals(playerToCheckId);
|
||||
}
|
||||
|
||||
|
|
|
@ -2450,7 +2450,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
|
||||
@Override
|
||||
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 monarch leaves the game on their turn, the next player in turn order becomes the monarch.
|
||||
if (playerId.equals(getMonarchId())) {
|
||||
if (!getActivePlayerId().equals(playerId)) {
|
||||
if (!isActivePlayer(playerId)) {
|
||||
setMonarchId(null, getActivePlayerId());
|
||||
} else {
|
||||
Player nextPlayer = getPlayerList().getNext(this);
|
||||
|
|
|
@ -2956,9 +2956,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
// Other activated abilities
|
||||
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
|
||||
getOtherUseableActivatedAbilities(card, Zone.GRAVEYARD, game, useable);
|
||||
for (Ability ability : useable.values()) {
|
||||
playable.add(ability);
|
||||
}
|
||||
playable.addAll(useable.values());
|
||||
}
|
||||
for (ExileZone exile : game.getExile().getExileZones()) {
|
||||
for (Card card : exile.getCards(game)) {
|
||||
|
|
|
@ -76,7 +76,7 @@ public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher {
|
|||
}
|
||||
|
||||
public List<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) {
|
||||
if (game.getActivePlayerId().equals(playerId)) {
|
||||
if (game.isActivePlayer(playerId)) {
|
||||
return enteringBattlefield.get(playerId);
|
||||
}
|
||||
return enteringBattlefieldLastTurn.get(playerId);
|
||||
|
|
Loading…
Reference in a new issue