<commit_before>var harvest = require('harvest');

module.exports = exports = function(creep) {
    if (creep.energy === 0) {
        creep.moveTo(Game.spawns.Spawn1);
        Game.spawns.Spawn1.transferEnergy(creep);
    }
    else {
        var target = creep.pos.findClosest(Game.CONSTRUCTION_SITES);
        if (target) {
            creep.moveTo(target);
            creep.build(target);
        } else {
            harvest(creep);
        }
    }
};<commit_msg>Update build method with better fallback.<commit_after>var harvest = require('harvest');

module.exports = exports = function(creep) {
    var spawn = Game.spawns[creep.memory.spawnName];
    var target = spawn.pos.findClosest(Game.CONSTRUCTION_SITES, {
        filter: function(site) {
            return site.my;
        }
    });

    if (target) {
        if (creep.energy === 0) {
            creep.moveTo(spawn);
            spawn.transferEnergy(creep);
        } else {
            creep.moveTo(target);
            creep.build(target);
        }
    } else {
        harvest(creep);
    }
};
{'fraction_non_alphanumeric': 0.13133208255159476, 'fraction_numerical': 0.00375234521575985, 'mean_word_length': 2.0485714285714285, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1008941', 'n_tokens_mistral': 342, 'n_tokens_neox': 347, 'n_words': 54}