-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] improve carry recycling #403
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, but implementation seems to be a bit hackish. I'd like to avoid carry- or whatever role -specific logic in common code. At least avoid new such code if possible)
Also make sure you won't recycle last carry for target
@@ -63,15 +63,22 @@ Creep.prototype.spawnCarry = function() { | |||
resourceAtPosition += _.sum(container.store); | |||
} | |||
|
|||
const waitTime = carryCapacity / (HARVEST_POWER * workParts) * | |||
Math.sqrt(carryCapacity / Math.max(resourceAtPosition, carryCapacity)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like it
src/prototype_creep_routing.js
Outdated
@@ -267,6 +267,10 @@ Creep.prototype.moveByPathMy = function(route, routePos, start, target, skipPreM | |||
if (this.memory.killPrevious) { | |||
this.killPrevious(); | |||
} | |||
if (this.memory.checkRecycle && this.isStuck() && !this.memory.routing.reverse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like it. carry may stuck not only because of lack of resources at sourcer
either way, name recycleOnStuck
would be better then checkRecycle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we may move it to carries pre-move?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little bit tricky to move this to pre-move because I need to use path.length
. Maybe we can store path.length
in creeps' memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can pass it the same way as directions
src/prototype_creep.js
Outdated
@@ -63,7 +63,7 @@ Creep.prototype.handle = function() { | |||
return; | |||
} | |||
|
|||
if (this.memory.recycle) { | |||
if (this.memory.recycle && this.memory.moveToSpawn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not like it at all. creep.memory.recycle
meant to be universal and easily to set manually from interface, if we need it
src/role_carry.js
Outdated
} | ||
} | ||
if (roles.carry.checkOnPathStart(creep)) { | ||
creep.memory.moveToSpawn = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to handle carries pre-recycle logic with another memory flag, and set recycle flag here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, I'll use resetTarget
for pre-recycle logic
@@ -63,15 +63,22 @@ Creep.prototype.spawnCarry = function() { | |||
resourceAtPosition += _.sum(container.store); | |||
} | |||
|
|||
const waitTime = carryCapacity / (HARVEST_POWER * workParts) * | |||
Math.sqrt(carryCapacity / Math.max(resourceAtPosition, carryCapacity)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach, can you explain a bit more what the idea is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce waitTime
according to resourceAtPosition
. I use Math.sqrt
in the hope that it will reach an equilibrium quickly (not call/spawn too much carries).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
K, cool, let's see
src/prototype_creep_harvest.js
Outdated
} | ||
|
||
// low minSpawnRate helps carry recycling | ||
let minSpawnRate = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract it to the config
// when ticksToLive > recycleThreshold, reuse carry | ||
recycleThreshold: 200, | ||
// keep at least one carry for a target | ||
ensureOne: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't think up a better name...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine, maybe ensureOnePerTarget
... :-)
if (baseRoom.controller.level < 4) { | ||
this.memory.wait = Math.max(waitTime, config.carry.minSpawnRate); | ||
} else { | ||
this.memory.wait = waitTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, waitTime
won't get too small because of Math.sqrt
.
@@ -139,7 +139,13 @@ global.config = { | |||
1800: [8, 15], // RCL 5 | |||
2300: [11, 21], // RCL 6 | |||
}, | |||
transferToCarry: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the intention is.
The default behavior should be that carries transfer to carries. If I understand the implementation correct, that would be disabled here.
And there are two methods, something like transferToCreep
which actually transferrs and something like checkForTransfer
which lets the carry move in the other direction because it will get energy in this tick.
Both needs to be adapted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can swap carries' target when they transfer to each other.
@@ -164,6 +192,35 @@ roles.carry.preMove = function(creep, directions) { | |||
} | |||
|
|||
reverse = creep.pickupWhileMoving(reverse); | |||
|
|||
// recycle carry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like the recycling idea sooo much.
If there is a problem with too many carries, the call carry
logic should be improved.
But fine until the call carry
logic is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ultimate solution to call carry
logic would be #294. My solution is making use of 'negative feedback'. The latter one is not as efficient as the former one, but it's easier to be implemented, and, in my opinion, their performance difference is not quite significant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with adding this one and I'm also not so sure about the perfect solution, especially due to the fact that paths should be shared over multiple sources, which makes it more tricky.
- move codes related to carry recycling into `role_carry.js` - add an option of keeping at least one carry for a target - normally carry spawn rate won't get too fast because `Math.sqrt` is used
- fixed pickupWhileMoving. carry might move back and forth next to sourcer - ensureOne: exclude creeps that have `resetTarget` flag
// when ticksToLive > recycleThreshold, reuse carry | ||
recycleThreshold: 200, | ||
// keep at least one carry for a target | ||
ensureOne: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine, maybe ensureOnePerTarget
... :-)
@@ -63,15 +63,22 @@ Creep.prototype.spawnCarry = function() { | |||
resourceAtPosition += _.sum(container.store); | |||
} | |||
|
|||
const waitTime = carryCapacity / (HARVEST_POWER * workParts) * | |||
Math.sqrt(carryCapacity / Math.max(resourceAtPosition, carryCapacity)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
K, cool, let's see
@@ -106,7 +99,7 @@ Creep.prototype.pickupWhileMoving = function(reverse) { | |||
if (resources.length > 0) { | |||
const resource = resources[0]; | |||
const amount = this.pickupOrWithdrawFromSourcer(resource); | |||
return _.sum(this.carry) + amount > 0.5 * this.carryCapacity; | |||
return this.checkEnergyTransfer(amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -164,6 +192,35 @@ roles.carry.preMove = function(creep, directions) { | |||
} | |||
|
|||
reverse = creep.pickupWhileMoving(reverse); | |||
|
|||
// recycle carry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with adding this one and I'm also not so sure about the perfect solution, especially due to the fact that paths should be shared over multiple sources, which makes it more tricky.
might have a look at my https://screeps.com/a/#!/room/shard1/W31N49 room. got a pretty good result with my amount calculation and creeps modifs. |
The main point of this commit is improving energy harvest efficiency.
resourceAtPostion
.With this improvement, carries will work more efficiently. Tested on the official server:
Stored about 900k energy in storage before upgrading to RCL6. (five sources in extern room)