public override void InitChildren() { base.InitChildren(); this.SetInputs(new InputHook().SetType(typeof(bool)).SetNode(this).SetName("Condition").SetDesc("Execute \"True\" or \"False\" dependant on this.").SetProgram(ParentProgram) as InputHook); SetRoutes( new ChainHook().SetNode(this).SetDirection(Direction.Out).SetName("True").SetDesc("This way if true").SetProgram(ParentProgram) as ChainHook, new ChainHook().SetNode(this).SetDirection(Direction.Out).SetName("False").SetDesc("This way if false").SetProgram(ParentProgram) as ChainHook ); PossibleRoutes.InitAll(); }
public void GetBestRoute(string source, string target) { var possibleRoute = new PossibleRoute { CurrentTarget = target, Source = source }; GetPossibleRoutes(ref possibleRoute, source, target); BestRoute = PossibleRoutes.FirstOrDefault(x => x.Value == PossibleRoutes.Select(route => route.Value).Min()); }
public override void InitChildren() { base.InitChildren(); this.SetInputs(new InputHook().SetType(typeof(int)).SetName("Duration").SetDesc("The duration in ticks that this will run.") as InputHook); this.SetOutputs(new OutputHook().SetType(typeof(int)).SetName("Counter").SetDesc("The counter of execution steps.") as OutputHook); SetRoutes( new ChainHook().SetNode(this).SetDirection(Direction.Out).SetName("During").SetDesc("Execute while running.").SetProgram(ParentProgram) as ChainHook, new ChainHook().SetNode(this).SetDirection(Direction.Out).SetName("Done").SetDesc("Execute when done.").SetProgram(ParentProgram) as ChainHook ); PossibleRoutes.InitAll(); }
public void GetPossibleRoutes(ref PossibleRoute possibleRoute, string source, string target) { var currentTarget = possibleRoute.CurrentTarget; var routes = Routes.Where(x => x.Target == currentTarget).ToList(); string routeSuffix = null; decimal value = 0; if (routes.Any()) { routeSuffix = possibleRoute.Route; value = possibleRoute.Value; } else { possibleRoute.Route = null; possibleRoute.Value = 0; } possibleRoute.Source = source; foreach (var route in routes) { possibleRoute.Route = $"{route.Source}-{possibleRoute.Route ?? routeSuffix}"; possibleRoute.Value = route.Value + (possibleRoute.Value == 0 ? value : possibleRoute.Value); if (route.Target == currentTarget && route.Source == source) { possibleRoute.Route = $"{possibleRoute.Route}{target}"; PossibleRoutes.Add(possibleRoute); possibleRoute = new PossibleRoute(); } else { possibleRoute.CurrentTarget = route.Source; GetPossibleRoutes(ref possibleRoute, source, target); } } }
public Part2() { distancesRepository = new DistancesRepository(); possibleRoutes = new PossibleRoutes(); }