JonathanSafer / screeps

Screeps AI
MIT License
25 stars 7 forks source link

creep efficiency. Cache path for transporters #110

Closed jordansafer closed 4 years ago

jordansafer commented 4 years ago

rn upgraders spend 5 cpu. 3.2 on upgrade controller, 0.8 on withdraw, ~1 cpu on move. transporter spends 2.4 cpu. 1.2 on findTarget, 0.2 on 'refill' miner spends 2.1 cpu, 1.7 cpu on harvest runner 1.2 cpu deposit miner 1 cpu ferry .95 cpu, getjob is .15 cpu powercreep 0.55 cpu, nextstate is .05 cpu builder 0.3 cpu. repare walls 0.2 cpu mineral miner .68 cpu, .38 cpu harvest link .6 cpu

Long pole is transporters wasting 1.2 cpu on findTarget. Paths should be cached.

jordansafer commented 4 years ago

check if the city has a cached path. if not, recalculate one. to find the path: get all extensions and a start point

getPath([], pos) = []
getPath(extensions, pos) =
   let nearest = getNearest(extensions)
   let path = findPathTo(nearest, range=1)
   let endPos = path[size-1]
   let nearExtensions, farExtensions = splitByDistance(extensions, distance=1)
   in (path, nearExtensions)::getPath(farExtensions, endPos)

^do that but use a while loop to make the javascript gods happy

jordansafer commented 4 years ago

made changes, caching list of extensions. currently saves %50 of findTarget cpu (0.6 instead of 1.2) but 66% of the remaining is spent on a single case statement checking energy available to decide if we need to visit sources.

cold start after a code deploy is super expensive now because it recalculates paths in all rooms, so this should be stored in memory