Page 1 of 1

AI issues of SpDestroyTgt

PostPosted: 03 Aug 2010, 12:37
by Sloth
To determine the best targets, the AI uses this entry:

Code: Select all
if(choices.size() > 0) {
                        for(int i = 0; i < Tgts.length; i++) {
                            if(Tgts[i].equals("Artifact")) {
                                if(CardFactoryUtil.AI_getBestArtifact(choices) != null) results.add(CardFactoryUtil.AI_getBestArtifact(choices));
                            } else if(Tgts[i].equals("Creature")) {
                                if(CardFactoryUtil.AI_getBestCreature(choices) != null) results.add(CardFactoryUtil.AI_getBestCreature(choices));
                            } else if(Tgts[i].equals("Enchantment")) {
                                if(CardFactoryUtil.AI_getBestEnchantment(choices, card, true) != null) results.add(CardFactoryUtil.AI_getBestEnchantment(
                                        choices, card, true));
                            } else if(Tgts[i].equals("Land")) {
                                if(CardFactoryUtil.AI_getBestLand(choices) != null) results.add(CardFactoryUtil.AI_getBestLand(choices));
                            } else if(Tgts[i].equals("Permanent")) {
                                if(CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true) != null) results.add(CardFactoryUtil.AI_getMostExpensivePermanent(
                                        choices, card, true));
                            }
                        }
                    }
So the AI only consideres target restrictions that are exactly Artifact, Creature, etc.,
but if the only possible targets have a form like Creature.nonBlack, they don't get considered and the AI won't find a target (Yes that means the AI is currently not able to use Doom Blade and most of all creature removal spells :shock: )

I fixed this for spBounceTgt by replacing Tgts[i].equals("Artifact") with Tgts[i].startsWith("Artifact"). I would suggest doing the same here.

Re: AI issues of SpDestroyTgt

PostPosted: 03 Aug 2010, 13:17
by Snacko
Better to use indexOf as it doesn't care where it finds the match as with startsWith. If the substring isn't found -1 is returned.

Re: AI issues of SpDestroyTgt

PostPosted: 03 Aug 2010, 13:52
by Sloth
Snacko wrote:Better to use indexOf as it doesn't care where it finds the match as with startsWith. If the substring isn't found -1 is returned.
Well, if the restriction is Creature.Artifact it doesn't have to add all artifact creatures twice though (it would already add everything twice with restrictions like Creature.Artifact,Creature.Black but it doesn't change anything).

Am I forgetting a case where your version is better?

Re: AI issues of SpDestroyTgt

PostPosted: 03 Aug 2010, 14:58
by Snacko
Ye in that case it would be better, I didn't check how those type intersections are done in Forge, however still you can't do Creature.Artifact as the code doesn't support it.

Re: AI issues of SpDestroyTgt

PostPosted: 03 Aug 2010, 15:20
by Rob Cashwalker
I recently went through this again in spDiscard. When I started looking at all the "getBest____" routines, the only one that wasn't simply the highest CMC was "getBestCreature" - it uses the p/t.

I think my new approach is more universal.

Code: Select all
if (dPChHand.size() > 0)
{
   CardList dChoices = new CardList();
   if (DiscardMethod.contains("Creature") && !DiscardMethod.contains("nonCreature"))
      dChoices.add(CardFactoryUtil.AI_getBestCreature(dPChHand));

   CardListUtil.sortByTextLen(dPChHand);
   dChoices.add(dPChHand.get(0));

   CardListUtil.sortCMC(dPChHand);
   dChoices.add(dPChHand.get(0));

   Card dC = dChoices.get(CardUtil.getRandomIndex(dChoices));
   
   dPChHand.remove(dC);
   
   CardList dCs = new CardList();
   dCs.add(dC);

   AllZone.Display.getChoiceOptional("Computer has chosen", dCs.toArray());

   AllZone.GameAction.discard(dC);
}
This logic checks for Creature as a target type, and uses the getBestCreature for that. Then it also uses other approaches. Some of these approaches may end up with the same result, which simply provides a higher probability that a given choice really is the best.

Re: AI issues of SpDestroyTgt

PostPosted: 03 Aug 2010, 15:38
by Sloth
I will only fix that the AI can cope with more refined target restrictions.

Maybe the AI should prefer to destroy creatures in the future, but I will leave that for now.