mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
added reveal method to PlayerController (should probably add one to game? to reveal to all players)
AI mulligan decision code moved to ComputerUtil
This commit is contained in:
@@ -143,9 +143,9 @@ public class DigEffect extends SpellAbilityEffect {
|
||||
}
|
||||
// Singletons.getModel().getGameAction().revealToCopmuter(top.toArray());
|
||||
// - for when it exists
|
||||
} else if (choser.isHuman() && !sa.hasParam("NoLooking")) {
|
||||
} else if (!sa.hasParam("NoLooking")) {
|
||||
// show the user the revealed cards
|
||||
GuiChoose.one("Looking at cards from library", top);
|
||||
choser.getController().reveal("Looking at cards from library", top, library.getZoneType(), library.getPlayer());
|
||||
}
|
||||
|
||||
if ((sa.hasParam("RememberRevealed")) && !sa.hasParam("RevealValid")) {
|
||||
@@ -251,7 +251,7 @@ public class DigEffect extends SpellAbilityEffect {
|
||||
}
|
||||
for (j = 0; j < changeNum; j++) {
|
||||
Card chosen = ComputerUtilCard.getBestAI(valid);
|
||||
if (sa.getActivatingPlayer().isHuman() && p.isHuman()) {
|
||||
if (sa.getActivatingPlayer().isOpponentOf(choser) && p.isOpponentOf(choser)) {
|
||||
chosen = ComputerUtilCard.getWorstAI(valid);
|
||||
}
|
||||
if (chosen == null) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.CardPredicates;
|
||||
import forge.Singletons;
|
||||
import forge.card.ability.AbilityFactory;
|
||||
@@ -54,8 +53,6 @@ public class InputMulligan extends Input {
|
||||
/** Constant <code>serialVersionUID=-8112954303001155622L</code>. */
|
||||
private static final long serialVersionUID = -8112954303001155622L;
|
||||
|
||||
private static final int AI_MULLIGAN_THRESHOLD = 5;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void showMessage() {
|
||||
@@ -100,24 +97,13 @@ public class InputMulligan extends Input {
|
||||
GameState game = Singletons.getModel().getGame();
|
||||
|
||||
// Computer mulligan
|
||||
for (Player ai : game.getPlayers()) {
|
||||
if (ai.isHuman()) {
|
||||
for (Player p : game.getPlayers()) {
|
||||
if (!(p instanceof AIPlayer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean aiTakesMulligan = true;
|
||||
|
||||
// Computer mulligans if there are no cards with converted mana cost of
|
||||
// 0 in its hand
|
||||
while (aiTakesMulligan) {
|
||||
|
||||
final List<Card> handList = ai.getCardsIn(ZoneType.Hand);
|
||||
final boolean hasLittleCmc0Cards = CardLists.getValidCards(handList, "Card.cmcEQ0", ai, null).size() < 2;
|
||||
aiTakesMulligan = (handList.size() > InputMulligan.AI_MULLIGAN_THRESHOLD) && hasLittleCmc0Cards;
|
||||
|
||||
if (aiTakesMulligan) {
|
||||
ai.doMulligan();
|
||||
}
|
||||
AIPlayer ai = (AIPlayer) p;
|
||||
while (ComputerUtil.wantMulligan(ai)) {
|
||||
ai.doMulligan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +121,7 @@ public class InputMulligan extends Input {
|
||||
final String effName = kw.split(":")[1];
|
||||
|
||||
final SpellAbility effect = AbilityFactory.getAbility(c.getSVar(effName), c);
|
||||
if (GuiDialog.confirm(c, "Use this card's ability?")) {
|
||||
if (GuiDialog.confirm(c, "Use " + c +"'s ability?")) {
|
||||
// If we ever let the AI memorize cards in the players
|
||||
// hand, this would be a place to do so.
|
||||
game.getActionPlay().playSpellAbilityNoStack(p, effect, false);
|
||||
@@ -143,7 +129,7 @@ public class InputMulligan extends Input {
|
||||
}
|
||||
}
|
||||
if (c.getName().startsWith("Leyline of")) {
|
||||
if (GuiDialog.confirm(c, "Use this card's ability?")) {
|
||||
if (GuiDialog.confirm(c, "Use " + c + "'s ability?")) {
|
||||
ga.moveToPlay(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1212,4 +1212,15 @@ public class ComputerUtil {
|
||||
threatened.addAll(ComputerUtil.predictThreatenedObjects(aiPlayer, saviour, topStack.getSubAbility()));
|
||||
return threatened;
|
||||
}
|
||||
|
||||
// Computer mulligans if there are no cards with converted mana cost of
|
||||
// 0 in its hand
|
||||
public static boolean wantMulligan(AIPlayer ai) {
|
||||
final int AI_MULLIGAN_THRESHOLD = 5;
|
||||
|
||||
final List<Card> handList = ai.getCardsIn(ZoneType.Hand);
|
||||
final boolean hasLittleCmc0Cards = CardLists.getValidCards(handList, "Card.cmcEQ0", ai, null).size() < 2;
|
||||
return (handList.size() > AI_MULLIGAN_THRESHOLD) && hasLittleCmc0Cards;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import forge.game.GameState;
|
||||
import forge.game.GameType;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.zone.ZoneType;
|
||||
|
||||
|
||||
/**
|
||||
@@ -100,4 +101,7 @@ public abstract class PlayerController {
|
||||
|
||||
public abstract List<Card> orderBlockers(Card attacker, List<Card> blockers);
|
||||
public abstract List<Card> orderAttackers(Card blocker, List<Card> attackers);
|
||||
|
||||
/** Shows the card to this player*/
|
||||
public abstract void reveal(String string, List<Card> cards, ZoneType zone, Player owner);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import forge.game.ai.AiInputCommon;
|
||||
import forge.game.ai.ComputerUtil;
|
||||
import forge.game.ai.ComputerUtilBlock;
|
||||
import forge.game.ai.ComputerUtilCombat;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiChoose;
|
||||
|
||||
|
||||
@@ -219,4 +220,12 @@ public class PlayerControllerAi extends PlayerController {
|
||||
return ComputerUtilBlock.orderAttackers(blocker, attackers);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.game.player.PlayerController#reveal(java.lang.String, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public void reveal(String string, List<Card> cards, ZoneType zone, Player owner) {
|
||||
// We don't know how to reveal cards to AI
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import java.util.Map;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
import forge.GameEntity;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
@@ -20,6 +22,7 @@ import forge.deck.DeckSection;
|
||||
import forge.game.GameState;
|
||||
import forge.game.GameType;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.gui.GuiDialog;
|
||||
import forge.gui.GuiUtils;
|
||||
@@ -274,4 +277,15 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
GuiUtils.setPanelSelection(blocker);
|
||||
return GuiChoose.order("Choose Blocking Order", "Damaged First", 0, attackers, null, blocker);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.game.player.PlayerController#reveal(java.lang.String, java.util.List, forge.game.zone.ZoneType, forge.game.player.Player)
|
||||
*/
|
||||
@Override
|
||||
public void reveal(String string, List<Card> cards, ZoneType zone, Player owner) {
|
||||
String message = string;
|
||||
if ( StringUtils.isBlank(message) )
|
||||
message = String.format("Looking at %s's %s", owner, zone);
|
||||
GuiChoose.oneOrNone(message, cards);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user