<commit_before>/**
* service.GridService Module
*
* Description
*/
angular.module('service.GridService', [
    'resource.GameData'
])
.factory('GridService', [
    'GameData',
function (
    GameData
){
    var GridService = {};
    GridService.grid = [];

    function getBoardSize() {
        return GameData.gameBoard.boardWidth;
    }

    function getBoardWidth() {
        return GameData.gameBoard.boardWidth;
    }

    function getBoardHeight() {
        return GameData.gameBoard.boardHeight;
    }

    GridService.buildEmptyGameBoard = function buildEmptyGameBoard() {
        var sizeOfBoard = getBoardWidth() * getBoardHeight();
        for (var i = 0; i < sizeOfBoard; i++) {
            GridService.grid[i] = {
                filled: false,
                shape: null
            };
        }
    };

    GridService.getGridService = function getGridService() {
        return GridService.grid;
    };

    GridService.insertPiece = function insertPiece(piece) {
        var coordArray = piece.getPieceCoordArray();
        for (var i = 0; i < coordArray.length; i++) {
            var pos = GridService._coordinatesToPosition(coordArray[i]);
            GridService.grid[pos].filled = true;
            GridService.grid[pos].shape = piece.getShape();
        }
    };

    GridService.isPieceVerify = function isPieceVerify(coord) {
        var pos = GridService._coordinatesToPosition(coord);
        if(GridService.grid[pos].filled) {
            return false;
        }
        return true;
    };

    GridService.checkAndClearFilledRow = function checkAndClearFilledRow(cb) {
        for(var i = 0; i < getBoardHeight(); i++) {
            var j = 0;
            for(; j < getBoardWidth(); j++) {
                var pos = GridService._coordinatesToPosition({x: j, y: i});
                if(!GridService.grid[pos].filled) {
                    break;
                }
            }
            if(j === getBoardWidth()) {
                // clear the row
                GridService
                    .clearNthRow(i)
                    .movePieceDownLevel(i);
                cb();
            }
        }
    };

    GridService.clearNthRow = function clearNthRow(row) {
        for(var z = 0; z < getBoardWidth(); z++) {
            var pos = GridService._coordinatesToPosition({x: z, y: row});
            GridService.grid[pos].filled = false;
        }
        return GridService;
    };

    GridService.movePieceDownLevel = function movePieceDownLevel(row) {
        for(var i = row - 1; i >= 0; i--) {
            for(var j = 0; j < getBoardWidth(); j++) {<commit_msg>assign shape to null when removing the shape<commit_after>/**
* service.GridService Module
*
* Description
*/
angular.module('service.GridService', [
    'resource.GameData'
])
.factory('GridService', [
    'GameData',
function (
    GameData
){
    var GridService = {};
    GridService.grid = [];

    function getBoardSize() {
        return GameData.gameBoard.boardWidth;
    }

    function getBoardWidth() {
        return GameData.gameBoard.boardWidth;
    }

    function getBoardHeight() {
        return GameData.gameBoard.boardHeight;
    }

    GridService.buildEmptyGameBoard = function buildEmptyGameBoard() {
        var sizeOfBoard = getBoardWidth() * getBoardHeight();
        for (var i = 0; i < sizeOfBoard; i++) {
            GridService.grid[i] = {
                filled: false,
                shape: null
            };
        }
    };

    GridService.getGridService = function getGridService() {
        return GridService.grid;
    };

    GridService.insertPiece = function insertPiece(piece) {
        var coordArray = piece.getPieceCoordArray();
        for (var i = 0; i < coordArray.length; i++) {
            var pos = GridService._coordinatesToPosition(coordArray[i]);
            GridService.grid[pos].filled = true;
            GridService.grid[pos].shape = piece.getShape();
        }
    };

    GridService.isPieceVerify = function isPieceVerify(coord) {
        var pos = GridService._coordinatesToPosition(coord);
        if(GridService.grid[pos].filled) {
            return false;
        }
        return true;
    };

    GridService.checkAndClearFilledRow = function checkAndClearFilledRow(cb) {
        for(var i = 0; i < getBoardHeight(); i++) {
            var j = 0;
            for(; j < getBoardWidth(); j++) {
                var pos = GridService._coordinatesToPosition({x: j, y: i});
                if(!GridService.grid[pos].filled) {
                    break;
                }
            }
            if(j === getBoardWidth()) {
                // clear the row
                GridService
                    .clearNthRow(i)
                    .movePieceDownLevel(i);
                cb();
            }
        }
    };

    GridService.clearNthRow = function clearNthRow(row) {
        for(var z = 0; z < getBoardWidth(); z++) {
            var pos = GridService._coordinatesToPosition({x: z, y: row});
            GridService.grid[pos].filled = false;
            GridService.grid[pos].shape = null;
        }
        return GridService;
    };

    GridService.movePieceDownLevel = function movePieceDownLevel(row) {
        for(var i = row - 1; i >= 0; i--) {
            for(var j = 0; j < getBoardWidth(); j++) {
{'fraction_non_alphanumeric': 0.1191602042746359, 'fraction_numerical': 0.0030262909022129754, 'mean_word_length': 1.88803932277444, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1061507', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1482, 'n_words': 305}