D.addLog("EAI:selectGoodCard() list: "+list ,debugLevel);
CardSim result = null;
if (list.size() == 0) return null;
Scoring scorting = new Scoring();
CardSimList creatures;
CardSimList creaturesO;
CardSimList lands;
CardSimList landsO;
CardSimList hand;
CardSimList orgList = list.copyList();
creaturesO = vmatch.getBattlefield(opponentNo).getSubListByType("Creature");
landsO = vmatch.getLand(opponentNo);
creatures = vmatch.getBattlefield(playerNo).getSubListByType("Creature");
lands = vmatch.getLand(playerNo).copyList();
hand = vmatch.getHand(playerNo);
lands.addList(hand.getSubListByType("Land"));
int creatureAdd=0;
int spellAdd=0;
int landScore = 10 - (lands.size()-1+hand.getSubListByType("Land").size())*2;
scorting.addScore(landScore, Scoring.LAND);
D.addLog("Scoring LAND: "+landScore,debugLevel);
int healthScore = spellAdd+(20 - vmatch.getLife(playerNo))/2;
scorting.addScore(healthScore, Scoring.HEALTH);
D.addLog("Scoring HEALTH: "+healthScore,debugLevel);
int opponentDamageScore = spellAdd+5-(vmatch.getLife(opponentNo)-5);
scorting.addScore(opponentDamageScore, Scoring.DAMAGE);
D.addLog("Scoring DAMAGE: "+opponentDamageScore,debugLevel);
int creatureScore = creatureAdd+(creaturesO.size()-creatures.size())*2;
scorting.addScore(creatureScore, Scoring.CREATURE);
D.addLog("Scoring CREATURE: "+creatureScore,debugLevel);
int creatureDamageScore = spellAdd+(creatureScore+2)/2;
scorting.addScore(creatureDamageScore, Scoring.CREATURE_DAMAGE);
D.addLog("Scoring CREATURE_DAMAGE: "+creatureDamageScore,debugLevel);
int landDestroyScore = (5-landsO.size())+ spellAdd;
scorting.addScore(landDestroyScore, Scoring.LAND_DESTROY);
D.addLog("Scoring LAND_DESTROY: "+landDestroyScore,debugLevel);
int handScore = spellAdd+10-(hand.size()*3);
scorting.addScore(handScore, Scoring.HAND);
D.addLog("Scoring HAND: "+handScore,debugLevel);
boolean nothingDone = false;
int NOTHING_SCORE = -99;
int lastScoreValue = -100;
while (result == null)
{
lastScoreValue = scorting.getHighScoreValue();
int switcher = scorting.getHighScoreType();
if ((!nothingDone) && (lastScoreValue<NOTHING_SCORE))
{
switcher = 22882; // a default :-)
}
if ((switcher == Scoring.NOTHING ) && (nothingDone))
{
break;
}
switch (switcher)
{
case Scoring.LAND_DESTROY:
{
D.addLog("Taken LAND_DESTROY",debugLevel);
scorting.removeType(Scoring.LAND_DESTROY);
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if (aHints.hasHint(HintTargetTypes.TY_LAND_TO_GRAVE))
{
if (!(aHints.hasHint(HintTargetCount.CT_ALL_CARDS)))
{
result = card;
D.addLog("Found: "+result,debugLevel);
}
}
}
break;
}
case Scoring.LAND:
{
D.addLog("Taken LAND",debugLevel);
scorting.removeType(Scoring.LAND);
CardSimList l = list.getSubListByType("Land");
if (l.size()>0)
{
result = l.getCard(0);
break;
}
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if (aHints.hasHint(HintTargetTypes.TY_LIBRARY_TO_HAND))
if ((aHints.getHintValue(HintTargetRestrictions.TR_CARD_TYPE_NEED).toUpperCase().indexOf("Land") != -1)
||
(aHints.getHintValue(HintTargetRestrictions.TR_CARD_TYPE_RESTRICTION).toUpperCase().indexOf("Land") == -1))
{
result = card;
D.addLog("Found: "+result,debugLevel);
break;
}
}
if (result == null)
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if (aHints.hasHint(HintTargetTypes.TY_LIBRARY_TO_LAND))
{
result = card;
D.addLog("Found: "+result,debugLevel);
break;
}
}
break;
}
case Scoring.HEALTH:
{
D.addLog("Taken HEALTH",debugLevel);
scorting.removeType(Scoring.HEALTH);
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if (aHints.hasHint(HintTargetTypes.TY_HEAL))
{
result = card;
D.addLog("Found: "+result,debugLevel);
break;
}
}
break;
}
case Scoring.DAMAGE:
{
D.addLog("Taken DAMAGE",debugLevel);
scorting.removeType(Scoring.DAMAGE);
String[] h={"EFFECT_ONE_PLAYER_DAMAGE"};
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if ((aHints.hasHint(HintTargetTypes.TY_DAMAGE))
|| (aHints.hasHint(HintSourceTypes.SY_DAMAGE)))
{
if ((aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT))
|| (aHints.hasHint(HintSourceRestrictions.SR_CARD_OPPONENT)))
{
if (!(card.isCreature()))
result = card;
}
}
}
break;
}
case Scoring.CREATURE:
{
D.addLog("Taken CREATURE",debugLevel);
scorting.removeType(Scoring.CREATURE);
CardSimList l = list.getSubListByType("Creature");
boolean testMana=true;
if (initiator!=null)
{
AIEnhancedCardHints iHints = AIEnhancedCardHints.getHints(initiator);
if (iHints.hasHint(HintTargetTypes.TY_LIBRARY_TO_FIELD))
{
testMana=false;
}
if (iHints.hasHint(HintTargetTypes.TY_HAND_TO_FIELD))
{
testMana=false;
}
}
if (testMana)
l = onlyEnoughManaGeneral(l, lands);
l = l.sortListByManaCost();
if (l.size()>0)
{
result = l.getCard(l.size()-1);
}
break;
}
case Scoring.CREATURE_DAMAGE:
{
D.addLog("Taken CREATURE_DAMAGE",debugLevel);
scorting.removeType(Scoring.CREATURE_DAMAGE);
// NOT checked if one of the sorcueries does damage to the player!
// (e.g. "Rain of Daggers")
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if ( ((aHints.hasHint(HintTargetTypes.TY_FIELD_TO_GRAVE)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT)))
|| ((aHints.hasHint(HintSourceTypes.SY_FIELD_TO_GRAVE)) && (aHints.hasHint(HintSourceRestrictions.SR_CARD_OPPONENT)))
)
{
{
result = card;
break;
}
}
}
if (result == null)
{
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if ( ((aHints.hasHint(HintTargetTypes.TY_FIELD_TO_HAND)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT)))
|| ((aHints.hasHint(HintSourceTypes.SY_FIELD_TO_HAND)) && (aHints.hasHint(HintSourceRestrictions.SR_CARD_OPPONENT)))
|| ((aHints.hasHint(HintTargetTypes.TY_LIBRARY_TOP)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT)))
)
{
result = card;
break;
}
}
}
if (result == null)
{
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if ( ((aHints.hasHint(HintTargetTypes.TY_DAMAGE)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT)))
|| ((aHints.hasHint(HintSourceTypes.SY_DAMAGE)) && (aHints.hasHint(HintSourceRestrictions.SR_CARD_OPPONENT)))
)
{
result = card;
break;
}
}
}
break;
}
case Scoring.HAND:
{
D.addLog("Taken HAND",debugLevel);
scorting.removeType(Scoring.HAND);
String[] h={"EFFECT_WHEN_DRAW_CARD"};
for (int i=0; i< list.size(); i++)
{
CardSim card = list.getCard(i);
AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
if ( ((aHints.hasHint(HintTargetTypes.TY_LIBRARY_TO_HAND)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_PLAYER)))
|| ((aHints.hasHint(HintSourceTypes.SY_LIBRARY_TO_HAND)) && (aHints.hasHint(HintSourceRestrictions.SR_CARD_PLAYER)))
)
{
result = card;
break;
}
}
break;
}
default: // NOTHING
{
D.addLog("Taken NOTHING",debugLevel);
nothingDone = true;
CardSimList nothingList = onlyEnoughManaGeneral(list, lands);
/*
// not HAND
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_WHEN_DRAW_CARD");
// not CREATURE DAMAGE
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_ONE_CREATURE_TO_GRAVE");
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_OPPONENT_CREATURE_TO_GRAVE");
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_ONE_CREATURE_TO_HAND");
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_ONE_CREATURE_TO_LIBRARY_TOP");
// NOT CREATURE
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_PLAYER_LIBRARY_TO_CREATURE");
// NOT DAMAGE
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_ONE_PLAYER_DAMAGE");
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_OPPONENT_DAMAGE");
// NOT HEAL
nothingList = AIHelper.removeWithHint(nothingList, "HEAL_AMOUNT");
// NOT LAND
nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_PLAYER_LIBRARY_LAND_TO_HAND");
nothingList = AIHelper.removeWithHint(nothingList, "ADD_LAND_FROM_LIBRARY");
*/
CardSimList l = nothingList;
l=l.sortListByManaCost();
if (l.size()>0)
{
result = l.getCard(csa.Global.getRand().nextInt(l.size()));
}
break;
}
}
/*