<commit_before>var calculateDistance = function(object1, object2){
    x = Math.abs(object1.x - object2.x);
    y = Math.abs(object1.y - object2.y);

    return Math.sqrt((x * x) + (y * y));
};

var calcMagnitude = function(x, y) {
    return Math.sqrt((x * x) + (y * y));
};

var calcVectorAdd = function(v1, v2) {
    return {x: v1.x + v2.x, y: v1.y + v2.y};
};

var random = function( min, max ) {

    return min + Math.random() * ( max - min );
};

var getRandomItem = function(list, weight) {
    var total_weight = weight.reduce(function (prev, cur, i, arr) {
        return prev + cur;
    });
     
    var random_num = random(0, total_weight);
    var weight_sum = 0;
    //console.log(random_num)
     
    for (var i = 0; i < list.length; i++) {
        weight_sum += weight[i];
        weight_sum = +weight_sum.toFixed(2);
         
        if (random_num <= weight_sum) {
            return list[i];
        }
    }
     
    // end of function
};

/***********************
BOID
***********************/
function Boid(x, y) {
    this.init(x, y);
}

Boid.prototype = {
    init: function(x, y) {
        //body
        this.type = "boid";
        this.alive = true;
        this.health = 1;
        this.maturity = 4;
        this.speed = 6;
        this.size = 5;
        this.hungerLimit = 12000;
        this.hunger = 0;
        this.isFull = false;
        this.digestTime = 400;
        this.color = 'rgb(' + ~~random(0,100) + ',' + ~~random(50,220) + ',' + ~~random(50,220) + ')';

        //brains
        this.eyesight = 100; //range for object dectection
        this.personalSpace = 20; //distance to avoid safe objects
        this.flightDistance = 60; //distance to avoid scary objects
        this.flockDistance = 100; //factor that determines how attracted the boid is to the center of the flock
        this.matchVelFactor = 6; //factor that determines how much the flock velocity affects the boid. less = more matching

        this.x = x || 0.0;
        this.y = y || 0.0;

        this.v = {
            x: random(-1, 1),
            y: random(-1, 1),
            mag: 0
        };

        this.unitV = {
            x: 0,
            y: 0,
        };

        this.v.mag = calcMagnitude(this.v.x, this.v.y);
        this.unitV.x = (this.v.x / this.v.mag);
        this.unitV.y = (this.v.y / this.v.mag);

    },
    wallAvoid: function(ctx) {
        var wallPad = 10;
        if (this.x < wallPad) {
            this.v.x = this.speed;
        } else if (this.x > ctx.width - wallPad) {
            this.v.x = -this.speed;
        }
        if (this.y < wallPad) {
            this.v.y = this.speed;
        } else if (this.y > ctx.height - wallPad) {
            this.v.y = -this.speed;
        }
    },
    ai: function(boids, index, ctx) {
        percievedCenter = {
            x: 0,
            y: 0,
            count: 0
        };
        percievedVelocity = {
            x: 0,
            y: 0,
            count: 0
        };
        mousePredator = {
            x: ((typeof ctx.touches[0] === "undefined") ? 0 : ctx.touches[0].x),
            y: ((typeof ctx.touches[0] === "undefined") ? 0 : ctx.touches[0].y)
        };
        
        for (var i = 0; i < boids.length; i++) {
            if (i != index) {

                dist = calculateDistance(this, boids[i]);

                //Find all other boids close to it
                if (dist < this.eyesight) {
                    //if the same species then flock
                    if (boids[i].type == this.type) {

                        //Alignment
                        percievedCenter.x += boids[i].x;
                        percievedCenter.y += boids[i].y;
                        percievedCenter.count++;

                        //Cohesion
                        percievedVelocity.x += boids[i].v.x;
                        percievedVelocity.y += boids[i].v.y;
                        percievedVelocity.count++;

                        //Separation
                        if (dist < this.personalSpace + this.size + this.health) {
                            this.avoidOrAttract("avoid", boids[i], this.personalSpace);
                        }
                    } else {
                        //if other species fight or flight
                        if (dist < this.size + this.health + boids[i].size + boids[i].health) {
                            this.eat(boids[i]);
                        } else {
                            this.handleOther(boids[i]);
                        }
                    }
                }//if close enough
            }//dont check itself
        }//Loop through boids

        //Get the average for all near boids
        if (percievedCenter.count > 0) {
            percievedCenter.x = ((percievedCenter.x / percievedCenter.count) - this.x) / this.flockDistance;
            percievedCenter.y = ((percievedCenter.y / percievedCenter.count) - this.y) / this.flockDistance;
            this.v = calcVectorAdd(this.v, percievedCenter);
        }
        if (percievedVelocity.count > 0) {
            percievedVelocity.x = ((percievedVelocity.x / percievedVelocity.count) - this.v.x) / this.matchVelFactor;
            percievedVelocity.y = ((percievedVelocity.y / percievedVelocity.count) - this.v.y) / this.matchVelFactor;
            this.v = calcVectorAdd(this.v, percievedVelocity);
        }

        //Avoid Mouse
        if (calculateDistance(mousePredator, this) < this.eyesight) {<commit_msg>removed excessive personal space modifier<commit_after>var calculateDistance = function(object1, object2){
    x = Math.abs(object1.x - object2.x);
    y = Math.abs(object1.y - object2.y);

    return Math.sqrt((x * x) + (y * y));
};

var calcMagnitude = function(x, y) {
    return Math.sqrt((x * x) + (y * y));
};

var calcVectorAdd = function(v1, v2) {
    return {x: v1.x + v2.x, y: v1.y + v2.y};
};

var random = function( min, max ) {

    return min + Math.random() * ( max - min );
};

var getRandomItem = function(list, weight) {
    var total_weight = weight.reduce(function (prev, cur, i, arr) {
        return prev + cur;
    });
     
    var random_num = random(0, total_weight);
    var weight_sum = 0;
    //console.log(random_num)
     
    for (var i = 0; i < list.length; i++) {
        weight_sum += weight[i];
        weight_sum = +weight_sum.toFixed(2);
         
        if (random_num <= weight_sum) {
            return list[i];
        }
    }
     
    // end of function
};

/***********************
BOID
***********************/
function Boid(x, y) {
    this.init(x, y);
}

Boid.prototype = {
    init: function(x, y) {
        //body
        this.type = "boid";
        this.alive = true;
        this.health = 1;
        this.maturity = 4;
        this.speed = 6;
        this.size = 5;
        this.hungerLimit = 12000;
        this.hunger = 0;
        this.isFull = false;
        this.digestTime = 400;
        this.color = 'rgb(' + ~~random(0,100) + ',' + ~~random(50,220) + ',' + ~~random(50,220) + ')';

        //brains
        this.eyesight = 100; //range for object dectection
        this.personalSpace = 20; //distance to avoid safe objects
        this.flightDistance = 60; //distance to avoid scary objects
        this.flockDistance = 100; //factor that determines how attracted the boid is to the center of the flock
        this.matchVelFactor = 6; //factor that determines how much the flock velocity affects the boid. less = more matching

        this.x = x || 0.0;
        this.y = y || 0.0;

        this.v = {
            x: random(-1, 1),
            y: random(-1, 1),
            mag: 0
        };

        this.unitV = {
            x: 0,
            y: 0,
        };

        this.v.mag = calcMagnitude(this.v.x, this.v.y);
        this.unitV.x = (this.v.x / this.v.mag);
        this.unitV.y = (this.v.y / this.v.mag);

    },
    wallAvoid: function(ctx) {
        var wallPad = 10;
        if (this.x < wallPad) {
            this.v.x = this.speed;
        } else if (this.x > ctx.width - wallPad) {
            this.v.x = -this.speed;
        }
        if (this.y < wallPad) {
            this.v.y = this.speed;
        } else if (this.y > ctx.height - wallPad) {
            this.v.y = -this.speed;
        }
    },
    ai: function(boids, index, ctx) {
        percievedCenter = {
            x: 0,
            y: 0,
            count: 0
        };
        percievedVelocity = {
            x: 0,
            y: 0,
            count: 0
        };
        mousePredator = {
            x: ((typeof ctx.touches[0] === "undefined") ? 0 : ctx.touches[0].x),
            y: ((typeof ctx.touches[0] === "undefined") ? 0 : ctx.touches[0].y)
        };
        
        for (var i = 0; i < boids.length; i++) {
            if (i != index) {

                dist = calculateDistance(this, boids[i]);

                //Find all other boids close to it
                if (dist < this.eyesight) {
                    //if the same species then flock
                    if (boids[i].type == this.type) {

                        //Alignment
                        percievedCenter.x += boids[i].x;
                        percievedCenter.y += boids[i].y;
                        percievedCenter.count++;

                        //Cohesion
                        percievedVelocity.x += boids[i].v.x;
                        percievedVelocity.y += boids[i].v.y;
                        percievedVelocity.count++;

                        //Separation
                        if (dist < this.personalSpace + this.size + this.health) {
                            this.avoidOrAttract("avoid", boids[i]);
                        }
                    } else {
                        //if other species fight or flight
                        if (dist < this.size + this.health + boids[i].size + boids[i].health) {
                            this.eat(boids[i]);
                        } else {
                            this.handleOther(boids[i]);
                        }
                    }
                }//if close enough
            }//dont check itself
        }//Loop through boids

        //Get the average for all near boids
        if (percievedCenter.count > 0) {
            percievedCenter.x = ((percievedCenter.x / percievedCenter.count) - this.x) / this.flockDistance;
            percievedCenter.y = ((percievedCenter.y / percievedCenter.count) - this.y) / this.flockDistance;
            this.v = calcVectorAdd(this.v, percievedCenter);
        }
        if (percievedVelocity.count > 0) {
            percievedVelocity.x = ((percievedVelocity.x / percievedVelocity.count) - this.v.x) / this.matchVelFactor;
            percievedVelocity.y = ((percievedVelocity.y / percievedVelocity.count) - this.v.y) / this.matchVelFactor;
            this.v = calcVectorAdd(this.v, percievedVelocity);
        }

        //Avoid Mouse
        if (calculateDistance(mousePredator, this) < this.eyesight) {
{'fraction_non_alphanumeric': 0.1397731430662276, 'fraction_numerical': 0.01500182949140139, 'mean_word_length': 1.4268590455049945, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, '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': '2796917', 'n_tokens_mistral': 3585, 'n_tokens_neox': 3386, 'n_words': 777}