Fixing the infinite loop when sending state with unattached attached cards.
This commit is contained in:
@@ -175,29 +175,24 @@ public class GameState {
|
|||||||
for (Map.Entry<String, Integer> stringIntegerEntry : _playerPosition.entrySet())
|
for (Map.Entry<String, Integer> stringIntegerEntry : _playerPosition.entrySet())
|
||||||
listener.setPlayerPosition(stringIntegerEntry.getKey(), stringIntegerEntry.getValue());
|
listener.setPlayerPosition(stringIntegerEntry.getKey(), stringIntegerEntry.getValue());
|
||||||
|
|
||||||
|
Set<PhysicalCard> cardsLeftToSent = new HashSet<PhysicalCard>(_inPlay);
|
||||||
Set<PhysicalCard> sentCardsFromPlay = new HashSet<PhysicalCard>();
|
Set<PhysicalCard> sentCardsFromPlay = new HashSet<PhysicalCard>();
|
||||||
Set<PhysicalCard> attachedCardsToSend = new HashSet<PhysicalCard>();
|
|
||||||
|
|
||||||
// First non-attached cards
|
int passes = 4;
|
||||||
for (PhysicalCardImpl physicalCard : _inPlay) {
|
|
||||||
if (physicalCard.getAttachedTo() == null) {
|
|
||||||
listener.cardCreated(physicalCard);
|
|
||||||
sentCardsFromPlay.add(physicalCard);
|
|
||||||
} else
|
|
||||||
attachedCardsToSend.add(physicalCard);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now the attached ones
|
while (cardsLeftToSent.size() > 0 && passes > 0) {
|
||||||
while (!attachedCardsToSend.isEmpty()) {
|
Set<PhysicalCard> newCardsLeft = new HashSet<PhysicalCard>();
|
||||||
Iterator<PhysicalCard> iter = attachedCardsToSend.iterator();
|
for (PhysicalCard physicalCard : cardsLeftToSent) {
|
||||||
while (iter.hasNext()) {
|
PhysicalCard attachedTo = physicalCard.getAttachedTo();
|
||||||
PhysicalCard attachedCard = iter.next();
|
if (attachedTo == null || sentCardsFromPlay.contains(attachedTo)) {
|
||||||
if (sentCardsFromPlay.contains(attachedCard.getAttachedTo())) {
|
listener.cardCreated(physicalCard);
|
||||||
listener.cardCreated(attachedCard);
|
sentCardsFromPlay.add(physicalCard);
|
||||||
sentCardsFromPlay.add(attachedCard);
|
} else {
|
||||||
iter.remove();
|
newCardsLeft.add(physicalCard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
passes--;
|
||||||
|
cardsLeftToSent = newCardsLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally the stacked ones
|
// Finally the stacked ones
|
||||||
|
|||||||
Reference in New Issue
Block a user