Exemple #1
0
    // sets up the final stage of a quest for this CPU player, in this strategy:
    // we need to get 40BP in as few cards as possible
    public List <Card> setUpFinalFoe(List <Card> hand, string questFoe)
    {
        strategyUtil strat = new strategyUtil();

        // instantiate a List of foes and weapons from the user's hand
        List <Card> foes    = new List <Card>();
        List <Card> weapons = new List <Card>();

        // seperate the foes and weapons into their own lists from the hand
        for (var i = 0; i < hand.Count; i++)
        {
            if (hand[i].type == "Foe Card")
            {
                foes.Add(hand[i]);
            }
            // make sure that we sort out weapons that are already in the weapons
            if (hand[i].type == "Weapon Card" && strat.checkDuplicate(hand[i], weapons, "Weapon Card"))
            {
                weapons.Add(hand[i]);
            }
        }
        foes    = strat.sortFoesByDescendingOrder(foes, questFoe);
        weapons = strat.sortWeaponsByDescendingOrder(weapons);

        // instantiate the foeEncounter list
        List <Card> foeEncounter = new List <Card>();

        // subtract the foe with the MOST BP in the user's hand from 40, the AI threshold
        FoeCard strongFoe = (FoeCard)foes[0];
        int     bpNeeded  = (40 - strongFoe.minBP);

        // Add this foe to the foeEncounter as the foe to be played
        foeEncounter.Add(foes[0]);
        hand.Remove(foes[0]);

        // initialize index as 0 to loop through the weapons
        int index = 0;

        // while we still need BP toreach our 40 threshold
        while (bpNeeded > 0 && index < weapons.Count)
        {
            // if we still have weapons to loop through
            // subtract the BP of the next most powerful weapon from the threshold
            WeaponCard nextWeapon = (WeaponCard)weapons[index];
            bpNeeded -= nextWeapon.battlePoints;
            // add this weapon to the encounter
            foeEncounter.Add(weapons[index]);
            hand.Remove(weapons[index]);
            // increment index
            index++;
        }

        // return the most powerful foe we have with the set of weapons that most quickly gets us to 40 BP.
        return(foeEncounter);
    }