<commit_before>import { TargettedTask } from '../targetted';
import { getObjectByIdOrDie, TASK_BUILD, TASK_REFILL, TASK_REPAIR, TASK_UPGRADE } from '../task';
import { StructurePriority } from './build';

type RefillTarget = (EnergyContainer & Structure) | Creep;

const constructiveTasks = {
  [TASK_BUILD]: true,
  [TASK_REPAIR]: true,
  [TASK_UPGRADE]: true
};

function isValidTarget(target: RefillTarget) {
  if (target instanceof Creep) {
    return !target.isFull() && constructiveTasks[target.task.type];
  }
  return target.energyCapacity ? target.energy < target.energyCapacity : false;
}

export class RefillTask extends TargettedTask<RefillTarget> {
  public static plan(room: Room) {
    return _.map(
      _.filter(
        _.flatten([room.myActiveStructures, room.myCreeps] as RefillTarget[][]),
        isValidTarget
      ),
      (s: RefillTarget) => new RefillTask(s)
    );
  }

  public get type() {
    return TASK_REFILL;
  }

  public get priority() {
    if (this.target instanceof Creep) {
      return this.target.task.priority * 1.1;
    }
    return 150 + (StructurePriority[this.target.structureType] || 100);
  }<commit_msg>Reduce refill priority based on target energy.<commit_after>import { TargettedTask } from '../targetted';
import { getObjectByIdOrDie, TASK_BUILD, TASK_REFILL, TASK_REPAIR, TASK_UPGRADE } from '../task';
import { StructurePriority } from './build';

type RefillTarget = (EnergyContainer & Structure) | Creep;

const constructiveTasks = {
  [TASK_BUILD]: true,
  [TASK_REPAIR]: true,
  [TASK_UPGRADE]: true
};

function isValidTarget(target: RefillTarget) {
  if (target instanceof Creep) {
    return !target.isFull() && constructiveTasks[target.task.type];
  }
  return target.energyCapacity ? target.energy < target.energyCapacity : false;
}

export class RefillTask extends TargettedTask<RefillTarget> {
  public static plan(room: Room) {
    return _.map(
      _.filter(
        _.flatten([room.myActiveStructures, room.myCreeps] as RefillTarget[][]),
        isValidTarget
      ),
      (s: RefillTarget) => new RefillTask(s)
    );
  }

  public get type() {
    return TASK_REFILL;
  }

  public get priority() {
    if (this.target instanceof Creep) {
      const creep = this.target;
      return creep.task.priority * 1.1 * Math.pow(1.0 - (creep.energy / creep.carryCapacity), 2);
    }
    const f = 1.0 - Math.pow(this.target.energy / this.target.energyCapacity, 2);
    return 150 + f * (StructurePriority[this.target.structureType] || 100);
  }
{'fraction_non_alphanumeric': 0.12599364069952304, 'fraction_numerical': 0.008744038155802861, 'mean_word_length': 3.6784386617100373, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1847659', 'n_tokens_mistral': 839, 'n_tokens_neox': 804, 'n_words': 188}