It is currently 16 Apr 2024, 20:13
   
Text Size

More AI for some cards

Post MTG Forge Related Programming Questions Here

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

More AI for some cards

Postby Hanmac » 02 May 2016, 20:23

hi want to add more AI for some cards but i don't know what the best way to do it. And for not polluting the Bug-Reports thread i want to make my own one.

what i want to do:
in a test game the AI has Accursed Witch, but the Enemy didn't use it aggressively because when the creature dies it gets a cure aura.
So it should attack even if i have stronger creatures. (Specially if i have stronger)
Hanmac
 
Posts: 954
Joined: 06 May 2013, 18:44
Has thanked: 229 times
Been thanked: 158 times

Re: More AI for some cards

Postby excessum » 03 May 2016, 23:51

For Accursed Witch, a simple way is to add the always-attack and/or sacrifice-me SVars (refer to other examples, I cannot remember the exact spelling...).

For general cases, I think it really depends. Personally, I will add new blocks in the SpellAbilityAi canPlay code for specific cards if they are unique (eg. planeswalkers) or new (eg. Converge mana payment). Then again, I only care about Standard/Limited so there is less to be concerned about.
excessum
 
Posts: 177
Joined: 21 Oct 2013, 02:30
Has thanked: 0 time
Been thanked: 19 times

Re: More AI for some cards

Postby Hanmac » 04 May 2016, 09:53

for Accursed Witch i need to see.
i found SacMe, but not the one with AttackAlways or something.
hm i might want to do it that its only active when a Opponent can be targeted. (so the opponent does not have Hexproof)
===
other AI for cards with Character defining Abilities, like Overbeing of Myth.
AI did use this last card in it's hand Necromantic Selection to destroy all creatures and did return something that does define its toughness from the cards in this hand (AI now has no cards) so the creature gets but on the graveyard again.

should i add NeedsToPlay to all that cards, or can a logic added to that character defining abilities to tell the AI that this is a bad card in this moment? (maybe checking for "Creatures get +1/+1" too)
Hanmac
 
Posts: 954
Joined: 06 May 2013, 18:44
Has thanked: 229 times
Been thanked: 158 times

Re: More AI for some cards

Postby excessum » 04 May 2016, 12:00

The hexproof check is probably overkill since it is only one card. Heck, it might as well check for cannot lose life, cannot lose the game, Death's Shadow etc...

Your idea with adding an SVar for such cards and adding a handler to AiController (I think) is probably the only solution. The issue is that the AI has no way to evaluate whether the spell(s) it can play is better than the "buff" to said creature. Even simple cases like holding lands will seem stupid if it has some bomb or awesome mana-sink in the library.

I have a feeling it is going to be too much work to be worth it as the decision to "not cast" spell(s) is harder to implement.
excessum
 
Posts: 177
Joined: 21 Oct 2013, 02:30
Has thanked: 0 time
Been thanked: 19 times

Re: More AI for some cards

Postby friarsol » 04 May 2016, 12:29

I think Erg Raiders has some type of "This should attack" SVar.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: More AI for some cards

Postby Hanmac » 04 May 2016, 12:55

thanks excessum & friarsol, i added the variables to SVar to Accursed Witch

i will add NeedsToPlay to the Character Defining Ones later.

i did add "SVar:NeedsToPlayVar:X GE2" and other,
but then i did found "SVar:NoZeroToughnessAI:True", now i need to think which is better.
But i don't know if AI will use this to check when to return creatures from the graveyard to hand.
Hanmac
 
Posts: 954
Joined: 06 May 2013, 18:44
Has thanked: 229 times
Been thanked: 158 times

Re: More AI for some cards

Postby Hanmac » 11 May 2016, 17:25

i try to add some code to EffectAi for cards with RemAIDeck

for Vizkopa Guildmage
(and probably other stuff that should be activated before life gain)

Code: Select all
if (logic.equals("BeforeGain")) {
               
  // if AI can't gain life, this is useless
  if (!ai.canGainLife()) {
    return false;
  }
 
  // basic logic for before GainLife on stack
  if (game.getStack().isEmpty()) {
    return false;
  }

  final SpellAbility topStack = game.getStack().peekAbility();
  final Card source = topStack.getHostCard();
  int lifeAmount = 0;

  // check if spell does gain life
  if(topStack.getApi() == ApiType.GainLife && AbilityUtils.getDefinedPlayers(source, topStack.getParam("Defined"), topStack).contains(ai)) {
    lifeAmount = AbilityUtils.calculateAmount(source, topStack.getParam("LifeAmount"), topStack);
  } else {
    SpellAbility sub = topStack;
    // check if sub abilities does gain life too
    while ((sub = sub.getSubAbility()) != null) {
      if(sub.getApi() == ApiType.GainLife && AbilityUtils.getDefinedPlayers(source, sub.getParam("Defined"), sub).contains(ai)) {
        lifeAmount = AbilityUtils.calculateAmount(sub.getHostCard(), sub.getParam("LifeAmount"), sub);
        break;
      }
    }
  }
               
  randomReturn = lifeAmount > 0;
}
i added debugging code like "System.out.println" but it seems the game.getStack().isEmpty() check does fail for stuff like Nyx-Fleece Ram
(and also other cards the AI does seems to have)
Hanmac
 
Posts: 954
Joined: 06 May 2013, 18:44
Has thanked: 229 times
Been thanked: 158 times

Re: More AI for some cards

Postby friarsol » 11 May 2016, 20:29

Hanmac wrote:i added debugging code like "System.out.println" but it seems the game.getStack().isEmpty() check does fail for stuff like Nyx-Fleece Ram
(and also other cards the AI does seems to have)
The AI passes priority when it controls the top item on the stack, I don't think your code will work very well.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: More AI for some cards

Postby Hanmac » 11 May 2016, 20:42

@friarsol: a that's explains it.
And also why the Code does not work yet.
Means it's not such so easy to do it. But I will keep it in mind.

But I have some other ideas I want to try for the AI.

PS:excessum thinks that my change in the Effect API with: "ComputerUtil.hasReasonToPlayCardThisTurn" and Narset and Rebound, might not work always, because the AI is not forced to play and i might do something with priority settings. 
Hanmac
 
Posts: 954
Joined: 06 May 2013, 18:44
Has thanked: 229 times
Been thanked: 158 times

Re: More AI for some cards

Postby Hanmac » 14 May 2016, 12:14

hey i did some thoughts about doing the AI for Dazzling Reflection.
the interesting of the part is that it can be used aggressively and passive:

like when the AI got attacked, it can target the strongest possible creature and make AI gain life, and the creature does not deal any damage.

or when AI does control the strongest creature, but an stack ability would destroy it. AI can use the effect to gain life so it does still gain benefit from the dying creature.

or the AI can activate it in an Endstep, targeting the strongest creature on the field. (or should it wait for a proper attack?)

Also the AI should use the card when its life is getting critical.

some other thoughts about this card?
Hanmac
 
Posts: 954
Joined: 06 May 2013, 18:44
Has thanked: 229 times
Been thanked: 158 times

Re: More AI for some cards

Postby excessum » 15 May 2016, 02:38

You really need to force the AI to cast the chosen spells for r31212 and r31206 if you remove RemAIDeck. The logic you added only checks that the AI has, and might, play an instant/sorcery from hand. Barring unfortunate cases like responding to/with an instant (eg. Counterspell, Apostle's Blessing), you need to force the AI to cast said instant/sorcery at the next available priority. The current implementation is just hoping that the AI will cast said instant/sorcery and is pretty likely to fail and make the AI look silly for wasting a planeswalker minus.

I am pretty sure that there is no simple way to implement AI for Howl of the Horde because it requires it to cast two spells that are unlikely to be free (same issue as Soulfire Grand Master).
excessum
 
Posts: 177
Joined: 21 Oct 2013, 02:30
Has thanked: 0 time
Been thanked: 19 times

Re: More AI for some cards

Postby Hanmac » 15 May 2016, 05:51

@excessum: yeah you are right, but I wanted to do it in baby steps with how much I can do and do the other stuff later.
For the two stuff, how can I force the AI to cast this spell (or one of them)?
And how can I check if the AI has enough mana for both the ability and the spell? (Or do I need to write such a check function?)

PS: what are your option for my thoughts about Dazzling Reflection?

Also I need to do a check for Devour, because the AI did cast Thromok the Insatiable without devouring anything. How can I tell the AI that this is a bad idea?
Hanmac
 
Posts: 954
Joined: 06 May 2013, 18:44
Has thanked: 229 times
Been thanked: 158 times

Re: More AI for some cards

Postby excessum » 15 May 2016, 06:50

If that's the case then you should not have removed the RemAIDeck flags since the AI is still broken. AiController.getSpellAbilityPriority() determines the order in which the AI evaluates available SpellAbility. How you go about forcing instant/sorceries up the priority without breaking other things is going to be an interesting problem.

There is no simple way to allocate mana for multiple costs. Even if the AI sums them up and determine that it can pay the cost, there is no guarantee that the mana abilities are used such that they can be paid in sequence due to the way paying mana costs are handled (ComputerUtilMana.payManaCost).

Regarding Dazzling Reflection, it is basically a mini-fog effect stapled with a gain-life effect so I don't see much point in implementing AI for it because it is not really Constructed-playable.

I think it is simply to just set Thromok the Insatiable to RemAIDeck since the AI does not have any convenient way to count the devour targets for NeedsToPlayVar. Besides, it just looks to be plain unplayable even in Limited...
excessum
 
Posts: 177
Joined: 21 Oct 2013, 02:30
Has thanked: 0 time
Been thanked: 19 times

Re: More AI for some cards

Postby Hanmac » 15 May 2016, 07:57

I see what I can do for them, I would prefer to make more cards playable for the AI instead of disabling more. Even if the cards seems to be useless.

About Thromok the Insatiable, the card is strong because with "Devour X" and you sacrifice 4 creatures you gain a 16/16 or a 25/25 for 5 creatures.

Ps:
I don't know if the optional trigger from Cunning Bandit // Azamuki, Treachery Incarnate does use the SetStateAi logic because I think about a way to tell the AI when it's better to flip the AI and when it's not.
Hanmac
 
Posts: 954
Joined: 06 May 2013, 18:44
Has thanked: 229 times
Been thanked: 158 times

Re: More AI for some cards

Postby friarsol » 15 May 2016, 11:41

Hanmac wrote:I see what I can do for them, I would prefer to make more cards playable for the AI instead of disabling more. Even if the cards seems to be useless.
But if the card doesn't work for the AI we should mark it as not for AI at least until the AI knows what to do with it, that's what the flag is for. One card efforts aren't as noticeable, as grouping the remAI cards and trying to add AI for things that would affect multiple cards.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 56 guests


Who is online

In total there are 56 users online :: 0 registered, 0 hidden and 56 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 56 guests

Login Form