living death
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
4 posts
• Page 1 of 1
living death
by 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
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***********************
- zen
- Posts: 27
- Joined: 13 Feb 2010, 19:21
- Has thanked: 0 time
- Been thanked: 0 time
Re: living death
by Snacko » 20 Feb 2010, 15:53
human_graveyard.iterator().hasNext()
You get a new iterator each time. So you "loop" the 1st element infinitely.
You get a new iterator each time. So you "loop" the 1st element infinitely.
Re: living death
by 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
by zen » 21 Feb 2010, 01:20
thanks again for the tip Snacko.
here's the code
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
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 31 guests