public World(List <List <Cell> > CurrentWorld, bool fixedSize = false)
        {
            var neighbour = new Neighbour(CurrentWorld);

            this.CurrentWorld = neighbour.UpdateWorldWithLivingNeighbours(fixedSize);
            this.FixedSize    = fixedSize;
        }
Exemple #2
0
        public static List <List <Cell> > StringToMatrix(string source, bool fixedSize)
        {
            var world = new List <List <Cell> >();

            source = source.Replace("|", Environment.NewLine);
            var strRows = source.Split(new char[] { }).Where(s => s != "");

            foreach (var strRow in strRows)
            {
                var row = new List <Cell>();

                var strCells = strRow.Select(i => new string(i, 1)).ToList();
                foreach (var strCell in strCells)
                {
                    if (strCell == "X")
                    {
                        row.Add(new Cell(State.Alive));
                    }
                    else
                    {
                        row.Add(new Cell(State.Dead));
                    }
                }
                world.Add(row);
            }
            var neighbour = new Neighbour(world);

            return(neighbour.UpdateWorldWithLivingNeighbours(fixedSize));
        }
        public World NextGeneration()
        {
            if (!FixedSize)
            {
                var extendWorld = new ExtendWorld(CurrentWorld);
                CurrentWorld = extendWorld.Extending();

                var neighbour = new Neighbour(CurrentWorld);
                CurrentWorld = neighbour.UpdateWorldWithLivingNeighbours();
            }

            var nextGeneration = GetNewState(CurrentWorld);

            return(new World(nextGeneration, FixedSize));
        }