Skip to content

Instantly share code, notes, and snippets.

View kbakdev's full-sized avatar
👋
dev

Kacper Bąk kbakdev

👋
dev
View GitHub Profile
Game.spawns['Spawn1'].spawnCreep( [WORK, CARRY, MOVE], 'Harvester1' );
module.exports.loop = function () {
var creep = Game.creeps['Harvester1'];
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
}
}
module.exports.loop = function () {
var creep = Game.creeps['Harvester1'];
if(creep.store.getFreeCapacity() > 0) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
}
}
else {
module.exports.loop = function () {
for(var name in Game.creeps) {
var creep = Game.creeps[name];
if(creep.store.getFreeCapacity() > 0) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
}
}
var roleHarvester = {
/** @param {Creep} creep **/
run: function(creep) {
if(creep.store.getFreeCapacity() > 0) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
}
}
@kbakdev
kbakdev / gist:12b03f014d2cd2cb25b541f6d0ceb18b
Created May 14, 2022 17:36
loop for calling module role.harvester
var roleHarvester = require('role.harvester');
module.exports.loop = function () {
for(var name in Game.creeps) {
var creep = Game.creeps[name];
roleHarvester.run(creep);
}
}
@kbakdev
kbakdev / main.js
Created May 14, 2022 17:43
screeps v2
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
module.exports.loop = function () {
for(var name in Game.creeps) {
var creep = Game.creeps[name];
if(creep.memory.role == 'harvester') {
roleHarvester.run(creep);
}
psql -U username -W -h hostname -d dbname -f db_dump.sql
@kbakdev
kbakdev / binets_formula.go
Created May 5, 2023 12:44
Binet's Formula Go
func FibonacciBinet(n int) int {
sqrt5 := math.Sqrt(5)
phi := (1 + sqrt5) / 2
return int(math.Round(math.Pow(phi, float64(n)) / sqrt5))
}
@kbakdev
kbakdev / fibonacci_recursive.go
Created May 5, 2023 12:49
Fibonacci Recursive Go
func FibonacciRecursive(n int) int {
if n <= 1 {
return n
}
return FibonacciRecursive(n-1) + FibonacciRecursive(n-2)
}