Akuukis / screeps-bot-brave

In cooperation with its kind it will strive to unite the server into a brave new world. Community! Identity! Stability!
GNU General Public License v2.0
49 stars 37 forks source link

Intro

At this moment all ideas ar work in progress. dev and master are both broken. I hope to get structure and concepts in place, as well creeps doing basic jobs as soon as possible (spring 2017?). That will be called version Alpha 1.0 and from that on I invite everyone to join in to develop this further together.

Check out legacy branch for simple code that runs a room on 3.50 CPU/tick.

Vision

Create BraveBot that in cooperation with its kind will unite the server into a brave new world. Community! Identity! Stability!

Roadmap

Currently I am only putting down to text and testing all ideas. Code mismatch with documentation in most parts, and there are several obsolete and broken parts. Also code contains unrelated basic logic to survive and make testing easier. I expect to move to organized developing somewhat soon, feel free to jump in to discuss concepts through issues or email.

  1. Put down concepts into notes and probably test them (focus on conceptual effectiveness)
  2. Make-it-work not to die off on its own (focus on scalability)
  3. Make-it-work using infrastructure (focus on scalability)
  4. Make-it-work defending (focus on scalability)
  5. Make-it-work scouting & expanding (focus on scalability)
  6. Make-it-work aggression & conquering (focus on scalability)
  7. Make-it-work diplomacy (focus on scalability)
  8. Rewrite notes into documentation and inline comments (focus on understandable)
  9. Review & improve concepts (focus on conceptual effectiveness)
  10. Make-it-work anything new (focus on scalability)
  11. Improvements & make-it-work Adis - Automatic Debugging & Isolation System (focus on error-prone)
  12. Improvements & make-it-work MUI - Memory based User Interface (focus on fun)
  13. Improvements and finish 100% expected functionality (focus on CPU and RAM efficiency)
  14. Together build wonder worth 161.8mil energy in public server (focus on fun)

How to participate

To use or test

  1. Fork
  2. Make sure default branch is master. That's in Github settings just under repository name
  3. It should work out-of-box (content of master branch). If not, report an issue

To participate

  1. Fork

  2. Change default branch to develop. That's in Github settings just under repository name

  3. It should work and not throw basic errors but use with caution

  4. To trigger screeps.com to repull your code from default branch commit on any branch

  5. Test & play around

    • To try out new code in 3 seconds, you can add alias in ~/.bash_profile file
    alias gitfix='git commit --all --amend --no-edit; git push -f'
  6. Pull request to any of feature-* branches, to develop, or to next release-* branch

Policy

  1. No hardcoded places, rates, targets, etc.
  2. Same code for small, big and emergency situations.
  3. Behavior is error, memory corruption and exception case safe.
  4. Swarm intelegence.
  5. Prioritized / flexible CPU load.
  6. Global parameters
    1. pulse is for cyclic recalculations to lower CPU load
    2. t is length of timespan (1=emergency,1000=longterm) the colony is in, for decision making
    3. threat is the global militarization level
  7. Code max 120 width, tabbed, camelCase, prefer aligned, optional spacing.

Debug snippets

Armagaddeon: var t = Memory.creeps; for(i in Memory){ Memory[i] = undefined; }; Memory.creeps=t;

Notes on performance

API calls:

// Every line starts with "var t=Game.getUsedCpu(); for(i=0;i<100;i++){ ", ends with "}; console.log(Game.getUsedCpu()-t);" and is entered into console.
Game.rooms.W4N5.lookAt(25,41); // 100-120 CPU
Game.rooms.W4N5.find(FIND_STRUCTURES, {filter: { structureType: STRUCTURE_SPAWN }}); // 2.0-6.5 CPU
Game.rooms.W4N5.find(FIND_DROPPED_ENERGY); // 1.5-5.5 CPU
Game.spawns["Spawn1"]; // 0.2-0.35 CPU
Game.getObjectById("557293f459189a99084ffa68"); // 0.2-0.35 CPU
test = new RoomPosition(1,1,'W8N4'); // 0.37-0.40

Javascript itself:

var t=Game.getUsedCpu(); var test="kuku"; for(i=0;i<1000;i++){ test=test||"blah" }; console.log(Game.getUsedCpu()-t); // 2.5-3.0, all types
var t=Game.getUsedCpu(); var test="kuku"; for(i=0;i<1000;i++){ if(!test){test="blah"}; }; console.log(Game.getUsedCpu()-t); // 1.5-2.0, all types

Concepts

Code consists of multiple tighly integrated modules. For module specific documentation see doc/<module>.md. Beware that main.js is automatically built using gulp to incoporate list of modules and bypass require of them.

Modularity

Code consists of multiple modules that communicate to each other directly via object methods (according to globally defined API) and indirectly via Memory (according to global data model). Internal logic of module can be interchanged without global problems, thus multiple alternative modules are supported and encouraged. When modules are hierarchical, the parent also tracks and measures performance of childs. If child behaves badly then parent may decide to change its logic to alternative module. Every module with "Squad" in it actually may control a creep, others don't. First and second level or hierarchy are "virtual" in a sense that they directly interact only with other modules and memory. The list of modules are as follows:

Naming convention (everyone ending with .js): *_launcher, *_economy, *_utilities, *_adis, *_player, *_diplomat, *_ambassador, *_marshal, *_major, *_executive, *_governor, *_spawner, *_storage, *_squadConsul, *_squadCaptain, *_squadMiner, *_squadMilita, *_squadExtractor, *_squadPolice, *_squadBuilder, *_squadLogistics.

Launcher

Scans folder for modules and requires them, caches objects or rebuids from memory, and executes modules.

Economy

Provides Agent class and bazaar* objects. Agent is class from which every economic player inherits that handles all transactions, accounting and metrics. bazaar* are objects that represent various internal markets for energy, creeps, etc. Everyone that inherits from Agent interacts with each other through one or more bazaar*.

Utilities

Miscellaneous stuff used globally, for example logger.

ADIS

The Automatic Debugging & Isolation System is used globally. It contains various routines that's main goal is to prevent coma as gracefully as possible.

Player

It is you! It also is an Agent.

Diplomat & Ambassadors

They deal with allies, manual trade, communication and other diplomatic stuff. To be developed a lot later.

Marshal & Majors

They deal with war, mostly offence and perhaps also strategic defense. To be developed later.

Executive & Governors

They deal with production and defense. Developing now.

Executive has mapped nearby room for their tactical usefulness and best locations for deff squads. According to their placement territory is divided into zones, and each zone has either state

Also Executive polls governor opinions about other rooms for their income potential and best spawn placement, thus prioritizing which room to take next.

Every room has a Governor. Governors plan structure layout, caches "paths", trade, supply other governors.

API & Memory Data Model

There is API and Memory data Model for each pair up & down the hierarchy, e.g. Executive to Governor. Also, globally API is present from each Agent to modules economy, utilities and adis.