Last active
June 5, 2021 07:42
-
-
Save PeterTheOne/5074d5465893c4163e5c to your computer and use it in GitHub Desktop.
Screeps http://www.screeps.com/
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
module.exports = function (creep) { | |
if(creep.energy == 0) { | |
creep.moveTo(Game.spawns.Spawn1); | |
Game.spawns.Spawn1.transferEnergy(creep); | |
} | |
else { | |
var targets = creep.room.find(Game.CONSTRUCTION_SITES); | |
if(targets.length) { | |
creep.moveTo(targets[0]); | |
creep.build(targets[0]); | |
} | |
} | |
} |
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
module.exports = function (creep) { | |
var target = creep.pos.findNearest(Game.HOSTILE_CREEPS); | |
if(target && creep.hits > creep.hitsMax - 500 /* no more attack */) { | |
creep.moveTo(target); | |
creep.attack(target); | |
} else { | |
creep.moveTo(Game.spawns.Spawn1); | |
} | |
} |
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
module.exports = function (creep) { | |
if(creep.energy === creep.energyCapacity) { | |
creep.memory.source = null; | |
creep.moveTo(Game.spawns.Spawn1); | |
creep.transferEnergy(Game.spawns.Spawn1); | |
return; | |
} | |
if (!creep.memory.source) { | |
var sources = creep.room.find(Game.SOURCES_ACTIVE); | |
sources.sort(function(a, b) { | |
var aDeltaX = Math.abs(creep.pos.x - a.pos.x); | |
var aDeltaY = Math.abs(creep.pos.y - a.pos.y); | |
var aDelta = Math.sqrt(aDeltaX + aDeltaY); | |
var bDeltaX = Math.abs(creep.pos.x - b.pos.x); | |
var bDeltaY = Math.abs(creep.pos.y - b.pos.y); | |
var bDelta = Math.sqrt(bDeltaX + bDeltaY); | |
return aDelta < bDelta; | |
}); | |
var harvesters = creep.room.find(Game.MY_CREEPS, function(creep) { | |
return creep.memory.role === 'harvester'; | |
}); | |
var target = sources[0]; | |
for (var i in sources) { | |
var count = 0; | |
for (var j in harvesters) { | |
if (harvesters[j].memory.source && | |
sources[i].pos.x === harvesters[j].memory.source.x && | |
sources[i].pos.y === harvesters[j].memory.source.y) { | |
count++; | |
} | |
} | |
if (count < 3) { | |
target = sources[i]; | |
} | |
} | |
creep.memory.source = { | |
id: target.id, | |
x: target.pos.x, | |
y: target.pos.y | |
} | |
} | |
creep.moveTo(creep.memory.source.x, creep.memory.source.y); | |
var sources = creep.pos.findInRange(Game.SOURCES, 1); | |
creep.harvest(sources[0]); | |
if (sources[0] && sources[0].energy == 0) { | |
creep.memory.source = null; | |
} | |
} |
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
module.exports = function (creep) { | |
var damagedCreep = creep.pos.findNearest(Game.MY_CREEPS, { | |
filter: function(object) { | |
return object !== creep && object.hits < object.hitsMax; | |
} | |
}); | |
if (creep.hits < creep.hitsMax - 100 /* no more heal */) { | |
creep.moveTo(Game.spawns.Spawn1); | |
creep.heal(damagedCreep); | |
return; | |
} | |
if(damagedCreep) { | |
creep.moveTo(damagedCreep); | |
creep.heal(damagedCreep); | |
return; | |
} | |
var guard = creep.pos.findNearest(Game.MY_CREEPS, { | |
filter: function(creep) { | |
return creep.memory.role === 'guard'; | |
} | |
}); | |
if (guard) { | |
creep.moveTo(guard); | |
} else { | |
creep.moveTo(Game.spawns.Spawn1); | |
creep.heal(damagedCreep); | |
} | |
} |
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
var builder = require('builder'); | |
var guard = require('guard'); | |
var harvester = require('harvester'); | |
var healer = require('healer'); | |
var harvesters = []; | |
var guards = []; | |
var builders = []; | |
var healers = []; | |
for (var i in Game.creeps) { | |
if(Game.creeps[i].memory.role == 'harvester') { | |
harvesters.push(Game.creeps[i]); | |
} | |
if(Game.creeps[i].memory.role == 'guard') { | |
guards.push(Game.creeps[i]); | |
} | |
if(Game.creeps[i].memory.role == 'builder') { | |
builders.push(Game.creeps[i]); | |
} | |
if(Game.creeps[i].memory.role == 'healer') { | |
healers.push(Game.creeps[i]); | |
} | |
} | |
if(harvesters.length < 4) { | |
Game.spawns.Spawn1.createCreep([Game.WORK, Game.CARRY, Game.MOVE], null, {role: 'harvester'}); | |
} else { | |
if ((guards.length + healers.length) / harvesters.length < 0.8) { | |
if (guards.length < 1) { | |
Game.spawns.Spawn1.createCreep([Game.TOUGH, Game.MOVE, Game.ATTACK, Game.MOVE, Game.ATTACK], null, {role: 'guard'}); | |
} else if (healers.length / guards.length < 0.5) { | |
Game.spawns.Spawn1.createCreep([Game.HEAL, Game.MOVE], null, {role: 'healer'}); | |
} else { | |
Game.spawns.Spawn1.createCreep([Game.TOUGH, Game.MOVE, Game.ATTACK, Game.MOVE, Game.ATTACK], null, {role: 'guard'}); | |
} | |
} else { | |
Game.spawns.Spawn1.createCreep([Game.WORK, Game.CARRY, Game.MOVE], null, {role: 'harvester'}); | |
} | |
} | |
/*if(harvesters.length < 3) { | |
Game.spawns.Spawn1.createCreep([Game.WORK, Game.CARRY, Game.MOVE], null, {role: 'harvester'}); | |
} else if(guards.length < 2) { | |
Game.spawns.Spawn1.createCreep([Game.ATTACK, Game.ATTACK, Game.TOUGH, Game.MOVE, Game.MOVE], null, {role: 'guard'}); | |
} else if(harvesters.length < 5) { | |
Game.spawns.Spawn1.createCreep([Game.WORK, Game.CARRY, Game.MOVE], null, {role: 'harvester'}); | |
} else if(healers.length < 1) { | |
Game.spawns.Spawn1.createCreep([Game.HEAL, Game.TOUGH, Game.MOVE], null, {role: 'healer'}); | |
} else if(guards.length < 3) { | |
Game.spawns.Spawn1.createCreep([Game.ATTACK, Game.ATTACK, Game.TOUGH, Game.MOVE, Game.MOVE], null, {role: 'guard'}); | |
} else if(guards.length < 6) { | |
Game.spawns.Spawn1.createCreep([Game.ATTACK, Game.ATTACK, Game.TOUGH, Game.MOVE, Game.MOVE], null, {role: 'guard'}); | |
}*/ | |
/*} else if(builders.length < 1) { | |
Game.spawns.Spawn1.createCreep([Game.WORK, Game.WORK, Game.CARRY, Game.MOVE], null, {role: 'builder'}); | |
}*/ | |
for(var name in Game.creeps) { | |
var creep = Game.creeps[name]; | |
if(creep.memory.role == 'harvester') { | |
harvester(creep); | |
} | |
if(creep.memory.role == 'builder') { | |
builder(creep); | |
} | |
if(creep.memory.role == 'guard') { | |
guard(creep); | |
} | |
if(creep.memory.role == 'healer') { | |
healer(creep); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment