Board index Programs with AI or Rules Enforcement Magic: The Gathering - Duels of the Planeswalkers Programming Talk
Help with Stitcher Geralf
Moderator: CCGHQ Admins
Re: Help with Stitcher Geralf
by Xander9009 » 09 Nov 2014, 19:38
I think I might have misunderstood what Riiak was saying, nonetheless, I think this should work no matter the number of cards or creature cards found. The only changes I made were to add the local variable Index and to replace certain instances of j with Index. It increments on every valid card and decrements on ever valid non-creature card. Not sure if this is what he was trying to suggest, but it's worth a shot.volrathxp wrote:That makes sense. How do I deal with the separate index variable? I'm not sure how to do that part. The i*3+j thing I get.RiiakShiNal wrote:Instead of using "j+i" you should use "(i * 3) + j". When you are using nested loops to fill a single dimensional array or list the other loop index needs to be multiplied by the inner loop max count to avoid overlap. So in your example for player 0 you would get (0*3)+j or indices 0, 1, 2 while for player 1 you would get (1*3)+j or indices 3, 4, 5, etc....
Now if you need to eliminate nil entries then you will need to maintain a separate index variable to keep track of the current index and whenever you add to the single dimensional array or list you add one to the index variable to prevent overlap. This is probably the approach you will need to take since you are not always guaranteed to find 3 cards (for example a player only has 2 cards left in his/her library due to mill effects).
- Code: Select all
<RESOLUTION_TIME_ACTION>
local answerDC = EffectDC():Make_Targets(0)
local queryDC = EffectDC():Make_Chest(1)
local Index = 0
for i=0,MTG():GetNumberOfPlayers()-1 do
local player = MTG():GetNthPlayer(i)
if player ~= nil then
for j=0,(3-1) do
local card = player:Library_GetNth(j)
if card ~= nil then
queryDC:Set_CardPtr(Index, card)
queryDC:Protect_CardPtr(Index)
if card:GetCardType():Test(CARD_TYPE_CREATURE) == false then
queryDC:QueryUnselect_CardPtr(Index)
Index = Index - 1
end
card:PutInGraveyard()
Index = Index + 1
else
break
end
end
end
end
EffectController():SetItemCount(2)
for n=0,(2-1) do
EffectController():SetItemPrompt(n, "CARD_QUERY_CHOOSE_CREATURE_TO_EXILE")
end
EffectController():ChooseItemsFromDC( queryDC, answerDC, QUERY_FLAG_UP_TO )
</RESOLUTION_TIME_ACTION>
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
-
Xander9009 - Programmer
- Posts: 2905
- Joined: 29 Jun 2013, 07:44
- Location: Indiana, United States
- Has thanked: 121 times
- Been thanked: 445 times
Re: Help with Stitcher Geralf
by volrathxp » 09 Nov 2014, 19:45
Yup. This is where I ended up with it. I'm gonna test and see how it goes.Xander9009 wrote:I think I might have misunderstood what Riiak was saying, nonetheless, I think this should work no matter the number of cards or creature cards found. The only changes I made were to add the local variable Index and to replace certain instances of j with Index. It increments on every valid card and decrements on ever valid non-creature card. Not sure if this is what he was trying to suggest, but it's worth a shot.volrathxp wrote:That makes sense. How do I deal with the separate index variable? I'm not sure how to do that part. The i*3+j thing I get.RiiakShiNal wrote:Instead of using "j+i" you should use "(i * 3) + j". When you are using nested loops to fill a single dimensional array or list the other loop index needs to be multiplied by the inner loop max count to avoid overlap. So in your example for player 0 you would get (0*3)+j or indices 0, 1, 2 while for player 1 you would get (1*3)+j or indices 3, 4, 5, etc....
Now if you need to eliminate nil entries then you will need to maintain a separate index variable to keep track of the current index and whenever you add to the single dimensional array or list you add one to the index variable to prevent overlap. This is probably the approach you will need to take since you are not always guaranteed to find 3 cards (for example a player only has 2 cards left in his/her library due to mill effects).
- Code: Select all
<RESOLUTION_TIME_ACTION>
local answerDC = EffectDC():Make_Targets(0)
local queryDC = EffectDC():Make_Chest(1)
local Index = 0
for i=0,MTG():GetNumberOfPlayers()-1 do
local player = MTG():GetNthPlayer(i)
if player ~= nil then
for j=0,(3-1) do
local card = player:Library_GetNth(j)
if card ~= nil then
queryDC:Set_CardPtr(Index, card)
queryDC:Protect_CardPtr(Index)
if card:GetCardType():Test(CARD_TYPE_CREATURE) == false then
queryDC:QueryUnselect_CardPtr(Index)
Index = Index - 1
end
card:PutInGraveyard()
Index = Index + 1
else
break
end
end
end
end
EffectController():SetItemCount(2)
for n=0,(2-1) do
EffectController():SetItemPrompt(n, "CARD_QUERY_CHOOSE_CREATURE_TO_EXILE")
end
EffectController():ChooseItemsFromDC( queryDC, answerDC, QUERY_FLAG_UP_TO )
</RESOLUTION_TIME_ACTION>
volrathxp
Re: Help with Stitcher Geralf
by RiiakShiNal » 10 Nov 2014, 11:52
What you have could work, but it makes things unnecessarily complex. You should never decrement a separate incrementing index (only increment it when you actually need to add something).
- Code: Select all
<RESOLUTION_TIME_ACTION>
local answerDC = EffectDC():Make_Targets(0)
local queryDC = EffectDC():Make_Chest(1)
local Index = 0
for i=0,MTG():GetNumberOfPlayers()-1 do
local player = MTG():GetNthPlayer(i)
if player ~= nil then
for j=0,(3-1) do
local card = player:Library_GetNth(j)
if card ~= nil then
if card:GetCardType():Test(CARD_TYPE_CREATURE) then
queryDC:Set_CardPtr(Index, card)
queryDC:Protect_CardPtr(Index)
Index = Index + 1
end
card:PutInGraveyard()
else
break
end
end
end
end
EffectController():SetItemCount(2)
for n=0,(2-1) do
EffectController():SetItemPrompt(n, "CARD_QUERY_CHOOSE_CREATURE_TO_EXILE")
end
EffectController():ChooseItemsFromDC( queryDC, answerDC, QUERY_FLAG_UP_TO )
</RESOLUTION_TIME_ACTION>
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: Help with Stitcher Geralf
by volrathxp » 10 Nov 2014, 12:25
That makes a lot more sense. Thanks for the clarification!RiiakShiNal wrote:What you have could work, but it makes things unnecessarily complex. You should never decrement a separate incrementing index (only increment it when you actually need to add something).
- Code: Select all
<RESOLUTION_TIME_ACTION>
local answerDC = EffectDC():Make_Targets(0)
local queryDC = EffectDC():Make_Chest(1)
local Index = 0
for i=0,MTG():GetNumberOfPlayers()-1 do
local player = MTG():GetNthPlayer(i)
if player ~= nil then
for j=0,(3-1) do
local card = player:Library_GetNth(j)
if card ~= nil then
if card:GetCardType():Test(CARD_TYPE_CREATURE) then
queryDC:Set_CardPtr(Index, card)
queryDC:Protect_CardPtr(Index)
Index = Index + 1
end
card:PutInGraveyard()
else
break
end
end
end
end
EffectController():SetItemCount(2)
for n=0,(2-1) do
EffectController():SetItemPrompt(n, "CARD_QUERY_CHOOSE_CREATURE_TO_EXILE")
end
EffectController():ChooseItemsFromDC( queryDC, answerDC, QUERY_FLAG_UP_TO )
</RESOLUTION_TIME_ACTION>
volrathxp
Re: Help with Stitcher Geralf
by Xander9009 » 10 Nov 2014, 13:59
I was under the impression there was a particular reason it was removing the cards after adding them rather than only adding valid ones. I actually thought to have it like you mention but I decided against it because I didn't know what that reason was (there apparently wasn't any particular reason). Anyway, why shouldn't you decrement an index like that?RiiakShiNal wrote:What you have could work, but it makes things unnecessarily complex. You should never decrement a separate incrementing index (only increment it when you actually need to add something).
- Code: Select all
<RESOLUTION_TIME_ACTION>
local answerDC = EffectDC():Make_Targets(0)
local queryDC = EffectDC():Make_Chest(1)
local Index = 0
for i=0,MTG():GetNumberOfPlayers()-1 do
local player = MTG():GetNthPlayer(i)
if player ~= nil then
for j=0,(3-1) do
local card = player:Library_GetNth(j)
if card ~= nil then
if card:GetCardType():Test(CARD_TYPE_CREATURE) then
queryDC:Set_CardPtr(Index, card)
queryDC:Protect_CardPtr(Index)
Index = Index + 1
end
card:PutInGraveyard()
else
break
end
end
end
end
EffectController():SetItemCount(2)
for n=0,(2-1) do
EffectController():SetItemPrompt(n, "CARD_QUERY_CHOOSE_CREATURE_TO_EXILE")
end
EffectController():ChooseItemsFromDC( queryDC, answerDC, QUERY_FLAG_UP_TO )
</RESOLUTION_TIME_ACTION>
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
-
Xander9009 - Programmer
- Posts: 2905
- Joined: 29 Jun 2013, 07:44
- Location: Indiana, United States
- Has thanked: 121 times
- Been thanked: 445 times
Re: Help with Stitcher Geralf
by RiiakShiNal » 11 Nov 2014, 00:24
The main reason you don't want to decrement a variable that only needs to be incremented is because it's much easier to make a mistake and if you do make a mistake in decrementing you could decrement too much and remove the valid results. For example if you decrement without an associated increment then if you have 1 valid and 2 invalid you have wiped out the valid and could even go negative (off-by-1 and missed line problems are very common when programming).Xander9009 wrote:I was under the impression there was a particular reason it was removing the cards after adding them rather than only adding valid ones. I actually thought to have it like you mention but I decided against it because I didn't know what that reason was (there apparently wasn't any particular reason). Anyway, why shouldn't you decrement an index like that?
Personally, I am an avid believer in the KISS principle and I apply it to my code whenever I can. KISS = Keep It Simple, Stupid. Those who utilize the KISS principle usually write better, cleaner code with fewer bugs than those who don't use it. Normally it would be rude to have the "Stupid" part there, but since it is usually used in self-reference it's a good moniker to keep yourself in check because if you think about using a complex solution and then think KISS it makes stop and consider if the complex solution is actually necessary or if maybe there is a simpler one.
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: Help with Stitcher Geralf
by Xander9009 » 11 Nov 2014, 01:06
So it's just for cleanliness and simplicity of code, okay. It sounded like there was something that wasn't going to work. Like I said, I only did it that way because I didn't know if there was a reason it was removing the invalid cards instead of only adding the valid ones. As it was coded, decrementing was the best way to go; though, yes, I agree that since there wasn't a reason for it, only adding the valid cards is obviously best.RiiakShiNal wrote:The main reason you don't want to decrement a variable that only needs to be incremented is because it's much easier to make a mistake and if you do make a mistake in decrementing you could decrement too much and remove the valid results. For example if you decrement without an associated increment then if you have 1 valid and 2 invalid you have wiped out the valid and could even go negative (off-by-1 and missed line problems are very common when programming).Xander9009 wrote:I was under the impression there was a particular reason it was removing the cards after adding them rather than only adding valid ones. I actually thought to have it like you mention but I decided against it because I didn't know what that reason was (there apparently wasn't any particular reason). Anyway, why shouldn't you decrement an index like that?
Personally, I am an avid believer in the KISS principle and I apply it to my code whenever I can. KISS = Keep It Simple, Stupid. Those who utilize the KISS principle usually write better, cleaner code with fewer bugs than those who don't use it. Normally it would be rude to have the "Stupid" part there, but since it is usually used in self-reference it's a good moniker to keep yourself in check because if you think about using a complex solution and then think KISS it makes stop and consider if the complex solution is actually necessary or if maybe there is a simpler one.
And I'm well aware of the KISS mnemonic. It's one of my father's favorites and he's happy to let me know every time he sees me not following it haha.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
-
Xander9009 - Programmer
- Posts: 2905
- Joined: 29 Jun 2013, 07:44
- Location: Indiana, United States
- Has thanked: 121 times
- Been thanked: 445 times
Re: Help with Stitcher Geralf
by volrathxp » 11 Nov 2014, 01:14
Just an fyi that with the changes RSN suggested, Geralf works like a dream.
volrathxp
Re: Help with Stitcher Geralf
by Kithkin » 11 Nov 2014, 09:51
Is there a ALL YOU ZOMBIES deck with Geralf and Gisa in the making?volrathxp wrote:Just an fyi that with the changes RSN suggested, Geralf works like a dream.
-
Kithkin - Posts: 456
- Joined: 21 Feb 2014, 07:12
- Location: Cologne, GERMANY
- Has thanked: 11 times
- Been thanked: 56 times
Re: Help with Stitcher Geralf
by volrathxp » 11 Nov 2014, 11:55
It's actually currently a UB Tokens deck, but eventually I'll get around to a zombie-centric build.Kithkin wrote:Is there a ALL YOU ZOMBIES deck with Geralf and Gisa in the making?volrathxp wrote:Just an fyi that with the changes RSN suggested, Geralf works like a dream.
volrathxp
25 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 8 guests