Skip to content

Instantly share code, notes, and snippets.

606026600, states 42, hash(depth) 1049636110(4)
616026600, states 8, hash(depth) 623785658(3)
606126600, states 8, hash(depth) 613885658(3)
616126600, states 2, hash(depth) 158491417(2)
606036600, states 26, hash(depth) 906136517(3)
616036600, states 6, hash(depth) 475364201(2)
606136600, states 6, hash(depth) 455564201(2)
616136600, states 2, hash(depth) 158531387(1)
606046600, states 1, hash(depth) 606046600(0)
606006610, states 376, hash(depth) 567139364(6)
let set = [];
play(matrix, depth);
function play(matrix, depth){
print(matrix, depth);
if(depth == 0) {
result(matrix);
return;
}
let moves = 0;
@lethern
lethern / gist:beac62d55acf044bc6018dfaed7a6caa
Last active January 1, 2025 01:52
JS running CodinGame server
#########################
### build/build_node.bat
# produces a nodejs executable with ai.js injected in
node --experimental-sea-config sea-config.json
node -e "require('fs').copyFileSync(process.execPath, 'ai.exe')"
npx postject ai.exe NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
# https://nodejs.org/api/single-executable-applications.html
#########################
### build/sea-config.json
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;
}