It is currently 06 Sep 2025, 20:31
   
Text Size

spRegrowth

Post MTG Forge Related Programming Questions Here

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

Re: spRegrowth

Postby Rob Cashwalker » 30 Jul 2010, 14:21

At first, I thought that the AI would be very different between graveyard returns and battlefield destroy/exile/bounce. But after typing out a message and realizing it, I deleted it and started typing this one.

Given a list of cards for a particular zone, matching the restrictions of the spell, the AI for all of these would attempt to choose the "best" card. Examples:
Return target creature to its owner's hand - Choose the human's best creature.
Return target card in a graveyard to play under your control - Choose the best card in all graveyards.
Exile target card in a graveyard - Choose the best card in the human's graveyard.
Destroy target creature - Choose the human's best creature.

I am thinking that the AI for this will become rather ugly, as each of the options for the effect would need to be taken into account. If the spell restricts targeting to a player ("your graveyard" or "creature an opponent controls") this is easy. However, if the spell can target both human and AI, for destroy/exile/bounce, the AI needs to only consider the human's cards, but for the graveyard effects, it would need to choose from both.
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: spRegrowth

Postby friarsol » 30 Jul 2010, 16:35

Yea I think a lot can be gained by having a strong targetBest function which we don't really have right now.

It wouldn't need to be too complex. We would pass in an array of zones, and an array of types to get the list of different choices. This would give us the flexibility to use this for most AI spells that target.

The tough decision making would be the logic of "what in this list is best" but that's something that we would just make rudimentary choices: "Strongest flyer with power > 2 or creature with strongest power"

The ultimate goal for AI would be to generate a threat scoring system. Giving points for conditions on the field. A Hypnotic Specter is a big threat, but if you have something that can trade/block the Specter, then a 5/5 trampler you can't trade/block with is a bigger threat. Once we get enough building blocks into place it'll be fun to try to put that together.

Very quickly:
Code: Select all
public Card chooseBest(final Card card, PlayerZone[] zones, final String[] types)
{
  CardList list = getTargetableZonesTypes(card, zones, types);
  // choose best logic here
}


public CardList getTargetableZonesTypes(final Card card, PlayerZone[] zones, final String[] types)
{
   CardList list = new CardList();
   for(Zone z : zones)
     list.add(z.getCards());

   list = list.filter(new CardListFilter(){
       public boolean addCard(Card c){
          if (!CardFactoryUtil.canTarget(card, c)) return false;
          for(String t : types)
              if (c.getType().contains(t))
                  return true;
         
          return false;
       }
   }
   return list;
}
Animate Dead would send in both player and computer graveyards, looking for creatures.
Disenchant would send in player battlefield looking for artifacts or enchantments.
Path to Exile would send in player battlefield looking for creatures.

We lose out on the chances to target friendly cards for negative spells when it would make sense (Bounce a Abyssal Persecutor if would win the game otherwise), but there's not much we can do about that for now.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Previous

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 26 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 26 users online :: 0 registered, 0 hidden and 26 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 26 guests

Login Form