It is currently 04 Sep 2025, 23:38
   
Text Size

AI issues of SpDestroyTgt

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

AI issues of SpDestroyTgt

Postby Sloth » 03 Aug 2010, 12:37

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.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: AI issues of SpDestroyTgt

Postby Snacko » 03 Aug 2010, 13:17

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.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: AI issues of SpDestroyTgt

Postby Sloth » 03 Aug 2010, 13:52

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?
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: AI issues of SpDestroyTgt

Postby Snacko » 03 Aug 2010, 14:58

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.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: AI issues of SpDestroyTgt

Postby Rob Cashwalker » 03 Aug 2010, 15:20

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.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: AI issues of SpDestroyTgt

Postby Sloth » 03 Aug 2010, 15:38

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.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 33 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 33 users online :: 0 registered, 0 hidden and 33 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 33 guests

Login Form