<commit_before>/**Only targets with less that this much health will be repaired by towers.*/
const TOWER_REPAIR_MAX_HEALTH = 100000;

/**Minimum energy for towers to save for attacking hostile targets.*/
const TOWER_MINIMUM_ENERGY = 700;

/**filter for helping a tower find a target to repair.*/
const TOWER_REPAIR_TARGET = {
  filter: (structure) => structure.hits < structure.hitsMax / 4 &&
    structure.hits !== undefined &&
    structure.hits > 0
};

/**
Runs tower logic for all towers.
*/
function runTowerLogic() {
  let towers = _.filter(Game.structures, (structure) =>
    structure.structureType == STRUCTURE_TOWER);
  for (let tower of towers) {

    let closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);

    //prioritize shooting enemy creeps over repairing structures.
    if (closestHostile) {
      tower.attack(closestHostile);
    } else {
      let structures = tower.room.find(FIND_MY_STRUCTURES, TOWER_REPAIR_TARGET);

      let lowestHitsStructure;
      for (let structure of structures) {
        if (lowestHitsStructure === undefined ||
          structure.hits < lowestHitsStructure.hits) {
          lowestHitsStructure = structure;
        }
      }
      //Only repair if enough energy is saved up (in case of attacks)
      if (lowestHitsStructure &&
        tower.energy > TOWER_MINIMUM_ENERGY &&
        lowestHitsStructure.hits < TOWER_REPAIR_MAX_HEALTH) {
        tower.repair(lowestHitsStructure);
      }
    }
  }
}

module.exports = {
  runTowerLogic
};<commit_msg>Added code so that towers would heal creeps after an attack (if no enemy creeps are in the room).<commit_after>/**Only targets with less that this much health will be repaired by towers.*/
const TOWER_REPAIR_MAX_HEALTH = 100000;

/**Minimum energy for towers to save for attacking hostile targets.*/
const TOWER_MINIMUM_ENERGY = 700;

/**filter for helping a tower find a target to repair.*/
const TOWER_REPAIR_TARGET = {
  filter: (structure) => structure.hits < structure.hitsMax / 4 &&
    structure.hits !== undefined &&
    structure.hits > 0
};

/**
Runs tower logic for all towers.
*/
function runTowerLogic() {
  let towers = _.filter(Game.structures, (structure) =>
    structure.structureType == STRUCTURE_TOWER);
  for (let tower of towers) {

    let closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);

    //prioritize shooting enemy creeps over healing or repairing structures.
    if (closestHostile) {
      tower.attack(closestHostile);
    } else {
      let damagedCreeps = tower.room.find(FIND_MY_CREEPS, {
        filter: (creep) => {
          return creep.hits < creep.hitsMax;
        }
      });

      //prioritize healing creeps over repairing structures
      if (damagedCreeps.length) {
        tower.heal(damagedCreeps[0]);
      } else {
        let structures = tower.room.find(FIND_MY_STRUCTURES, TOWER_REPAIR_TARGET);

        let lowestHitsStructure;
        for (let structure of structures) {
          if (lowestHitsStructure === undefined ||
            structure.hits < lowestHitsStructure.hits) {
            lowestHitsStructure = structure;
          }
        }
        //Only repair if enough energy is saved up (in case of attacks)
        if (lowestHitsStructure &&
          tower.energy > TOWER_MINIMUM_ENERGY &&
          lowestHitsStructure.hits < TOWER_REPAIR_MAX_HEALTH) {
          tower.repair(lowestHitsStructure);
        }
      }
    }
  }
}

module.exports = {
  runTowerLogic
};
{'fraction_non_alphanumeric': 0.09490940465918896, 'fraction_numerical': 0.006614897900488927, 'mean_word_length': 2.9794050343249427, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '1474391', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1062, 'n_words': 282}