It is currently 18 Apr 2024, 22:44
   
Text Size

Is there a way to get all unblocked creatures power?

Discuss Upcoming Releases, Coding New Cards, Etc.
PLEASE DO NOT REPORT BUGS HERE!

Moderators: BAgate, drool66, Aswan jaguar, gmzombie, stassy, CCGHQ Admins

Is there a way to get all unblocked creatures power?

Postby Aswan jaguar » 29 Oct 2020, 16:19

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;
}
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

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

Postby drool66 » 30 Oct 2020, 06:46

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?
User avatar
drool66
Programmer
 
Posts: 1163
Joined: 25 Nov 2010, 22:38
Has thanked: 186 times
Been thanked: 267 times

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

Postby FastEddie » 30 Oct 2020, 06:49

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.
---
Argivian Archaeologist in the Library of Leng studying the Spells of the Ancients
User avatar
FastEddie
 
Posts: 246
Joined: 24 Dec 2019, 10:59
Has thanked: 15 times
Been thanked: 19 times

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

Postby Aswan jaguar » 30 Oct 2020, 16:36

Thanks for the help guys, it works now. I am quite happy with AI now.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times


Return to Development

Who is online

Users browsing this forum: No registered users and 21 guests

cron

Who is online

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

Login Form