Screeps AI: First Rewrite and moving to Typescript

Posted by Argha Sen on August 1, 2022

This is the second part of my journey in screeps. In the first part I spoke about how the use of javascript in writing the AI was extremely errorprone. So based on that the plan was to use Typescript and create a functioning AI. This proved to be hard as learning Typescript was not as simple as it seemed initally. The language has its own interesting features and tooling so it took me some time to figure out how to get things working in Typescript.

Screeps-Typescript-Starter is a really good point to start building the AI in screeps.

Design on the AI

At the base of the AI is the the concept of Managers who decide and control the activities of the entire system.

  1. The Room Managers are responsible for all the functions of the room.
  2. The Worker Managers are responsible for the working of the creeps.
  3. The Building Managers are responsible for building of infrasructure.

The three managers have been quite good in helping us progress in screeps.

Different Types of Creeps

  • Harvester: These creeps are the most basic and their job is to harvest energy from the sources and pass them to the spawn and extensions.
  • Upgraders: These look to upgrade the room controller.
  • Builders: They build all the infrastructure needed for the room.
  • Continuous Harvester: They are specialized harvesters which only have WORK and MOVE parts. Their job is to harvest the energy.

Features of the AI:

The AI at the moment tries to go up to RCL level 2 and then create 5 extensions and roads to the spawn to the energy sources. This helps speed up operations and from there it grinds up in levels. All other structures have to be placed manually and the AI will build it.


The AI has basic defense code as well as long as we can manually create a tower and the AI will use it to defend against the NPC attackers that spawn from time to time.

Future Plans

The next target for the AI is to be automatically creating more extensions at RCL3. Also I will be looking into container mining as it is considered more efficient.