Package csa.jportal.ai.helper

Examples of csa.jportal.ai.helper.Scoring


        else if (inculdeScoringInfo)
        {
            int playerScore = weighting.buildScore(match, player, false);
            int opponentScore = weighting.buildScore(match, (player+1)%2, false);
            int oldScore = playerScore - opponentScore;
            Scoring score = new Scoring();


            // inculdeScoringInfo
            /*
                Blocking analyses
                -----------------
                a) will die? -> decide MUST Block / no need
                b) if Must block:
                   - decide best kill, if best kill is less expansive than attacker -> kill
                   - if not -> block with cheapest
                c) if no need to block
                   - check if score of cheapest block is
                   - higher than damage, than block
                   - otherwise accept damage
             *
             */

            int maxAttackerCreaturs = mAttackCandidates.size();
            int maxOpponentCreaturs = mBlockCandidates.getSubListByType("Creature").size();


            /*
            1) is it possible to kill all attackers wo any own dying -> yes? ->done

            2) Kill all with least own dead -> score

            3) Kill all with no dead, take damage -> score

            4) Block all with least dead -> score

            5) Block as much as possible with no dead, take damage -> score

            6) Block has much as possible, deaths dont matter, take damage -> score

            7) Kill in expansive order, take rest damage -> score

            8) block in expansive order, kill in cheapest order, take damage -> score

            9) take all damage -> score
              */

            // 1) is it possible to kill all attackers wo any own dying -> yes? ->done
            if (maxAttackerCreaturs <= maxOpponentCreaturs)
            {
                // only possible if more blockers than attackers

                // smallest first
                CardSimList attackerTest = mAttackCandidates.sortListByToughness();
                CardSimList blockerTest = mBlockCandidates.sortListByPower();

                simpleFormation = new CombatFormation();
                boolean canKillAll = true;
                // go thru all attackers
                // most tough first
                for (int a = attackerTest.size()-1; a >=0; a--)
                {
                    CardSim attacker = attackerTest.getCard(a);
                    CardSimList blockers = getNoDeadKillers(attacker, blockerTest, 0, true, config);
                    if (blockers == null)
                    {
                        canKillAll = false;
                        break;
                    }
                    blockerTest.removeListDirect(blockers);
               
                    SingleFight s = SingleFight.getFight(attacker, blockers, config);
                    simpleFormation.singleFights.add(s);
                }
                if (canKillAll)
                {
                    for (int a = 0; a < mToBeAddedAttackers.size(); a++)
                    {
                        CardSim attacker = mToBeAddedAttackers.getCard(a);
                        SingleFight s = SingleFight.getFight(attacker, new CardSimList(), config);

                        // add the new single Fight
                        simpleFormation.singleFights.add(s);
                    }
                    return true;
                }
            }
           
            // 2) Kill all with least own dead -> score
            CombatFormation killAllFormation = new CombatFormation();
            killAllFormation.name = "killAllFormation";
            int killAllScore = -100000;
            if (maxAttackerCreaturs <= maxOpponentCreaturs)
            {
                // only possible if more blockers than attackers

                // smallest first
                CardSimList attackerTest = mAttackCandidates.sortListByToughness();
                CardSimList blockerTest = mBlockCandidates.sortListByPower();

                boolean canKillAll = true;

                // go thru all attackers
                // most tough first
                for (int a = attackerTest.size()-1; a >=0; a--)
                {
                    CardSim attacker = attackerTest.getCard(a);

                    CardSimList blockers = getNoDeadKillers(attacker, blockerTest, 0, true, config);
                    if (blockers == null)
                    {
                        blockers = getLeastDeadKillers(attacker, blockerTest, 0, true, config);
                    }
                    if (blockers == null)
                    {
                        canKillAll = false;
                        break;
                    }
                    blockerTest.removeListDirect(blockers);

                    SingleFight s = SingleFight.getFight(attacker, blockers, config);
                    killAllFormation.singleFights.add(s);
                }
                if (killAllFormation.singleFights.size() > 0)
                {
                    killAllScore = difScoreFormation(killAllFormation, match, player, oldScore, weighting);
                    score.addScore(killAllScore, killAllFormation);
                }
            }

            //3) Kill all with no dead, take damage -> score
            CombatFormation killTakeDamageFormation = new CombatFormation();
            killTakeDamageFormation.name = "killTakeDamageFormation";
            int killKeepDamageScore = Integer.MIN_VALUE;
            //if (maxAttackerCreaturs <= maxOpponentCreaturs)
            {
                // smallest first
                CardSimList attackerTest = mAttackCandidates.sortListByToughness();
                CardSimList blockerTest = mBlockCandidates.sortListByPower();

                boolean canKillAll = true;
                // go thru all attackers
                // most tough first
                for (int a = attackerTest.size()-1; a >=0; a--)
                {
                    CardSim attacker = attackerTest.getCard(a);
                    CardSimList blockers = getNoDeadKillers(attacker, blockerTest, 0, true, config);
                    if (blockers == null)
                    {
                        continue;
                    }
                    blockerTest.removeListDirect(blockers);

                    SingleFight s = SingleFight.getFight(attacker, blockers, config);
                    killTakeDamageFormation.singleFights.add(s);
                }
                if (killTakeDamageFormation.singleFights.size() > 0)
                {
                    killKeepDamageScore = difScoreFormation(killTakeDamageFormation, match, player, oldScore, weighting);
                    score.addScore(killKeepDamageScore, killTakeDamageFormation);
                }
            }

            // 4) Block allpossible with No dead -> score
            CombatFormation blockNoDeadAll = new CombatFormation();
            blockNoDeadAll.name = "blockNoDeadAll";
            int blockNoDeadAllScore = Integer.MIN_VALUE;
            if (maxAttackerCreaturs <= maxOpponentCreaturs)
            {
                // smallest first
                CardSimList attackerTest = mAttackCandidates.sortListByToughness();
                CardSimList blockerTest = mBlockCandidates.sortListByPower();

                // go thru all attackers
                // most tough first
                boolean blockAll = true;
                for (int a = attackerTest.size()-1; a >=0; a--)
                {
                    CardSim attacker = attackerTest.getCard(a);
                    CardSim oneBlock = hasSingleKiller( attacker,  blockerTest, config);
                    CardSimList blockers = new CardSimList();
                    if (oneBlock == null)
                    {
                        oneBlock = hasSingleNoDeadBlock(attacker, blockerTest, config);
                        if (oneBlock == null)
                        {
                            blockAll = false;
                            break;
                        }
                        else
                            blockers.addCard(oneBlock);
                    }
                    else
                    {
                        blockers.addCard(oneBlock);
                    }

                    blockerTest.removeListDirect(blockers);
                    SingleFight s = SingleFight.getFight(attacker, blockers, config);
                    blockNoDeadAll.singleFights.add(s);
                }
                if (blockAll)
                {
                    blockNoDeadAllScore = difScoreFormation(blockNoDeadAll, match, player, oldScore, weighting);
                    score.addScore(blockNoDeadAllScore, blockNoDeadAll);
                }
            }

            // 5) Block as much as possible with no dead, take damage -> score
            CombatFormation blockNoDead = new CombatFormation();
            blockNoDead.name = "blockNoDead";
            int blockNoDeadScore = Integer.MIN_VALUE;
            {
                // smallest first
                CardSimList attackerTest = mAttackCandidates.sortListByToughness();
                CardSimList blockerTest = mBlockCandidates.sortListByPower();

                // go thru all attackers
                // most tough first
                for (int a = attackerTest.size()-1; a >=0; a--)
                {
                    CardSim attacker = attackerTest.getCard(a);
                    CardSimList blockers = getNoDeadKillers(attacker, blockerTest, 0, true, config);
                    if (blockers == null)
                    {
                        CardSim oneBlock = hasSingleNoDeadBlock(attacker, blockerTest, config);
                        if (oneBlock == null)
                            continue;
                        blockers = new CardSimList();
                        blockers.addCard(oneBlock);
                    }
                    blockerTest.removeListDirect(blockers);

                    SingleFight s = SingleFight.getFight(attacker, blockers, config);
                    blockNoDead.singleFights.add(s);
                }
                if (blockNoDead.singleFights.size() > 0)
                {
                    blockNoDeadScore = difScoreFormation(blockNoDead, match, player, oldScore, weighting);
                    score.addScore(blockNoDeadScore, blockNoDead);
                }
            }

            // 6) Block has much as possible, deaths dont matter, take damage -> score
            CombatFormation blockManyFormation = new CombatFormation();
            blockManyFormation.name = "blockManyFormation";
            int blockMany = Integer.MIN_VALUE;
            {
                // smallest first
                CardSimList attackerTest = mAttackCandidates.sortListByToughness();
                CardSimList blockerTest = mBlockCandidates.sortListByPower();

                // go thru all attackers
                // most tough first
                for (int a = attackerTest.size()-1; a >=0; a--)
                {
                    CardSim attacker = attackerTest.getCard(a);

                    CardSim oneBlock = hasSingleNoDeadKiller(attacker, blockerTest, config);
                    CardSimList blockers = new CardSimList();
                    if (oneBlock != null)
                    {
                        blockers.addCard(oneBlock);
                    }
                    else
                    {
                        oneBlock = hasSingleKiller(attacker, blockerTest, config);
                        if (oneBlock != null)
                        {
                            blockers.addCard(oneBlock);
                        }
                        else
                        {
                            oneBlock = hasSingleNoDeadBlock(attacker, blockerTest, config);
                            if (oneBlock != null)
                            {
                                blockers.addCard(oneBlock);
                            }
                            else
                            {
                                if (blockerTest.size() > 0)
                                {
                                    oneBlock = blockerTest.getCard(0);


                                    blockers.addCard(oneBlock);
                                }
                            }
                        }
                    }
                    if (oneBlock == null)
                    {
                        continue;
                    }
                    blockerTest.removeListDirect(blockers);

                    SingleFight s = SingleFight.getFight(attacker, blockers, config);
                    blockManyFormation.singleFights.add(s);
                }
                if (blockerTest.size() > 0)
                {
                    // there are more blockers than attackers,
                    // try to kill attackers with
                    // left over blockers.
                    addToKill(blockManyFormation, blockerTest);
                }
                blockMany = difScoreFormation(blockManyFormation, match, player, oldScore, weighting);
                score.addScore(blockMany, blockManyFormation);
            }

            // 7) Kill in expansive order, take rest damage -> score
            CombatFormation killExpansiveFormation = new CombatFormation();
            killExpansiveFormation.name = "killExpansiveFormation";
            int killExpansiveScore = Integer.MIN_VALUE;
            {
                // smallest first
                CardSimList attackerTest = mAttackCandidates.sortListByCost();
                CardSimList blockerTest = mBlockCandidates.sortListByPower();

                // go thru all attackers
                // most tough first
                for (int a = attackerTest.size()-1; a >=0; a--)
                {
                    CardSim attacker = attackerTest.getCard(a);

                    CardSimList blockers = getNoDeadKillers(attacker, blockerTest, 0, true, config);
                    if (blockers == null)
                    {
                        blockers = getLeastDeadKillers(attacker, blockerTest, 0, true, config);
                    }
                    if (blockers == null)
                    {
                        continue;
                    }
                    blockerTest.removeListDirect(blockers);

                    SingleFight s = SingleFight.getFight(attacker, blockers, config);
                    killExpansiveFormation.singleFights.add(s);
                }
                if (killExpansiveFormation.singleFights.size() > 0)
                {
                    killExpansiveScore = difScoreFormation(killExpansiveFormation, match, player, oldScore, weighting);
                    score.addScore(killExpansiveScore, killExpansiveFormation);
                }
           }

            // 8) block in expansive order, kill in cheapest order, take damage -> score
            CombatFormation blockExpansiveFormation = new CombatFormation();
            blockExpansiveFormation.name = "blockExpansiveFormation";
            int blockExpansiveMany = Integer.MIN_VALUE;
            {
                // smallest first
                CardSimList attackerTest = mAttackCandidates.sortListByCost();
                CardSimList blockerTest = mBlockCandidates.sortListByPower();

                // go thru all attackers
                // most tough first
                for (int a = attackerTest.size()-1; a >=0; a--)
                {
                    CardSim attacker = attackerTest.getCard(a);

                    CardSim oneBlock = hasSingleNoDeadKiller(attacker, blockerTest, config);
                    CardSimList blockers = new CardSimList();
                    if (oneBlock != null)
                    {
                        blockers.addCard(oneBlock);
                    }
                    else
                    {
                        oneBlock = hasSingleKiller(attacker, blockerTest, config);
                        if (oneBlock != null)
                        {
                            blockers.addCard(oneBlock);
                        }
                        else
                        {
                            oneBlock = hasSingleNoDeadBlock(attacker, blockerTest, config);
                            if (oneBlock != null)
                            {
                                blockers.addCard(oneBlock);
                            }
                            else
                            {
                                if (blockerTest.size() > 0)
                                {
                                    oneBlock = blockerTest.getCard(0);
                                    blockers.addCard(oneBlock);
                                }
                            }
                        }
                    }
                    if (oneBlock == null)
                    {
                        continue;
                    }
                    blockerTest.removeListDirect(blockers);

                    SingleFight s = SingleFight.getFight(attacker, blockers, config);
                    blockExpansiveFormation.singleFights.add(s);
                }
                if (blockerTest.size() > 0)
                {
                    // there are more blockers than attackers,
                    // try to kill attackers with
                    // left over blockers.
                    addToKill(blockExpansiveFormation, blockerTest);
                }
                blockExpansiveMany = difScoreFormation(blockExpansiveFormation, match, player, oldScore, weighting);
                score.addScore(blockExpansiveMany, blockExpansiveFormation);
            }

            // 9) take all damage -> score
            CombatFormation takeAllDamageFormation = new CombatFormation();
            takeAllDamageFormation.name = "takeAllDamageFormation";
            int takeAllDamageScore = difScoreFormation(null, match, player, oldScore, weighting);
            score.addScore(takeAllDamageScore, takeAllDamageFormation);
            simpleFormation = (CombatFormation) score.getHighScoreTypeObject();

            for (int a = 0; a < mToBeAddedAttackers.size(); a++)
            {
                CardSim attacker = mToBeAddedAttackers.getCard(a);
                SingleFight s = SingleFight.getFight(attacker, new CardSimList(), config);
View Full Code Here


            if (newLand.getNowColor().toUpperCase().indexOf("G") != -1)
                greenNeed+=2;
        }
       
       
        Scoring sc = new Scoring();
        sc.addScore(redNeed, "R");
        sc.addScore(blackNeed, "B");
        sc.addScore(blueNeed, "U");
        sc.addScore(greenNeed, "G");
        sc.addScore(whiteNeed, "W");
        //sc.sort();
        String neededColor = sc.getHighScoreTypeString();
        return landsOnly.getLand(neededColor);
    }
View Full Code Here

    {
        return AIHelper.getColorOfLessFrequence(landList, handList);
    }
    public static String getColorOfLessFrequence(CardSimList landList, CardList handList)
    {
        Scoring s = new Scoring();
        int b = landList.getSubListBySubType("Swamp").size();
        int r = landList.getSubListBySubType("Mountain").size();
        int w = landList.getSubListBySubType("Plains").size();
        int u = landList.getSubListBySubType("Island").size();
        int g = landList.getSubListBySubType("Forest").size();

        int hb = handList.getSubListBySubType("Swamp").size();
        int hr = handList.getSubListBySubType("Mountain").size();
        int hw = handList.getSubListBySubType("Plains").size();
        int hu = handList.getSubListBySubType("Island").size();
        int hg = handList.getSubListBySubType("Forest").size();
        if ((b == 0) && (hb >0)) return "B";
        if ((r == 0) && (hr >0)) return "R";
        if ((w == 0) && (hw >0)) return "W";
        if ((u == 0) && (hu >0)) return "U";
        if ((g == 0) && (hg >0)) return "G";

        s.addScore(b, "B");
        s.addScore(r, "R");
        s.addScore(w, "W");
        s.addScore(u, "U");
        s.addScore(g, "G");

        String col;

        col = s.getLeastNotNull();
        s.removeType(col);
        if (handList.getSubListByColor(col).size()>0) return col;

        col = s.getLeastNotNull();
        s.removeType(col);
        if (handList.getSubListByColor(col).size()>0) return col;

        col = s.getLeastNotNull();
        s.removeType(col);
        if (handList.getSubListByColor(col).size()>0) return col;

        col = s.getLeastNotNull();
        s.removeType(col);
        if (handList.getSubListByColor(col).size()>0) return col;

        col = s.getLeastNotNull();
        s.removeType(col);
        return col;
    }
View Full Code Here

        int opponentNo = (playerNo+1)%2;

        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);
View Full Code Here

        ManaCollection costCopy = new ManaCollection(cost);

        // copy.removeUnusableMana(card);
        Vector<ManaItem> useToPay = new Vector<ManaItem>();

        Scoring manaPoolScore = new Scoring();
        manaPoolScore.addScore(copy.getMana("G"), "G");
        manaPoolScore.addScore(copy.getMana("R"), "R");
        manaPoolScore.addScore(copy.getMana("B"), "B");
        manaPoolScore.addScore(copy.getMana("U"), "U");
        manaPoolScore.addScore(copy.getMana("W"), "W");

        String color = manaPoolScore.getLeastNotNull();
        int allNeeded = all;
        boolean success = color != null;

        while ((color != null) && (success))
        {
            int neededToPay = costCopy.getMana(color);
            if (neededToPay == 0)
            {
                manaPoolScore.removeType(color);
                color = manaPoolScore.getLeastNotNull();
                continue;
            }
            else
            {
                // pay one
                costCopy.removeAColor(color);
                ManaItem used = copy.removeAColor(color);
                manaPoolScore.reduceScore(1, color);
                color = manaPoolScore.getLeastNotNull();

                if (used == null)
                {
                    success = false;
                    return false;
                }
                useToPay.addElement(used);
            }
        }
        if (!success) return false;
       
        // restore scoring since we removed all colors above
        manaPoolScore = new Scoring();
        manaPoolScore.addScore(copy.getMana("G"), "G");
        manaPoolScore.addScore(copy.getMana("R"), "R");
        manaPoolScore.addScore(copy.getMana("B"), "B");
        manaPoolScore.addScore(copy.getMana("U"), "U");
        manaPoolScore.addScore(copy.getMana("W"), "W");

        // remove uncolored Mana-Needs
        int neededToPay = costCopy.getMana("*"); // uncolored
        for (int i=0; i < neededToPay; i++)
        {
            String cc = manaPoolScore.getHighScoreTypeString();
            manaPoolScore.reduceScore(1, cc);
            ManaItem used = copy.removeAColor(cc);
            if (used == null)
            {
                success = false;
                return false;
View Full Code Here

        ManaCollection costCopy = new ManaCollection(cost);

        // copy.removeUnusableMana(card);
        Vector<ManaItem> useToPay = new Vector<ManaItem>();

        Scoring manaPoolScore = new Scoring();
        manaPoolScore.addScore(copy.getMana("G"), "G");
        manaPoolScore.addScore(copy.getMana("R"), "R");
        manaPoolScore.addScore(copy.getMana("B"), "B");
        manaPoolScore.addScore(copy.getMana("U"), "U");
        manaPoolScore.addScore(copy.getMana("W"), "W");

        String color = manaPoolScore.getLeastNotNull();
        int allNeeded = all;
        boolean success = color != null;

        // this removes only colors needed!
        while ((color != null) && (success))
        {
            int neededToPay = costCopy.getMana(color);
            if (neededToPay == 0)
            {
                manaPoolScore.removeType(color);
                color = manaPoolScore.getLeastNotNull();
                continue;
            }
            else
            {
                // pay one
                costCopy.removeAColor(color);
                ManaItem used = copy.removeAColor(color);
                manaPoolScore.reduceScore(1, color);
                color = manaPoolScore.getLeastNotNull();

                if (used == null)
                {
                    success = false;
                    return null;
                }
                useToPay.addElement(used);
            }
        }
        if (!success) return null;

        if (otherPossiblePlayouts != null)
        {
            // restore scoring since we removed all colors above
            manaPoolScore = new Scoring();
            if (!isNeededInFuture("G", otherPossiblePlayouts))
                manaPoolScore.addScore(copy.getMana("G"), "G");
            if (!isNeededInFuture("R", otherPossiblePlayouts))
                manaPoolScore.addScore(copy.getMana("R"), "R");
            if (!isNeededInFuture("B", otherPossiblePlayouts))
                manaPoolScore.addScore(copy.getMana("B"), "B");
            if (!isNeededInFuture("U", otherPossiblePlayouts))
                manaPoolScore.addScore(copy.getMana("U"), "U");
            if (!isNeededInFuture("W", otherPossiblePlayouts))
                manaPoolScore.addScore(copy.getMana("W"), "W");

            // remove uncolored Mana-Needs
            int neededToPay = costCopy.getMana("*"); // uncolored
            for (int i=0; i < neededToPay; i++)
            {
                String cc = manaPoolScore.getHighScoreTypeString();
                manaPoolScore.reduceScore(1, cc);
    //            = null?
                ManaItem used = copy.removeAColor(cc);
                if (used == null)
                {
                    continue;
                }
                costCopy.removeAColor(1);
                useToPay.addElement(used);
            }
        }

        // if nothing else helps - do it the other way

        // restore scoring since we removed all colors above
        manaPoolScore = new Scoring();

        manaPoolScore.addScore(copy.getMana("G"), "G");
        manaPoolScore.addScore(copy.getMana("R"), "R");
        manaPoolScore.addScore(copy.getMana("B"), "B");
        manaPoolScore.addScore(copy.getMana("U"), "U");
        manaPoolScore.addScore(copy.getMana("W"), "W");

        // remove uncolored Mana-Needs
        int neededToPay = costCopy.getMana("*"); // uncolored
        for (int i=0; i < neededToPay; i++)
        {
            String cc = manaPoolScore.getHighScoreTypeString();
            manaPoolScore.reduceScore(1, cc);
            ManaItem used = copy.removeAColor(cc);
            if (used == null)
            {
                success = false;
                return null;
View Full Code Here

        AIPlayer aiPlayer = player.getAIPlayer();

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

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

        MatchPlayable p;
        MatchPlayable o;
        if (isPlayer)
        {
            p = player;
            o = opponent;
        }
        else
        {
            o = player;
            p = opponent;
        }

        creaturesO = match.getBattlefield(o).getSubListByType("Creature");
        landsO = match.getLand(o);
        creatures = match.getBattlefield(p).getSubListByType("Creature");
        lands = match.getLand(p);
        hand = match.getHand(p);
        lands.addList(hand.getSubListByType("Land"));

        int creatureAdd=0;
        int spellAdd=0;
        if (aiPlayer.mStrategie.getCreatureSpellPriority()>5)
        {
            spellAdd += (aiPlayer.mStrategie.getCreatureSpellPriority()-5)*2;
            creatureAdd -= (aiPlayer.mStrategie.getCreatureSpellPriority()-5);
        }
        else
        {
            creatureAdd += (5- aiPlayer.mStrategie.getCreatureSpellPriority())*2;
            spellAdd -= (5- aiPlayer.mStrategie.getCreatureSpellPriority());
        }

        int landScore = 10 - (lands.size()-1)*2 + csa.Global.getRand().nextInt(10-aiPlayer.mStrategie.getIntelligence()+1);
        scorting.addScore(landScore, Scoring.LAND);
        D.addLog("Scoring LAND: "+landScore,debugLevel);

        int healthScore = spellAdd+(20 - match.getLife(p))/+ csa.Global.getRand().nextInt(10-aiPlayer.mStrategie.getIntelligence()+1);
        scorting.addScore(healthScore, Scoring.HEALTH);
        D.addLog("Scoring HEALTH: "+healthScore,debugLevel);

        int opponentDamageScore = spellAdd+5-(match.getLife(o)-5+ csa.Global.getRand().nextInt(10-aiPlayer.mStrategie.getIntelligence()+1);
        scorting.addScore(opponentDamageScore, Scoring.DAMAGE);
        D.addLog("Scoring DAMAGE: "+opponentDamageScore,debugLevel);

        int creatureScore = creatureAdd+(creaturesO.size()-creatures.size())*+ csa.Global.getRand().nextInt(10-aiPlayer.mStrategie.getIntelligence()+1);
        scorting.addScore(creatureScore, Scoring.CREATURE);
        D.addLog("Scoring CREATURE: "+creatureScore,debugLevel);

        int creatureDamageScore = spellAdd+(creatureScore+2)/+ csa.Global.getRand().nextInt(10-aiPlayer.mStrategie.getIntelligence()+1);
        scorting.addScore(creatureDamageScore, Scoring.CREATURE_DAMAGE);
        D.addLog("Scoring CREATURE_DAMAGE: "+creatureDamageScore,debugLevel);

        int landDestroyScore = (5-landsO.size())+ spellAdd+ csa.Global.getRand().nextInt(10-aiPlayer.mStrategie.getIntelligence()+1);
        scorting.addScore(landDestroyScore, Scoring.LAND_DESTROY);
        D.addLog("Scoring LAND_DESTROY: "+landDestroyScore,debugLevel);

        int handScore = spellAdd+10-(hand.size()*3+ csa.Global.getRand().nextInt(10-aiPlayer.mStrategie.getIntelligence()+1);
        scorting.addScore(handScore, Scoring.HAND);
        D.addLog("Scoring HAND: "+handScore,debugLevel);

        boolean nothingDone = false;
        int NOTHING_SCORE = -5;
        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);

                    String[] h={"EFFECT_ONE_LAND_TO_GRAVE"};
                    for (int i=0; i< list.size(); i++)
                    {
                        Card card = list.getCard(i);
                        if (AIHelper.hasHints(card, h))
                        {
                            if (!(AIHelper.hasHint(card, "EFFECT_ALL_OF_A_KIND")))
                            {
                                result = card;
                                D.addLog("Found: "+result,debugLevel);
                            }
                        }

                    }
                    break;
                }

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

                    String[] h={"HEAL_AMOUNT"};
                    for (int i=0; i< list.size(); i++)
                    {
                        Card card = list.getCard(i);
                        if (AIHelper.hasHints(card, h)) result = card;
                        D.addLog("Found: "+result,debugLevel);
                    }
                    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++)
                    {
                        Card card = list.getCard(i);
                        if (!(card.isCreature()))
                                if (AIHelper.hasHints(card, h)) result = card;
                    }
                    if (result == null)
                    {
                        String[] h2 = {"EFFECT_OPPONENT_DAMAGE"};
                        for (int i=0; i< list.size(); i++)
                        {
                            Card card = list.getCard(i);
                            if (!(card.isCreature()))
                            if (AIHelper.hasHints(card, h2)) result = card;
                        }
                    }
                    break;
                }
                case Scoring.CREATURE:
                {
                    D.addLog("Taken CREATURE",debugLevel);
                    scorting.removeType(Scoring.CREATURE);
                    CardList l = list.getSubListByType("Creature");

                    boolean testMana=true;
                    if (initiator!=null)
                    {
                        if (AIHelper.hasHint(initiator, "EFFECT_PLAYER_LIBRARY_TO_CREATURE"))
                        {
                            testMana=false;
                        }
                        if (AIHelper.hasHint(initiator, "EFFECT_PLAYER_CREATURE_FROM_HAND_TO_PLAY"))
                        {
                            testMana=false;
                        }
                    }
                    if (testMana)
                        l = AIHelper.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);
                    String[] h={
                        "EFFECT_ONE_CREATURE_TO_GRAVE",
                        "EFFECT_OPPONENT_CREATURE_TO_GRAVE",
                        "EFFECT_OPPONENT_ALL_TAPPED_CREATURE_TO_GRAVE",
                        "EFFECT_OPPONENT_ALL_CREATURE_TO_GRAVE"
                        };

                    // 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++)
                    {
                        Card card = list.getCard(i);
                        if (!(card.isCreature()))
                            if (AIHelper.hasHints(card, h))
                            {
                                result = card;
                                break;
                            }
                    }
                    if (result == null)
                    {
                        String[] h2 = {
                                    "EFFECT_ONE_CREATURE_TO_HAND",
                                    "EFFECT_ONE_CREATURE_TO_LIBRARY_TOP" };
                        for (int i=0; i< list.size(); i++)
                        {
                            Card card = list.getCard(i);
                                if (!(card.isCreature()))
                                if (AIHelper.hasHints(card, h2))
                                {
                                    result = card;
                                    break;
                                }
                        }
                    }
                    if ((result == null) && (fightScan))
                    {
                        int intelligence  = aiPlayer.mStrategie.getIntelligence();
                        D.addLog("Sorcery Formation Own creatures given: "+creatures,debugLevel);
                        sorceryAction = AIHelper.simSorceries(list, match.getLand(p), creaturesO, creatures, intelligence);

                        D.addLog("Sorcery Formation chosen: "+sorceryAction,debugLevel);
                        if ((sorceryAction != null) && (sorceryAction.getSpell()!=null)) return sorceryAction.getSpell();
                        else
                        {
                            sorceryAction = null;
                            // all damage cards suck - remove them,
                            CardList tmp = new CardList();
                            for (int t = 0; t< list.size(); t++)
                            {
                                Card ccc = list.getCard(t);
                                if (!AIHelper.hasHint(ccc, "EFFECT_ONE_CREATURE_DAMAGE"))
                                {
                                    tmp.addCard(ccc);
                                }
                                else
                                {
                                    if (ccc.isCreature())
                                        tmp.addCard(ccc);
                                 }
                            }
                            list = tmp;
                        }
                    }
                    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++)
                    {
                        Card card = list.getCard(i);
View Full Code Here

        return null;
    }

    public static String getColorOfLessFrequence(CardList landList)
    {
        Scoring s = new Scoring();
        int b = landList.getSubListBySubType("Swamp").size();
        int r = landList.getSubListBySubType("Mountain").size();
        int w = landList.getSubListBySubType("Plains").size();
        int u = landList.getSubListBySubType("Island").size();
        int g = landList.getSubListBySubType("Forest").size();
        s.addScore(b, "B");
        s.addScore(r, "R");
        s.addScore(w, "W");
        s.addScore(u, "U");
        s.addScore(g, "G");

        return s.getLeastNotNull();
    }
View Full Code Here

        return s.getLeastNotNull();
    }

    public static String getColorOfLessFrequence(CardList landList, CardList handList)
    {
        Scoring s = new Scoring();
        int b = landList.getSubListBySubType("Swamp").size();
        int r = landList.getSubListBySubType("Mountain").size();
        int w = landList.getSubListBySubType("Plains").size();
        int u = landList.getSubListBySubType("Island").size();
        int g = landList.getSubListBySubType("Forest").size();

        int hb = handList.getSubListBySubType("Swamp").size();
        int hr = handList.getSubListBySubType("Mountain").size();
        int hw = handList.getSubListBySubType("Plains").size();
        int hu = handList.getSubListBySubType("Island").size();
        int hg = handList.getSubListBySubType("Forest").size();
        if ((b == 0) && (hb >0)) return "B";
        if ((r == 0) && (hr >0)) return "R";
        if ((w == 0) && (hw >0)) return "W";
        if ((u == 0) && (hu >0)) return "U";
        if ((g == 0) && (hg >0)) return "G";

        s.addScore(b, "B");
        s.addScore(r, "R");
        s.addScore(w, "W");
        s.addScore(u, "U");
        s.addScore(g, "G");

        String col;

        col = s.getLeastNotNull();
        s.removeType(col);
        if (handList.getSubListByColor(col).size()>0) return col;

        col = s.getLeastNotNull();
        s.removeType(col);
        if (handList.getSubListByColor(col).size()>0) return col;

        col = s.getLeastNotNull();
        s.removeType(col);
        if (handList.getSubListByColor(col).size()>0) return col;

        col = s.getLeastNotNull();
        s.removeType(col);
        if (handList.getSubListByColor(col).size()>0) return col;

        col = s.getLeastNotNull();
        s.removeType(col);
        return col;

    }
View Full Code Here

    }

    public static String getColorOfMostFrequence(CardList landList)
    {
        if (landList.size()==0) return null;
        Scoring s = new Scoring();
        int b = landList.getSubListBySubType("Swamp").size();
        int r = landList.getSubListBySubType("Mountain").size();
        int w = landList.getSubListBySubType("Plains").size();
        int u = landList.getSubListBySubType("Island").size();
        int g = landList.getSubListBySubType("Forest").size();
        s.addScore(b, "B");
        s.addScore(r, "R");
        s.addScore(w, "W");
        s.addScore(u, "U");
        s.addScore(g, "G");
        return s.getHighScoreTypeString();
    }
View Full Code Here

TOP

Related Classes of csa.jportal.ai.helper.Scoring

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.