Examples of CardSimList


Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

        c.blockerLands = vMatch.getLand((attacker+1)%2);
        int blockerHealth = vMatch.getLife((attacker+1)%2);
        CombatSimNew csim = new CombatSimNew(allAttackers, allBlockers, c, false);
        CombatFormation formation = csim.computeBestBlock(blockerHealth, Weighting.DEFAULT,0);

        CardSimList blockersUsed = new CardSimList();
       
        for (int i=0; i< formation.singleFights.size(); i++)
        {
            SingleFight sf = formation.singleFights.elementAt(i);
            for(int b=0; b<sf.blocker.size(); b++)
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

    {
        if ((undangeredAttackers_ != null) && (undangeredAttackers_.size() >0))
        {
            E.cconfig.blockerLands = vMatch.getLand((player+1)%2);
           
            CardSimList currentList = undangeredAttackers_.copyList();
            // b) undangeredAttackers
            //for (int i=currentList.size()-1; i >=0 ; i--)
            {
                CardSim at = currentList.getCard(0);
                currentList.remove(at);

                EAIPlanTree leaf;
                if (shorten.size() >= 0)
                {
                    // add one without this attacker
                    leaf  = new EAIPlanTree(this);
                    leafs.addElement(leaf);
                    leaf.buildUndangeredAttackers(currentList, shorten);
                }

                // add one WITH this attacker
                leaf  = new EAIPlanTree(this);
               
                leaf.leafExceuteOneAttackAction(at, null);
                leafs.addElement(leaf);
                leaf.buildUndangeredAttackers(currentList, shorten);
            }
            return;
        }
       
        // c) all other attackers
        // now build attacker variations with shorten!
        E.cconfig.attackers = shorten; // this is not correct -> but correct enough
        E.cconfig.attackerLands = vMatch.getLand(player);
        E.cconfig.blockerLands = vMatch.getLand((player+1)%2);

//        String eKey = shorten.toUHString();
//        eKey += vMatch.getBattlefield((player+1)%2).toUHString();
   
        // power!
        // smallest first
        Vector<CardSimList> powerAsc = new Vector<CardSimList>();
        Vector<CardSimList> powerDesc = new Vector<CardSimList>();
        Vector<CardSimList> toughAsc = new Vector<CardSimList>();
        Vector<CardSimList> toughDesc = new Vector<CardSimList>();
        CardSimList evaluate = null;
        int max = MAX_ATTACK_STEP;
        if (max == 0) max = 1000000;
       
        if (ATTACK_BY_POWER)
        {
            evaluate = (CardSimList) shorten.sortListByPower().clone();
            int step = max;
            if (step > evaluate.size()-1) step = evaluate.size()-1;
            step = evaluate.size()-1-step;
   
            if (ATTACK_BY_INCREASE)
            {
                // none and all are left out!
                for (int i=step; i< evaluate.size()-1; i++)
                {
                    CardSimList currentList = new CardSimList();
                    for (int ii=0; ii<=i; ii++)
                    {
                        currentList.addCard(evaluate.getCard(ii));
                    }
                    powerAsc.addElement(currentList);
                    currentList.info = "powerAsc";
                }
            }
            if (ATTACK_BY_DECREASE)
            {
                // none and all are left out!
                for (int i=step; i< evaluate.size()-1; i++)
                {
                    CardSimList currentList = new CardSimList();
                    for (int ii=0; ii<=i; ii++)
                    {
                        currentList.addCard(evaluate.getCard(evaluate.size()-1-ii));
                    }
                    powerDesc.addElement(currentList);
                    currentList.info = "powerDesc";
                }
            }
        }

        if (ATTACK_BY_TOUGHNESS)
        {
            evaluate = (CardSimList) shorten.sortListByToughness().clone();
            int step = max;
            if (step > evaluate.size()-1) step = evaluate.size()-1;
            step = evaluate.size()-1-step;


            if (ATTACK_BY_INCREASE)
            {
                // none and all are left out!
                for (int i=step; i< evaluate.size()-1; i++)
                {
                    CardSimList currentList = new CardSimList();
                    for (int ii=0; ii<=i; ii++)
                    {
                        currentList.addCard(evaluate.getCard(ii));
                    }
                    toughAsc.addElement(currentList);
                    currentList.info = "toughAsc";
                }
            }
            if (ATTACK_BY_DECREASE)
            {
                // none and all are left out!
                for (int i=step; i< evaluate.size()-1; i++)
                {
                    CardSimList currentList = new CardSimList();
                    for (int ii=0; ii<=i; ii++)
                    {
                        currentList.addCard(evaluate.getCard(evaluate.size()-1-ii));
                    }
                    toughDesc.addElement(currentList);
                    currentList.info = "DescAsc";
                }
            }
        }
        removeDoubleCombos(powerDesc, powerAsc);
       
        removeDoubleCombos(toughAsc, powerAsc);
        removeDoubleCombos(toughAsc, powerDesc);
       
        removeDoubleCombos(toughDesc, powerAsc);
        removeDoubleCombos(toughDesc, powerDesc);
        removeDoubleCombos(toughDesc, toughAsc);
       
        CardSimList all = shorten.copyList();
        all.info = "all";
        CardSimList none = new CardSimList();
        none.info = "none";
       
        Vector<CardSimList> allVariants = new Vector<CardSimList>();
        if (all.size() != 0)
            allVariants.addElement(none);
        allVariants.addElement(all);
        allVariants.addAll(powerAsc);
        allVariants.addAll(powerDesc);
        allVariants.addAll(toughAsc);
        allVariants.addAll(toughDesc);
       
        // todo remove not good scored sorted variants
        for (int i=0; i<allVariants.size(); i++ )
        {
            EAIPlanTree leaf  = new EAIPlanTree(this);
            leafs.addElement(leaf);
            CardSimList attackers = allVariants.elementAt(i);
            for (int ii=0; ii< attackers.size(); ii++)
            {
                CardSim at = attackers.getCard(ii);
                leaf.leafExceuteOneAttackAction(at, null);
            }
            leaf.attackInfo = attackers.info;
        }       
    }
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

   
    void removeDoubleCombos(Vector<CardSimList> removeFrom, Vector<CardSimList> toCheck)
    {
        for (int i=removeFrom.size()-1;i>=0; i--)
        {
            CardSimList check = removeFrom.elementAt(i);
            if (isComboIn(check, toCheck))
            {
                removeFrom.removeElementAt(i);
            }
        }
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

    boolean isComboIn(CardSimList list, Vector<CardSimList> toCheck)
    {
        boolean ret = false;
        for (int i=0; i< toCheck.size(); i++)
        {
            CardSimList checkList = toCheck.elementAt(i);
            if (checkList.isEqualUnsorted(list))
            {
                return true;
            }
        }
        return ret;
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

                EAIPlanTree leaf = new EAIPlanTree(this, false);
                leafs.addElement(leaf);
               
                // opponent: activate cards that are in battlefield -> like kings assassin!
                ManaCollection possibleMana = EAIHelper.getMaxAvailableMana(vMatch, opponent);
                CardSimList possibleActivateableCards = vMatch.getBattlefield(opponent);
                possibleActivateableCards = EAIHelper.onlyAllowedToActivate(possibleActivateableCards, currentPhase, true, vMatch);
                possibleActivateableCards = EAIHelper.onlyUntappedToActivate(possibleActivateableCards);

                Vector<CardAndMana> _cam = new Vector<CardAndMana>();
                for(int c=0; c< possibleActivateableCards.size(); c++)
                {
                    CardSim card = possibleActivateableCards.getCard(c);
                    ManaCollection cost = ManaCollection.getActivateCost(card);
                   
                    // TODO: hack for kicker prevention
                    //
                    if (!card.getCard().isKicker())
                        if (possibleMana.isCostFit(cost))
                        {
                            _cam.addElement(new CardAndMana(CardAndMana.CAM_ACTIVATE , card, cost));
                            possibleMana = possibleMana.subMana(cost);
                        }
                }

                // cams ready, now -> targets! (one)
                for (int i = _cam.size()-1; i >= 0; i--)
                {
                    CardAndMana cam = _cam.elementAt(i);
                    AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(cam.card);
                    Vector<EAIAction> sources = createOneOpponentSource(cam, hints); // at least one empty target! or null -> must targets not available!
                    if (sources == null)
                    {
                        continue;
                    }
                    Vector<EAIAction> targets = createOneOpponentTarget(cam, hints)// at least one empty target! or null -> must targets not available!
                    if (targets == null)
                    {
                        continue;
                    }
                    Vector<EAIAction> target = joinSourceAndTarget(sources, targets);
                    boolean successfull = leaf.leafExceuteOneAction(cam, target, opponent, camListBefor(_cam, i));
                }
            }
            else if(currentPhase == MatchConstants.PHASE_COMBAT_DECLARE_ATTACKERS)
            {
                if (mDoStacking)
                {
                    // in stack I dont estimate opponents attackers
                    EAIPlanTree leaf = new EAIPlanTree(this, false); // try out
                    leafs.addElement(leaf);
                    return;
                }

                // opponent: activate cards that are in battlefield

                // todo build best attacking opponent can do
                // which would be the worst case scenario
                // doing an ALL OUT attack :-)
                // therefor only that option is to be tested
                // "Phew" - no explosion of choices here!

//System.out.println("Try declaring attackers of other AI!");
                // generate instant, activations

                // generate instant, activations
                // after that create all possible attackers

                // create permutations
                // possibly reuse same in different leafs (not known from here,
                // other leafs are in parent - caching and cloning?

                // now for each leaf all attack possibilities

                // dummy as long as above is not implemented
                // allways add a empty leaf
                EAIPlanTree leaf = new EAIPlanTree(this, false);

                // opponent: activate cards that are in battlefield -> like kings assassin!
                ManaCollection possibleMana = EAIHelper.getMaxAvailableMana(vMatch, opponent);
                CardSimList possibleActivateableCards = vMatch.getBattlefield(opponent);
                possibleActivateableCards = EAIHelper.onlyAllowedToActivate(possibleActivateableCards, currentPhase, true, vMatch);
                possibleActivateableCards = EAIHelper.onlyUntappedToActivate(possibleActivateableCards);

                CardSimList activated = new CardSimList();
               
                Vector<CardAndMana> _cam = new Vector<CardAndMana>();
                for(int c=0; c< possibleActivateableCards.size(); c++)
                {
                    CardSim card = possibleActivateableCards.getCard(c);
                    ManaCollection cost = ManaCollection.getActivateCost(card);
                    if (possibleMana.isCostFit(cost))
                    {
                        _cam.addElement(new CardAndMana(CardAndMana.CAM_ACTIVATE , card, cost));
                        possibleMana = possibleMana.subMana(cost);
                    }
                }

                // cams ready, now -> targets! (one)
                for (int i = _cam.size()-1; i >= 0; i--)
                {
                    CardAndMana cam = _cam.elementAt(i);
                    AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(cam.card);
                    Vector<EAIAction> sources = createOneOpponentSource(cam, hints); // at least one empty target! or null -> must targets not available!
                    if (sources == null)
                    {
                        continue;
                    }
                    Vector<EAIAction> targets = createOneOpponentTarget(cam, hints)// at least one empty target! or null -> must targets not available!
                    if (targets == null)
                    {
                        continue;
                    }
                    Vector<EAIAction> target = joinSourceAndTarget(sources, targets);
                    boolean successfull = leaf.leafExceuteOneAction(cam, target, opponent, camListBefor(_cam, i));
                    activated.addCard(cam.card);
                }

                leafs.addElement(leaf);

                int no = 0;
                for (int i = 0; i < leafs.size(); i++)
                {
                    leaf = leafs.elementAt(i);
                    CardSimList possibleAttackers = leaf.vMatch.getPossibleAttackers();
                    possibleAttackers.removeListDirect(activated);
    //public CombatFormation computeBestAttack(Weighting weighting, int attackerHealth, int blockerHealth, CardSimList notHereEvaluatedAttackers, CardSimList externalRemovedAttackers, CardSimList allBlockers)

           
                    CombatSimConfig c = new CombatSimConfig(E.aiPlayer);
                    c.attackers = possibleAttackers;
                    c.attackerLands = vMatch.getLand(opponent);
                    c.blockerLands = vMatch.getLand(player);
                    CardSimList blocker = vMatch.getBattlefield(player).getSubListByType("Creature");
                    blocker = blocker.removeActivateable();
                    //blocker = vMatch.removeAllreadyBlocking(blocker);
                    blocker = blocker.onlyTapstate(false);

                    CombatSimNew csim = new CombatSimNew(possibleAttackers, blocker, c, false);
                    int blockerHealth = vMatch.getLife(player);

                    // TEST new Attacking!
                    CombatFormation attackFormation = csim.computeBestAttack(Weighting.DEFAULT, blockerHealth);

                    for (int a=0; a< attackFormation.singleFights.size(); a++)
                    {
                        CardSim at = attackFormation.singleFights.elementAt(a).attacker;
                        EAIAction attack = EAIAction.createDeclareAttackerAction(no++, at);

                        boolean success = leaf.vMatch.executeAction(attack, opponent, false);
                        if (success)
                        {
                            leaf.addAction(currentPhaseExtended, attack);
                            String key = EnhancedAI.generateCurrentVMatchKey(leaf.vMatch, player);
                            attack.setVMatchKeyAfter(key);
                        }
                    }

                    /*
                    // old -> all out attack
                    for (int a=0; a< possibleAttackers.size(); a++)
                    {
                        CardSim at = possibleAttackers.getCard(a);
                        EAIAction attack = EAIAction.createDeclareAttackerAction(no++, at);

                        boolean success = leaf.vMatch.executeAction(attack, opponent, false);
                        if (success)
                        {
                            leaf.addAction(currentPhaseExtended, attack);
                            String key = EnhancedAI.generateCurrentVMatchKey(leaf.vMatch, player);
                            attack.setVMatchKeyAfter(key);
                        }
                    }
                    *
                    */
                }
               
                flatten();

            }
            else if (currentPhase == MatchConstants.PHASE_COMBAT_DECLARE_BLOCKERS)
            {
                // todo build best blocking for ourselfs to block oppoents attack
//System.out.println("Try declaring blockers!");


                // do nothing if there is nothing to block!
                // stupid thing wants to play giant growth on no attacket!

                // here we come for each of our own attacker definitions
                // in order to simulate the game
                // here we get a best guess - of our opponents bloking actions

                // sets all corresponding actions!

                // generate instant, activations
                // after that create all possible attackers
                futurePrePlan.addAll(generatePossibleActionsGeneral(true, null));

                // rod of ruin
                buildLeafs(futurePrePlan);
                if (leafs.isEmpty())
                {
                    EAIPlanTree leaf = new EAIPlanTree(this, false); // try out
                    leafs.addElement(leaf);
                }
                flattenNoScore();
                // create permutations
                // possibly reuse same in different leafs (not known from here,
                // other leafs are in parent - caching and cloning?

                // now for each leaf all attack possibilities

                // Todo: for now opponent strategy!
                int opponentBlockStrategy = E.aiPlayer.getEAIConfig().getOpponentBlockStrategy();
                if (E.aiPlayer.getEAIConfig().getOpponentAdaptiveBlocking())
                {
                    int life = vMatch.getLife(player);
                    int maxDamage = EAIHelper.getPowerSum(vMatch.getAttacker());

                    if (life <= maxDamage+E.aiPlayer.getEAIConfig().getSavetyHealthThreshold())
                        opponentBlockStrategy = BLOCK_PLAYER_LEAST_DAMAGE;
                    else
                        opponentBlockStrategy = BLOCK_PLAYER_LEAST_CREATURE_DEAD;
                }
                generatePlayerBlockerActions(opponentBlockStrategy); // for now!
            }
            else if (currentPhase == MatchConstants.PHASE_COMBAT_END)
            {
                if (UID == 7325)
                    System.out.println("Buh!");
                vMatch.doCombat((player+1)%2);
            }

            if (leafs.isEmpty())
            {
                EAIPlanTree leaf = new EAIPlanTree(this, false); // try out
                leafs.addElement(leaf);
            }
            return;
        }
        if (currentPhase == MatchConstants.PHASE_BEGINNING_UNTAP)
        {
            CACHEHIT = false;
            int actionCounter = 0;
            Vector<CardAndMana> willBeActions = new Vector<CardAndMana>();
            Vector<CardAndMana> futurePlanWithoutActions = new Vector<CardAndMana>();

            CardSimList lands = vMatch.getLand(E.pNumber);
            CardSimList creatures = vMatch.getBattlefield(E.pNumber);
            Vector ls = lands.getCards();
            for (int i = 0; i < ls.size(); i++)
            {
                CardSim card = (CardSim) ls.elementAt(i);
                if (card.isTapped())
                {
                    CardAndMana untapLand = new CardAndMana(CardAndMana.CAM_UNTAP,card, null);
                    willBeActions.add(untapLand);
                }
            }
            Vector cs = creatures.getCards();
            for (int i = 0; i < cs.size(); i++)
            {
                CardSim card = (CardSim) cs.elementAt(i);
                if (card.isTapped())
                {
                    CardAndMana untapCreature = new CardAndMana(CardAndMana.CAM_UNTAP,card, null);
                    willBeActions.add(untapCreature);
                }
            }

            if (willBeActions.isEmpty())
            {
                // will allways be empty if nextRound() by match was played
                // sincew vmatch resets all tapped items on newRound()!
                EAIPlanTree leaf = new EAIPlanTree(this, false);
                leafs.addElement(leaf);
                return;
            }

            EAIPlanTree leaf = new EAIPlanTree(this);
            leaf.futurePrePlan = futurePlanWithoutActions;
            while (!willBeActions.isEmpty())
            {
                CardAndMana cam = willBeActions.elementAt(0);
                willBeActions.removeElement(cam);
                boolean reEvaluate = leaf.leafExceuteOneAction(cam, new Vector<EAIAction>(), player, null); // no targets (as of yet) for untapping
            }
            leaf.playerScore = Weighting.DEFAULT.buildScore(leaf.getMatch(), player, false);
            leaf.opponentScore = Weighting.DEFAULT.buildScore(leaf.getMatch(), (player+1)%2, false);
            leaf.difScore = leaf.playerScore-leaf.opponentScore;
            leafs.addElement(leaf);
        }
        if (currentPhase == MatchConstants.PHASE_BEGINNING_DRAW)
        {
            EAIPlanTree leaf = new EAIPlanTree(this);
            leaf.vMatch.drawLibCardToHand(player);
            leafs.addElement(leaf);
        }
        else if(currentPhase == MatchConstants.PHASE_MAIN1)
        {
            futurePrePlan.addAll(generatePossibleActionsGeneral(true, null));
            // in future plan all possible playing cards / actions are ilsted
            // permutation of these are done in build leafs...

            buildLeafs(futurePrePlan);
        }
        else if(currentPhase == MatchConstants.PHASE_MAIN2)
        {
            futurePrePlan.addAll(generatePossibleActionsGeneral(true, null));
            buildLeafs(futurePrePlan);
        }
        else if (currentPhase == MatchConstants.PHASE_COMBAT_DECLARE_ATTACKERS)
        {
            // generate instant, activations
            // after that create all possible attackers
            futurePrePlan.addAll(generatePossibleActionsGeneral(true, null));
           
// 10572          
            buildLeafs(futurePrePlan);
            if (leafs.isEmpty())
            {
                EAIPlanTree leaf = new EAIPlanTree(this, false); // try out
                leafs.addElement(leaf);
            }
            flatten();
            // create permutations
            // possibly reuse same in different leafs (not known from here,
            // other leafs are in parent - caching and cloning?

            // now for each leaf all attack possibilities
            for (int i = 0; i < leafs.size(); i++)
            {
                EAIPlanTree leaf = leafs.elementAt(i);
                // attackers in respect to allready activated cards -> therefor in respect to leaf!
                CardSimList possibleAttackers = new CardSimList();
                CardSimList removedPossibleAttackers = new CardSimList();

                // removed possible attackers are interesting for blocking a re attack! (Evaluation)
                leaf.generatePossibleAttackers(E.pNumber, possibleAttackers, removedPossibleAttackers);

                // NOTICE:
                // general Attacking Hints (SELF - ONLY!) are applied in
                // SingleFight:  applyAttackingHints(CardSim at)
                // targetting attacking hints are applied here!

                /*
                 * look for attackers which inherently do something upon attack
                  e.g. Seasoned marshal.
                  Than build leaves for attack / no attack

                 */
                CardSimList tryAttackerList = new CardSimList();
                for (int t=possibleAttackers.size()-1; t>=0; t--)
                {
                    CardSim card = possibleAttackers.getCard(t);
                    AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(card);
                    if (hints == null) continue;
                    if (hints.hasKey(HintAll.HINT_SITUATION_ATTACKER))
                    {
                        if (EAIHelper.isRemoveHand(card, HintAll.HINT_SITUATION_ATTACKER))
                            continue;
                       
                        if (!hints.hasHint(HintAll.HINT_SITUATION_ATTACKER, HintAll.PA_NO_EXTERNAL_INFLUENCE))
                        {
                            tryAttackerList.addCard(card);
                            possibleAttackers.remove(card);
                        }
                    }
                }
                // what should be done is try
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

        int minTargets = EAIHelper.getMinSourceCount(cam.card, hints, key);
        int maxTargets = EAIHelper.getMaxSourceCount(cam.card, hints, key);

        // now generate possible "sources"
        boolean isHidden = vMatch.isLibraryHidden();
        CardSimList possibleCardTargets = vMatch.getSourceEffectedList(key, cam.card, E.pNumber, hints);
        if (isHidden)
            vMatch.hideLibrary();
       
       
        boolean rochade = hints.hasAnyHint(key, new HintBundle(HintSourceTypes.SY_LIBRARY_ROCHADE));
        if (rochade)
        {
            // assume we would like to switch only cards which are right now unplayable
            possibleCardTargets = EAIHelper.onlyNotEnoughManaGeneral(possibleCardTargets, vMatch.getLand(cam.card.getOwner()));
        }

        int good = EAIHelper.isGoodEffectCardSource(cam.card, key);
        if (E.aiPlayer.getEAIConfig().getDontDamageOwn())
        {
             if (good == -1) // BAD
             {
                 if (EAIHelper.cardTargetOpponentPossible(cam.card, key , true))
                 {
                    possibleCardTargets = EAIHelper.removeOwnerCards(possibleCardTargets, player);
                 }
             }
             else if (good == 1) // good
             {
                 if (EAIHelper.cardTargetPlayerPossible(cam.card, key , true))
                 {
                    possibleCardTargets = EAIHelper.removeOwnerCards(possibleCardTargets, (player+1)%2);
                 }
             }
        }



        if (possibleCardTargets.hasRealCards())
            possibleCardTargets = possibleCardTargets.removeDummies();
        Vector<Integer> possiblePlayerTargets = vMatch.getPlayerSourceEffectedList(key, cam.card, E.pNumber, hints);

        // searching thru the library would otherwise return the WHOLE library!
        // - > permutation overload!
        //possibleCardTargets = reduceEqualIDsToMax(possibleCardTargets, maxTargets);
        possibleCardTargets = reduceSameToMax(possibleCardTargets, maxTargets);
       
        int SOME_SENSIBLE_CHOSING_SIZE = LIBRARY_SEARCH_WIDTH;
        if (possibleCardTargets.size() > SOME_SENSIBLE_CHOSING_SIZE)
        {
            possibleCardTargets = reduceTargetToSensible(possibleCardTargets, SOME_SENSIBLE_CHOSING_SIZE, player, vMatch, cam.card, good);
        }

        // now create actions
        Vector<EAIAction> actions = new Vector<EAIAction>();
        for (int i = 0; i < possibleCardTargets.size(); i++)
        {
            CardSim card = possibleCardTargets.getCard(i);
            // if card is a damaging X card
            // only allow targets which will be destroyed by it exactly
            if (good != 1) // not good
            {
                if (EAIHelper.isCreatureDamageCardSource(cam.card, key))
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

        // and than create all permutations of all actions and return them
        int minTargets = EAIHelper.getMinTargetCount(cam.card, hints, key);
        int maxTargets = EAIHelper.getMaxTargetCount(cam.card, hints, key);

        // now generate possible "sources"
        CardSimList possibleCardTargets = vMatch.getSourceEffectedList(key, cam.card, viewPlayer, hints);
        int good = EAIHelper.isGoodEffectCardSource(cam.card, key);
        if (E.aiPlayer.getEAIConfig().getDontDamageOwn())
        {
             if (good == -1) // bad
             {
                int countOpponent = EAIHelper.countOwnerCards(possibleCardTargets, (viewPlayer+1)%2);
                if (countOpponent >= minTargets)
                {
                    possibleCardTargets = EAIHelper.removeOwnerCards(possibleCardTargets, viewPlayer);
                }
             }
             else if (good == 1) // good
             {
                int playerCards = EAIHelper.countOwnerCards(possibleCardTargets, viewPlayer);
                if (playerCards >= minTargets)
                {
                    possibleCardTargets = EAIHelper.removeOwnerCards(possibleCardTargets, (viewPlayer+1)%2);
                }
             }
        }



        if (possibleCardTargets.hasRealCards())
            possibleCardTargets = possibleCardTargets.removeDummies();
        Vector<Integer> possiblePlayerTargets = vMatch.getPlayerSourceEffectedList(key, cam.card, viewPlayer, hints);

        // searching thru the library would otherwise return the WHOLE library!
        // - > permutation overload!
        //possibleCardTargets = reduceEqualIDsToMax(possibleCardTargets, maxTargets);
        possibleCardTargets = reduceSameToMax(possibleCardTargets, maxTargets);
        possibleCardTargets = reduceTargetToSensible(possibleCardTargets, minTargets, viewPlayer, vMatch, cam.card, good);

        // now create actions
        for (int i = 0; i < possibleCardTargets.size(); i++)
        {
            CardSim card = possibleCardTargets.getCard(i);
            // if card is a damaging X card
            // only allow targets which will be destroyed by it exactly
            if (good != 1) // not good
            {
                if (cam.card.getCard().getManaCost() == -1)
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

            ret.addElement(yesV);
            ret.addElement(noV);
            return ret;
        }
        boolean isHidden = vMatch.isLibraryHidden();
        CardSimList possibleCardTargets = vMatch.getTargetEffectedList(key, cam.card, E.pNumber, hints, sources);
        if (sourceListDependened)
        {
            // add source targets
            for (int i = 0; i < sources.size(); i++) {
                EAIAction action = sources.elementAt(i);
                if (action.getSCard()!=null)
                    possibleCardTargets.addCard(action.getSCard());
            }
        }
       
        if (isHidden)
            vMatch.hideLibrary();
//taregt edependeble on source new hint
        possibleCardTargets = adjustSourcesToTargets(key, cam.card, sources, possibleCardTargets);

        int tc = EAIHelper.getTargetCount(cam.card, hints, key);

        if (tc == 0)
        {
            if (EAIHelper.hasHint(cam.card, key, new HintBundle(HintTargetCount.CT_TARGET_COUNT_CHOSEN)))
            {
                tc = -1;
            }
            else
            {
                ret.addElement(new Vector<EAIAction>());
                return ret;
            }
        }


        // and than create all permutations of all actions and return them
        int minTargets = EAIHelper.getMinTargetCount(cam.card, hints, key);
        int maxTargets = EAIHelper.getMaxTargetCount(cam.card, hints, key);

       
        boolean creatureDamage = EAIHelper.isCreatureDamageCardTarget(cam.card, key);
        boolean creatureBuf = EAIHelper.isBufCardTarget(cam.card, key);
        boolean doPermutations = true;

        int good = EAIHelper.isGoodEffectCardTarget(cam.card, key);
       
       
        boolean isMoveBad = EAIHelper.isMoveBadTarget(cam.card, key);
        boolean isMoveHand = EAIHelper.isMoveHandTarget(cam.card, key);
       
        if (isMoveBad && isMoveHand) isMoveBad = false;
       
        if (E.aiPlayer.getEAIConfig().getDontDamageOwn())
        {
             if (good==-1) // bad
             {
                 // only remove own targets if opponent target are at all possible!
                 if (EAIHelper.cardTargetOpponentPossible(cam.card, key , false))
                 {
                    // getDontDamageOwn ! so don´t try this!
                    
                     if (countOwnerCards(possibleCardTargets, (player+1)%2)>=maxTargets)
                        possibleCardTargets = EAIHelper.removeOwnerCards(possibleCardTargets, player);
                     else
                     {
                         boolean may = false;
                         if (EAIHelper.hasHint(cam.card, key, new HintBundle(HintTargetTypes.TY_PASSIV_OPTIONAL)))
                         {
                             may = true;
                             passiveMay = true;
                         }
                         if (EAIHelper.hasHint(cam.card, key, new HintBundle(HintTargetTypes.TY_ACTIVE_OPTIONAL)))
                         {
                             may = true;
                             activeMay = true;
                         }
                         if (may)
                            possibleCardTargets = EAIHelper.removeOwnerCards(possibleCardTargets, player);

                     }



                 }
                 if (isMoveBad)
                 {
                     // this is in general a destroy card card
                     // select max the two expansive cards as optimazattion
                     possibleCardTargets = possibleCardTargets.onlyExpansive(2);
                    
                 }
                
             }
             else if (good==1) // good
             {
                 if (EAIHelper.cardTargetPlayerPossible(cam.card, key , false))
                 {
                    if (countOwnerCards(possibleCardTargets, player)>=maxTargets)
                        possibleCardTargets = EAIHelper.removeOwnerCards(possibleCardTargets, (player+1)%2);
                    if (cam.card.isEnchantment())
                        possibleCardTargets = EAIHelper.removeOwnerCards(possibleCardTargets, (player+1)%2);
                 }
             }
             else // good = 0
             {
                 if (isMoveHand)
                 {
                     possibleCardTargets = EAIHelper.removeExtraPlayoutFeaturesPlayersCard(possibleCardTargets, (player+1)%2);
                 }
             }
        }
        if (good == 0)
        {
             if (isMoveHand)
             {
                 possibleCardTargets = EAIHelper.removeNotExtraPlayoutFeaturesPlayersCard(possibleCardTargets, player);
             }
        }

        Vector<Integer> possiblePlayerTargets = vMatch.getPlayerTargetEffectedList(key, cam.card, E.pNumber, hints);
       
        if (possibleCardTargets.hasRealCards())
            possibleCardTargets = possibleCardTargets.removeDummies();

        if (good == 1) // good
        {
            for (int i=0; i < possiblePlayerTargets.size(); i++)
            {
                int tt = possiblePlayerTargets.elementAt(i);
                if (tt == ((player+1)%2) )
                {
                    possiblePlayerTargets.remove(i);
                    break;
                }
            }
        }
        if (good == -1) // bad
        {
            for (int i=0; i < possiblePlayerTargets.size(); i++)
            {
                int tt = possiblePlayerTargets.elementAt(i);
                if (tt == player )
                {
                    possiblePlayerTargets.remove(i);
                    break;
                }
            }
        }

        // debug with err 1 4 times alaborn!!!
        int SOME_SENSIBLE_CHOSING_SIZE = LIBRARY_SEARCH_WIDTH;
        //if (SOME_SENSIBLE_CHOSING_SIZE > maxTargets) SOME_SENSIBLE_CHOSING_SIZE = maxTargets;
        // possibleCardTargets = reduceEqualIDsToMax(possibleCardTargets, maxTargets);
        possibleCardTargets = reduceSameToMax(possibleCardTargets, maxTargets);
        if (SOME_SENSIBLE_CHOSING_SIZE < maxTargets)
            SOME_SENSIBLE_CHOSING_SIZE = maxTargets;
        if (possibleCardTargets.size() > SOME_SENSIBLE_CHOSING_SIZE)
        {
/* todo in reduce to sensible take into account the amount of damage a card can do
            int damage = 0;
            if (creatureDamage)
            {
                damage = hints.getHintValueInt(key, HintAll.CS_AMOUNT_COUNT);
            }
*/
            if (EAIHelper.isMoveHandTarget(cam.card, key))
            {
                // check if playout has a nice effect
                CardSimList possibleCardTargetsTest = removePlayerCardsWithNotNicePlayoutEffects(possibleCardTargets, player, vMatch);
                if (possibleCardTargetsTest.size() < minTargets)
                {
                    // get cheapest till count ok
                    CardSimList temp = possibleCardTargets.removeOwner((player+1)%2).sortListByCost();
                    while ((possibleCardTargetsTest.size() < minTargets) && (temp.size()>0))
                    {
                        CardSim c = temp.getCard(0);
                        temp.remove(c);
                        possibleCardTargetsTest.addCard(c);
                       
                    }
                }
                possibleCardTargets = possibleCardTargetsTest;
               
                possibleCardTargetsTest = removeOpponentCardsWithNicePlayoutEffects(possibleCardTargets, player, vMatch);
                if (possibleCardTargetsTest.size() < minTargets)
                {
                    // get expansive till count ok
                    CardSimList temp = possibleCardTargets.removeOwner((player+1)%2).sortListByCost();
                    while ((possibleCardTargetsTest.size() < minTargets) && (temp.size()>0))
                    {
                        CardSim c = temp.getCard(temp.size()-1);
                        temp.remove(c);
                        possibleCardTargetsTest.addCard(c);
                       
                    }
                   
                }
                possibleCardTargets = possibleCardTargetsTest;
            }
            possibleCardTargets = reduceTargetToSensible(possibleCardTargets, SOME_SENSIBLE_CHOSING_SIZE, player, vMatch, cam.card, good);
        }

        // now create actions
        Vector<EAIAction> actions = new Vector<EAIAction>();

        if ((EAIHelper.hasHint(cam.card, key, new HintBundle(HintTargetTypes.TY_DIVIDE_AMOUNT))) && (creatureDamage))
        {
            int divided = 0;
            // e.g. forked lightning!
            for (int tt = 0; tt < maxTargets; tt++)
            {
                for (int i = 0; i < possibleCardTargets.size(); i++)
                {
                    CardSim card = possibleCardTargets.getCard(i);

                    // reduce creature targets to only the ones we can actually kill
                    // we do not test only the damage this card can do
                    // but all possible damage we can do till the end of testing
                    // within this leaf
                    // compared to the "damage" allready taken (ToughnessNOW)
                    if (vMatch.getPhase() != MatchConstants.PHASE_COMBAT_DECLARE_BLOCKERS)
                        if ((card.getNowToughness() > maxDamageInTodo) && (onlyCreatureKillDamage))
                            continue;
                    if (card.getNowToughness() <= card.helper)
                        continue; // creature is already dead!

                    EAIAction action = EAIAction.createTargetAction(0, vMatch.getPhase(), card, -1);
                    action.isTarget = true;
                    actions.addElement(action);
                   
                    // helper helps us to only add cards to divided damage
                    // as long as the divided damage for that card is
                    // not enough to kill it
                    card.helper++; // plus one damage
                    divided++; // only divide actions for max Targets!
                    if (divided>=maxTargets) break;
                }
                if (divided>=maxTargets) break;

            }
        }
        else
        {
            int currentChosenCount = 0;
            boolean choseCount = (EAIHelper.hasHint(cam.card, key, new HintBundle(HintTargetCount.CT_TARGET_COUNT_CHOSEN)));

            // for "Ransack" as it is implemented now!
            boolean actionsDone = false;
            if ((choseCount) && (possibleCardTargets.size() >0))
            {
                int sizeChosen = 1;
                if (maxTargets > 1)
                {
                    sizeChosen = maxTargets / 2;
                }
                CardSimList goodHalf = new CardSimList();
                CardSimList badHalf = possibleCardTargets.copyList();

                int cPlayer = 0;
                if (sourceDependened)
                    cPlayer =dependenedPlayer;
                else
                    cPlayer = badHalf.getCard(0).getOwner();
               
               
                // from cPlayer point of view
                for (int ii=badHalf.size()-1;ii >=0; ii--)
                {
                    CardSim g = EAIHelper.selectGoodCard(badHalf, true, cPlayer, vMatch, cam.card);
                    if (g == null) break;
                    goodHalf.addCard(g);
                    badHalf.remove(g);
                    if (goodHalf.size() >=sizeChosen) break;
                }
                if (EAIHelper.hasHint(cam.card, key, new HintBundle(HintTargetTypes.TY_CHOICE_LIBTOP_BOTTOM)));
                {
                    doPermutations = false;
                    if (player == cPlayer)
                    {
                        // put good cards on top of lib
                        actionsDone = true;
                        for (int i = 0; i < goodHalf.size(); i++)
                        {
                            CardSim card = goodHalf.getCard(i);
                            EAIAction action = EAIAction.createTargetAction(0, vMatch.getPhase(), card, -1);
                            action.isTarget = true;
                            actions.addElement(action);
                        }
                    }
                    else
                    {
                        // put good cards on top of lib
                        actionsDone = true;
                        for (int i = 0; i < badHalf.size(); i++)
                        {
                            CardSim card = badHalf.getCard(i);
                            EAIAction action = EAIAction.createTargetAction(0, vMatch.getPhase(), card, -1);
                            action.isTarget = true;
                            actions.addElement(action);
                        }
                    }
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

    // there give the result back
    void generatePossibleAttackers(int player, CardSimList possibleAttackers, CardSimList removedPossibleAttackers)
    {
        // todo
        // optimization pending
        CardSimList temp = vMatch.getBattlefield(player).getSubListByType("Creature");
        CardSimList tempClone = temp.copyList();

        temp = temp.removeTapped();
        temp = temp.removeSick();
        temp = vMatch.removeAlreadyAttacking(temp);
       
        for (int i=0; i<temp.size(); i++)
        {
            if (SingleFight.canAttack(temp.getCard(i), player, vMatch, true))
                possibleAttackers.addCard(temp.getCard(i));
        }
        tempClone.removeListDirect(possibleAttackers);
        removedPossibleAttackers.addList(tempClone);
    }
View Full Code Here

Examples of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

            p = (player+1)%2;
        }
       
       
        // ATTACKERS
        CardSimList possibleAttackers = new CardSimList();
        CardSimList removedPossibleAttackers = new CardSimList();

        key+="attacker:";
        // removed possible attackers are interesting for blocking a re attack! (Evaluation)
        generatePossibleAttackers(p, possibleAttackers, removedPossibleAttackers);
        for(int c=0; c< possibleAttackers.size(); c++)
        {
            CardSim card = possibleAttackers.getCard(c);
            key += card.getCard().getUniqueID()+": "+card.getNowPower()+"/"+card.getNowToughness()+""+card.getNowCardAbilities();
        }
        for(int c=0; c< removedPossibleAttackers.size(); c++)
        {
            CardSim card = removedPossibleAttackers.getCard(c);
            key += card.getCard().getUniqueID()+": "+card.getNowPower()+"/"+card.getNowToughness()+""+card.getNowCardAbilities();
        }
       
        // BLOCKERS
        CardSimList blocker = vMatch.getBattlefield(o).getSubListByType("Creature").onlyTapstate(false);

        // remove creatures with activation ability
//        blocker = blocker.onlyTapstate(false);
        // strange things happen - there was a cache hit, where actions in attavk were done on opponents
        // creatures that were not in comnbat
        // and this cretaure was on hit removed to lib - null pointer exeption...
        // thererfor here - ALL opponents creaturs
        key+="blocker:";
        for(int c=0; c< blocker.size(); c++)
        {
            CardSim card = blocker.getCard(c);
            key += card.getCard().getUniqueID()+": "+card.getNowPower()+"/"+card.getNowToughness()+""+card.getNowCardAbilities();
        }

        // attacker may decide to cats instants in attack phase on blockers which are even tapped!
        if ((playerIsAttacker) && (vMatch.getHand(p).onlyWithTypes("Instant").size() >0))
        {
            blocker = vMatch.getBattlefield(o).getSubListByType("Creature").onlyTapstate(true);
            key+="tapped blocker:";
            for(int c=0; c< blocker.size(); c++)
            {
                CardSim card = blocker.getCard(c);
                key += card.getCard().getUniqueID()+": "+card.getNowPower()+"/"+card.getNowToughness()+""+card.getNowCardAbilities();
            }
        }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.