Page 1 of 1

Is there a way to get all unblocked creatures power?

PostPosted: 29 Oct 2020, 16:19
by Aswan jaguar
I want to use it in AI code in cards with clause "If you do, ~ assigns no combat damage this turn." so AI doesn't screw that by selecting to not assign damage with that creature when AI goes for an alpha strike. Because for now I check only the card with that ability to assign combat damage if opponent's life is equal or less to the creatures power but I want to check all unblocked creatures.
I tried the following which still counts only the creature with this ability
and not all unblocked attackers (but possibly I am not doing it correctly):
Code: Select all
int card_farrels_zealot(int player, int card, event_t event){
   /* CARD_ID_FARRELS_ZEALOT   1777
   Farrel's Zealot   |1|W|W
   Creature - Human 2/2
   Whenever ~ attacks and isn't blocked, you may have it deal 3 damage to target creature. If you do, ~ assigns no combat damage this turn. */

   if( event == EVENT_DECLARE_BLOCKERS ){
      if( is_unblocked(player, card) && ! is_humiliated(player, card) ){
         int ai_choice = 1;
         //int gp = get_power(player, card);
         int unblocked_att_pow = 0;
         int c;
         target_definition_t td;
         default_target_definition(player, card, &td, TYPE_CREATURE);
          for(c=active_cards_count[current_turn]-1; c > -1; c--){
             if( in_play(current_turn, c) && is_what(current_turn, c, TYPE_CREATURE) && is_attacking(current_turn, c) &&
                is_unblocked(current_turn, c) )
             {
                 unblocked_att_pow = get_power(current_turn, c);
             }
         }
         if( IS_AI(player) && current_turn == player && !( unblocked_att_pow >= life[1-player]) ){
             td.toughness_requirement = 3 | TARGET_PT_LESSER_OR_EQUAL | TARGET_PT_INCLUDE_DAMAGE;
             ai_choice = 0;
         }      

         int choice = do_dialog(player, player, card, -1, -1, " Damage creature\n Pass", ai_choice);
         if( choice == 0 ){
            if( can_target(&td) && pick_target(&td, "TARGET_CREATURE") ){
               damage_target0(player, card, 3);
               negate_combat_damage_this_turn(player, card, player, card, 0);
            }
         }
         get_card_instance(player, card)->number_of_targets = 0;
      }
   }
   return 0;
}

Re: Is there a way to get all unblocked creatures power?

PostPosted: 30 Oct 2020, 06:46
by drool66
To add up all the powers, I think you could just change:
unblocked_att_pow = get_power(current_turn, c);

to:
unblocked_att_pow += get_power(current_turn, c);

I'm not sure, but if you include "is_unblocked" do you necessarily need to check if it's a creature or if it's attacking?

Re: Is there a way to get all unblocked creatures power?

PostPosted: 30 Oct 2020, 06:49
by FastEddie
Drool66 beat me on that.

What you want is
Code: Select all
unblocked_att_pow = unblocked_att_pow + get_power(current_turn, c);
of which
Code: Select all
unblocked_att_pow += get_power(current_turn, c);
is the shorter (and more common) form.
I'm not sure, but if you include "is_unblocked" do you necessarily need to check if it's a creature or if it's attacking?
Is_unblocked() checks whether STATE_ATTACKING is set. So you don't need to check that. A quick search didn't show, however, where this is set (look for something like "| STATE_ATTACKING" or "|= STATE_ATTACKING") so I don't know whether you also can safely cut out the creature check.

Re: Is there a way to get all unblocked creatures power?

PostPosted: 30 Oct 2020, 16:36
by Aswan jaguar
Thanks for the help guys, it works now. I am quite happy with AI now.