Body generation algorithm bug
-
Hi everyone, having trouble with my body generation algorithm. While testing with parameters
generateBody ([WORK, CARRY], 300)
, it outputs (asconsole.log
says)work, carry, move
. If I try to pass [WORK, CARRY, MOVE] to theconsole.log
, it shows me the same message, but a comparsion says that this functions output and an actual bodypart array above are not equal. And if I try to use the output to create a creep, the spawn throws a -10 error (ERR_INVALID_ARGS), which meant that the body isn't properly described. All the other functions in my codebase work just fine (tested), so the mistake must be somwhere here:function generateBody (baseParts, maxEnergy) { var baseBody = []; baseBody = baseBody.concat (baseParts); // Add enough MOVE parts to let it move at half the max speed for (var i = 0; i < baseParts.length / 2; i++) { baseBody.push (MOVE); } // How many baseBodys we can produce with maxEnergy var times = Math.floor (maxEnergy / calculateCost(baseBody)); // If there are more parts than maximum, lower the 'times' accordingly if (times * baseBody.length > MAX_PARTS) { times = Math.floor (MAX_PARTS / baseBody.length); } else if (times == 0) { return []; } // Construct a finalBody out of 'times' baseBodys, which is the biggest body affordable for the maxEnergy var finalBody = []; for (var i = 0; i < times; i++) { finalBody = finalBody.concat (baseBody); } return finalBody; }
Thanks!
-
Thats strange - it just started working. I probably just should've reloaded the simulation.