Skip to content

Instantly share code, notes, and snippets.

@seth10
Created October 3, 2016 17:41
Show Gist options
  • Save seth10/ed999b2b5b5095f71b1822179fbab692 to your computer and use it in GitHub Desktop.
Save seth10/ed999b2b5b5095f71b1822179fbab692 to your computer and use it in GitHub Desktop.
Calculate optimal configuration for Screeps creeps
import math
def roundUp(x,y):
return int(math.ceil(float(x)/y))
d = input('Distance: ') #10 #distance of path betweem source and controller
SPAWN_ENERGY_CAPACITY = 300
CONTROLLER_STRUCTURES = { "extension": { 3: 10 } }
STRUCTURE_EXTENSION = "extension"
EXTENSION_ENERGY_CAPACITY = { 3: 50 }
BODYPART_COST = { "work": 100, "carry": 50, "move": 50 }
WORK = "work"
CARRY = "carry"
MOVE = "move"
CARRY_CAPACITY = 50
HARVEST_POWER = 2
#SOURCE_ENERGY_CAPACITY = 3000
energyCapacity = SPAWN_ENERGY_CAPACITY + CONTROLLER_STRUCTURES[STRUCTURE_EXTENSION][3]*EXTENSION_ENERGY_CAPACITY[3] #Game.creeps['asdf'].room.energyCapacityAvailable
best = (0, 0, 0, 0)
for w in range(1, ((energyCapacity - 1*BODYPART_COST[CARRY] - 1*BODYPART_COST[MOVE]) / BODYPART_COST[WORK])+1): #+1 b/c python range exclusive
for c in range(1, ((energyCapacity - w*BODYPART_COST[WORK] - 1*BODYPART_COST[MOVE]) / BODYPART_COST[CARRY])+1):
m = (energyCapacity - w*BODYPART_COST[WORK] - c*BODYPART_COST[CARRY])/BODYPART_COST[MOVE]
#print w, c, m
timeToGetThere = roundUp(w,m) * d
timeToMine = roundUp(c*CARRY_CAPACITY, w*HARVEST_POWER)
timeToGetBack = roundUp(w+c,m) * d
#print w, c, m, timeToGetThere, timeToMine, timeToGetBack
totalTime = timeToGetThere + timeToMine + timeToGetBack
energyMined = c*CARRY_CAPACITY
efficiency = float(energyMined) / totalTime
#print w, c, m, totalTime, energyMined, efficiency
if efficiency > best[0]:
best = (efficiency, w,c,m)
print best
# remove unneeded move parts in energyToSpawn cost and printout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment