Board index Programs with AI or Rules Enforcement Magic: The Gathering - Duels of the Planeswalkers Programming Talk
infect AI
Moderator: CCGHQ Admins
infect AI
by BlindWillow » 13 Oct 2012, 22:02
I think we've all noticed by now that the AI has no idea what to do with Infect creatures. So I wanted to start a thread where we could discuss the best way to address that issue.
I've tried dummy triggered abilities (even ones with dangerous="1") that trigger on attacking and custom score codes of various kinds, but no luck so far. Any ideas?
I've tried dummy triggered abilities (even ones with dangerous="1") that trigger on attacking and custom score codes of various kinds, but no luck so far. Any ideas?
- BlindWillow
- Posts: 213
- Joined: 19 Jul 2012, 00:26
- Has thanked: 11 times
- Been thanked: 46 times
Re: infect AI
by RiiakShiNal » 13 Oct 2012, 22:31
About the only way I can think of getting the AI to handle infect properly is to scrap the built-in infect mechanism and to code our own infect system. This would entail all infect creatures/spells to make use of on damage triggers and infect functions from a central function library which we can make changes to as well as coming up with our own method of handling poison counters and the like. It is a fairly complex undertaking (I know because I did it for DotP 2010), but it should then allow the AI to block those creatures much like it would block standard creatures though there is still the possibility that due to the way the AI calculates what will happen it may still act like it does now. There are also several downsides to that method including using tokens for poison counters the extra abilities that would have to be added, possible bugs with damage handling, etc.... All in all, I would recommend against doing that, living with the poor AI handling of infect is in my opinion better than all the bugs and extra code that would be required to try and fix it (which may or may not work).
Just getting started: Xander9009's DotP 2014 Community Wad
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
- RiiakShiNal
- Programmer
- Posts: 2185
- Joined: 16 May 2011, 21:37
- Has thanked: 75 times
- Been thanked: 497 times
Re: infect AI
by BlindWillow » 14 Oct 2012, 01:33
There's got to be some "incentive" we can give the AI to attack players with infect creatures. Maybe there's some function that was never implemented but that the AI might still blindly value. I guess it's time to scour the .exe file again...
- BlindWillow
- Posts: 213
- Joined: 19 Jul 2012, 00:26
- Has thanked: 11 times
- Been thanked: 46 times
Re: infect AI
by BlindWillow » 15 Oct 2012, 06:08
I've come up with the following code to add to my infect creatures (with slight variations for creatures with abilities that change how they block/are blocked, like protection and reach). Basically it checks to see if any opponent has blockers and if not forces the AI to attack. For blocking, it checks to see if the total power of attacking creatures is equal to or greater than the number of poison counters (calculated using thefiremind's code) needed to force a loss. It still leaves the AI with a sizable share of stupidity, but at least it won't act completely insane (like not attacking when there are no blockers or not blocking when lethal damage is incoming). Anyone see any problems or improvements that could be made here?
- Code: Select all
<TRIGGERED_ABILITY internal="1">
<TRIGGER value="BEGINNING_OF_STEP" simple_qualifier="controller">
if ( EffectController():IsAI() ~= 0 and EffectController():MyTurn() ~= 0 and MTG():GetStep() == STEP_BEGIN_COMBAT ) then
local infect_check = Object():GetCurrentCharacteristics():Characteristic_Get( CHARACTERISTIC_INFECT )
local num_players = MTG():GetNumberOfPlayers()
for i=0,num_players-1 do
local player = MTG():GetNthPlayer(i)
if ( player ~= nil and player:GetTeam() ~= EffectController():GetTeam() ) then
local filter = Object():GetFilter()
filter:Clear()
filter:SetController( player )
filter:SetZone( ZONE_IN_PLAY )
filter:AddCardType( CARD_TYPE_CREATURE )
filter:AddExtra( FILTER_EXTRA_CREATURE_UNTAPPED )
filter:NotTargetted()
if ( filter:Count() == 0 and infect_check ~= 0 ) then
return TriggeredForMe()
end
end
end
end
</TRIGGER>
<CONTINUOUS_ACTION>
local characteristics = Object():GetCurrentCharacteristics()
characteristics:Characteristic_Set( CHARACTERISTIC_MUST_ATTACK_EACH_TURN, 1 )
</CONTINUOUS_ACTION>
<DURATION>
return MTG():GetPhase() ~= PHASE_COMBAT
</DURATION>
</TRIGGERED_ABILITY>
<TRIGGERED_ABILITY internal="1">
<TRIGGER value="ATTACKING" simple_qualifier="self">
local player = Object():GetPlayerAttacked()
if player:IsAI() ~= 0 then
local infect_check = Object():GetCurrentCharacteristics():Characteristic_Get( CHARACTERISTIC_INFECT )
local poison_check = ( 10 - player:PlayerDataChest():Int_Get( PLAYER_UTILITY_COMPARTMENT_ID_POISON_READING ) )
local filter = Object():GetFilter()
filter:Clear()
filter:SetZone( ZONE_IN_PLAY )
filter:AddCardType( CARD_TYPE_CREATURE )
filter:SetController( EffectController() )
filter:AddCharacteristic( CHARACTERISTIC_INFECT )
filter:AddExtra( FILTER_EXTRA_CREATURE_ATTACKING )
filter:NotTargetted()
local filter_count = filter:EvaluateObjects()
local total_power = 0
for i=0,filter_count-1 do
local card = filter:GetNthEvaluatedObject(i)
total_power = total_power + card:GetCurrentPower()
end
return ( infect_check ~= 0 and total_power >= poison_check )
end
return false
</TRIGGER>
<CONTINUOUS_ACTION>
local characteristics = Object():GetCurrentCharacteristics()
characteristics:Characteristic_Set( CHARACTERISTIC_MUST_BE_BLOCKED_IF_ABLE, 1 )
</CONTINUOUS_ACTION>
<DURATION>
return MTG():GetPhase() ~= PHASE_COMBAT
</DURATION>
</TRIGGERED_ABILITY>
<TRIGGERED_ABILITY internal="1" active_zone="ZONE_ANY">
<TRIGGER value="PLAYER_POISON_CHANGED">
return TriggerPlayer() ~= nil
</TRIGGER>
<RESOLUTION_TIME_ACTION>
TriggerPlayer():PlayerDataChest():Int_Set( PLAYER_UTILITY_COMPARTMENT_ID_POISON_READING, GetAmount() )
</RESOLUTION_TIME_ACTION>
</TRIGGERED_ABILITY>
- BlindWillow
- Posts: 213
- Joined: 19 Jul 2012, 00:26
- Has thanked: 11 times
- Been thanked: 46 times
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 11 guests