public AutomataProcessor(AutomataDefinition definition, AutomataGrid grid)
        {
            _definition = definition;

            _currentGrid = new AutomataGrid(definition.Neighbourhood == Neighbourhood.Moore, definition.Wrap);
            _backbufferGrid = new AutomataGrid(definition.Neighbourhood == Neighbourhood.Moore, definition.Wrap);

            _currentGrid.Resize(grid.Width, grid.Height);
            _backbufferGrid.Resize(grid.Width, grid.Height);

            for (int idxX = 0; idxX < _currentGrid.Width; ++idxX)
            {
                for (int idxY = 0; idxY < _currentGrid.Height; ++idxY)
                {
                    _currentGrid[idxX, idxY] = grid[idxX, idxY];
                }
            }
        }
        public static bool Load(Stream stream, out string formula, out AutomataGrid grid)
        {
            formula = string.Empty;
            grid = null;

            var reader = new StreamReader(stream);

            string line = reader.ReadLine();

            while(line != null)
            {
                if(string.IsNullOrWhiteSpace(line))
                {
                    break;
                }

                formula += line + "|";
                line = reader.ReadLine();
            }

            formula = formula.TrimEnd('|');

            var rows = new List<List<byte>>();

            int width = 0;
            int height = 0;

            line = reader.ReadLine();
            while (line != null)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    break;
                }

                var row = new List<byte>();
                rows.Add(row);

                height++;

                string[] values = line.Split(' ', '\t');

                foreach(var value in values)
                {
                    if(string.IsNullOrWhiteSpace(value))
                    {
                        continue;
                    }

                    byte state;
                    byte.TryParse(value, out state);

                    row.Add(state);
                    width = Math.Max(width, row.Count);
                }

                line = reader.ReadLine();
            }

            grid = new AutomataGrid();

            if (width > 0 && height > 0)
            {
                grid.Resize(width, height);
            }

            for (int idxY = 0; idxY < rows.Count; ++idxY)
            {
                var row = rows[idxY];

                for (int idxX = 0; idxX < row.Count; ++idxX)
                {
                    byte state = row[idxX];
                    grid[idxX, idxY] = state;
                }
            }

            return true;
        }