It is currently 07 May 2024, 12:03
   
Text Size

Help with Stitcher Geralf

Moderator: CCGHQ Admins

Re: Help with Stitcher Geralf

Postby Xander9009 » 09 Nov 2014, 19:38

volrathxp wrote:
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).
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.
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.
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
User avatar
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

Postby volrathxp » 09 Nov 2014, 19:45

Xander9009 wrote:
volrathxp wrote:
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).
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.
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.
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>
Yup. This is where I ended up with it. I'm gonna test and see how it goes.
volrathxp
User avatar
volrathxp
 
Posts: 362
Joined: 23 Jul 2014, 17:34
Has thanked: 9 times
Been thanked: 17 times

Re: Help with Stitcher Geralf

Postby 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>
RiiakShiNal
Programmer
 
Posts: 2185
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: Help with Stitcher Geralf

Postby volrathxp » 10 Nov 2014, 12:25

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>
That makes a lot more sense. Thanks for the clarification!
volrathxp
User avatar
volrathxp
 
Posts: 362
Joined: 23 Jul 2014, 17:34
Has thanked: 9 times
Been thanked: 17 times

Re: Help with Stitcher Geralf

Postby Xander9009 » 10 Nov 2014, 13:59

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>
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?
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
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

Postby RiiakShiNal » 11 Nov 2014, 00:24

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?
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).

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.
RiiakShiNal
Programmer
 
Posts: 2185
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: Help with Stitcher Geralf

Postby Xander9009 » 11 Nov 2014, 01:06

RiiakShiNal wrote:
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?
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).

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

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

Postby volrathxp » 11 Nov 2014, 01:14

Just an fyi that with the changes RSN suggested, Geralf works like a dream.
volrathxp
User avatar
volrathxp
 
Posts: 362
Joined: 23 Jul 2014, 17:34
Has thanked: 9 times
Been thanked: 17 times

Re: Help with Stitcher Geralf

Postby Kithkin » 11 Nov 2014, 09:51

volrathxp wrote:Just an fyi that with the changes RSN suggested, Geralf works like a dream.
Is there a {U} {B} ALL YOU ZOMBIES deck with Geralf and Gisa in the making? :twisted:
User avatar
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

Postby volrathxp » 11 Nov 2014, 11:55

Kithkin wrote:
volrathxp wrote:Just an fyi that with the changes RSN suggested, Geralf works like a dream.
Is there a {U} {B} ALL YOU ZOMBIES deck with Geralf and Gisa in the making? :twisted:
It's actually currently a UB Tokens deck, but eventually I'll get around to a zombie-centric build.
volrathxp
User avatar
volrathxp
 
Posts: 362
Joined: 23 Jul 2014, 17:34
Has thanked: 9 times
Been thanked: 17 times

Previous

Return to Programming Talk

Who is online

Users browsing this forum: No registered users and 8 guests


Who is online

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

Login Form