gpt-4.1-mini-2025-04-14· OpenAI
LMArena Human Preference 140K
create a screep code to evolute my colony
- User
create a screep code to evolute my colony
- Assistant
It looks like you want a Screeps script to help evolve or develop your colony. Screeps is a programming game where you control units (creeps) with JavaScript to build and manage your colony.
Here’s a simple example of a Screeps script that will:
- Spawn basic worker creeps (harvesters, builders, upgraders)
- Assign roles to creeps
- Make creeps harvest energy, build structures, and upgrade the controller
This is a basic "colony evolution" script to get you started:
module.exports.loop = function () { // Memory cleanup for dead creeps for (let name in Memory.creeps) { if (!Game.creeps[name]) { delete Memory.creeps[name]; console.log('Clearing non-existing creep memory:', name); } } // Define desired number of creeps per role const roleCounts = { harvester: 3, builder: 2, upgrader: 2, }; // Count creeps by role const creepsByRole = { harvester: _.filter(Game.creeps, (c) => c.memory.role == 'harvester'), builder: _.filter(Game.creeps, (c) => c.memory.role == 'builder'), upgrader: _.filter(Game.creeps, (c) => c.memory.role == 'upgrader'), }; // Spawn creeps if needed const spawn = Game.spawns['Spawn1']; // Change to your spawn name if (spawn.spawning == null) { for (const role in roleCounts) { if (creepsByRole[role].length < roleCounts[role]) { const newName = role + Game.time; spawn.spawnCreep([WORK, CARRY, MOVE], newName, { memory: { role: role } }); console.log('Spawning new ' + role + ': ' + newName); break; } } } // Role behaviors for (const name in Game.creeps) { const creep = Game.creeps[name]; if (creep.memory.role == 'harvester') { if (creep.store.getFreeCapacity() > 0) { // Harvest energy from nearest source const source = creep.pos.findClosestByPath(FIND_SOURCES_ACTIVE); if (source) { if (creep.harvest(source) == ERR_NOT_IN_RANGE) { creep.moveTo(source, { visualizePathStyle: { stroke: '#ffaa00' } }); } } } else { // Transfer energy to spawn or extensions const target = creep.pos.findClosestByPath(FIND_STRUCTURES, { filter: (structure) => { return (structure.structureType == STRUCTURE_SPAWN || structure.structureType == STRUCTURE_EXTENSION) && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0; } }); if (target) { if (creep.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(target, { visualizePathStyle: { stroke: '#ffffff' } }); } } } } else if (creep.memory.role == 'builder') { if (creep.store[RESOURCE_ENERGY] == 0) { // Harvest energy if empty const source = creep.pos.findClosestByPath(FIND_SOURCES_ACTIVE); if (source) { if (creep.harvest(source) == ERR_NOT_IN_RANGE) { creep.moveTo(source, { visualizePathStyle: { stroke: '#ffaa00' } }); } } } else { // Build construction sites const target = creep.pos.findClosestByPath(FIND_CONSTRUCTION_SITES); if (target) { if (creep.build(target) == ERR_NOT_IN_RANGE) { creep.moveTo(target, { visualizePathStyle: { stroke: '#ffffff' } }); } } else { // No construction sites, upgrade controller instead if (creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { creep.moveTo(creep.room.controller, { visualizePathStyle: { stroke: '#ffffff' } }); } } } } else if (creep.memory.role == 'upgrader') { if (creep.store[RESOURCE_ENERGY] == 0) { // Harvest energy if empty const source = creep.pos.findClosestByPath(FIND_SOURCES_ACTIVE); if (source) { if (creep.harvest(source) == ERR_NOT_IN_RANGE) { creep.moveTo(source, { visualizePathStyle: { stroke: '#ffaa00' } }); } } } else { // Upgrade the room controller if (creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { creep.moveTo(creep.room.controller, { visualizePathStyle: { stroke: '#ffffff' } }); } } } } };
How this script works:
- Keeps your memory clean of dead creeps.
- Maintains a minimum number of harvesters, builders, and upgraders.
- Harvesters gather energy and fill your spawn/extensions.
- Builders build construction sites or upgrade the controller if no building is needed.
- Upgraders focus on upgrading the controller.
- Uses simple pathfinding and role assignment.
How to use:
- Replace
'Spawn1'with your actual spawn name. - Paste this code into your main loop in Screeps.
- Make sure you have some energy in your spawn to start spawning creeps.
- Expand by adding more roles or advanced logic as you grow.
If you want a more advanced or specific colony evolution script (e.g., defense, mining, remote harvesting), just ask!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.