Search in sources :

Example 1 with Creep

use of coderoyale2.units.Creep in project cg by nmahoude.

the class Player method readPreGame.

private static void readPreGame(Scanner in) {
    numSites = in.nextInt();
    creepsStart = numSites + 2;
    sites = new Site[numSites];
    barracksCache = new Barrack[numSites];
    minesCache = new Mine[numSites];
    towersCache = new Tower[numSites];
    for (int i = 0; i < numSites; i++) {
        int siteId = in.nextInt();
        int x = in.nextInt();
        int y = in.nextInt();
        int radius = in.nextInt();
        Site site = new Site(siteId, new Point(x, y), radius);
        sites[siteId] = site;
        all[i] = site;
        barracksCache[siteId] = new Barrack(site);
        minesCache[siteId] = new Mine(site);
        towersCache[siteId] = new Tower(site);
        site.structure = null;
    }
    queens[0] = new Queen(0);
    queens[1] = new Queen(1);
    all[numSites] = queens[0];
    all[numSites + 1] = queens[1];
    creepsStart = numSites + 2;
    for (int i = 0; i < MAX_CREEPS; i++) {
        all[creepsStart + i] = new Creep(-1);
    }
}
Also used : Site(coderoyale2.units.Site) Creep(coderoyale2.units.Creep) Queen(coderoyale2.units.Queen) Barrack(coderoyale2.structures.Barrack) Mine(coderoyale2.structures.Mine) Tower(coderoyale2.structures.Tower)

Example 2 with Creep

use of coderoyale2.units.Creep 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 3 with Creep

use of coderoyale2.units.Creep in project cg by nmahoude.

the class Player method readGameState.

private static void readGameState(Scanner in) {
    turn++;
    queens[0].gold = in.nextInt();
    // -1 if none
    queens[0].touchedSite = in.nextInt();
    for (int i = 0; i < numSites; i++) {
        int siteId = in.nextInt();
        // used in future leagues
        int gold = in.nextInt();
        // used in future leagues
        int maxMineSize = in.nextInt();
        Site site = sites[siteId];
        site.gold = gold;
        site.maxMineSize = maxMineSize;
        // -1 = No structure, 2 = Barracks
        int structureType = in.nextInt();
        // -1 = No structure, 0 = Friendly, 1 = Enemy
        int owner = in.nextInt();
        int param1 = in.nextInt();
        int param2 = in.nextInt();
        Structure structure;
        if (structureType == Structure.BARRACK) {
            Barrack b = barracksCache[siteId];
            structure = b;
            b.turnBeforeTrain = param1;
            // KNIGHT, ... , GIANT
            b.subtype = param2;
        } else if (structureType == Structure.TOWER) {
            Tower t = towersCache[siteId];
            structure = t;
            t.life = param1;
            t.attackRadius = param2;
        } else if (structureType == Structure.MINE) {
            Mine m = minesCache[siteId];
            structure = m;
            m.incomeRate = param1;
        } else {
            structure = Structure.NONE;
        }
        structure.type = structureType;
        structure.owner = owner;
        site.structure = structure;
    }
    int numUnits = in.nextInt();
    creepsFE = creepsStart;
    for (int i = 0; i < numUnits; i++) {
        int x = in.nextInt();
        int y = in.nextInt();
        int owner = in.nextInt();
        // -1 = QUEEN, 0 = KNIGHT, 1 = ARCHER
        int unitType = in.nextInt();
        int health = in.nextInt();
        if (unitType == -1 && owner == 0) {
            queens[0].location.x = x;
            queens[0].location.y = y;
            queens[0].health = health;
        } else if (unitType == -1 && owner == 1) {
            queens[1].location.x = x;
            queens[1].location.y = y;
            queens[1].health = health;
        } else {
            Creep c = (Creep) all[creepsFE++];
            c.setType(unitType);
            c.location.x = x;
            c.location.y = y;
            c.owner = owner;
            c.health = health;
        }
    }
}
Also used : Site(coderoyale2.units.Site) Creep(coderoyale2.units.Creep) Barrack(coderoyale2.structures.Barrack) Mine(coderoyale2.structures.Mine) Tower(coderoyale2.structures.Tower) Structure(coderoyale2.structures.Structure)

Example 4 with Creep

use of coderoyale2.units.Creep in project cg by nmahoude.

the class Simulation method creepDealDamage.

private void creepDealDamage() {
    for (int i = Player.creepsStart; i < Player.creepsFE; i++) {
        Creep creep = (Creep) Player.all[i];
        if (creep.health <= 0)
            continue;
        creep.dealDamage();
    }
}
Also used : Creep(coderoyale2.units.Creep) Point(coderoyale2.Point)

Example 5 with Creep

use of coderoyale2.units.Creep in project cg by nmahoude.

the class Barrack method onComplete.

public void onComplete() {
    int creepCount;
    if (this.subtype == Structure.KNIGHT) {
        creepCount = 4;
    } else if (this.subtype == Structure.ARCHER) {
        creepCount = 2;
    } else {
        creepCount = 1;
    }
    for (int i = 0; i < creepCount; i++) {
        Creep newCreep = (Creep) Player.all[Player.creepsFE++];
        newCreep.setType(this.subtype);
        newCreep.owner = owner;
        newCreep.location.x = this.attachedTo.location.x + i;
        newCreep.location.y = this.attachedTo.location.y + i;
    // TODO code it
    // it.location = it.location.towards(barracks.owner.enemyPlayer.queenUnit.location, 30.0)
    }
// TODO code it
// fixCollisions(allEntities())
}
Also used : Creep(coderoyale2.units.Creep)

Aggregations

Creep (coderoyale2.units.Creep)7 Point (coderoyale2.Point)4 Barrack (coderoyale2.structures.Barrack)3 Mine (coderoyale2.structures.Mine)3 Tower (coderoyale2.structures.Tower)3 Site (coderoyale2.units.Site)2 Action (coderoyale2.simulation.Action)1 Simulation (coderoyale2.simulation.Simulation)1 Structure (coderoyale2.structures.Structure)1 Queen (coderoyale2.units.Queen)1 Scanner (java.util.Scanner)1