Mirroar/hivemind

New body-builder generating creep bodies with more than 50 (MAX_CREEP_SIZE) parts when weights and non default movement mode

Closed this issue · 2 comments

So I was doing some combat trials with your bot as an NPC on my private server and noticed that spawning had stopped.

I managed to get a test that should help you. It requires the setWeights() to have something other than a MOVE in there (so MOVE:1 will work but MOVE:1, CARRY,1 fails) when combined with the MovementMode.

it('Max size with weights and MOVEMENT_MODE_ROAD should be 50 or under', () => {
    expect((new BodyBuilder())
      .setWeights({
        [WORK]: 4,
        [CARRY]: 3
      })
      .setMovementMode(MOVEMENT_MODE_ROAD)
      .build().length).toBeLessThanOrEqual(MAX_CREEP_SIZE); // This fails
  });
  it('Max size with weights and MOVEMENT_MODE_PLAINS should be 50 or under', () => {
    expect((new BodyBuilder())
      .setWeights({
        [WORK]: 4,
        [CARRY]: 3
      })
      .setMovementMode(MOVEMENT_MODE_PLAINS)
      .build().length).toBeLessThanOrEqual(MAX_CREEP_SIZE); // Pass
  });

Oh and in CalculatePartCounts const nextPart = this.getNextBodyPart(partCounts); getNextBodyPart could return null so nextPart could be null causing issues.

Thanks for reporting this issue, I haven't really noticed it myself, so it's very helpful. I had noticed a different issue - initial builder creeps were generated without move parts, or did not adhere to the given energy limit. In fixing that, this problem also seems to be gone, at least you test generates a creep with 50 body parts for me. The commit in question is 4af8ecb

As for the second note: The only way getNextBodyPart could return null is if the weights are empty, which is not supported, anyway.

Don't see this error anymore so closing to clear up.