Package csa.jportal.ai.enhancedAI.enhancedSim

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


    }
    public static CardSim getMostTough(CardSimList list)
    {
        if (list==null) return null;
        if (list.size()==0) return null;
        CardSimList orderedList = list.sortListByToughness();
        return orderedList.getCard(orderedList.size()-1);
    }
View Full Code Here


        D.addLog("EAI:selectGoodCard() list: "+list ,debugLevel);
        CardSim result = null;
        if (list.size() == 0) return null;
        Scoring scorting = new Scoring();

        CardSimList creatures;
        CardSimList creaturesO;
        CardSimList lands;
        CardSimList landsO;
        CardSimList hand;
        CardSimList orgList = list.copyList();

        creaturesO = vmatch.getBattlefield(opponentNo).getSubListByType("Creature");
        landsO = vmatch.getLand(opponentNo);
        creatures = vmatch.getBattlefield(playerNo).getSubListByType("Creature");
        lands = vmatch.getLand(playerNo).copyList();
        hand = vmatch.getHand(playerNo);
        lands.addList(hand.getSubListByType("Land"));

        int creatureAdd=0;
        int spellAdd=0;

        int landScore = 10 - (lands.size()-1+hand.getSubListByType("Land").size())*2;
        scorting.addScore(landScore, Scoring.LAND);
        D.addLog("Scoring LAND: "+landScore,debugLevel);

        int healthScore = spellAdd+(20 - vmatch.getLife(playerNo))/2;
        scorting.addScore(healthScore, Scoring.HEALTH);
        D.addLog("Scoring HEALTH: "+healthScore,debugLevel);

        int opponentDamageScore = spellAdd+5-(vmatch.getLife(opponentNo)-5);
        scorting.addScore(opponentDamageScore, Scoring.DAMAGE);
        D.addLog("Scoring DAMAGE: "+opponentDamageScore,debugLevel);

        int creatureScore = creatureAdd+(creaturesO.size()-creatures.size())*2;
        scorting.addScore(creatureScore, Scoring.CREATURE);
        D.addLog("Scoring CREATURE: "+creatureScore,debugLevel);

        int creatureDamageScore = spellAdd+(creatureScore+2)/2;
        scorting.addScore(creatureDamageScore, Scoring.CREATURE_DAMAGE);
        D.addLog("Scoring CREATURE_DAMAGE: "+creatureDamageScore,debugLevel);

        int landDestroyScore = (5-landsO.size())+ spellAdd;
        scorting.addScore(landDestroyScore, Scoring.LAND_DESTROY);
        D.addLog("Scoring LAND_DESTROY: "+landDestroyScore,debugLevel);

        int handScore = spellAdd+10-(hand.size()*3);
        scorting.addScore(handScore, Scoring.HAND);
        D.addLog("Scoring HAND: "+handScore,debugLevel);

        boolean nothingDone = false;
        int NOTHING_SCORE = -99;
        int lastScoreValue = -100;
        while (result == null)
        {
            lastScoreValue = scorting.getHighScoreValue();

            int switcher = scorting.getHighScoreType();
            if ((!nothingDone) && (lastScoreValue<NOTHING_SCORE))
            {
                switcher = 22882; // a default :-)
            }
            if ((switcher == Scoring.NOTHING ) && (nothingDone))
            {
                break;
            }
            switch (switcher)
            {
                case Scoring.LAND_DESTROY:
                {
                    D.addLog("Taken LAND_DESTROY",debugLevel);
                    scorting.removeType(Scoring.LAND_DESTROY);

                    for (int i=0; i< list.size(); i++)
                    {
                        CardSim card = list.getCard(i);
                        AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                        if (aHints.hasHint(HintTargetTypes.TY_LAND_TO_GRAVE))
                        {
                            if (!(aHints.hasHint(HintTargetCount.CT_ALL_CARDS)))
                            {
                                result = card;
                                D.addLog("Found: "+result,debugLevel);
                            }
                        }
                    }
                    break;
                }

                case Scoring.LAND:
                {
                    D.addLog("Taken LAND",debugLevel);
                    scorting.removeType(Scoring.LAND);
                    CardSimList l = list.getSubListByType("Land");
                    if (l.size()>0)
                    {
                        result = l.getCard(0);
                        break;
                    }

                    for (int i=0; i< list.size(); i++)
                    {
                        CardSim card = list.getCard(i);
                        AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                        if (aHints.hasHint(HintTargetTypes.TY_LIBRARY_TO_HAND))
                        if ((aHints.getHintValue(HintTargetRestrictions.TR_CARD_TYPE_NEED).toUpperCase().indexOf("Land") != -1)
                            ||
                            (aHints.getHintValue(HintTargetRestrictions.TR_CARD_TYPE_RESTRICTION).toUpperCase().indexOf("Land") == -1))
                        {
                            result = card;
                            D.addLog("Found: "+result,debugLevel);
                            break;
                        }

                    }
                    if (result == null)
                    for (int i=0; i< list.size(); i++)
                    {
                        CardSim card = list.getCard(i);
                        AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                        if (aHints.hasHint(HintTargetTypes.TY_LIBRARY_TO_LAND))
                        {
                            result = card;
                            D.addLog("Found: "+result,debugLevel);
                            break;
                        }
                    }
                    break;
                }
                case Scoring.HEALTH:
                {
                    D.addLog("Taken HEALTH",debugLevel);
                    scorting.removeType(Scoring.HEALTH);

                    for (int i=0; i< list.size(); i++)
                    {
                        CardSim card = list.getCard(i);
                        AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                        if (aHints.hasHint(HintTargetTypes.TY_HEAL))
                        {
                            result = card;
                            D.addLog("Found: "+result,debugLevel);
                            break;
                        }

                    }
                    break;
                }
                case Scoring.DAMAGE:
                {
                    D.addLog("Taken DAMAGE",debugLevel);
                    scorting.removeType(Scoring.DAMAGE);
                    String[] h={"EFFECT_ONE_PLAYER_DAMAGE"};
                    for (int i=0; i< list.size(); i++)
                    {
                        CardSim card = list.getCard(i);
                        AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                        if ((aHints.hasHint(HintTargetTypes.TY_DAMAGE))
                            || (aHints.hasHint(HintSourceTypes.SY_DAMAGE)))
                        {
                            if ((aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT))
                                || (aHints.hasHint(HintSourceRestrictions.SR_CARD_OPPONENT)))
                            {
                                if (!(card.isCreature()))
                                    result = card;
                            }
                        }
                    }
                    break;
                }
                case Scoring.CREATURE:
                {
                    D.addLog("Taken CREATURE",debugLevel);
                    scorting.removeType(Scoring.CREATURE);
                    CardSimList l = list.getSubListByType("Creature");

                    boolean testMana=true;
                    if (initiator!=null)
                    {
                        AIEnhancedCardHints iHints = AIEnhancedCardHints.getHints(initiator);

                        if (iHints.hasHint(HintTargetTypes.TY_LIBRARY_TO_FIELD))
                        {
                            testMana=false;
                        }
                        if (iHints.hasHint(HintTargetTypes.TY_HAND_TO_FIELD))
                        {
                            testMana=false;
                        }
                    }
                    if (testMana)
                        l = onlyEnoughManaGeneral(l, lands);

                    l = l.sortListByManaCost();
                    if (l.size()>0)
                    {
                        result = l.getCard(l.size()-1);
                    }
                    break;
                }
                case Scoring.CREATURE_DAMAGE:
                {
                    D.addLog("Taken CREATURE_DAMAGE",debugLevel);
                    scorting.removeType(Scoring.CREATURE_DAMAGE);

                    // NOT checked if one of the sorcueries does damage to the player!
                    // (e.g. "Rain of Daggers")
                    for (int i=0; i< list.size(); i++)
                    {
                        CardSim card = list.getCard(i);
                        AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                        if (   ((aHints.hasHint(HintTargetTypes.TY_FIELD_TO_GRAVE)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT)))
                            || ((aHints.hasHint(HintSourceTypes.SY_FIELD_TO_GRAVE)) && (aHints.hasHint(HintSourceRestrictions.SR_CARD_OPPONENT)))
                             )
                        {
                            {
                                result = card;
                                break;
                            }
                        }
                    }


                    if (result == null)
                    {
                        for (int i=0; i< list.size(); i++)
                        {
                            CardSim card = list.getCard(i);
                            AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                            if (   ((aHints.hasHint(HintTargetTypes.TY_FIELD_TO_HAND)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT)))
                                || ((aHints.hasHint(HintSourceTypes.SY_FIELD_TO_HAND)) && (aHints.hasHint(HintSourceRestrictions.SR_CARD_OPPONENT)))
                                || ((aHints.hasHint(HintTargetTypes.TY_LIBRARY_TOP)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT)))
                                )
                                {
                                    result = card;
                                    break;
                                }
                        }
                    }
                    if (result == null)
                    {
                        for (int i=0; i< list.size(); i++)
                        {
                            CardSim card = list.getCard(i);
                            AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                            if (   ((aHints.hasHint(HintTargetTypes.TY_DAMAGE)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_OPPONENT)))
                                || ((aHints.hasHint(HintSourceTypes.SY_DAMAGE)) && (aHints.hasHint(HintSourceRestrictions.SR_CARD_OPPONENT)))
                                )
                                {
                                    result = card;
                                    break;
                                }
                        }
                    }
                    break;
                }

                case Scoring.HAND:
                {
                    D.addLog("Taken HAND",debugLevel);
                    scorting.removeType(Scoring.HAND);

                    String[] h={"EFFECT_WHEN_DRAW_CARD"};
                    for (int i=0; i< list.size(); i++)
                    {
                        CardSim card = list.getCard(i);
                        AIEnhancedCardHints aHints = AIEnhancedCardHints.getHints(card);
                        if (   ((aHints.hasHint(HintTargetTypes.TY_LIBRARY_TO_HAND)) && (aHints.hasHint(HintTargetRestrictions.TR_CARD_PLAYER)))
                            || ((aHints.hasHint(HintSourceTypes.SY_LIBRARY_TO_HAND)) && (aHints.hasHint(HintSourceRestrictions.SR_CARD_PLAYER)))
                            )
                            {
                                result = card;
                                break;
                            }
                    }
                    break;
                }
                default: // NOTHING
                {
                    D.addLog("Taken NOTHING",debugLevel);
                    nothingDone = true;
                    CardSimList nothingList = onlyEnoughManaGeneral(list, lands);
/*

                    // not HAND
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_WHEN_DRAW_CARD");

                    // not CREATURE DAMAGE
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_ONE_CREATURE_TO_GRAVE");
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_OPPONENT_CREATURE_TO_GRAVE");
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_ONE_CREATURE_TO_HAND");
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_ONE_CREATURE_TO_LIBRARY_TOP");

                    // NOT CREATURE
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_PLAYER_LIBRARY_TO_CREATURE");

                    // NOT DAMAGE
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_ONE_PLAYER_DAMAGE");
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_OPPONENT_DAMAGE");

                    // NOT HEAL
                    nothingList = AIHelper.removeWithHint(nothingList, "HEAL_AMOUNT");

                    // NOT LAND
                    nothingList = AIHelper.removeWithHint(nothingList, "EFFECT_PLAYER_LIBRARY_LAND_TO_HAND");
                    nothingList = AIHelper.removeWithHint(nothingList, "ADD_LAND_FROM_LIBRARY");
*/
                    CardSimList l = nothingList;
                    l=l.sortListByManaCost();
                    if (l.size()>0)
                    {
                        result = l.getCard(csa.Global.getRand().nextInt(l.size()));
                    }
                    break;
                }
            }
            /*
 
View Full Code Here

            return EAIHelper.hasHint(sourceCard, key, new HintBundle(HintAll.SR_CARD_PLAYER));
        return EAIHelper.hasHint(sourceCard, key, new HintBundle(HintAll.TR_CARD_PLAYER));
    }
    public static CardSimList removeOwnerCards(CardSimList list, int pNo)
    {
        CardSimList ret = new CardSimList();
        for (int i=0; i < list.size(); i++)
        {
            CardSim card = list.getCard(i);
            if (card.getOwner() != pNo)
            {
                ret.addCard(card);
            }
        }
        return ret;
    }
View Full Code Here

    }

    // general, meaning only "myTurn" restriction
    public static CardSimList onlyAllowedToPlay(CardSimList list, boolean ownTurn)
    {
        CardSimList ret = new CardSimList();
        for (int i = 0; i < list.size(); i++)
        {
            CardSim card = list.getCard(i);
            AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(card);
            boolean notAllowed = false;

            if (    (card.isArtifact()) ||
                    (card.isCreature()) ||
                    (card.isLand()) ||
                    (card.isSorcery()) ||
                    (card.isEnchantment()) )
            {
                if (!ownTurn)
                {
                    continue;
                }
            }
            else if(card.isInstant())
            {
                if (ownTurn)
                {
                    notAllowed = notAllowed || hints.hasHint(HINT_SITUATION_INSTANT, PR_PLAYER_TURN_NOT_ALLOWED);
                }
                else
                {
                    notAllowed = notAllowed || hints.hasHint(HINT_SITUATION_INSTANT, PR_OPPONENT_TURN_NOT_ALLOWED);
                }
            }
            else
            {
                notAllowed = true;
            }

            if (!notAllowed)
            {
                ret.addCard(card);
            }
        }
        return ret;
    }
View Full Code Here

    // not checked if enough or/ at all fitting targets for are card are present!
    // land not checked to any "match" if played already...
    public static CardSimList onlyAllowedToPlay(CardSimList list, int phase, boolean ownTurn, Vector<EAIAction> stack, boolean isFinalCall)
    {
        CardSimList ret = new CardSimList();
        for (int i = 0; i < list.size(); i++)
        {
            CardSim card = list.getCard(i);
            boolean allowed = isAllowedToPlay(card, phase, ownTurn, stack, isFinalCall);
            if (allowed)
            {
                ret.addCard(card);
            }
        }
        return ret;
    }
View Full Code Here

    // not checked if enough or/ at all fitting targets for are card are present!
    // land not checked to any "match" if played already...
    // general, meaning only "myTurn" restriction
    public static CardSimList onlyAllowedToActivate(CardSimList list, boolean ownTurn, VirtualMatch vMatch)
    {
        CardSimList ret = new CardSimList();
        for (int i = 0; i < list.size(); i++)
        {
            CardSim card = list.getCard(i);
            AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(card);
            boolean notAllowed = false;
            if (ownTurn)
            {
                notAllowed = notAllowed || hints.hasHint(HINT_SITUATION_ACTIVATION, PR_PLAYER_TURN_NOT_ALLOWED);
            }
            else
            {
                notAllowed = notAllowed || hints.hasHint(HINT_SITUATION_ACTIVATION, PR_OPPONENT_TURN_NOT_ALLOWED);
            }

            if (hints.hasHint(HINT_SITUATION_ACTIVATION, PR_BEFOR_ATTACKER))
            {
                if (vMatch.getAttacker().size() > 0)
                    notAllowed = true;
            }
            if (!notAllowed)
            {
                ret.addCard(card);
            }

        }
        return ret;
    }
View Full Code Here

    // all cards remain, that are not
    // HAVE TaP Abitilty && TAPPED
    // also respects sickness!
    public static CardSimList onlyUntappedToActivate(CardSimList list)
    {
        CardSimList ret = new CardSimList();
        for (int i = 0; i < list.size(); i++)
        {
            CardSim card = list.getCard(i);
            if (card.hasTapAbility())
            {
                if (!card.isTapped())
                {
                    if (!card.isSick())
                    {
                        ret.addCard(card);
                    }
                }
            }
            else
            {
                ret.addCard(card);
            }
        }
        return ret;
    }
View Full Code Here

    }

    // regarding to phase
    public static CardSimList onlyAllowedToActivate(CardSimList list, int phase, boolean ownTurn, VirtualMatch vMatch)
    {
        CardSimList ret = new CardSimList();
        for (int i = 0; i < list.size(); i++)
        {
            CardSim card = list.getCard(i);
            boolean allowed = isAllowedToActivate(card, phase, ownTurn, vMatch);
            if (allowed)
            {
                ret.addCard(card);
            }
        }
        return ret;
    }
View Full Code Here

    // but only if any card remains
    // e.g. Man o War
    // only target one cards which have extra playout, like heal, destroy creature - upon playout....
    public static CardSimList removeNotExtraPlayoutFeaturesPlayersCard(CardSimList list, int player)
    {
        CardSimList ret = new CardSimList();
        for (int i = 0; i < list.size(); i++)
        {
            CardSim card = list.getCard(i);
            if (card.getOwner() == player)
            {
                AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(card);

                if (!hints.hasKey(HintAll.HINT_SITUATION_CARD_PLAYED))
                {
                    continue;
                }
                int good = isGoodEffectCard(card, HintAll.HINT_SITUATION_CARD_PLAYED);
                if (good == -1)
                    continue;
            }
            ret.addCard(card);
        }
        if (ret.size() == 0) return list;
        return ret;
    }
View Full Code Here

    }

    // remove creatures which have special playout features for given player
    public static CardSimList removeExtraPlayoutFeaturesPlayersCard(CardSimList list, int badOwner)
    {
        CardSimList ret = new CardSimList();
        for (int i = 0; i < list.size(); i++)
        {
            CardSim card = list.getCard(i);
            if (card.getOwner() == badOwner)
            {
                AIEnhancedCardHints hints = AIEnhancedCardHints.getHints(card);

                // do not remove with "bad" features!
                int good = isGoodEffectCard(card, HintAll.HINT_SITUATION_CARD_PLAYED);
                if (good != -1)
                    if (hints.hasKey(HintAll.HINT_SITUATION_CARD_PLAYED))
                    {
                        continue;
                    }
            }
            ret.addCard(card);
        }
        return ret;
    }
View Full Code Here

TOP

Related Classes of csa.jportal.ai.enhancedAI.enhancedSim.CardSimList

Copyright © 2018 www.massapicom. 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.