/// <summary>
        /// Converts a GameGrid tp a GameState.
        /// </summary>
        /// <param name="gameGrid"></param>
        /// <returns></returns>
        private GameState ToGameState(GameGrid gameGrid, string state)
        {
            string line_count   = Convert.ToString(gameGrid.LineCount, 2).PadLeft(8, '0');
            string column_count = Convert.ToString(gameGrid.ColumnCount, 2).PadLeft(8, '0');
            string cells        = string.Empty;

            gameGrid.Cells.ForEach(cell => cells += cell.Occupied ? "1" : "0");

            GameState gameState = new GameState();

            gameState.State = state;
            gameState.Grid  = line_count + column_count + cells;
            gameState.Date  = string.Format("{0}_{1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString());

            return(gameState);
        }
        /// <summary>
        /// Converts a GameState to a GameGrid.
        /// </summary>
        /// <param name="gameState"></param>
        /// <returns></returns>
        public GameGrid FromGameState(GameState gameState, out string state)
        {
            string line_count_str   = gameState.Grid.Substring(0, 8);
            string column_count_str = gameState.Grid.Substring(8, 8);
            string cells_str        = gameState.Grid.Substring(16);

            state = gameState.State;

            GameGrid gameGrid = new GameGrid();

            gameGrid.LineCount   = Convert.ToInt32(line_count_str, 2);
            gameGrid.ColumnCount = Convert.ToInt32(column_count_str, 2);

            //Translate cells binary string to 2D array of cells.
            int ln = 0, col = 0;

            foreach (var c in cells_str)
            {
                Cell cell = new Cell();
                cell.Occupied = c != '0';
                cell.Position = new Tuple <int, int>(ln, col);
                gameGrid.Cells.Add(cell);

                if (col < gameGrid.ColumnCount - 1)
                {
                    col++;
                }
                else
                {
                    ln++;
                    col = 0;
                }
            }

            return(gameGrid);
        }