public OrderDiscountCalculator( IRuleStrategy ruleStrategy, IDiscountStrategy discountStrategy ) { this.ruleStrategy = ruleStrategy; this.discountStrategy = discountStrategy; }
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); } }
public bool RuleIsSatisfied() { RuleFactory ruleFactory = new RuleFactory(); IRuleStrategy ruleStrategy = ruleFactory.GetRuleStrategy(_rule); Context ruleContext = new Context(ruleStrategy); if (ruleContext.Execute(_rule, _liveEventsThatFitIntoRule.ToList())) { ClearProcessedEvents(); return(true); } return(false); }
private void MakeNextGeneration(INeighborhoodStrategy neighborhood, IRuleStrategy ruleStrategy, int maxGenerations) { foreach (var cellIndex in Area.GetCellIndexes()) { var neighborhoodCount = neighborhood.GetLifeNeighborhoodCount(cellIndex); if (ruleStrategy.IsDyingCellPolicy(cellIndex, neighborhoodCount, maxGenerations)) { cellIndex.SetDyingCell(); continue; } if (ruleStrategy.IsNewCellPolicy(cellIndex, neighborhoodCount)) { cellIndex.SetNewCell(); continue; } } Area.UpdateCells(); }
public IRuleStrategy Decorate(IRuleStrategy strategy) => new PlusStrategy(strategy);
public SameStrategy(IRuleStrategy inner, bool wall) { this.inner = inner; this.wall = wall; }
public IRuleStrategy Decorate(IRuleStrategy strategy) => new SameStrategy(strategy, this.wall);
public Context(IRuleStrategy strategy) { _strategy = strategy; }
public IRuleStrategy Decorate(IRuleStrategy strategy) => new ElementalStrategy(strategy);
public PlusStrategy(IRuleStrategy inner) { this.inner = inner; }
public RuleStrategyBuilder Add(IRuleStrategyDecorator strategy) { this.strategy = strategy.Decorate(this.strategy); return(this); }
public ElementalStrategy(IRuleStrategy inner) { this.inner = inner; }
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(); } } }