<commit_before>var creepsHelper = require('utils.creepsHelper');
var nameGenerator = require('utils.nameGenerator');

var populationFactory = {
    run: function(population, spawnName) {
        for (var i = 0; i < population.length; i++) {
            var populationRule = population[i];

            var creepsInRoleCount = creepsHelper.getCreepsInRole(populationRule.role).length;
            while (creepsInRoleCount < populationRule.count) {
                var creepMemory = { role : populationRule.role };
                if (typeof populationRule.startAction !== 'undefined') {
                    creepMemory.action = populationRule.startAction;
                }

                var createCreepResult = Game.spawns[spawnName].createCreep(
                    populationRule.parts,
                    nameGenerator.new(populationRule.role),
                    creepMemory);
                if(createCreepResult === ERR_NOT_ENOUGH_ENERGY) {
                    var fullRoomEnergy = Game.rooms.W54S28.energyAvailable;
                    console.log('Cannot create creep - no energy (' + fullRoomEnergy+ ')');
                } else if(createCreepResult === ERR_BUSY) {
                    // busy
                } else {
                    console.log('Creep creation result: Name = [' + createCreepResult + '], ' +
                        'Role = [' + Game.creeps[createCreepResult].memory.role + ']');
                }
                creepsInRoleCount++;
            }
        }
    }
};



module.exports = populationFactory;<commit_msg>Fix population factory<commit_after>var creepsHelper = require('utils.creepsHelper');
var nameGenerator = require('utils.nameGenerator');

var populationFactory = {
    run: function(population, spawnName) {
        for (var i = 0; i < population.length; i++) {
            var populationRule = population[i];

            var creepsInRoleCount = creepsHelper.getCreepsInRole(populationRule.role).length;
            while (creepsInRoleCount < populationRule.count) {
                var creepMemory = { role : populationRule.role };
                if (typeof populationRule.startAction !== 'undefined') {
                    creepMemory.action = populationRule.startAction;
                }

                var createCreepResult = Game.spawns[spawnName].createCreep(
                    populationRule.parts,
                    nameGenerator.new(populationRule.role),
                    creepMemory);
                if(createCreepResult === ERR_NOT_ENOUGH_ENERGY) {
                    var fullRoomEnergy = Game.rooms.W54S28.energyAvailable;
                    console.log('Cannot create creep - no energy (' + fullRoomEnergy+ ')');
                } else if(createCreepResult === ERR_BUSY) {
                    // busy
                } else {
                    var creep = Game.creeps[createCreepResult];
                    if (creep) {
                        console.log('Creep creation result: Name = [' + createCreepResult + '], ' +
                            'Role = [' + creep.memory.role + ']');
                    } else {
                        console.log('Cannot create creep. Result = ' + createCreepResult);
                    }

                }
                creepsInRoleCount++;
            }
        }
    }
};



module.exports = populationFactory;
{'fraction_non_alphanumeric': 0.10203470975463794, 'fraction_numerical': 0.002992220227408737, 'mean_word_length': 1.6851405622489959, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6588875', 'n_tokens_mistral': 886, 'n_tokens_neox': 802, 'n_words': 150}