Screeps Arena

Flee function
I want to talk about a simple function that I don't see implemented very often in arena code. It is an absolute requirement for effective warfare however. The ability to retreat from combat when a unit is threatened. It helps preserve your units, as well as gives them a much higher degree of flexibility in combat. If you're concerned about unit cohesion you can have all units retreat to the same point on the map. Or if you want to fragment your enemies just have your units flee in random paths. This will leave you with a core of units that havent been attacked among scattered enemies.

function flee(creep: Creep, targets: GameObject[], range=4) {
    const result = searchPath(
      creep,
      targets.map((i) => ({ pos: i, range })),
      { flee: true }
    );
    if (result.path.length > 0) {
      const direction = getDirection(
        result.path[0].x - creep.x,
        result.path[0].y - creep.y
      );
      creep.move(direction);
    }
  }
  
The parameters for input are the Creep that is fleeing, the list of targets to avoid (enemies) and the range to avoid an enemy (eg stay at least 4 squares away to be out of range). This searches for a path that avoids enemy units ( note flee:true makes this happen). It then moves on the first step of that path.

Screeps World Open Source AI....Coming soon!

Im busy writing new features in the AI before I talk about them here
The stuff I'm currently working on is:
  • Basic war code
  • Tower targeting optimizations- attempting to stop enemies from draining a room