exaV / screeps-kotlin-starter

A starting point for a Screeps AI written in Kotlin
MIT License
46 stars 63 forks source link

Screeps Arena #14

Closed mjedynak closed 5 months ago

mjedynak commented 2 years ago

Is it possible to use the project in Screeps Arena?

exaV commented 2 years ago

I don't know. How does arena work? Is there an api documentation? If it uses the same api as screeps (meaning this one https://docs.screeps.com/api/) then it will work otherwise probably not

Zomis commented 4 weeks ago

@exaV The Arena API does look slightly different, but has a lot of similarities. It can be found here.

https://arena.screeps.com/docs/#arenaInfo

Worthy of note is that Screeps Arena does use a different module system and imports for the code. For example, here is the code I wrote for the construction part of the tutorial:

import { getObjectsByPrototype } from 'game/utils';
import { Creep, Source, StructureContainer } from 'game/prototypes';
import { ERR_NOT_IN_RANGE, RESOURCE_ENERGY } from 'game/constants';
import { } from 'arena';

import { createConstructionSite } from 'game/utils';
import { StructureTower } from 'game/prototypes';

let constructionSite = null;

export function loop() {
    let source = getObjectsByPrototype(StructureContainer)[0];
    if (!constructionSite) {
        constructionSite = createConstructionSite({x: 50, y: 55}, StructureTower).object;
    }
    let creep = getObjectsByPrototype(Creep)[0];

    if (creep.store.getFreeCapacity() > 0) {
        console.log("Harvest");
        if (creep.withdraw(source, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
            creep.moveTo(source);
        }
    } else if (creep.store.getUsedCapacity() > 0) {
        console.log("Build");
        if (creep.build(constructionSite) == ERR_NOT_IN_RANGE) {
            creep.moveTo(constructionSite);
        }
    }

}