示例#1
0
        public void MakeNextGenerations()
        {
            IRuleStrategy ruleStrategy = StrategiesFactory.GetRuleStrategy(this);

            INeighborhoodStrategy neighborhood = StrategiesFactory.GetNeighborhoodStrategy(this);

            int stepCount = Params.StepCount;

            for (int i = 0; i < stepCount; i++)
            {
                MakeNextGeneration(neighborhood, ruleStrategy, Params.Generations);
            }
        }
示例#2
0
        public static void TestCode(string inFile, string outFile)
        {
            PlayData playData = new PlayData(File.ReadAllLines(inFile));

            Console.WriteLine($"inFile                   : {Path.GetFileName(inFile)}");
            Console.WriteLine($"Command                  : {playData.Command}");
            Console.WriteLine($"Generations              : {playData.Params.Generations}");
            Console.WriteLine($"NeighborhoodStrategyName : {playData.Params.NeighborhoodStrategyName}");
            Console.WriteLine($"RulesStrategyName        : {playData.Params.RulesStrategyName}");
            Console.WriteLine($"Count                    : {playData.Params.Count}");
            Console.WriteLine($"LifeNewBirth             : {playData.Params.LifeNewBirth.Combine(", ")}");
            Console.WriteLine($"LifeSurvivals            : {playData.Params.LifeSurvivals.Combine(", ")}");

            switch (playData.Command)
            {
            case "CalcFieldSize":
            {
                File.WriteAllText(outFile, (playData.Area.Cols * playData.Area.Rows).ToString());
                break;
            }

            case "CalcLiveCells":
            {
                int count = playData.Area.GetCellIndexes(c => c.IsLifeCell).Count();
                File.WriteAllText(outFile, count.ToString());
                break;
            }

            case "CalcParamsCount":
            {
                File.WriteAllText(outFile, playData.Params.Count.ToString());
                break;
            }

            case "CalcSurvivingCells":
            {
                IRuleStrategy         ruleStrategy         = StrategiesFactory.GetRuleStrategy(playData);
                INeighborhoodStrategy neighborhoodStrategy = StrategiesFactory.GetNeighborhoodStrategy(playData);
                var maxGenerations = playData.Params.Generations;

                int count = playData.Area.GetCellIndexes().Count(c => { return(c.IsLifeCell && !ruleStrategy.IsDyingCellPolicy(c, neighborhoodStrategy.GetLifeNeighborhoodCount(c), maxGenerations)); });

                File.WriteAllText(outFile, count.ToString());
                break;
            }

            case "CalcNewCells":
            {
                IRuleStrategy         ruleStrategy         = StrategiesFactory.GetRuleStrategy(playData);
                INeighborhoodStrategy neighborhoodStrategy = StrategiesFactory.GetNeighborhoodStrategy(playData);

                int count = playData.Area.GetCellIndexes().Count(c => ruleStrategy.IsNewCellPolicy(c, neighborhoodStrategy.GetLifeNeighborhoodCount(c)));

                File.WriteAllText(outFile, count.ToString());
                break;
            }

            case "NextGeneration":
            {
                playData.MakeNextGenerations();

                playData.Area.WriteArea(outFile, playData.Params.UseGenerations);
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }
        }