This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Put this at the top of your main.js file. Log `extraCPU` at the end to see how much extra CPU will be spent. | |
If you're using the "loop" architecture you have to move some stuff around. Just reset `extraCPU` and `called` every tick. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function longPath(from, to) { | |
let rooms = {}; | |
Game.map.findRoute(from.roomName, to.roomName).forEach(function(step, ii, route) { | |
function generateCostMatrix(dir1, dir2) { | |
let cm = new PathFinder.CostMatrix; | |
let dir = 1 << dir1 | 1 << dir2; | |
for (let ii = 0; ii < 49; ++ii) { | |
if (!(dir & 1 << TOP)) { | |
cm.set(ii, 0, 0xff); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addBlockedRoomsToMatrix(theRoom) | |
{ | |
console.log(theRoom) | |
var theMatrix = new PathFinder.CostMatrix | |
{ | |
var exits = Game.map.describeExits(theRoom); | |
for(var ext in exits) | |
{ | |
var room = exits[ext]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[...] | |
// Reverse of parseRoomName | |
renderRoomName(room) { | |
if (room[0] === 255) { | |
return 'sim'; | |
} | |
return ( | |
(room[0] < 0 ? 'W'+ (-room[0] - 1) : 'E'+ room[0])+ | |
(room[1] < 0 ? 'N'+ (-room[1] - 1) : 'S'+ room[1]) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getPx('https://s3.amazonaws.com/static.screeps.com/map2/'+ roomName+ '.png', function(err, pixels) { | |
if (err) { | |
throw err; | |
} | |
let kyskip = 50 * 3 * 3 * 4; | |
let kxskip = 3 * 4; | |
for (let yy = 0; yy < 50; ++yy) { | |
for (let xx = 0; xx < 50; ++xx) { | |
let px = pixels.data[xx * kxskip + yy * kyskip] * 0x10000 + pixels.data[xx * kxskip + yy * kyskip + 1] * 0x100 + pixels.data[xx * kxskip + yy * kyskip + 2]; | |
switch (px) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marcel@marcel-2 ~ $ node -v | |
v5.10.1 | |
marcel@marcel-2 ~ $ cat a.js | |
"use strict"; | |
switch (1) { | |
case 2: | |
let foo; | |
} | |
foo.bar; | |
marcel@marcel-2 ~ $ node a.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Long = require('long'); | |
class Long128 { | |
constructor(lo, hi) { | |
this.lo = lo; | |
this.hi = hi; | |
} | |
static mul64(left, right) { | |
let u1 = new Long(left.low, 0, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <string.h> | |
#define HI(n) ((uint64_t)(n)>>32) | |
#define LO(n) ((uint64_t)(n)&0xffffffff) | |
#define U128(hi,lo) ((my_uint128_t){ .high = hi, .low = lo}) | |
typedef struct { | |
uint64_t high; | |
uint64_t low; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marcel@localhost ~/isolated-vm $ g++ thing.cc -std=c++11 | |
thing.cc: In instantiation of 'void MakeThing(Args&& ...) [with Args = {}]': | |
thing.cc:16:12: required from here | |
thing.cc:12:44: error: use of deleted function 'Thing::Thing(const Thing&)' | |
Thing instance(std::forward<Args>(args)...); | |
^ | |
thing.cc:5:2: note: declared here | |
Thing(const Thing&) = delete; | |
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Matrix of any type which holds a value for each position in a room | |
template <typename Type, typename Store, size_t Pack, bool Packed = sizeof(Store) << 3 != Pack> | |
class local_matrix_store_t {}; | |
template <typename Type, typename Store, size_t Pack> | |
class local_matrix_store_t<Type, Store, Pack, false> { | |
protected: | |
std::array<Store, 2500> costs; | |
using reference = Type&; | |
using const_reference = typename std::conditional<std::is_trivial<Type>::value && sizeof(Type) <= sizeof(size_t), Type, const Type&>::type; |