Board index
Programs with AI or Rules Enforcement
Magic: The Gathering - Duels of the Planeswalkers
Programming Talk
Programs with AI or Rules Enforcement
Magic: The Gathering - Duels of the Planeswalkers
Programming Talk
Argothian Wurm
Moderator: CCGHQ Admins
3 posts
• Page 1 of 1
Argothian Wurm
by skullblakka » 22 Nov 2012, 23:13
Hi everyone!
i'm trying to make Argothian Wurm but when there is the trigger the AI choose during an infinite time...
maybe the CountLandsInPlayOfPlayer don't exist? (i modified an existant CountCreaturesInPlayOfPlayer)
even with CountCreaturesInPlayOfPlayer and a creature in play the AI can't choose an answer...
is it impossible to ask to the AI to choose a land to sacrifice?
i'm trying to make Argothian Wurm but when there is the trigger the AI choose during an infinite time...
- Code: Select all
<TRIGGERED_ABILITY dangerous="1" filter_zone="ZONE_IN_PLAY">
<LOCALISED_TEXT LanguageCode="en-US"><![CDATA[When Argothian Wurm enters the battlefield, any player may sacrifice a land. If a player does, put Argothian Wurm on top of its owner's library.]]></LOCALISED_TEXT>
<TRIGGER value="ZONECHANGE_END" simple_qualifier="self" to_zone="ZONE_IN_PLAY" />
<RESOLUTION_TIME_ACTION repeating="1">
local n = MTG():GetActionRepCount()
local num_players = MTG():GetNumberOfPlayers()
local playerindex = n/2
local parity = n % 2
local player = MTG():GetNthPlayer(playerindex)
local filter = Object():GetFilter()
if player ~= nil and n < num_players*2 then
if player:GetTeam() ~= EffectController():GetTeam() then
if parity == 0 then
player:BeginNewMultipleChoice()
player:AddMultipleChoiceAnswer( "CARD_QUERY_OPTION_NO" )
if CountLandsInPlayOfPlayer(player) > 0 then
player:AddMultipleChoiceAnswer( "CARD_QUERY_OPTION_YES" )
end
player:AskMultipleChoiceQuestion( "CARD_QUERY_MC_SACRIFICE_LAND" )
else
if Object():GetMultipleChoiceResult() == 1 then
if EffectSource() ~= nil then
EffectSource():Tap()
EffectSource():AddCounters( MTG():PlusOnePlusOneCounters(), 1 )
end
filter:Clear()
filter:NotTargetted()
filter:SetController( player )
filter:SetZone( ZONE_IN_PLAY )
filter:AddCardType( CARD_TYPE_LAND )
filter:SetHint( HINT_ENEMY, player )
player:ChooseTarget( NO_VALIDATION, "CARD_QUERY_CHOOSE_LAND_TO_SACRIFICE", EffectDC():Make_Targets(0) )
return false
end
end
end
return true
else
return false
end
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
if EffectDC():Get_Targets(0) ~= nil then
local target = EffectDC():Get_Targets(0):Get_CardPtr(0)
if target ~= nil then
target:Sacrifice(target:GetController())
end
end
</RESOLUTION_TIME_ACTION>
</TRIGGERED_ABILITY>
<HELP title="MORE_INFO_BADGE_TITLE_10" body="MORE_INFO_BADGE_BODY_10" zone="ZONE_ANY" />
<SFX text="COMBAT_PESTS_LARGE_ATTACK" power_boundary_min="4" power_boundary_max="-1" />
<SFX text="COMBAT_PESTS_SMALL_ATTACK" power_boundary_min="1" power_boundary_max="3" />
</CARD_V2>
maybe the CountLandsInPlayOfPlayer don't exist? (i modified an existant CountCreaturesInPlayOfPlayer)
even with CountCreaturesInPlayOfPlayer and a creature in play the AI can't choose an answer...
is it impossible to ask to the AI to choose a land to sacrifice?
apology my so bad english speaking 
-

skullblakka - Posts: 71
- Joined: 31 Jul 2012, 20:16
- Has thanked: 16 times
- Been thanked: 17 times
Re: Argothian Wurm
by thefiremind » 23 Nov 2012, 10:01
I can't even find CountCreaturesInPlayOfPlayer, but just CountCreaturesInPlay, which is a function declared in EXTRACTINFO.LOL. Where did you find CountCreaturesInPlayOfPlayer?
Understanding the flow of the code in a repeating action is always a challenge so it's hard to see what's wrong at first sight, but I'll try. You left the "tap and add a +1/+1 counter" from Desecration Demon, that's not the main problem but you should remove it. Also note that Desecration Demon asks only the opponents, while Argothian Wurm asks all the players... I know you'll probably never want to sacrifice your own land to put your own Wurm on top of library, but if you want to be precise, you should allow each player to decide. This still doesn't explain why the AI gets stuck, and to be honest I don't feel like struggling with this code when I would code Argothian Wurm (and Desecration Demon) in an easier way.
Instead of asking a multiple query and then asking what to sacrifice, why don't you ask immediately what to sacrifice, with QUERY_FLAG_CAN_BE_FINISHED_EARLY + QUERY_FLAG_CAN_BE_FINISHED_EARLY_FOR_AI_AS_WELL? If you don't want to sacrifice anything, you just "finish" the query without selecting anything. The problem about allowing the player to answer "yes" only when there's something to sacrifice wouldn't exist anymore because with a lack of targets you won't be asked at all.
This is how I would code Argothian Wurm:
Understanding the flow of the code in a repeating action is always a challenge so it's hard to see what's wrong at first sight, but I'll try. You left the "tap and add a +1/+1 counter" from Desecration Demon, that's not the main problem but you should remove it. Also note that Desecration Demon asks only the opponents, while Argothian Wurm asks all the players... I know you'll probably never want to sacrifice your own land to put your own Wurm on top of library, but if you want to be precise, you should allow each player to decide. This still doesn't explain why the AI gets stuck, and to be honest I don't feel like struggling with this code when I would code Argothian Wurm (and Desecration Demon) in an easier way.
This is how I would code Argothian Wurm:
- Code: Select all
<RESOLUTION_TIME_ACTION repeating="1">
local n = MTG():GetActionRepCount()
local num_players = MTG():GetNumberOfPlayers()
local playerindex = n/2
local parity = n % 2
local player = MTG():GetNthPlayer(playerindex)
if player ~= nil and n < num_players*2 then
if parity == 0 then
local filter = Object():GetFilter()
filter:Clear()
filter:NotTargetted()
filter:SetPlayer( player )
filter:SetZone( ZONE_IN_PLAY )
filter:AddCardType( CARD_TYPE_LAND )
filter:SetHint( HINT_ENEMY, player )
filter:May()
player:ChooseTargetWithFlags( NO_VALIDATION, "CARD_QUERY_CHOOSE_LAND_TO_SACRIFICE", EffectDC():Make_Targets(playerindex),
QUERY_FLAG_CAN_BE_FINISHED_EARLY + QUERY_FLAG_CAN_BE_FINISHED_EARLY_FOR_AI_AS_WELL )
else
local sac_target = EffectDC():Get_Targets(playerindex):Get_CardPtr(0)
if sac_target ~= nil then
player:Sacrifice(sac_target)
if EffectSource() ~= nil then
EffectSource():PutInLibrary(0)
end
return false
end
end
return true
else
return false
end
</RESOLUTION_TIME_ACTION>
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-

thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 722 times
Re: Argothian Wurm
by skullblakka » 23 Nov 2012, 20:27
thx for your help

but i had the same problem.
anyways, it works better with the "can be finished early", thanks!
i just didn't though about it... my bad it was so easywhy don't you ask immediately what to sacrifice, with QUERY_FLAG_CAN_BE_FINISHED_EARLY + QUERY_FLAG_CAN_BE_FINISHED_EARLY_FOR_AI_AS_WELL?
yeah i didn't paste the good one but you even understood my problem, i tested without the repeating and with the sacrifice instead of tap then get counters, and i also remooved the line that filters opponents only.Understanding the flow of the code in a repeating action is always a challenge so it's hard to see what's wrong at first sight, but I'll try. You left the "tap and add a +1/+1 counter" from Desecration Demon, that's not the main problem but you should remove it. Also note that Desecration Demon asks only the opponents, while Argothian Wurm asks all the players... I know you'll probably never want to sacrifice your own land to put your own Wurm on top of library, but if you want to be precise, you should allow each player to decide. This still doesn't explain why the AI gets stuck, and to be honest I
but i had the same problem.
anyways, it works better with the "can be finished early", thanks!
apology my so bad english speaking 
-

skullblakka - Posts: 71
- Joined: 31 Jul 2012, 20:16
- Has thanked: 16 times
- Been thanked: 17 times
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 10 guests