Skip to content

Instantly share code, notes, and snippets.

If your creep needs to find...
(can be accessed as creep.pos, or any other RoomPosition)
creep.pos.findClosestByRange(type, options) -- returns one object, type is FIND_xx, for example: target = creep.pos.findClosestByRange(FIND_MY_SPAWNS);
creep.pos.findClosestByPath(type, options) -- as above, but more CPU costly (searches by real path, not distance)
creep.pos.findInRange(type, range, options) -- array, type is FIND_xx. Searches in square. All 8 adjacent tiles to creep are in range 1
creep.pos.lookFor(type) -- array of objects that are at same position as creep. Type is LOOK_xx, for example LOOK_CONSTRUCTION_SITES
(can be accessed as creep.room, or any other Room)
creep.room.find(type, options) -- array, type is FIND_xx, for example FIND_DROPPED_RESOURCES. Options can have filter - as a function or object, like
module.getItemNames = function (item_ids, cb) {
dbItems.find({ 'id': { $in: item_ids } }).toArray(function (err, docs) {
if (err) {
log.error("getContracts_items: Error for dbItems.find", { err });
cb(err);
return;
}
var fullquery = docs.map(d => d.id);
let UTILS_ROOM = {};
UTILS_ROOM.getSpawns = function (room) {
//return getCached(room.name, "spawn", () =>
return room.find(FIND_MY_STRUCTURES, {
filter: { structureType: STRUCTURE_SPAWN }
})
//);
};
let UTILS = {};
//let UTILS = require('./utils');
//let UTILS_ROOM = require('./utils.room');
let UTILS_ROOM = {};
UTILS_ROOM.getSpawns = function (room) {
//return getCached(room.name, "spawn", () =>
return room.find(FIND_MY_STRUCTURES, {
filter: { structureType: STRUCTURE_SPAWN }
// cacheEnum
CACHE.E_ROOM = 1;
CACHE.coreInit = function () {
if (!global.my_caches) {
CACHE[CACHE.E_ROOM] = Memory.rooms;
global.my_caches = true;
}
function renderMatrix(roomName, costMatrix, color = '#ff0000') {
var vis = Game.rooms[roomName].visual;
const array = costMatrix._bits;
var max = _.max(array);
for (var x = 0; x < 50; ++x) {
for (var y = 0; y < 50; ++y) {
var value = array[x * 50 + y];
const PLAIN_COST = 3;
const SWAMP_COST = 6;
const WALL_COST = 30 * PLAIN_COST;
const EXISTING_PATH_COST = PLAIN_COST - 2;
function getDestinations(room) {
let destinations = room.find(FIND_SOURCES);
destinations.push({ pos: room.getPositionAt(1, 25) });
return destinations;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Funkcja: Update()
// Działanie: update..
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Bohater :: Update()
{
brain->Update();
cycles++;
Procedure naucz(var _siec :Tsiec;var _uczacy :Tuczacy);
{uczenie sieci metoda wstecznej propagacji bledow, liczba warstw: min 3}
var
_out :Tout; _in :Tin; _delta :Tdelta; _blad :Tblad;
_i,_i2,_i3 :integer; waga_tmp :real;
begin
for _i2:=1 to _siec.liczba_n[1] do _out[1,_i2]:=_uczacy.we[_i2]; {warstwa we}
for _i:=1 to _siec.liczba_w-1 do _out[_i,_siec.liczba_n[_i]]:=1; {bias}
{mnozenie wejsc przez wagi dla kazdego neuronu}
for _i:=2 to _siec.liczba_w do
function planner_loop (roomName, opts = {}) {
let _this = {};
_this.visual = new RoomVisual(roomName);
_this.anchor = getAnchor(roomName);
_this.terrain = new Room.Terrain(roomName);
if (!_this.anchor) return;
let s = 1;