It is currently 29 Oct 2025, 18:13
   
Text Size

AF_Counter AI Ideas

Post MTG Forge Related Programming Questions Here

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

AF_Counter AI Ideas

Postby friarsol » 03 May 2011, 14:09

I've converted all of the Counter code to use the standardized Target system. But I need to test a few corner cases before I can submit (particularly cards that Counter spells that are Targeting Valid<X>). While I'm in here I was going to improve the AI a bit though and was curious if anyone had some ideas.

Currently the AI is based on Computer_CounterSpells2. And basically compares the Counterspells CMC (I don't think it cares about the Activation Cost) to the Card that's being cast CMC. And a single hardcoded Spell is the only exception. I'd rather have this be much more generic.

The AI also (incorrectly) plays Counterspells without having priority, which I plan on fixing as well (and thus ushering in the first cards that can respond to things on the Stack legitimately).

Ideally, when looking at a hand full of Counterspells the AI would use the most restrictive one that can be cast to Counter a particular SA. A Remove Soul should counter a Creature before a Counterspell would if they are both in the AIs hand. An AB$Counter is probably better to use sooner since it (generally) would be card advantage.

So hook me up with some additional ideas, when I get some time this week I'll see if I can implement any of them.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: AF_Counter AI Ideas

Postby Chris H. » 03 May 2011, 14:39

I recently spent some time trying to create a deck using Mana Leak type cards and the AI would not activate the ab if it was an "AB$ Counter" rather than a "SP$ Counter".

I did not get a chance to study the code and I am not sure why the AI failed to use "AB$ Counter" abs.

There also may be a few implemented cards that I could not convert to using the newer DB$ code. I think that the non-standard targeting was responsible for this.
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: AF_Counter AI Ideas

Postby Sloth » 03 May 2011, 14:51

friarsol wrote:Ideally, when looking at a hand full of Counterspells the AI would use the most restrictive one that can be cast to Counter a particular SA. A Remove Soul should counter a Creature before a Counterspell would if they are both in the AIs hand. An AB$Counter is probably better to use sooner since it (generally) would be card advantage.
This, comparing CMCs (and checking for "CARDNAME can't be countered") should be enough to make a passable AI. Most other considerations will be much too complicated.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: AF_Counter AI Ideas

Postby friarsol » 04 May 2011, 04:55

So I built a scoring system similar to AI_getBestCreature() for Countering. So the AI will get the "best" Counterspell to play.

Since any SA is thrown out that can't target the top SA (the only one that's considered) here is the current considerations.

More expensive spells have more weight (less chances to play)
Certain costs will have negative weight (Play less often)
Abilities have stronger weight than spells. (Should play these often)
More restrictive spells (like Avoid Fate) have stronger weight (less chances to play it)
Unless costs have weight proportional to their Unless cost. (the AI will throw out any of these that predict the Human can pay for)

So I have some arbitrary values in there now, but for ValidTgts I don't really have a good way to consider the values (since there are many many of them).

Is there a) something like this already setup for ValidTgts that I can just steal? Or b) a slick way to do it so I can do less work?

For now, I might cheat if it's not "Card" give some bonus points. But otherwise not distinguish....

I could cheat even worse and look through ALL of the Human's cards and base that value on how many total possible targets in the whole deck the AI has, but that seems wrong.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: AF_Counter AI Ideas

Postby Rob Cashwalker » 04 May 2011, 19:40

One thought, Mana Leak should be played ahead of Counterspell, if the target player doesn't have 3 mana open.
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: AF_Counter AI Ideas

Postby friarsol » 04 May 2011, 20:15

Rob Cashwalker wrote:One thought, Mana Leak should be played ahead of Counterspell, if the target player doesn't have 3 mana open.
Yep, while it might not be very clear from my list that's exactly what I want to happen with the weighting. Since Mana Leak and Counterspell have the exact same weight from CMC and Targetability and Ab/Sp and Mana Leak will gain weight for having an Unless Cost, it will be played first.

If the AI thinks the Human can afford the Unless Cost, then Mana Leak won't be available to play at all.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: AF_Counter AI Ideas

Postby Sloth » 05 May 2011, 13:13

friarsol wrote:
Rob Cashwalker wrote:One thought, Mana Leak should be played ahead of Counterspell, if the target player doesn't have 3 mana open.
Yep, while it might not be very clear from my list that's exactly what I want to happen with the weighting. Since Mana Leak and Counterspell have the exact same weight from CMC and Targetability and Ab/Sp and Mana Leak will gain weight for having an Unless Cost, it will be played first.

If the AI thinks the Human can afford the Unless Cost, then Mana Leak won't be available to play at all.
Does this mean we can remove SVar:RemAIDeck:True from Spell Pierce and friends?
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: AF_Counter AI Ideas

Postby friarsol » 05 May 2011, 13:50

Sloth wrote:
friarsol wrote:If the AI thinks the Human can afford the Unless Cost, then Mana Leak won't be available to play at all.
Does this mean we can remove SVar:RemAIDeck:True from Spell Pierce and friends?
We should probably get some other people to do some extra testing before we do that, but I believe the AI will be smarter at playing the card. It won't necessarily be smarter at leaving mana open for that, but thems the breaks.

Also, the AI isn't very picky on what it will counter yet (although it never was), so it should be pretty apparent if they can counter and they don't.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: AF_Counter AI Ideas

Postby friarsol » 11 May 2011, 14:11

So I recently added some code for the AI to test for ETB abilities on Spell_Permanents and consider what it does before playing them. This works by checking the DoTrigger() function (only if the Trigger Ability is a Sub_Ability) and seeing if the Trigger would be played if it were optional.

Now I was planning expanding it so the AI would properly play Spellstutter Sprite (or other similar cards) the main caveat is the AI will never play this card if it doesn't have an acceptable target. Is this a worthy sacrifice? While I see times where it might be good just to have a body in play, I don't think I can finetune the comparisons that much at this time. I was mostly doing this since there was a lot of chatter over on the Decks forum about this card and I had been improving the AI on the ETB area.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: AF_Counter AI Ideas

Postby Chris H. » 11 May 2011, 14:31

I think that the trade off would be acceptable. Some fine tuning can be applied later if/when needed.

Oh, and what about cards that do not target? And what about cards that state "enters the battlefield, you may " do something "target" something.
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: AF_Counter AI Ideas

Postby friarsol » 11 May 2011, 14:53

Chris H. wrote:I think that the trade off would be acceptable. Some fine tuning can be applied later if/when needed.

Oh, and what about cards that do not target? And what about cards that state "enters the battlefield, you may " do something "target" something.
This is a different situation because it deals with cards with Flash that Counter Spells when they ETB. Right now, the AI will not cast non-Counter SAs in response to something on the Stack.

The code is already in place for "normal" things. I've converted Foul Imp has a sample. Feel free to try out your second example. If the Trigger is written like this:

Trigger <Self ETB>
SVar:TRAbility:AB$ <Something>

This code is not "Tested". But if the code is written like this:

Trigger <Self ETB>
SVar:TRAbility:DB$ <Something>

then it will be tested because it has those extra functions that a regular Ability doesn't have.

For ETB effects that are already optional, this ETB testing code won't restrict it. But we can add those restrictions in the future, or at least reduce the likelihood that they would be played if the Trigger won't be accepted.

Of course a target chosen during the "testing" isn't necessarily going to be the same as the target when the Ability actually hits the stack. But this shouldn't really make too much of a difference.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: AF_Counter AI Ideas

Postby Sloth » 11 May 2011, 16:08

I just want to say that I like these additions a lot. When I have some time I will take a look at the code and try to come up with something to improve the AI.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: AF_Counter AI Ideas

Postby Sloth » 14 May 2011, 17:39

friarsol wrote:
Sloth wrote:
friarsol wrote:If the AI thinks the Human can afford the Unless Cost, then Mana Leak won't be available to play at all.
Does this mean we can remove SVar:RemAIDeck:True from Spell Pierce and friends?
We should probably get some other people to do some extra testing before we do that, but I believe the AI will be smarter at playing the card. It won't necessarily be smarter at leaving mana open for that, but thems the breaks.

Also, the AI isn't very picky on what it will counter yet (although it never was), so it should be pretty apparent if they can counter and they don't.
I've tested a bit and the unless cost was used quite well. I will remove the RemAI SVar fro these cards.
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 7 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 7 users online :: 0 registered, 0 hidden and 7 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 7 guests

Login Form