hivemind icon indicating copy to clipboard operation
hivemind copied to clipboard

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

Open FutureAstroMiner opened this issue 1 year ago • 1 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.

FutureAstroMiner avatar Nov 10 '23 19:11 FutureAstroMiner

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 4af8ecb36e7722b115c11a39df25d31598c609da

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

Mirroar avatar Nov 12 '23 20:11 Mirroar

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

FutureAstroMiner avatar Aug 02 '24 07:08 FutureAstroMiner