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

How to make AI choose the right creature type?

Moderator: CCGHQ Admins

How to make AI choose the right creature type?

Postby sumomole » 02 Aug 2013, 04:50

I try Engineered Plague, I can only do so much, when there are enough creatures on the battlefield, AI can make the right choices, but when no creature on the battlefield, the computer will select the first type: human , or only Phantasmal Bear on the battlefield, AI actually chose Bear rather than Illusion #-o .Please help me, masters, how to improve the AI, so that it can choose the most appropriate creature type? [-o< [-o< [-o<

Engineered Plague | Open
Code: Select all
<?xml version="1.0"?>
<CARD_V2 ExportVersion="1">
  <FILENAME text="ENGINEERED_PLAGUE_628046" />
  <CARDNAME text="ENGINEERED_PLAGUE" />
  <TITLE>
    <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Engineered Plague]]></LOCALISED_TEXT>
  </TITLE>
  <MULTIVERSEID value="628046" />
  <ARTID value="628046" />
  <ARTIST name="Andrew Goldhawk" />
  <CASTING_COST cost="{2}{B}" />
  <TYPE metaname="Enchantment" />
  <EXPANSION value="DPI" />
  <RARITY metaname="U" />
  <TRIGGERED_ABILITY replacement_query="1" linked_ability_group="1" active_zone="ZONE_TRANSITION">
    <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[As Engineered Plague enters the battlefield, choose a creature type.]]></LOCALISED_TEXT>
    <TRIGGER value="ZONECHANGE_TRANSITION" simple_qualifier="self" to_zone="ZONE_BATTLEFIELD" from_zone="ZONE_ANY" />
    <RESOLUTION_TIME_ACTION>
    local zone
    local player
    local chest = EffectDC():Make_Chest(0)
    local exist_count = 0
    for i=0,227 do
      local filter = ClearFilter()
      filter:Add( FE_SUBTYPE, OP_IS, 1000+i )
      filter:Add( FE_CHARACTERISTIC, OP_NOT, CHARACTERISTIC_CHANGELING )
      if zone ~= nil then
        filter:SetZone( zone )
        if player ~= nil then
          filter:Add( FE_CONTROLLER, OP_IS, player)
        end
      else
        filter:SetZone( ZONE_ANYWHERE )
      end
      if filter:CountStopAt(1) == 1 then
        chest:Set_Int(exist_count, i)
        exist_count = exist_count + 1
      else
        chest:Set_Int(227-i+exist_count, i)
      end
    end
    if zone == nil or exist_count == 0 then
      exist_count = 228
    elseif exist_count &lt; 4 then
      exist_count = 4
    end
    chest:Set_Int(298, exist_count)
    chest:Set_Int(299, 0)
    </RESOLUTION_TIME_ACTION>
    <RESOLUTION_TIME_ACTION repeating="1">
    local n = MTG():GetActionRepCount()
    local parity = n % 2
    local player = EffectController()
    local result = player:GetMultipleChoiceResult()
    local chest = EffectDC():Get_Chest(0)
    local type_count = chest:Get_Int(298)
    local current_types = chest:Get_Int(299)
    local current_type = {}
    for i=0,3 do
      current_type[i+1] = chest:Get_Int((current_types + i) % type_count)
    end
    if (((result == 0 or result == 5) and player:IsAI() == false) or (player:IsAI() and n == 0)) then
      if parity == 0 and player:IsAI() == false then
        player:BeginNewMultipleChoice()
        player:AddMultipleChoiceAnswer( "UI_PROMOTIONAL_PREV" )
        player:AddMultipleChoiceAnswer( "CARD_QUERY_CREATURE_TYPE_"..current_type[1] )
        player:AddMultipleChoiceAnswer( "CARD_QUERY_CREATURE_TYPE_"..current_type[2] )
        player:AddMultipleChoiceAnswer( "CARD_QUERY_CREATURE_TYPE_"..current_type[3] )
        player:AddMultipleChoiceAnswer( "CARD_QUERY_CREATURE_TYPE_"..current_type[4] )
        player:AddMultipleChoiceAnswer( "UI_PROMOTIONAL_NEXT" )
        player:AskMultipleChoiceQuestion( "CARD_QUERY_MC_CHOOSE_CREATURE_TYPE" )
      elseif parity == 1 and player:IsAI() == false then
        if result == 0 then
          current_types = current_types - 4
          if current_types &lt; 0 then
            current_types = current_types + type_count
          end
        elseif result == 5 then
          current_types = current_types + 4
        end
         chest:Set_Int(299, current_types)
      elseif player:IsAI() then
        player:BeginNewNumericalChoice()
        player:AddNumericalChoiceAnswer(type_count-1)
        player:AskNumericalChoiceQuestion("CARD_QUERY_MC_CHOOSE_CREATURE_TYPE")
      end
       return true
    else
      if player:IsAI() then
         LinkedDC():Set_Int(0, 1000 + player:GetNumericalChoiceResult())
      else
         LinkedDC():Set_Int(0, 1000 + current_type[result])
      end
       return false
    end
    </RESOLUTION_TIME_ACTION>
  </TRIGGERED_ABILITY>
  <STATIC_ABILITY linked_ability_group="1">
    <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[All creatures of the chosen type get -1/-1.]]></LOCALISED_TEXT>
    <FILTER filter_id="0">
    local filter = ClearFilter()
    filter:Add( FE_TYPE, OP_IS, CARD_TYPE_CREATURE  )
    filter:Add( FE_SUBTYPE, OP_IS, LinkedDC():Get_Int(0) )
    </FILTER>
    <CONTINUOUS_ACTION layer="7C" filter_id="0">
    if FilteredCard() ~= nil then
       local characteristics = FilteredCard():GetCurrentCharacteristics()
       characteristics:Power_Add( -1 )
       characteristics:Toughness_Add( -1 )
    end
    </CONTINUOUS_ACTION>
  </STATIC_ABILITY>
  <AI_BASE_SCORE score="900" zone="ZONE_BATTLEFIELD" />
</CARD_V2>
User avatar
sumomole
Programmer
 
Posts: 611
Joined: 07 Jun 2011, 08:34
Has thanked: 51 times
Been thanked: 234 times

Re: How to make AI choose the right creature type?

Postby thefiremind » 02 Aug 2013, 08:24

I guess you probably thought about that already, but why not looking for the most common creature type in the opponents' library/libraries? It wouldn't be a disadvantage for the human players since we can look at the decks before playing against them.
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 721 times

Re: How to make AI choose the right creature type?

Postby sumomole » 02 Aug 2013, 08:46

Mybe other cards we can do this, such as Urza's Incubator that damienx45 is requesting, but Engineered Plague need to consider the type of tokens that may exist, and I have no way to confirm them before they enter the battlefield.
User avatar
sumomole
Programmer
 
Posts: 611
Joined: 07 Jun 2011, 08:34
Has thanked: 51 times
Been thanked: 234 times

Re: How to make AI choose the right creature type?

Postby thefiremind » 02 Aug 2013, 09:04

Then the only idea that I have is the long and boring one: make a LOL file where you define, for each token-creating card, which creature types it creates and maybe a symbolic "weight" that indicates how many of those creature types could be on the battlefield because of that card (for example, Sprout makes 1 Saproling, while Jade Mage can potentially make infinite so you could set it to 5 or something like that).
If you really want to do this, I wish you good luck. :D
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 721 times


Return to Programming Talk

Who is online

Users browsing this forum: No registered users and 12 guests


Who is online

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

Login Form