How to make AI choose the right creature type?

by sumomole
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
.Please help me, masters, how to improve the AI, so that it can choose the most appropriate creature type?




- 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 < 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 < 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>