package cfvbaibai.cardfantasy.engine;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import cfvbaibai.cardfantasy.CardFantasyRuntimeException;
import cfvbaibai.cardfantasy.Randomizer;
import cfvbaibai.cardfantasy.data.Race;

public class Deck extends CardPile {

    public Deck(Collection <CardInfo> cards) {
        List <CardInfo> cloned = new ArrayList<CardInfo>(cards);
        this.getCards().addAll(cloned);
    }
    
    public boolean isEmpty() {
        return this.getCards().isEmpty();
    }

    public CardInfo draw() {
        if (this.getCards().isEmpty()) {
            return null;
        }
        return this.getCards().remove(0);
    }
    
    public void removeCard(CardInfo card) {
        if (!this.getCards().remove(card)) {
            throw new CardFantasyRuntimeException("Cannot find card in deck: " + card.getShortDesc());
        }
    }
    
    public void shuffle() {
        Randomizer.getRandomizer().shuffle(this.getCards());
        List<CardInfo> bosses = new ArrayList<CardInfo>();
        for (CardInfo card : this.getCards()) {
            if (card.getRace() == Race.BOSS) {
                bosses.add(card);
            }
        }
        for (CardInfo boss : bosses) {
            this.getCards().remove(boss);
            this.getCards().add(0, boss);
        }
    }
}

@@ -215,48 +215,8 @@
 zer;
-%0Aimport cfvbaibai.cardfantasy.data.Race;
 %0A%0Apu
@@ -958,353 +958,8 @@
 ));%0A
-        List%3CCardInfo%3E bosses = new ArrayList%3CCardInfo%3E();%0A        for (CardInfo card : this.getCards()) %7B%0A            if (card.getRace() == Race.BOSS) %7B%0A                bosses.add(card);%0A            %7D%0A        %7D%0A        for (CardInfo boss : bosses) %7B%0A            this.getCards().remove(boss);%0A            this.getCards().add(0, boss);%0A        %7D%0A
     

Fix deck sorting issue in boss battle