<commit_before>var reducer = require("../core/reducer");
var _ = require('underscore');

function _mergeNgh(ngh, first, a) {
    var to = _.reduce(ngh,
        function(memo, n) {
            return _.union(memo, first[n])
        }, ngh);
    to = _.without(to, parseInt(a));
    return to;
}

var areaNeighbour = function(n) { return typeof n != "string"; };

function _seaUnion(area, sea) {
    return _.filter(_.union(area, sea || []), areaNeighbour);
}

function TribeMover(map, moveLimit, seaCost) {
    this.start = {};
    this.map = _.clone(map);
    this.neighbours = {};
    this.neighbours2 = {};
    this.neighboursSea = {};
    this.neighboursSea2 = {};
    moveLimit = moveLimit ? moveLimit : 1;
    this.moveLimit = moveLimit;
    seaCost = seaCost === undefined ? -1 : seaCost;
    this.seaCost = seaCost;
    
    var seas = _.object(_.map(this.map, function(area, n) {
        // TODO: Should this use engine.isSeaNeighbour in some way?
        // Find the seas
        var ss = _.filter(area.neighbours, function (e) { return typeof e == "string" && e != 'frontier'; });
        var seangh = [];
        
        // Determine the sea neighbours
        for (var a in this.map)
        {
            if (a != n && _.intersection(this.map[a].neighbours, ss).length > 0)
            {
                seangh.push(parseInt(a));
            }
        }
        return [parseInt(n), seangh];
    }, this));
    
    _.each(this.map, function(area, ak) {
        this.neighbours[ak] = _.filter(area.neighbours, areaNeighbour);
        this.neighboursSea[ak] = _.union(this.neighbours[ak], seas[ak]);
    }, this);
    
    if (seaCost > -1)
        this.neighbours = this.neighboursSea;
    
    // First level neighbours with moveLimit
    for (var m = 1; m < moveLimit; m++)
    {
        var nextFirst = {};
        _.each(this.neighbours, function(ngh, ak) {
            nextFirst[ak] = _mergeNgh(ngh, this.neighbours, ak);
        });
        _.each(this.neighbours, function(ngh, ak) {
            this.neighbours[ak] = nextFirst[ak];
        });
    }
    // Second level neighbours<commit_msg>Added missing this's<commit_after>var reducer = require("../core/reducer");
var _ = require('underscore');

function _mergeNgh(ngh, first, a) {
    var to = _.reduce(ngh,
        function(memo, n) {
            return _.union(memo, first[n])
        }, ngh);
    to = _.without(to, parseInt(a));
    return to;
}

var areaNeighbour = function(n) { return typeof n != "string"; };

function _seaUnion(area, sea) {
    return _.filter(_.union(area, sea || []), areaNeighbour);
}

function TribeMover(map, moveLimit, seaCost) {
    this.start = {};
    this.map = _.clone(map);
    this.neighbours = {};
    this.neighbours2 = {};
    this.neighboursSea = {};
    this.neighboursSea2 = {};
    moveLimit = moveLimit ? moveLimit : 1;
    this.moveLimit = moveLimit;
    seaCost = seaCost === undefined ? -1 : seaCost;
    this.seaCost = seaCost;
    
    var seas = _.object(_.map(this.map, function(area, n) {
        // TODO: Should this use engine.isSeaNeighbour in some way?
        // Find the seas
        var ss = _.filter(area.neighbours, function (e) { return typeof e == "string" && e != 'frontier'; });
        var seangh = [];
        
        // Determine the sea neighbours
        for (var a in this.map)
        {
            if (a != n && _.intersection(this.map[a].neighbours, ss).length > 0)
            {
                seangh.push(parseInt(a));
            }
        }
        return [parseInt(n), seangh];
    }, this));
    
    _.each(this.map, function(area, ak) {
        this.neighbours[ak] = _.filter(area.neighbours, areaNeighbour);
        this.neighboursSea[ak] = _.union(this.neighbours[ak], seas[ak]);
    }, this);
    
    if (seaCost > -1)
        this.neighbours = this.neighboursSea;
    
    // First level neighbours with moveLimit
    for (var m = 1; m < moveLimit; m++)
    {
        var nextFirst = {};
        _.each(this.neighbours, function(ngh, ak) {
            nextFirst[ak] = _mergeNgh(ngh, this.neighbours, ak);
        },this);
        _.each(this.neighbours, function(ngh, ak) {
            this.neighbours[ak] = nextFirst[ak];
        },this);
    }
    // Second level neighbours
{'fraction_non_alphanumeric': 0.1519434628975265, 'fraction_numerical': 0.003297997644287397, 'mean_word_length': 2.2142316426949282, 'pattern_counts': {'":': 0, '<': 5, '<?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': '764130', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1403, 'n_words': 311}