Search in sources :

Example 1 with Action

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

the class Player method main.

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    readPreGame(in);
    // game loop
    while (true) {
        readGameState(in);
        backupGameState();
        Action[] actions = new Action[10];
        Action[] bestActions = new Action[10];
        for (int i = 0; i < 10; i++) {
            actions[i] = new Action();
            bestActions[i] = new Action();
        }
        double bestScore = -1;
        long start = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            for (int a = 0; a < 10; a++) {
                actions[a].angle = 2 * Math.PI * rand.nextDouble();
                double lrand = rand.nextDouble();
                if (lrand > 0.5) {
                    actions[a].length = 60;
                } else {
                    actions[a].length = 2.0 * lrand * 60;
                }
            }
            new Simulation().simulate(actions);
            double score = queens[0].health;
            for (int c = creepsStart; c < creepsFE; c++) {
                Creep creep = (Creep) all[c];
                if (creep.health <= 0)
                    continue;
                if (creep.owner == 0)
                    continue;
                double dist = creep.location.distanceTo(queens[0].location);
                score += dist;
            }
            if (score > bestScore) {
                bestScore = score;
                for (int a = 0; a < 10; a++) {
                    bestActions[a].angle = actions[a].angle;
                    bestActions[a].length = actions[a].length;
                }
            }
            restoreGameState();
        }
        long end = System.currentTimeMillis();
        System.err.println("Think in " + (end - start) + " ms");
        if (bestActions[0].length == 0) {
            System.out.println("WAIT");
        } else {
            int x = (int) (queens[0].location.x + bestActions[0].length * Math.cos(bestActions[0].angle));
            int y = (int) (queens[0].location.y + bestActions[0].length * Math.sin(bestActions[0].angle));
            System.out.println("MOVE " + x + " " + y);
        }
        System.out.println("TRAIN");
    }
}
Also used : Scanner(java.util.Scanner) Action(coderoyale2.simulation.Action) Simulation(coderoyale2.simulation.Simulation) Creep(coderoyale2.units.Creep)

Example 2 with Action

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

the class SimpleAI2 method summonCards.

private void summonCards() {
    boolean cardChosen = false;
    System.err.println("Summon cards ...");
    for (int i = 0; i < me.handCardsFE; i++) {
        Card current = me.handCards[i];
        current.debug();
    }
    do {
        cardChosen = false;
        double bestScore = Double.NEGATIVE_INFINITY;
        int bestIndex = -1;
        for (int i = 0; i < me.handCardsFE; i++) {
            Card current = me.handCards[i];
            if (me.boardCardsFE < 9 && current.model.type == CardType.CREATURE && current.model.cost <= me.mana) {
                double score = 0.0;
                score += 1.0 * (current.attack + current.defense) / current.model.cost;
                if (current.isGuard() && me.guardsCount < 3)
                    score += 5;
                if (score > bestScore) {
                    bestScore = score;
                    bestIndex = i;
                }
            }
        }
        if (bestIndex != -1) {
            Card card = me.handCards[bestIndex];
            Action action = Action.summon(bestIndex);
            sim.run(me, opp, action);
            actions.add("SUMMON " + card.model.instanceId);
            cardChosen = true;
        }
    } while (cardChosen);
}
Also used : Action(lcm2.simulation.Action) Card(lcm2.cards.Card)

Example 3 with Action

use of coderoyale2.simulation.Action 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 4 with Action

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

the class SimpleAI2 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 5 with Action

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

Aggregations

Action (lcm2.simulation.Action)12 Card (lcm2.cards.Card)9 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