mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
changes to support multiplayer
This commit is contained in:
parent
f32b05eef1
commit
7d27c06329
2 changed files with 16 additions and 27 deletions
|
@ -44,6 +44,7 @@ import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Outcome;
|
import mage.Constants.Outcome;
|
||||||
|
import mage.Constants.RangeOfInfluence;
|
||||||
import mage.Constants.Zone;
|
import mage.Constants.Zone;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
import mage.abilities.ActivatedAbility;
|
import mage.abilities.ActivatedAbility;
|
||||||
|
@ -72,12 +73,10 @@ import mage.cards.Card;
|
||||||
import mage.cards.Cards;
|
import mage.cards.Cards;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.choices.Choice;
|
import mage.choices.Choice;
|
||||||
import mage.filter.common.FilterCreatureForAttack;
|
|
||||||
import mage.filter.common.FilterCreatureForCombat;
|
import mage.filter.common.FilterCreatureForCombat;
|
||||||
import mage.filter.common.FilterLandCard;
|
import mage.filter.common.FilterLandCard;
|
||||||
import mage.filter.common.FilterNonlandCard;
|
import mage.filter.common.FilterNonlandCard;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameState;
|
|
||||||
import mage.game.combat.CombatGroup;
|
import mage.game.combat.CombatGroup;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
@ -94,7 +93,7 @@ import mage.util.TreeNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* only suitable for two player games
|
* suitable for two player games and some multiplayer games
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
|
@ -107,8 +106,8 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
private transient List<Card> playableInstant = new ArrayList<Card>();
|
private transient List<Card> playableInstant = new ArrayList<Card>();
|
||||||
private transient List<ActivatedAbility> playableAbilities = new ArrayList<ActivatedAbility>();
|
private transient List<ActivatedAbility> playableAbilities = new ArrayList<ActivatedAbility>();
|
||||||
|
|
||||||
public ComputerPlayer(String name, Deck deck) {
|
public ComputerPlayer(String name, Deck deck, RangeOfInfluence range) {
|
||||||
super(name, deck);
|
super(name, deck, range);
|
||||||
human = false;
|
human = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +125,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
@Override
|
@Override
|
||||||
public boolean chooseTarget(Outcome outcome, Target target, Game game) {
|
public boolean chooseTarget(Outcome outcome, Target target, Game game) {
|
||||||
logger.fine("chooseTarget: " + outcome.toString() + ":" + target.toString());
|
logger.fine("chooseTarget: " + outcome.toString() + ":" + target.toString());
|
||||||
UUID opponentId = game.getOpponents(playerId).get(0);
|
UUID opponentId = game.getOpponents(playerId).iterator().next();
|
||||||
if (target instanceof TargetPlayer) {
|
if (target instanceof TargetPlayer) {
|
||||||
if (outcome.isGood()) {
|
if (outcome.isGood()) {
|
||||||
if (target.canTarget(playerId, game)) {
|
if (target.canTarget(playerId, game)) {
|
||||||
|
@ -190,7 +189,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
@Override
|
@Override
|
||||||
public void priority(Game game) {
|
public void priority(Game game) {
|
||||||
logger.fine("priority");
|
logger.fine("priority");
|
||||||
UUID opponentId = game.getOpponents(playerId).get(0);
|
UUID opponentId = game.getOpponents(playerId).iterator().next();
|
||||||
if (game.getActivePlayerId().equals(playerId)) {
|
if (game.getActivePlayerId().equals(playerId)) {
|
||||||
if (game.isMainPhase() && game.getStack().isEmpty()) {
|
if (game.isMainPhase() && game.getStack().isEmpty()) {
|
||||||
playLand(game);
|
playLand(game);
|
||||||
|
@ -339,7 +338,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(playerId)) {
|
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) {
|
||||||
for (ActivatedAbility ability: permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
|
for (ActivatedAbility ability: permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
|
||||||
if (!(ability instanceof ManaAbility) && ability.canActivate(playerId, game)) {
|
if (!(ability instanceof ManaAbility) && ability.canActivate(playerId, game)) {
|
||||||
ManaOptions abilityOptions = ability.getManaCosts().getOptions();
|
ManaOptions abilityOptions = ability.getManaCosts().getOptions();
|
||||||
|
@ -515,7 +514,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
@Override
|
@Override
|
||||||
public void selectAttackers(Game game) {
|
public void selectAttackers(Game game) {
|
||||||
logger.fine("selectAttackers");
|
logger.fine("selectAttackers");
|
||||||
UUID opponentId = game.getOpponents(playerId).get(0);
|
UUID opponentId = game.getCombat().getDefenders().iterator().next();
|
||||||
Attackers attackers = getPotentialAttackers(game);
|
Attackers attackers = getPotentialAttackers(game);
|
||||||
List<Permanent> blockers = getOpponentBlockers(opponentId, game);
|
List<Permanent> blockers = getOpponentBlockers(opponentId, game);
|
||||||
List<Permanent> actualAttackers = new ArrayList<Permanent>();
|
List<Permanent> actualAttackers = new ArrayList<Permanent>();
|
||||||
|
@ -588,7 +587,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
protected List<Permanent> getAvailableManaProducers(Game game) {
|
protected List<Permanent> getAvailableManaProducers(Game game) {
|
||||||
logger.fine("getAvailableManaProducers");
|
logger.fine("getAvailableManaProducers");
|
||||||
List<Permanent> result = new ArrayList<Permanent>();
|
List<Permanent> result = new ArrayList<Permanent>();
|
||||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(playerId)) {
|
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) {
|
||||||
for (ManaAbility ability: permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
|
for (ManaAbility ability: permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
|
||||||
if (ability.canActivate(playerId, game)) {
|
if (ability.canActivate(playerId, game)) {
|
||||||
result.add(permanent);
|
result.add(permanent);
|
||||||
|
@ -605,7 +604,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
List<Permanent> creatures = super.getAvailableAttackers(game);
|
List<Permanent> creatures = super.getAvailableAttackers(game);
|
||||||
for (Permanent creature: creatures) {
|
for (Permanent creature: creatures) {
|
||||||
int potential = combatPotential(creature, game);
|
int potential = combatPotential(creature, game);
|
||||||
if (potential > 0) {
|
if (potential > 0 && creature.getPower().getValue() > 0) {
|
||||||
List<Permanent> l = attackers.get(potential);
|
List<Permanent> l = attackers.get(potential);
|
||||||
if (l == null)
|
if (l == null)
|
||||||
attackers.put(potential, l = new ArrayList<Permanent>());
|
attackers.put(potential, l = new ArrayList<Permanent>());
|
||||||
|
@ -631,16 +630,14 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
protected List<Permanent> getAvailableBlockers(Game game) {
|
protected List<Permanent> getAvailableBlockers(Game game) {
|
||||||
logger.fine("getAvailableBlockers");
|
logger.fine("getAvailableBlockers");
|
||||||
FilterCreatureForCombat blockFilter = new FilterCreatureForCombat();
|
FilterCreatureForCombat blockFilter = new FilterCreatureForCombat();
|
||||||
blockFilter.getControllerId().add(playerId);
|
List<Permanent> blockers = game.getBattlefield().getAllActivePermanents(blockFilter, playerId);
|
||||||
List<Permanent> blockers = game.getBattlefield().getActivePermanents(blockFilter);
|
|
||||||
return blockers;
|
return blockers;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Permanent> getOpponentBlockers(UUID opponentId, Game game) {
|
protected List<Permanent> getOpponentBlockers(UUID opponentId, Game game) {
|
||||||
logger.fine("getOpponentBlockers");
|
logger.fine("getOpponentBlockers");
|
||||||
FilterCreatureForCombat blockFilter = new FilterCreatureForCombat();
|
FilterCreatureForCombat blockFilter = new FilterCreatureForCombat();
|
||||||
blockFilter.getControllerId().add(opponentId);
|
List<Permanent> blockers = game.getBattlefield().getAllActivePermanents(blockFilter, opponentId);
|
||||||
List<Permanent> blockers = game.getBattlefield().getActivePermanents(blockFilter);
|
|
||||||
return blockers;
|
return blockers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,15 +740,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Permanent> threats(UUID playerId, TargetPermanent target, Game game) {
|
protected List<Permanent> threats(UUID playerId, TargetPermanent target, Game game) {
|
||||||
List<Permanent> threats = game.getBattlefield().getActivePermanents(target.getFilter());
|
List<Permanent> threats = game.getBattlefield().getAllActivePermanents(target.getFilter(), playerId);
|
||||||
Iterator<Permanent> it = threats.iterator();
|
|
||||||
while(it.hasNext()) {
|
|
||||||
Permanent permanent = it.next();
|
|
||||||
if (!permanent.getControllerId().equals(playerId)) {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(threats, new PermanentComparator(game));
|
Collections.sort(threats, new PermanentComparator(game));
|
||||||
return threats;
|
return threats;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class ActionSimulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int evaluateState() {
|
public int evaluateState() {
|
||||||
Player opponent = game.getPlayer(game.getOpponents(player.getId()).get(0));
|
Player opponent = game.getPlayer(game.getOpponents(player.getId()).iterator().next());
|
||||||
if (game.isGameOver()) {
|
if (game.isGameOver()) {
|
||||||
if (player.hasLost() || opponent.hasWon())
|
if (player.hasLost() || opponent.hasWon())
|
||||||
return Integer.MIN_VALUE;
|
return Integer.MIN_VALUE;
|
||||||
|
@ -70,10 +70,10 @@ public class ActionSimulator {
|
||||||
int value = player.getLife();
|
int value = player.getLife();
|
||||||
value -= opponent.getLife();
|
value -= opponent.getLife();
|
||||||
PermanentEvaluator evaluator = new PermanentEvaluator();
|
PermanentEvaluator evaluator = new PermanentEvaluator();
|
||||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(player.getId())) {
|
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(player.getId())) {
|
||||||
value += evaluator.evaluate(permanent, game);
|
value += evaluator.evaluate(permanent, game);
|
||||||
}
|
}
|
||||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(player.getId())) {
|
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(player.getId())) {
|
||||||
value -= evaluator.evaluate(permanent, game);
|
value -= evaluator.evaluate(permanent, game);
|
||||||
}
|
}
|
||||||
value += player.getHand().size();
|
value += player.getHand().size();
|
||||||
|
|
Loading…
Reference in a new issue