<commit_before>
class MetaRole {

  recharge(creep) {
    if (creep.carry[RESOURCE_ENERGY] <= 0) {
      creep.memory.recharge = true
    }
    if (creep.carry[RESOURCE_ENERGY] >= creep.carryCapacity) {
      creep.memory.recharge = false
    }
    if (creep.memory.recharge) {
      var sources = creep.room.find(FIND_SOURCES_ACTIVE)
      let idx = parseInt(creep.name[creep.name.length - 1], 36)
      var source = sources[idx % sources.length]
      if (!creep.pos.isNearTo(source)) {
        creep.moveTo(source)
      }
      if (creep.pos.isNearTo(source)) {
        creep.harvest(source)
      }
      return true
    }
    return false
  }

}<commit_msg>Sort sources by distance to controller<commit_after>
class MetaRole {

  recharge(creep) {
    if (creep.carry[RESOURCE_ENERGY] <= 0) {
      creep.memory.recharge = true
    }
    if (creep.carry[RESOURCE_ENERGY] >= creep.carryCapacity) {
      creep.memory.recharge = false
    }
    if (creep.memory.recharge) {
      var sources = creep.room.find(FIND_SOURCES_ACTIVE)
      sources.sort((a, b) => a.pos.getRangeTo(a.room.controller) - b.pos.getRangeTo(b.room.controller))
      let idx = parseInt(creep.name[creep.name.length - 1], 36)
      var source = sources[idx % sources.length]
      if (!creep.pos.isNearTo(source)) {
        creep.moveTo(source)
      }
      if (creep.pos.isNearTo(source)) {
        creep.harvest(source)
      }
      return true
    }
    return false
  }

}
{'fraction_non_alphanumeric': 0.12852233676975944, 'fraction_numerical': 0.005498281786941581, 'mean_word_length': 2.533980582524272, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '4180875', 'n_tokens_mistral': 538, 'n_tokens_neox': 522, 'n_words': 85}