It is currently 11 Sep 2025, 18:53
   
Text Size

living death

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

living death

Postby zen » 20 Feb 2010, 12:49

any ideas on why this infinite loops?
must be the iterators in the while, but I'm not sure why they aren't working properly


Code: Select all

    //********************Start********Start***********************
    else if(cardName.equals("Living Death"))
    {
       final SpellAbility spell = new Spell(card)
       {
          private static final long serialVersionUID = -7657135492744579098L;
          
          
          public void resolve()
          {   //grab make 4 creature lists: human_play, human_graveyard, computer_play, computer_graveyard
             CardList human_play = new CardList();
             human_play.addAll(AllZone.Human_Play.getCards());
             human_play = human_play.filter(new CardListFilter()
             {
                public boolean addCard(Card c) { return c.isCreature(); }
             });
             CardList human_graveyard = new CardList();
             human_graveyard.addAll(AllZone.Human_Graveyard.getCards());
             human_graveyard = human_graveyard.filter(new CardListFilter()
             {
                public boolean addCard(Card c) { return c.isCreature(); }
             });
             CardList computer_play = new CardList();
             computer_play.addAll(AllZone.Computer_Play.getCards());
             computer_play = computer_play.filter(new CardListFilter()
             {
                public boolean addCard(Card c) { return c.isCreature(); }
             });
             CardList computer_graveyard = new CardList();
             computer_graveyard.addAll(AllZone.Human_Graveyard.getCards());
             computer_graveyard = computer_graveyard.filter(new CardListFilter()
             {
                public boolean addCard(Card c) { return c.isCreature(); }
             });
             
             while(human_play.iterator().hasNext())
             { AllZone.Human_Play.remove(human_play.iterator().next()); }
             while(human_play.iterator().hasNext())
             { AllZone.Human_Graveyard.add(human_play.iterator().next()); }
             
             while(human_graveyard.iterator().hasNext())
             {AllZone.Human_Graveyard.remove(human_graveyard.iterator().next());}
             while(human_graveyard.iterator().hasNext())
             { AllZone.Human_Play.add(human_graveyard.iterator().next()); }
             
             while(computer_play.iterator().hasNext())
             { AllZone.Computer_Play.remove(computer_play.iterator().next()); }
             while(computer_play.iterator().hasNext())
             { AllZone.Computer_Graveyard.add(computer_play.iterator().next()); }
             
             while(computer_graveyard.iterator().hasNext())
             {AllZone.Computer_Graveyard.remove(computer_graveyard.iterator().next()); }
             while(computer_graveyard.iterator().hasNext())
             { AllZone.Computer_Play.add(computer_graveyard.iterator().next()); }
             
          }//resolve
       };//spellability
       card.clearSpellAbility();
        card.addSpellAbility(spell);
     }//*********************END**********END***********************

thanks
zen
 
Posts: 27
Joined: 13 Feb 2010, 19:21
Has thanked: 0 time
Been thanked: 0 time

Re: living death

Postby Snacko » 20 Feb 2010, 15:53

human_graveyard.iterator().hasNext()
You get a new iterator each time. So you "loop" the 1st element infinitely.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: living death

Postby zen » 21 Feb 2010, 00:46

thank you for that! sometimes i look so close at the code, i look right through it.
zen
 
Posts: 27
Joined: 13 Feb 2010, 19:21
Has thanked: 0 time
Been thanked: 0 time

Re: living death

Postby zen » 21 Feb 2010, 01:20

thanks again for the tip Snacko.
here's the code

Code: Select all
    //********************Start********Start***********************
    else if(cardName.equals("Living Death"))
    {
       final SpellAbility spell = new Spell(card)
       {
          private static final long serialVersionUID = -7657135492744579098L;
          
          
          public void resolve()
          {   //grab make 4 creature lists: human_play, human_graveyard, computer_play, computer_graveyard
             CardList human_play = new CardList();
             human_play.addAll(AllZone.Human_Play.getCards());
             human_play = human_play.filter(new CardListFilter()
             {
                public boolean addCard(Card c) { return c.isCreature(); }
             });
             CardList human_graveyard = new CardList();
             human_graveyard.addAll(AllZone.Human_Graveyard.getCards());
             human_graveyard = human_graveyard.filter(new CardListFilter()
             {
                public boolean addCard(Card c) { return c.isCreature(); }
             });
             CardList computer_play = new CardList();
             computer_play.addAll(AllZone.Computer_Play.getCards());
             computer_play = computer_play.filter(new CardListFilter()
             {
                public boolean addCard(Card c) { return c.isCreature(); }
             });
             CardList computer_graveyard = new CardList();
             computer_graveyard.addAll(AllZone.Computer_Graveyard.getCards());
             computer_graveyard = computer_graveyard.filter(new CardListFilter()
             {
                public boolean addCard(Card c) { return c.isCreature(); }
             });
                       
             Card c = new Card();
             Iterator<Card> it = human_play.iterator();
             while(it.hasNext())
             {
                c = it.next();
                AllZone.GameAction.moveTo(AllZone.Human_Play,c);
                AllZone.GameAction.moveTo(AllZone.Human_Graveyard,c);
             }
             
             it = human_graveyard.iterator();
             while(it.hasNext())
             {
                c = it.next();
                AllZone.GameAction.moveTo(AllZone.Human_Graveyard,c);
                AllZone.GameAction.moveTo(AllZone.Human_Play,c);
             }
             
             it = computer_play.iterator();
             while(it.hasNext())
             {
                c = it.next();
                AllZone.GameAction.moveTo(AllZone.Computer_Play,c);
                AllZone.GameAction.moveTo(AllZone.Computer_Graveyard,c);
             }
             
             it = computer_graveyard.iterator();
             while(it.hasNext())
             {
                c = it.next();
                AllZone.GameAction.moveTo(AllZone.Computer_Graveyard,c);
                AllZone.GameAction.moveTo(AllZone.Computer_Play,c);
             }
             
          }//resolve
       };//spellability
       card.clearSpellAbility();
        card.addSpellAbility(spell);
     }//*********************END**********END***********************
zen
 
Posts: 27
Joined: 13 Feb 2010, 19:21
Has thanked: 0 time
Been thanked: 0 time


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 36 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 36 users online :: 0 registered, 0 hidden and 36 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 36 guests

Login Form