leafs.addElement(leaf);
boolean changeBreak = false;
for (int i = fixed.size()-1; ((i >=0 ) && (!changeBreak)); i--)
{
CardAndMana cam = fixed.elementAt(i);
// if (cam.card.getId().equals("6523"))
// System.out.println("Buh!");
fixed.removeElement(cam);
boolean isX = (cam.card.getCard().getManaCost() == -1);
Vector<CardAndMana> newVariable = (Vector<CardAndMana>) variable.clone();
Vector<CardAndMana> newFixed = (Vector<CardAndMana>) fixed.clone();
// and (possibly) one WITH
AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(cam.card);
Vector<Vector> sources = createSources(cam, hints); // at least one empty target! or null -> must targets not available!
if (sources == null)
{
continue;
}
int sourceCount = sources.size();
for (int s=0; s< sourceCount; s++)
{
Vector<EAIAction> currentSource = sources.elementAt(s);
Vector<Vector> targets = createTargets(cam, hints, currentSource); // at least one empty target! or null -> must targets not available!
if (targets == null)
{
break;
}
int targetCount = targets.size();
for (int t=0; t< targetCount; t++)
{
Vector<EAIAction> currentTargets = targets.elementAt(t);
Vector<EAIAction> target = joinSourceAndTarget(currentSource, currentTargets);
leaf = new EAIPlanTree(this);
leaf.maxDamageInTodo = maxDamageInTodo;
boolean successfull = leaf.leafExceuteOneAction(cam, target, player, camList(fixed,variable) );
if (doTestTwins)
{
String key = EnhancedAI.generateCurrentVMatchKeyID(leaf.vMatch, player) + target.toString();
if (isX) key += cam.card.getCard().getUniqueID()+cam.cost.getAllManaCount();
String hintKey = "";
if (cam.type == CardAndMana.CAM_ACTIVATE)
hintKey = HintAll.HINT_SITUATION_ACTIVATION;
else if(cam.type == CardAndMana.CAM_PLAY)
if (cam.card.isInstant()) hintKey = HintAll.HINT_SITUATION_INSTANT;
else hintKey = HintAll.HINT_SITUATION_CARD_PLAYED;
// assumes ONE source
// assumes depends on source is player!
if (hints.hasHint(hintKey, HintAll.TR_TARGET_DEPENDS_ON_SOURCE)) // card has targets, but they are not to be selected
{
if (currentSource.size() > 0)
{
if (currentSource.elementAt(0).targetIsPlayer)
key+=""+currentSource.elementAt(0).targetPlayerNumber;
else
key+=""+currentSource.elementAt(0).getSCard();
}
}
String test = twinTest.get(key);
if (test == null)
{
test = twinTest.put(key, key);
}
else
{
successfull = false;
}
}
if (successfull)
{
leaf.maxDamageInTodo = adjustMaxDamage(cam, leaf.maxDamageInTodo);
// indicates whether the played out card had
// changed the preconditions for evaluating the current
// playable cards.
// Played out lands DO change things
boolean changesThings = cam.card.isLand();
int orgHandSize = vMatch.getHand(E.pNumber).size();
int newHandSize = leaf.vMatch.getHand(E.pNumber).size();
if (cam.type == CardAndMana.CAM_PLAY) orgHandSize--;
// if after playing out a card is the handsize different
// from befor -> that means that the hand changed and
// possibly something else can be played...
if (orgHandSize != newHandSize)
changesThings = true;
int orgLandSize = vMatch.getLand(E.pNumber).size();
int newLandSize = leaf.vMatch.getLand(E.pNumber).size();
if (cam.card.isLand()) orgLandSize++;
if (orgLandSize != newLandSize)
changesThings = true;
if (!changesThings)
{
String key = "";
if (cam.type == CardAndMana.CAM_ACTIVATE)
key = HintAll.HINT_SITUATION_ACTIVATION;
else if(cam.type == CardAndMana.CAM_PLAY)
if (cam.card.isInstant()) key = HintAll.HINT_SITUATION_INSTANT;
else key = HintAll.HINT_SITUATION_CARD_PLAYED;
changesThings = EAIHelper.hasHandChanges(cam.card, key);
}
leafs.addElement(leaf);
if (changesThings)
{
Vector<CardAndMana> shorten;
shorten = new Vector<CardAndMana>();
shorten = leaf.generatePossibleActionsGeneral(true, null) ;
cleanLands(shorten);
leaf.buildLeafs(shorten);
}
else
{
newFixed = (Vector<CardAndMana>) fixed.clone();
// remove all instances of just played X card from CAM
// one card cannot be played twice per round!
if (isX)
{
String uid = cam.card.getCard().getUniqueID();
for (int r=newFixed.size()-1; r>=0; r--)
{
CardAndMana icam = newFixed.elementAt(r);
if (icam.card.getCard().getUniqueID().equals(uid))
newFixed.remove(r);
}
}
newFixed = leaf.onlyEnoughMana(newFixed);