<commit_before>/*
 * theminesweeper
 * https://github.com/leosartaj/jquery.minesweeper.js
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

(function($) {

    var levels = [
        { height: 8 , width: 8, mines: 10 }
    ];

    // Defines the widget
    $.widget('ss.theminesweeper', {

        
        // widget currrent version
        version: '0.1.0',

        options: {
            levels: levels
        },

        _create: function() {
            this.element.addClass('ss-minesweeper');
            this._createWrapper();
            this._createButtons();
            this._generateMines();
            this._renderMarkup();

            this._on({
                'click button': this._clickHandler
            });
        },
        
        _createWrapper: function() {
            var el = $('<div/>'), display;

            this.shell = el.clone().addClass('ss-minesweeper-shell');
            display = el.clone().addClass('ss-minesweeper-display').appendTo(this.shell);
        },

        _createButtons: function() {
            var el = $('<button/>'), container = $('<div/>').addClass('ss-minesweeper-buttons'), i = 0, j, level = this.options.levels[0], height = level.height, width = level.width, buttons = [];

            for(i = 0; i < width; i++) {
                buttons[i] = [];
                for(j = 0; j < height; j++) {
                    if(j === 0) {
                        buttons[i][j] = {label: ' ', mine: 'n', classname: 'ss-minesweeper-left'};
                    }
                    else {
                        buttons[i][j] = {label: ' ', mine: 'n'};
                    }
                }
            }
            i = 0; j = 0;
            $.each(buttons, function(i, button) {
                $.each(button, function(j, but) {
                    var btn = el.clone().text(but.label).appendTo(container).button();
                    if(!!but.classname) {
                        btn.addClass(but.classname);
                    }

                    if(!!but.classname) {
                        btn.addClass(but.classname);
                    }
                    btn.data('x', j);
                    btn.data('y', i);
                });
            });
            level.buttons = buttons;
            container.appendTo(this.shell);
        },

        _renderMarkup: function() {
            this.shell.appendTo(this.element);
        },

        _setOptions: function() {
            this._superApply(arguments);
        },

        _setOption: function(key, val) {
            this._super(key, val);

            if(key === 'levels') {
                this.shell.find('button').remove();
                this._createButtons();
                this._generateMines();
                this._renderMarkup();
            }
            else if(key === 'disable') {
                this.shell.find('button').button('option', key, val);
            }
        },

        _generateMines: function() {
            var level = this.options.levels[0],mines = level.mines, width = level.width, height = level.height, x, y;

            while(mines !== 0) {
                x = Math.floor(width * Math.random());
                y = Math.floor(height * Math.random());
                if(level.buttons[x][y].mine === 'n') {
                    level.buttons[x][y].mine = 'y';
                    console.log(x + ',' + y);
                    mines--;
                }
            }

        },

        _clickHandler: function(e) {
            var btn = $(e.target).closest('button');
            this._checkMine(e, btn);
        },

        _checkMine: function(e, ui) {
            var level = this.options.levels[0], x = +ui.data('x'), y = +ui.data('y'), check = level.buttons[x][y].mine;

            if(check === 'y') {
                ui.text('m');
                return 0;
            }
            this._checkNum(e, ui);
        },

        _checkNum: function(e, ui) {
            var level = this.options.levels[0], x = +ui.data('x'), y = +ui.data('y');
            var num = 0;
            if(x - 1 > -1 && y - 1 > -1) {
                if(level.buttons[x - 1][y - 1].mine === 'y') {
                    num++;
                }
            }
            if(y - 1 > -1) {
                if(level.buttons[x][y - 1].mine === 'y') {
                    num++;
                }
            }
            if(x - 1 > -1) {
                if(level.buttons[x - 1][y].mine === 'y') {
                    num++;
                }
            }
            if(x + 1 < levels.width && y + 1 < levels.height) {
                if(level.button[x + 1][y + 1].mine === 'y') {
                    num++;
                }
            }
            if (x + 1 < levels.width) {
                if(level.buttons[x + 1][y].mine === 'y') {
                    num++;
                }
            }
            if(y + 1 < levels.height) {
                if(level.buttons[x][y + 1].mine === 'y') {
                    num++;
                }
            }
            if (x + 1 < levels.width && y - 1 > -1) {
                if(level.buttons[x + 1][y - 1].mine === 'y') {
                    num++;
                }
            }
            if(x - 1 > -1 && y + 1 < levels.height) {
                if(level.buttons[x - 1][y + 1].mine === 'y') {
                    num++;
                }
            }
        }

    });

}(jQuery));<commit_msg>too musch recursion :(<commit_after>/*
 * theminesweeper
 * https://github.com/leosartaj/jquery.minesweeper.js
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

(function($) {

    var levels = [
        { height: 8 , width: 8, mines: 10 }
    ];

    // Defines the widget
    $.widget('ss.theminesweeper', {

        
        // widget currrent version
        version: '0.1.0',

        options: {
            levels: levels
        },

        _create: function() {
            this.element.addClass('ss-minesweeper');
            this._createWrapper();
            this._createButtons();
            this._generateMines();
            this._renderMarkup();

            this._on({
                'click button': this._clickHandler
            });
        },
        
        _createWrapper: function() {
            var el = $('<div/>'), display;

            this.shell = el.clone().addClass('ss-minesweeper-shell');
            display = el.clone().addClass('ss-minesweeper-display').appendTo(this.shell);
        },

        _createButtons: function() {
            var el = $('<button/>'), container = $('<div/>').addClass('ss-minesweeper-buttons'), i = 0, j, level = this.options.levels[0], height = level.height, width = level.width, buttons = [];

            for(i = 0; i < width; i++) {
                buttons[i] = [];
                for(j = 0; j < height; j++) {
                    if(j === 0) {
                        buttons[i][j] = {label: 'x', mine: 'n', classname: 'ss-minesweeper-left'};
                    }
                    else {
                        buttons[i][j] = {label: 'x', mine: 'n'};
                    }
                }
            }
            for(i = 0; i < width; i++) {
                for(j = 0; j < height; j++) {
                    var btn = el.clone().text(buttons[i][j].label).appendTo(container).button();

                    if(!!buttons[i][j].classname) {
                        btn.addClass(buttons[i][j].classname);
                    }
                    btn.data('x', j);
                    btn.data('y', i);
                }
            }
            level.buttons = buttons;
            container.appendTo(this.shell);
        },

        _renderMarkup: function() {
            this.shell.appendTo(this.element);
        },

        _setOptions: function() {
            this._superApply(arguments);
        },

        _setOption: function(key, val) {
            this._super(key, val);

            if(key === 'levels') {
                this.shell.find('button').remove();
                this._createButtons();
                this._generateMines();
                this._renderMarkup();
            }
            else if(key === 'disable') {
                this.shell.find('button').button('option', key, val);
            }
        },

        _generateMines: function() {
            var level = this.options.levels[0],mines = level.mines, width = level.width, height = level.height, x, y;

            while(mines !== 0) {
                x = Math.floor(width * Math.random());
                y = Math.floor(height * Math.random());
                if(level.buttons[x][y].mine === 'n') {
                    level.buttons[x][y].mine = 'y';
                    console.log('yes');
                    mines--;
                }
            }

        },

        _clickHandler: function(e) {
            var btn = $(e.target).closest('button');
            this._checkMine(e, btn);
        },

        _checkMine: function(e, ui) {
            var level = this.options.levels[0], x = +ui.data('x'), y = +ui.data('y');

            if(level.buttons[x][y].mine === 'y') {
                ui.find('span').text('9');
                return 0;
            }
            ui.find('span').text(this._checkNum(x, y));
        },

        _checkNum: function(x, y) {
            var level = this.options.levels[0], num = 0;

            if(((x - 1) > -1) && ((y - 1) > -1)) {
                if(level.buttons[x - 1][y - 1].mine === 'y') {
                    num++;
                }
            }
            if((y - 1) > -1) {
                if(level.buttons[x][y - 1].mine === 'y') {
                    num++;
                }
            }
            if((x - 1) > -1) {
                if(level.buttons[x - 1][y].mine === 'y') {
                    num++;
                }
            }
            if(((y + 1) < level.width) && ((x + 1) < level.height)) {
                if(level.buttons[x + 1][y + 1].mine === 'y') {
                    num++;
                }
            }
            if ((x + 1) < level.height) {
                if(level.buttons[x + 1][y].mine === 'y') {
                    num++;
                }
            }
            if((y + 1) < level.width) {
                if(level.buttons[x][y + 1].mine === 'y') {
                    num++;
                }
            }
            if (((x + 1) < level.height) && ((y - 1) > -1)) {
                if(level.buttons[x + 1][y - 1].mine === 'y') {
                    num++;
                }
            }
            if(((x - 1) > -1) && ((y + 1) < level.width)) {
                if(level.buttons[x - 1][y + 1].mine === 'y') {
                    num++;
                }
            }

            if(num === 0) {
                this._checkNum(x - 1, y + 1);
                this._checkNum(x + 1, y - 1);
                this._checkNum(x, y - 1);
                this._checkNum(x, y + 1);
                this._checkNum(x - 1, y - 1);
                this._checkNum(x + 1, y);
                this._checkNum(x + 1, y + 1);
                this._checkNum(x - 1, y - 1);
            }
            return num;
        }


    });

}(jQuery));
{'fraction_non_alphanumeric': 0.16638263521392052, 'fraction_numerical': 0.01103237958561306, 'mean_word_length': 1.0915400487713374, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '2985959', 'n_tokens_mistral': 3413, 'n_tokens_neox': 3142, 'n_words': 593}