Esempio n. 1
0
        /// <summary>
        /// Apply the cycle to cubes that have not been added to the list yet (three dimensions)
        /// </summary>
        private void ApplyCycleToCubesOutsideOfMapThreeDimensions(int startX, int endX, int startY, int endY, int startZ, int endZ)
        {
            var thereWereChanges = false;
            var cubesList        = new List <Cube>();

            for (var x = startX; x <= endX; x++)
            {
                for (var y = startY; y <= endY; y++)
                {
                    for (var z = startZ; z <= endZ; z++)
                    {
                        var cube = new Cube(x, y, z, '.');
                        cube.Neighbours = GetNeighboursThreeDimensions(cube);
                        cube.ApplyCycle();
                        if (cube.ChangeState)
                        {
                            // The state has been changed, we need to add this to the list
                            thereWereChanges = true;
                        }
                        cubesList.Add(cube);
                    }
                }
            }

            // If there were any changes, than we need to add these cubes to the Cubes list
            if (thereWereChanges)
            {
                Cubes.AddRange(cubesList);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Apply the cycle to cubes that have not been added to the list yet (four dimensions)
        /// </summary>
        private void ApplyCycleToCubesOutsideOfMapFourDimensions(int startX, int endX, int startY, int endY, int startZ, int endZ, int startW, int endW)
        {
            var thereWereChanges = false;
            var cubesList        = new List <Cube>();

            for (var x = startX; x <= endX; x++)
            {
                Console.WriteLine($"    Checking X {x} of {endX}");
                for (var y = startY; y <= endY; y++)
                {
                    for (var z = startZ; z <= endZ; z++)
                    {
                        for (var w = startW; w <= endW; w++)
                        {
                            var existingCube = Cubes.SingleOrDefault(cube => cube.X == x && cube.Y == y && cube.Z == z && cube.W == w);
                            if (existingCube != null)
                            {
                                // If the cube already exists, it should already have been handled
                                if (!existingCube.Seen)
                                {
                                    throw new InvalidOperationException("Something went wrong. Cube has not been Seen");
                                }

                                continue;
                            }

                            var cube = new Cube(x, y, z, w, '.');
                            cube.Neighbours = GetNeighboursFourDimensions(cube);
                            cube.ApplyCycle();
                            cube.Seen = true;
                            if (cube.ChangeState)
                            {
                                // The state has been changed, we need to add this to the list
                                thereWereChanges = true;
                                cubesList.Add(cube);
                            }
                        }
                    }
                }
            }

            // If there were any changes, than we need to add these cubes to the Cubes list
            if (thereWereChanges)
            {
                Cubes.AddRange(cubesList);
            }
        }