// TODO: hack for kicker prevention
//
if (!card.getCard().isKicker())
if (possibleMana.isCostFit(cost))
{
_cam.addElement(new CardAndMana(CardAndMana.CAM_ACTIVATE , card, cost));
possibleMana = possibleMana.subMana(cost);
}
}
// cams ready, now -> targets! (one)
for (int i = _cam.size()-1; i >= 0; i--)
{
CardAndMana cam = _cam.elementAt(i);
AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(cam.card);
Vector<EAIAction> sources = createOneOpponentSource(cam, hints); // at least one empty target! or null -> must targets not available!
if (sources == null)
{
continue;
}
Vector<EAIAction> targets = createOneOpponentTarget(cam, hints); // at least one empty target! or null -> must targets not available!
if (targets == null)
{
continue;
}
Vector<EAIAction> target = joinSourceAndTarget(sources, targets);
boolean successfull = leaf.leafExceuteOneAction(cam, target, opponent, camListBefor(_cam, i));
}
}
else if(currentPhase == MatchConstants.PHASE_COMBAT_DECLARE_ATTACKERS)
{
if (mDoStacking)
{
// in stack I dont estimate opponents attackers
EAIPlanTree leaf = new EAIPlanTree(this, false); // try out
leafs.addElement(leaf);
return;
}
// opponent: activate cards that are in battlefield
// todo build best attacking opponent can do
// which would be the worst case scenario
// doing an ALL OUT attack :-)
// therefor only that option is to be tested
// "Phew" - no explosion of choices here!
//System.out.println("Try declaring attackers of other AI!");
// generate instant, activations
// generate instant, activations
// after that create all possible attackers
// create permutations
// possibly reuse same in different leafs (not known from here,
// other leafs are in parent - caching and cloning?
// now for each leaf all attack possibilities
// dummy as long as above is not implemented
// allways add a empty leaf
EAIPlanTree leaf = new EAIPlanTree(this, false);
// opponent: activate cards that are in battlefield -> like kings assassin!
ManaCollection possibleMana = EAIHelper.getMaxAvailableMana(vMatch, opponent);
CardSimList possibleActivateableCards = vMatch.getBattlefield(opponent);
possibleActivateableCards = EAIHelper.onlyAllowedToActivate(possibleActivateableCards, currentPhase, true, vMatch);
possibleActivateableCards = EAIHelper.onlyUntappedToActivate(possibleActivateableCards);
CardSimList activated = new CardSimList();
Vector<CardAndMana> _cam = new Vector<CardAndMana>();
for(int c=0; c< possibleActivateableCards.size(); c++)
{
CardSim card = possibleActivateableCards.getCard(c);
ManaCollection cost = ManaCollection.getActivateCost(card);
if (possibleMana.isCostFit(cost))
{
_cam.addElement(new CardAndMana(CardAndMana.CAM_ACTIVATE , card, cost));
possibleMana = possibleMana.subMana(cost);
}
}
// cams ready, now -> targets! (one)
for (int i = _cam.size()-1; i >= 0; i--)
{
CardAndMana cam = _cam.elementAt(i);
AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(cam.card);
Vector<EAIAction> sources = createOneOpponentSource(cam, hints); // at least one empty target! or null -> must targets not available!
if (sources == null)
{
continue;
}
Vector<EAIAction> targets = createOneOpponentTarget(cam, hints); // at least one empty target! or null -> must targets not available!
if (targets == null)
{
continue;
}
Vector<EAIAction> target = joinSourceAndTarget(sources, targets);
boolean successfull = leaf.leafExceuteOneAction(cam, target, opponent, camListBefor(_cam, i));
activated.addCard(cam.card);
}
leafs.addElement(leaf);
int no = 0;
for (int i = 0; i < leafs.size(); i++)
{
leaf = leafs.elementAt(i);
CardSimList possibleAttackers = leaf.vMatch.getPossibleAttackers();
possibleAttackers.removeListDirect(activated);
//public CombatFormation computeBestAttack(Weighting weighting, int attackerHealth, int blockerHealth, CardSimList notHereEvaluatedAttackers, CardSimList externalRemovedAttackers, CardSimList allBlockers)
CombatSimConfig c = new CombatSimConfig(E.aiPlayer);
c.attackers = possibleAttackers;
c.attackerLands = vMatch.getLand(opponent);
c.blockerLands = vMatch.getLand(player);
CardSimList blocker = vMatch.getBattlefield(player).getSubListByType("Creature");
blocker = blocker.removeActivateable();
//blocker = vMatch.removeAllreadyBlocking(blocker);
blocker = blocker.onlyTapstate(false);
CombatSimNew csim = new CombatSimNew(possibleAttackers, blocker, c, false);
int blockerHealth = vMatch.getLife(player);
// TEST new Attacking!
CombatFormation attackFormation = csim.computeBestAttack(Weighting.DEFAULT, blockerHealth);
for (int a=0; a< attackFormation.singleFights.size(); a++)
{
CardSim at = attackFormation.singleFights.elementAt(a).attacker;
EAIAction attack = EAIAction.createDeclareAttackerAction(no++, at);
boolean success = leaf.vMatch.executeAction(attack, opponent, false);
if (success)
{
leaf.addAction(currentPhaseExtended, attack);
String key = EnhancedAI.generateCurrentVMatchKey(leaf.vMatch, player);
attack.setVMatchKeyAfter(key);
}
}
/*
// old -> all out attack
for (int a=0; a< possibleAttackers.size(); a++)
{
CardSim at = possibleAttackers.getCard(a);
EAIAction attack = EAIAction.createDeclareAttackerAction(no++, at);
boolean success = leaf.vMatch.executeAction(attack, opponent, false);
if (success)
{
leaf.addAction(currentPhaseExtended, attack);
String key = EnhancedAI.generateCurrentVMatchKey(leaf.vMatch, player);
attack.setVMatchKeyAfter(key);
}
}
*
*/
}
flatten();
}
else if (currentPhase == MatchConstants.PHASE_COMBAT_DECLARE_BLOCKERS)
{
// todo build best blocking for ourselfs to block oppoents attack
//System.out.println("Try declaring blockers!");
// do nothing if there is nothing to block!
// stupid thing wants to play giant growth on no attacket!
// here we come for each of our own attacker definitions
// in order to simulate the game
// here we get a best guess - of our opponents bloking actions
// sets all corresponding actions!
// generate instant, activations
// after that create all possible attackers
futurePrePlan.addAll(generatePossibleActionsGeneral(true, null));
// rod of ruin
buildLeafs(futurePrePlan);
if (leafs.isEmpty())
{
EAIPlanTree leaf = new EAIPlanTree(this, false); // try out
leafs.addElement(leaf);
}
flattenNoScore();
// create permutations
// possibly reuse same in different leafs (not known from here,
// other leafs are in parent - caching and cloning?
// now for each leaf all attack possibilities
// Todo: for now opponent strategy!
int opponentBlockStrategy = E.aiPlayer.getEAIConfig().getOpponentBlockStrategy();
if (E.aiPlayer.getEAIConfig().getOpponentAdaptiveBlocking())
{
int life = vMatch.getLife(player);
int maxDamage = EAIHelper.getPowerSum(vMatch.getAttacker());
if (life <= maxDamage+E.aiPlayer.getEAIConfig().getSavetyHealthThreshold())
opponentBlockStrategy = BLOCK_PLAYER_LEAST_DAMAGE;
else
opponentBlockStrategy = BLOCK_PLAYER_LEAST_CREATURE_DEAD;
}
generatePlayerBlockerActions(opponentBlockStrategy); // for now!
}
else if (currentPhase == MatchConstants.PHASE_COMBAT_END)
{
if (UID == 7325)
System.out.println("Buh!");
vMatch.doCombat((player+1)%2);
}
if (leafs.isEmpty())
{
EAIPlanTree leaf = new EAIPlanTree(this, false); // try out
leafs.addElement(leaf);
}
return;
}
if (currentPhase == MatchConstants.PHASE_BEGINNING_UNTAP)
{
CACHEHIT = false;
int actionCounter = 0;
Vector<CardAndMana> willBeActions = new Vector<CardAndMana>();
Vector<CardAndMana> futurePlanWithoutActions = new Vector<CardAndMana>();
CardSimList lands = vMatch.getLand(E.pNumber);
CardSimList creatures = vMatch.getBattlefield(E.pNumber);
Vector ls = lands.getCards();
for (int i = 0; i < ls.size(); i++)
{
CardSim card = (CardSim) ls.elementAt(i);
if (card.isTapped())
{
CardAndMana untapLand = new CardAndMana(CardAndMana.CAM_UNTAP,card, null);
willBeActions.add(untapLand);
}
}
Vector cs = creatures.getCards();
for (int i = 0; i < cs.size(); i++)
{
CardSim card = (CardSim) cs.elementAt(i);
if (card.isTapped())
{
CardAndMana untapCreature = new CardAndMana(CardAndMana.CAM_UNTAP,card, null);
willBeActions.add(untapCreature);
}
}
if (willBeActions.isEmpty())
{
// will allways be empty if nextRound() by match was played
// sincew vmatch resets all tapped items on newRound()!
EAIPlanTree leaf = new EAIPlanTree(this, false);
leafs.addElement(leaf);
return;
}
EAIPlanTree leaf = new EAIPlanTree(this);
leaf.futurePrePlan = futurePlanWithoutActions;
while (!willBeActions.isEmpty())
{
CardAndMana cam = willBeActions.elementAt(0);
willBeActions.removeElement(cam);
boolean reEvaluate = leaf.leafExceuteOneAction(cam, new Vector<EAIAction>(), player, null); // no targets (as of yet) for untapping
}
leaf.playerScore = Weighting.DEFAULT.buildScore(leaf.getMatch(), player, false);
leaf.opponentScore = Weighting.DEFAULT.buildScore(leaf.getMatch(), (player+1)%2, false);