Search in sources :

Example 1 with Simulator

use of lcm2.simulation.Simulator in project cg by nmahoude.

the class SimpleAI2 method think.

private void think() {
    System.err.println("----------- think ---------------");
    actions.clear();
    sim = new Simulator();
    List<Card> oppOrder = sortOppCards(opp);
    // play cards from board
    for (int i = 0 + 1; i < me.boardCardsFE; i++) {
        Card current = me.boardCards[i];
        if (current.attack == 0) {
            continue;
        }
        // check if we can go for the face kill
        if (canFaceKillAndDoIt(i, current))
            continue;
        Card bestCard = null;
        double bestScore = Double.NEGATIVE_INFINITY;
        for (Card oppCard : oppOrder) {
            double score = scoreCard(current, oppCard);
            System.err.println("Score of " + current.model.instanceId + " vs " + oppCard.model.instanceId + " = " + score);
            if (score > bestScore) {
                bestScore = score;
                bestCard = oppCard;
            }
        }
        if (bestCard != null) {
            Action action = Action.attack(i, indexFromCard(bestCard));
            sim.run(me, opp, action);
            actions.add("ATTACK " + current.model.instanceId + " " + bestCard.model.instanceId);
        }
    }
    summonCards();
    actions.add("PASS");
}
Also used : Action(lcm2.simulation.Action) Simulator(lcm2.simulation.Simulator) Card(lcm2.cards.Card)

Example 2 with Simulator

use of lcm2.simulation.Simulator in project cg by nmahoude.

the class SimpleAI3 method think.

private void think() {
    System.err.println("----------- think ---------------");
    actions.clear();
    sim = new Simulator();
    List<Card> oppOrder = sortOppCards(opp);
    List<Card> myCards = myPlayingCardsAsList();
    for (Card oppCard : oppOrder) {
        if (!oppCard.isGuard() && opp.guardsCount > 0)
            continue;
        List<Card> cardsToPlay = new Ordonanceur().find(me, myCards, oppCard);
        System.err.println("Attacking " + oppCard.model.instanceId + " with ... ");
        for (Card play : cardsToPlay) {
            if (play.attack == 0)
                continue;
            play.debug();
            int index = indexFromCard(me, play);
            Action action = Action.attack(index, indexFromCard(opp, oppCard));
            sim.run(me, opp, action);
            actions.add("ATTACK " + play.model.instanceId + " " + oppCard.model.instanceId);
            myCards.remove(play);
        }
    }
    // FACE
    if (myCards.size() > 0 && opp.guardsCount == 0) {
        for (Card c : myCards) {
            Action action = Action.attack(indexFromCard(me, c), 0);
            sim.run(me, opp, action);
            actions.add("ATTACK " + c.model.instanceId + " -1");
        }
    }
    summonCards();
    actions.add("PASS");
}
Also used : Action(lcm2.simulation.Action) Simulator(lcm2.simulation.Simulator) Card(lcm2.cards.Card)

Example 3 with Simulator

use of lcm2.simulation.Simulator in project cg by nmahoude.

the class SimpleAI method think.

private void think() {
    System.err.println("----------- think ---------------");
    actions.clear();
    Simulator sim = new Simulator();
    // play cards from board
    for (int i = 0 + 1; i < me.boardCardsFE; i++) {
        Card current = me.boardCards[i];
        boolean attack = false;
        if (current.attack == 0) {
            continue;
        }
        // kill guards
        if (opp.guardsCount > 0) {
            System.err.println("Opp number of guards : " + opp.guardsCount);
            int guardIndex = getIndexOfGuard(opp);
            Card guard = opp.boardCards[guardIndex];
            Action action = Action.attack(i, guardIndex);
            sim.run(me, opp, action);
            System.err.println("his guard after attack ... dead? " + guard.isDead());
            opp.boardCards[guardIndex].debug();
            System.err.println("Opp number of guards : " + opp.guardsCount);
            actions.add("ATTACK " + current.model.instanceId + " " + guard.model.instanceId);
            attack = true;
        }
        // check if we can go for the face kill
        if (!attack) {
            int attackSum = 0;
            for (int r = i; r < me.boardCardsFE; r++) {
                Card remaining = me.boardCards[r];
                attackSum += remaining.attack;
            }
            if (attackSum >= opp.boardCards[0].defense) {
                // go for faces
                Action action = Action.attack(i, 0);
                sim.run(me, opp, action);
                System.err.println("Go for the kill " + current.model.instanceId);
                actions.add("ATTACK " + me.boardCards[i].model.instanceId + " " + opp.boardCards[0].model.instanceId);
                attack = true;
            }
        }
        // kill without being killed => go for it
        if (!attack) {
            for (int o = 1; o < opp.boardCardsFE; o++) {
                Card oppCard = opp.boardCards[o];
                if (oppCard.isDead())
                    continue;
                if (oppCard.defense <= current.attack && oppCard.attack < current.defense) {
                    Action action = Action.attack(i, o);
                    sim.run(me, opp, action);
                    System.err.println("Kill without being killed, go for it. " + current.model.instanceId + " --> " + oppCard.model.instanceId);
                    actions.add("ATTACK " + current.model.instanceId + " " + oppCard.model.instanceId);
                    attack = true;
                    break;
                }
            }
        }
        // double kill, but intersting only if we are not a guard ...
        if (!attack && !current.isGuard()) {
            for (int o = 1; o < opp.boardCardsFE; o++) {
                Card oppCard = opp.boardCards[o];
                if (oppCard.isDead())
                    continue;
                // our card will kill it but will be killed too
                if (oppCard.defense <= current.attack) {
                    // interesting to exchange ?
                    if (oppCard.attack > current.attack || oppCard.isLethal()) {
                        Action action = Action.attack(i, o);
                        sim.run(me, opp, action);
                        System.err.println("Dbl-Kill but intersting " + current.model.instanceId + " <> " + oppCard.model.instanceId);
                        actions.add("ATTACK " + current.model.instanceId + " " + oppCard.model.instanceId);
                        attack = true;
                        break;
                    }
                }
            }
        }
        if (!attack) {
            // go for faces
            Action action = Action.attack(i, 0);
            sim.run(me, opp, action);
            actions.add("ATTACK " + me.boardCards[i].model.instanceId + " " + opp.boardCards[0].model.instanceId);
            attack = true;
        }
    }
    // play cards from hand
    for (int i = 0; i < me.handCardsFE; i++) {
        Card current = me.handCards[i];
        current.debug();
        if (me.boardCardsFE < 9 && current.model.type == CardType.CREATURE && current.model.cost <= me.mana) {
            Action action = Action.summon(i);
            sim.run(me, opp, action);
            actions.add("SUMMON " + current.model.instanceId);
        }
    }
    actions.add("PASS");
}
Also used : Action(lcm2.simulation.Action) Simulator(lcm2.simulation.Simulator) Card(lcm2.cards.Card)

Aggregations

Card (lcm2.cards.Card)3 Action (lcm2.simulation.Action)3 Simulator (lcm2.simulation.Simulator)3