<commit_before>/*!
 * world.rules.js
 * Rules class
 *
 * World JS: Evolution Simulator
 * https://github.com/anvoz/world-js
 * Copyright (c) 2013 <NAME> - <EMAIL>
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 */

(function(window, undefined) {
    'use strict';

    var WorldJS = window.WorldJS,
        Rules;

    /**
     * Rules constructor
     */
    Rules = WorldJS.Rules = function() {
        var rules = this;

        rules.baseIQ = 0;

        // Base chance
        rules.Chance = {
            death: 0,
            marriage: 0,
            childbirth: 0
        };
        // Chance that incr/decr base on some specific value
        // See the Rules.Famine below for example
        rules.ChanceIncr = {
            death: 0,
            marriage: 0,
            childbirth: 0
        };

        rules.Food = {
            adult: -2,      // Consume 2 food per year
            child: -1,
            min: -10000     // Food of the world cannot < this value
        };

        // Death chance increase 50%
        // and childbirth decrease 50%
        // every -1000 food
        rules.Famine = {
            deathChanceIncr: 0.5,
            childbirthChanceIncr: -0.5,
            unit: -1000
        };

        // Food decrease 90% every 100 years
        rules.FoodSpoilage = {
            foodDecr: 0.9,
            interval: 100
        };
    };

    /**
     * Change rules of the world
     */
    Rules.prototype.change = function(world) {
        var Rules = world.Rules,
            Statistic = world.Statistic,
            food = Statistic.food,
            deathChance = 0,
            childbirthChange = 0;

        var totalChildren = Statistic.boys + Statistic.girls,
            totalAdult = Statistic.population - totalChildren;
        food += (
            totalAdult * Rules.Food.adult + 
            totalChildren * Rules.Food.child
        );

        if (food < Rules.Food.min) {
            food = Rules.Food.min;
        }

        // Famine: increase death chance, decrease childbirth chance
        if (food <= Rules.Famine.unit) {
            var delta = Math.floor(food / Rules.Famine.unit);
            deathChance += delta * Rules.Famine.deathChanceIncr;
            childbirthChange += delta * Rules.Famine.childbirthChanceIncr;
        }

        // Food spoilage: decrease food
        if (Statistic.year % Rules.FoodSpoilage.interval === 0 && food > 0) {
            food -= Math.round(food * Rules.FoodSpoilage.foodDecr);
        }

        Statistic.food = food;
        Rules.Chance.death = deathChance + Rules.ChanceIncr.death;
        Rules.Chance.childbirth = childbirthChange + Rules.ChanceIncr.childbirth;
    };
})(window);<commit_msg>Edit Famine rule: remove childbirth decrease Edit comments<commit_after>/*!
 * world.rules.js
 * Rules class
 *
 * World JS: Evolution Simulator
 * https://github.com/anvoz/world-js
 * Copyright (c) 2013 <NAME> - <EMAIL>
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 */

(function(window, undefined) {
    'use strict';

    var WorldJS = window.WorldJS,
        Rules;

    /**
     * Rules constructor
     * Define default rules of the world
     */
    Rules = WorldJS.Rules = function() {
        var rules = this;

        rules.baseIQ = 0;

        // Base chances
        rules.Chance = {
            death: 0,
            marriage: 0,
            childbirth: 0
        };

        // Chances that increase or decrease temporarily
        // based on some specific value
        rules.ChanceIncr = {
            death: 0,
            marriage: 0,
            childbirth: 0
        };

        rules.Food = {
            adult: -2,      // Consume 2 food per year
            child: -1,      // Consume 1 food per year
            min: -10000     // Minimum food value
        };

        // When famine affected,
        // death chance increase 50% every -1000 food
        rules.Famine = {
            deathChanceIncr: 0.5,
            unit: -1000
        };

        // Food decrease 90% every 100 years
        rules.FoodSpoilage = {
            foodDecr: 0.9,
            interval: 100
        };
    };

    /**
     * Change rules of the world
     */
    Rules.prototype.change = function(world) {
        var Rules = world.Rules,
            Statistic = world.Statistic,
            food = Statistic.food,
            totalAdult = Statistic.men + Statistic.women,
            totalChildren = Statistic.boys + Statistic.girls;

        food += (
            totalAdult * Rules.Food.adult + 
            totalChildren * Rules.Food.child
        );

        if (food < Rules.Food.min) {
            food = Rules.Food.min;
        }

        var deathChance = 0;

        // Famine: increase death chance
        if (food <= Rules.Famine.unit) {
            var delta = Math.floor(food / Rules.Famine.unit);
            deathChance += delta * Rules.Famine.deathChanceIncr;
        }

        // Food spoilage: decrease food
        if (Statistic.year % Rules.FoodSpoilage.interval === 0 && food > 0) {
            food -= Math.round(food * Rules.FoodSpoilage.foodDecr);
        }

        // Apply new changes
        Statistic.food = food;
        Rules.Chance.death = deathChance + Rules.ChanceIncr.death;
    };
})(window);
{'fraction_non_alphanumeric': 0.10668670172802404, 'fraction_numerical': 0.017655897821187077, 'mean_word_length': 1.541766109785203, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '184771', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1489, 'n_words': 386}