/**
* 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] = false;
        }
    };

    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 = this._coordinatesToPosition(coordArray[i]);
            GridService.grid[pos] = true;
        }
    };

    GridService.isPieceVerify = function isPieceVerify(coord) {
        var pos = this._coordinatesToPosition(coord);
        if(GridService.grid[pos]) {
            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 = this._coordinatesToPosition({x: j, y: i});
                if(!this.grid[pos]) {
                    break;
                }
            }
            if(j === getBoardWidth()) {
                // clear the row
                this.clearNthRow(i);
                this.movePieceDownLevel(i);
                cb();
            }
        }
    };

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

    GridService.movePieceDownLevel = function movePieceDownLevel(row) {
        for(var i = row - 1; i > 0; i--) {
            for(var j = 0; j < getBoardWidth(); j++) {
                var curPos = this._coordinatesToPosition({x: j, y: i}),
                    nextPos = this._coordinatesToPosition({x: j, y: i+1});
                if (this.grid[curPos]) {
                    this.grid[nextPos] = true;
                }
                this.grid[curPos] = false;
            }
        }
    };

    GridService._positionToCoordinates = function _positionToCoordinates(i) {
        var x = i % getBoardSize(),
            y = (i - x) / getBoardSize();

        return {
            x: x,
            y: y
        };
    };

    GridService._coordinatesToPosition = function _coordinatesToPosition(pos) {
        return (pos.y * getBoardSize()) + pos.x;
    };

    return GridService;
}]);
@@ -699,29 +699,98 @@
 e.grid%5Bi%5D = 
-false
+%7B%0A                filled: false,%0A                shape: null%0A            %7D
 ;%0A        %7D%0A
@@ -1165,23 +1165,90 @@
 rid%5Bpos%5D
- = true
+.filled = true;%0A            GridService.grid%5Bpos%5D.shape = piece.getShape()
 ;%0A      
@@ -1401,32 +1401,39 @@
 ervice.grid%5Bpos%5D
+.filled
 ) %7B%0A            
@@ -1788,16 +1788,23 @@
 rid%5Bpos%5D
+.filled
 ) %7B%0A    
@@ -2268,16 +2268,23 @@
 rid%5Bpos%5D
+.filled
  = false
@@ -2678,16 +2678,23 @@
 %5BcurPos%5D
+.filled
 ) %7B%0A    
@@ -2727,16 +2727,23 @@
 nextPos%5D
+.filled
  = true;
@@ -2794,16 +2794,23 @@
 %5BcurPos%5D
+.filled
  = false

Append an object instead of boolean value in the grid