Search in sources :

Example 11 with Action

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

the class LowestPickerAI method think.

private void think() {
    int best = 0;
    double bestScore = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < 3; i++) {
        Card card = me.handCards[i];
        double score = 0;
        if (card.model.type == CardType.CREATURE) {
            score = 100 - card.model.cost;
        }
        System.err.println("Score for " + i + " => " + score);
        if (score > bestScore) {
            bestScore = score;
            best = i;
        }
    }
    Card bestCard = me.handCards[best];
    cardsByCosts[bestCard.model.cost]++;
    action = "PICK " + best;
    System.err.println("Chosen action " + action);
}
Also used : Card(lcm2.cards.Card)

Example 12 with Action

use of lcm2.simulation.Action 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)

Example 13 with Action

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

the class SimpleAI3 method canFaceKillAndDoIt.

private boolean canFaceKillAndDoIt(int ourCardIndex, Card current) {
    if (opp.guardsCount == 0) {
        int attackSum = 0;
        for (int r = ourCardIndex; r < me.boardCardsFE; r++) {
            Card remaining = me.boardCards[r];
            attackSum += remaining.attack;
        }
        if (attackSum >= opp.face.defense) {
            // go for face
            Action action = Action.attack(ourCardIndex, 0);
            sim.run(me, opp, action);
            System.err.println("Go for the kill " + current.model.instanceId);
            actions.add("ATTACK " + me.boardCards[ourCardIndex].model.instanceId + " " + opp.boardCards[0].model.instanceId);
            return true;
        }
    }
    return false;
}
Also used : Action(lcm2.simulation.Action) Card(lcm2.cards.Card)

Example 14 with Action

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

the class Simulator method resolveAttack.

private void resolveAttack(Action action) {
    Card card = me.getFreshCard(action.from);
    Card oppCard = opp.getFreshCard(action.target);
    if (action.target == 0) {
        attackFace(card, oppCard);
    } else {
        attackCreature(card, oppCard);
    }
}
Also used : Card(lcm2.cards.Card)

Example 15 with Action

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

the class MC method think.

public void think(Agent originalMe, Agent originalOpp) {
    double bestScore = Double.NEGATIVE_INFINITY;
    bestActions[0] = Action.pass();
    bestActionsFE = 1;
    int iter = 0;
    while (true) {
        iter++;
        me.copyFrom(originalMe);
        opp.copyFrom(originalOpp);
        currentActionsFE = 0;
        boolean stop = false;
        while (!stop) {
            if (Player.random.nextInt(100) > 98) {
                stop = true;
            } else {
                possibleActionsFE = 0;
                // TODO possible de precompute tous les summon possible pour pick dedans sur le 1er tour
                computeSummons();
                computeAttacks();
                computeUse();
                if (possibleActionsFE == 0) {
                    stop = true;
                } else {
                    int rand = Player.random.nextInt(possibleActionsFE);
                    Action chosen = possibleActions[rand];
                    currentActions[currentActionsFE++] = chosen;
                    sim.run(me, opp, chosen);
                }
            }
        }
        double score = scorer.score(me, opp);
        if (score > bestScore) {
            bestScore = score;
            bestActionsFE = currentActionsFE;
            Action[] tmp = currentActions;
            currentActions = bestActions;
            bestActions = tmp;
        }
        if (iter % 255 == 0) {
            if (System.currentTimeMillis() - Player.start > 90) {
                break;
            }
        }
    }
    System.err.println("Iterations = " + iter);
    if (bestActionsFE != 0) {
        me.copyFrom(originalMe);
        opp.copyFrom(originalOpp);
        for (int i = 0; i < bestActionsFE; i++) {
            System.err.println("Action = " + bestActions[i]);
            bestActions[i].print(me, opp, System.out);
            System.out.print(";");
            sim.run(me, opp, bestActions[i]);
        }
        // policy: attack with all remaining cards
        if (opp.guardsCount == 0) {
            for (int i = 1; i < me.boardCardsFE; i++) {
                Card myCard = me.boardCards[i];
                if (!myCard.canAttack)
                    continue;
                Action.attack(i, -1).print(me, opp, System.out);
            }
        }
        System.out.println();
    } else {
        System.err.println("No best node");
        System.out.println("PASS");
    }
}
Also used : Action(lcm2.simulation.Action) Card(lcm2.cards.Card)

Aggregations

Card (lcm2.cards.Card)12 Action (lcm2.simulation.Action)12 Simulator (lcm2.simulation.Simulator)3 Agent (lcm2.Agent)2 Action (coderoyale2.simulation.Action)1 Simulation (coderoyale2.simulation.Simulation)1 Creep (coderoyale2.units.Creep)1 Scanner (java.util.Scanner)1 CardModel (lcm2.cards.CardModel)1