<commit_before>(function() {
    extend = function ( t, s, b ) {
        if (s) {
            for ( var k in s ) {
                if (!b || !t.hasOwnProperty(k)) {
                    t[k] = s[k];
                }
            }
        }
        return t;
    };

    var randomArray = function(array,source){
        if(array.length == 0) {
            return null;
        }
        var key =  parseInt(Math.random()*array.length);
        var res = array[key];
        if(source) {
            if(!source[res]) {
                var cloneArr = array.concat([]);
                cloneArr.splice(key,1);
                return randomArray(cloneArr,source);
            } else {
                return res;
            }
        } else {
            return res;
        }
    }
    var Snake = function(cfg){
        var _default = {
            columns : 25,
            rows : 25,
            unitLength : 15,
            containerId : '',
            defCss : 'snake',
            activeCssList : ['a','b','c'],
            allowBack : false,
            speed : 400,
            score : 1, //每吃一个食物所加的分数,
            range : 3, //出现特殊食物的机率
            maxUsers : 5
        };

        this.config = function(cfg){
            if(cfg) {
                extend(_default,cfg);
            }
            return  _default;
        }
    }

    Snake.prototype = {
        __fill : {}, //记录所有块。

        __map : {}, //此处记录块有没有被占用

        __keyMap : [],

        __foodPlugins : [],

        __timer  : null,

        __foodNums : 0,

        __events : {},

        players : {},

        playerIds : [],

        alives : 0,

        setKey :  function(l,t){
            return l + '_' + t;
        },
        draw : function(){
            var cfg = this.config();
            var container = document.getElementById(cfg.containerId);
            
            if(!container) {
                return;
            }

            for(var j = 1; j <= cfg.rows; j ++) {
                for(var i = 1; i <= cfg.columns ; i++) {
                    var key = this.setKey(i,j);
                    var span = document.createElement('span');
                    span.className = cfg.defCss;
                    span.style.display = 'inline-block';
                    span.style.width = cfg.unitLength + 'px';
                    span.style.height = cfg.unitLength + 'px';
                    
                    this.__fill[key] = span;
                    this.__fill[key]._offset = {left : i, top :j};
                    this.__map[key] = 1;
                    this.__keyMap.push(key);
                    container.appendChild(span);
                }
            }
            container.style.width = cfg.unitLength * cfg.columns + 'px'
            container.style.height = cfg.unitLength * cfg.rows + 'px'
        },

        createBlock : function(l,t,c){
            var cfg = this.config();
            var key = this.setKey(l,t);
            if(!this.__fill[key] || (!this.__fill[key].plugin && this.__map[key] == 0)) {
                return null;
            }
            this.__fill[key].className = c || '';
            this.__map[key] = 0; 
            return this.__fill[key];
        },

        deleteBlock : function(l,t) {
            var cfg = this.config();
            var key = this.setKey(l,t);
            if(!this.__fill[key]) {
                return;
            }
            this.__fill[key].className = cfg.defCss;
            this.__fill[key].plugin = null;
            this.__map[key] = 1;
        },

        randomBlock : function(c){
            var key = randomArray(this.__keyMap,this.__map);
            if(key) {
                var _key = key.split('_'); 
                return this.createBlock(_key[0],_key[1],c);
            }
            return null
        },
        
        regFood : function(o){
            this.__foodPlugins.push(o);
        },
        
        regBaseFood : function(json){
            var cfg = this.config();
            var _json = extend({
                fp : 0,
                effect : function(player,snake,food){
                    snake.body.unshift(food);
                },
                score : cfg.score,
                cssName : 'b'
            },json || {});
            this.__foodPlugins.unshift(_json);
        },
        
        createFood : function(c){
            var cfg = this.config();
            var range = Math.ceil(Math.random()*10)
            var plugin;
            if(range <= cfg.range && this.__foodPlugins.length >1) { 
                var _food = this.__foodPlugins.concat([]);
                _food.shift();
                plugin = randomArray(_food);
            } else {
                plugin = this.__foodPlugins[0]; 
            }
            var fBody = this.randomBlock(plugin.cssName);
            fBody.plugin = plugin;
            this.__foodNums ++;
            return fBody;
        },
        removeFood : function(food){
            this.deleteBlock(food);
            this.__foodNums --;
            food.plugin = null;
            if(this.__foodNums <0) {
                this.__foodNums = 0;
            }
        },
        eatFood : function(player,snake,food){

            var cfg = this.config();
            food.plugin.effect.apply(this,arguments);
            player.scores += player.baseScore * food.plugin.score;
            this.evtFire('eat',arguments);
            this.removeFood(food);
            this.createFood();
        },
        createSnake : function(length, direction, id, c){
            var snakeBody = [];
            var cfg = this.config();
            switch(direction) {<commit_msg>color<commit_after>(function() {
    extend = function ( t, s, b ) {
        if (s) {
            for ( var k in s ) {
                if (!b || !t.hasOwnProperty(k)) {
                    t[k] = s[k];
                }
            }
        }
        return t;
    };

    var randomArray = function(array,source){
        if(array.length == 0) {
            return null;
        }
        var key =  parseInt(Math.random()*array.length);
        var res = array[key];
        if(source) {
            if(!source[res]) {
                var cloneArr = array.concat([]);
                cloneArr.splice(key,1);
                return randomArray(cloneArr,source);
            } else {
                return res;
            }
        } else {
            return res;
        }
    }
    var Snake = function(cfg){
        var _default = {
            columns : 25,
            rows : 25,
            unitLength : 15,
            containerId : '',
            defCss : 'snake',
            activeCssList : ['a','b','c'],
            allowBack : false,
            speed : 400,
            score : 1, //每吃一个食物所加的分数,
            range : 3, //出现特殊食物的机率
            maxUsers : 5
        };

        this.config = function(cfg){
            if(cfg) {
                extend(_default,cfg);
            }
            return  _default;
        }
    }

    Snake.prototype = {
        __fill : {}, //记录所有块。

        __map : {}, //此处记录块有没有被占用

        __keyMap : [],

        __foodPlugins : [],

        __timer  : null,

        __foodNums : 0,

        __events : {},

        players : {},

        playerIds : [],

        playerScors : {},

        alives : 0,

        setKey :  function(l,t){
            return l + '_' + t;
        },
        draw : function(){
            var cfg = this.config();
            var container = document.getElementById(cfg.containerId);
            
            if(!container) {
                return;
            }

            for(var j = 1; j <= cfg.rows; j ++) {
                for(var i = 1; i <= cfg.columns ; i++) {
                    var key = this.setKey(i,j);
                    var span = document.createElement('span');
                    span.className = cfg.defCss;
                    span.style.display = 'inline-block';
                    span.style.width = cfg.unitLength + 'px';
                    span.style.height = cfg.unitLength + 'px';
                    
                    this.__fill[key] = span;
                    this.__fill[key]._offset = {left : i, top :j};
                    this.__map[key] = 1;
                    this.__keyMap.push(key);
                    container.appendChild(span);
                }
            }
            container.style.width = cfg.unitLength * cfg.columns + 'px'
            container.style.height = cfg.unitLength * cfg.rows + 'px'
        },

        createBlock : function(l,t,c){
            var cfg = this.config();
            var key = this.setKey(l,t);
            if(!this.__fill[key] || (!this.__fill[key].plugin && this.__map[key] == 0)) {
                return null;
            }
            this.__fill[key].className = c || '';
            this.__map[key] = 0; 
            return this.__fill[key];
        },

        deleteBlock : function(l,t) {
            var cfg = this.config();
            var key = this.setKey(l,t);
            if(!this.__fill[key]) {
                return;
            }
            this.__fill[key].className = cfg.defCss;
            this.__fill[key].plugin = null;
            this.__map[key] = 1;
        },

        randomBlock : function(c){
            var key = randomArray(this.__keyMap,this.__map);
            if(key) {
                var _key = key.split('_'); 
                return this.createBlock(_key[0],_key[1],c);
            }
            return null
        },
        
        regFood : function(o){
            this.__foodPlugins.push(o);
        },
        
        regBaseFood : function(json){
            var cfg = this.config();
            var _json = extend({
                fp : 0,
                effect : function(player,snake,food){
                    snake.body.unshift(food);
                },
                score : cfg.score,
                cssName : 'b'
            },json || {});
            this.__foodPlugins.unshift(_json);
        },
        
        createFood : function(c){
            var cfg = this.config();
            var range = Math.ceil(Math.random()*10)
            var plugin;
            if(range <= cfg.range && this.__foodPlugins.length >1) { 
                var _food = this.__foodPlugins.concat([]);
                _food.shift();
                plugin = randomArray(_food);
            } else {
                plugin = this.__foodPlugins[0]; 
            }
            var fBody = this.randomBlock(plugin.cssName);
            fBody.plugin = plugin;
            this.__foodNums ++;
            return fBody;
        },
        removeFood : function(food){
            this.deleteBlock(food);
            this.__foodNums --;
            food.plugin = null;
            if(this.__foodNums <0) {
                this.__foodNums = 0;
            }
        },
        eatFood : function(player,snake,food){

            var cfg = this.config();
            food.plugin.effect.apply(this,arguments);
            player.scores += player.baseScore * food.plugin.score;
            this.playerScors[player.name] = player.scores;
            this.evtFire('eat',arguments);
            this.removeFood(food);
            this.createFood();
        },
        createSnake : function(length, direction, id, c){
            var snakeBody = [];
            var cfg = this.config();
            switch(direction) {
{'fraction_non_alphanumeric': 0.12620932277924363, 'fraction_numerical': 0.005452946350043976, 'mean_word_length': 1.14506696849651, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '3342496', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3120, 'n_words': 591}