- AI for Fight

This commit is contained in:
mcrawford620
2012-07-19 03:48:33 +00:00
parent 1ba819d162
commit 15ff211f3c
4 changed files with 37 additions and 6 deletions

View File

@@ -3,7 +3,6 @@ ManaCost:G
Types:Sorcery
Text:no text
A:SP$ Fight | Cost$ G | ValidTgts$ Creature | TgtPrompt$ Select target creature | TargetsFromDifferentZone$ True | TargetMin$ 2 | TargetMax$ 2 | SpellDescription$ Target creature you control fights target creature you don't control. (Each deals damage equal to its power to the other.)
SVar:RemAIDeck:True
SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/prey_upon.jpg
SetInfo:M13|Common|http://magiccards.info/scans/en/m13/181.jpg

View File

@@ -632,7 +632,6 @@ public class AbilityFactoryAttach {
prefList = prefList.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
System.out.println("Not Attaching");
return !c.getSVar("Targeting").equals("Dies");
}
});

View File

@@ -1842,9 +1842,42 @@ public class AbilityFactoryDealDamage {
}
private boolean fightCanPlayAI(final AbilityFactory af, final SpellAbility sa) {
Target tgt = sa.getTarget();
tgt.resetTargets();
//final Target tgt = sa.getTarget();
CardList aiCreatures = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer());
aiCreatures = aiCreatures.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
return !c.getSVar("Targeting").equals("Dies");
}
});
CardList humCreatures = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
final Random r = MyRandom.getRandom();
boolean rr = false;
if (r.nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn())) {
rr = true;
}
if (humCreatures.size() > 0 && aiCreatures.size() > 0) {
for (Card humanCreature : humCreatures) {
for (Card aiCreature : aiCreatures) {
if (humanCreature.getNetDefense() <= aiCreature.getNetAttack()
&& humanCreature.getNetAttack() < aiCreature.getNetDefense()) {
// todo: check min/max targets; see if we picked the best matchup
tgt.addTarget(humanCreature);
tgt.addTarget(aiCreature);
return rr;
} else if (humanCreature.getSVar("Targeting").equals("Dies")) {
tgt.addTarget(humanCreature);
tgt.addTarget(aiCreature);
return rr;
}
}
}
}
return false;
}

View File

@@ -579,7 +579,7 @@ public class ComputerUtil {
* (is for canPayCost, if true does not change the game state)
* @param extraMana
* a int.
* @param checkPlayable
* @param checkPlayable
* should we check if playable? use for hypothetical "can AI play this"
* @return a boolean.
* @since 1.0.15
@@ -759,7 +759,7 @@ public class ComputerUtil {
* @param partPriority
* @param costParts
* @param foundAllSources
* @return Were all mana sources found?
* @return Were all mana sources found?
*/
private static Boolean findManaSources(final HashMap<String, ArrayList<AbilityMana>> manaAbilityMap,
final ArrayList<ArrayList<AbilityMana>> partSources, final ArrayList<Integer> partPriority,
@@ -818,7 +818,7 @@ public class ComputerUtil {
srcFound.addAll(manaAbilityMap.get(costParts[nPart]));
}
}
// add sources to array lists
partSources.add(nPart, srcFound);
// add to sorted priority list