public TreeRecordNode(TreeContext context, SourceLocation location, string?name, ImmutableArray <TreeRecordField> fields) : base(context, location) { Name = name; Fields = fields; }
public BehaviorReturnCode Behave(TreeContext context) { context.OnAboutToCall(this); this.ReturnCode = this.OnBehave(context); context.OnCalled(this, this.ReturnCode); return(this.ReturnCode); }
/// <summary> /// performs the given behavior /// </summary> /// <returns>the behaviors return code</returns> public override BehaviorReturnCode OnBehave(TreeContext context) { try { switch (_Behavior.Behave(context)) { case BehaviorReturnCode.Failure: ReturnCode = BehaviorReturnCode.Success; return(ReturnCode); case BehaviorReturnCode.Success: ReturnCode = BehaviorReturnCode.Failure; return(ReturnCode); case BehaviorReturnCode.Running: ReturnCode = BehaviorReturnCode.Running; return(ReturnCode); } } catch (Exception e) { #if DEBUG Console.Error.WriteLine(e.ToString()); #endif ReturnCode = BehaviorReturnCode.Success; return(ReturnCode); } ReturnCode = BehaviorReturnCode.Success; return(ReturnCode); }
/// <summary> /// performs the given behavior /// </summary> /// <returns>the behaviors return code</returns> public override BehaviorReturnCode OnBehave(TreeContext context) { _Random = new Random(DateTime.Now.Millisecond); try { switch (_Behaviors[_Random.Next(0, _Behaviors.Length)].Behave(context)) { case BehaviorReturnCode.Failure: ReturnCode = BehaviorReturnCode.Failure; return(ReturnCode); case BehaviorReturnCode.Success: ReturnCode = BehaviorReturnCode.Success; return(ReturnCode); case BehaviorReturnCode.Running: ReturnCode = BehaviorReturnCode.Running; return(ReturnCode); default: ReturnCode = BehaviorReturnCode.Failure; return(ReturnCode); } } catch (Exception e) { #if DEBUG Console.Error.WriteLine(e.ToString()); #endif ReturnCode = BehaviorReturnCode.Failure; return(ReturnCode); } }
public IQueryable <EasyTree> GetList(TreeContext db) { IQueryable <EasyTree> list = db.EasyTrees.AsQueryable(); return(list); }
/// <summary> /// performs the given behavior /// </summary> /// <returns>the behaviors return code</returns> public override BehaviorReturnCode OnBehave(TreeContext context) { for (int i = 0; i < _Behaviors.Length; i++) { try { switch (_Behaviors[i].Behave(context)) { case BehaviorReturnCode.Failure: continue; case BehaviorReturnCode.Success: ReturnCode = BehaviorReturnCode.Success; return(ReturnCode); case BehaviorReturnCode.Running: ReturnCode = BehaviorReturnCode.Running; return(ReturnCode); default: continue; } } catch (Exception e) { #if DEBUG Console.Error.WriteLine(e.ToString()); #endif continue; } } ReturnCode = BehaviorReturnCode.Failure; return(ReturnCode); }
private static INode CreateNodeForFilterGroup(this TreeContext context, IFilterGroup filterGroup) { var groupDependencies = GroupFiltersService.GetGroupDependencies(context, filterGroup); var provider = new GroupProvider(groupDependencies, filterGroup, context.Store, filterGroup.DiagInfo); return(Node.CreateNode(filterGroup.NodeToken, provider, true, context)); }
private static void AssignNode(INode node, TreeContext context) { node.Provider.ForDependencies((dep1, dep2) => context.ReorderNodes(node.Provider, dep1, dep2)); var parent = context.GetAssignmentNode(node.Provider); node.Parent = parent; node.SourceParent = parent; }
public ActionResult Move(int nodeId, int?newParentId, bool list) //Метод перемещения ветви в другую ветвь { if (list) { return(RedirectToAction("Index")); } if (nodeId == newParentId) { return(RedirectToAction("Index")); } using (TreeContext context = new TreeContext()) { if (newParentId.HasValue && ContainsChilds(context, nodeId, newParentId.Value)) { return(RedirectToAction("Index")); } var node = context.Folders.Where(x => x.Id == nodeId).Single(); node.ParentId = newParentId; context.SaveChanges(); } return(RedirectToAction("Index")); }
public TreeCheckFieldAccessNode(TreeContext context, SourceLocation location, TreeReference subject, string name) : base(context, location) { Subject = subject; Name = name; }
public static void CreateNonEqualFilter(this TreeContext context, INode node1, INode node2, IFilterGroup parentGroup, IDiagInfo diagInfo) { if (node1.Token.Type != node2.Token.Type) { return; } var tuple = new Tuple <IToken, IToken>(node1.Token, node2.Token); var reverseTuple = new Tuple <IToken, IToken>(node2.Token, node1.Token); if (context.NonEqualFilters.Contains(tuple) || context.NonEqualFilters.Contains(reverseTuple)) { return; } context.NonEqualFilters.Add(tuple); var dep1 = new SingleDependency(node1.Token); var dep2 = new SingleDependency(node2.Token); var newInfo = new FilterInfo(context.Store.NextId, diagInfo, parentGroup?.FilterInfo.FilterToken); var filter = new Filter2 <IResolutionContext, IResolutionContext>(dep1, dep2, (x, y) => !x.Equals(y), newInfo); context.Filters.Add(filter); }
/// <summary> /// performs the given behavior /// </summary> /// <returns>the behaviors return code</returns> public override BehaviorReturnCode OnBehave(TreeContext context) { try { _TimeElapsed += _ElapsedTimeFunction.Invoke(); if (_TimeElapsed >= _WaitTime) { _TimeElapsed = 0; ReturnCode = _Behavior.Behave(context); return(ReturnCode); } else { ReturnCode = BehaviorReturnCode.Running; return(BehaviorReturnCode.Running); } } catch (Exception e) { #if DEBUG Console.Error.WriteLine(e.ToString()); #endif ReturnCode = BehaviorReturnCode.Failure; return(BehaviorReturnCode.Failure); } }
public override BehaviorReturnCode OnBehave(TreeContext context) { for (int i = 0; i < this.conditions.Length; i++) { try { switch (this.conditions[i].Behave(context)) { case BehaviorReturnCode.Failure: return(BehaviorReturnCode.Failure); case BehaviorReturnCode.Running: return(BehaviorReturnCode.Running); default: continue; } } catch (Exception e) { #if DEBUG Console.Error.WriteLine(e.ToString()); #endif continue; } } return(this.action.Behave(context)); }
public static void ForNodes(this Dictionary<IToken, List<INode>> nodeDependencies, TreeContext context, Action<INode> action) { var nodesQueue = new Queue<INode>(new[] { context.Tree.Root }); var assigned = new HashSet<IToken> { context.Tree.Root.Token }; while (nodesQueue.Any()) { var current = nodesQueue.Dequeue(); List<INode> children; if (!nodeDependencies.TryGetValue(current.Token, out children)) { continue; } foreach (var child in children) { var dependencies = context.GetDependencies(child); if (!dependencies.All(x => assigned.Contains(x.Token))) { continue; } action(child); assigned.Add(child.Token); nodesQueue.Enqueue(child); } } }
/// <summary> /// performs the given behavior /// </summary> /// <returns>the behaviors return code</returns> public override BehaviorReturnCode OnBehave(TreeContext context) { try { switch (_Bool.Invoke()) { case true: ReturnCode = BehaviorReturnCode.Success; return(ReturnCode); case false: ReturnCode = BehaviorReturnCode.Failure; return(ReturnCode); default: ReturnCode = BehaviorReturnCode.Failure; return(ReturnCode); } } catch (Exception e) { #if DEBUG Console.Error.WriteLine(e.ToString()); #endif ReturnCode = BehaviorReturnCode.Failure; return(ReturnCode); } }
public override BehaviorReturnCode OnBehave(TreeContext context) { this.lastCallHierarchy = context.CallingHierarchy; this.handledThisTick = false; context.RegisterOnNotCalledBehavior(this); return(BehaviorReturnCode.Success); }
/// <summary> /// performs the given behavior /// </summary> /// <returns>the behaviors return code</returns> public override BehaviorReturnCode OnBehave(TreeContext context) { try { if (_Counter < _MaxCount) { _Counter++; ReturnCode = BehaviorReturnCode.Running; return(BehaviorReturnCode.Running); } else { _Counter = 0; ReturnCode = _Behavior.Behave(context); return(ReturnCode); } } catch (Exception e) { #if DEBUG Console.Error.WriteLine(e.ToString()); #endif ReturnCode = BehaviorReturnCode.Failure; return(BehaviorReturnCode.Failure); } }
public TreeSetNode(TreeContext context, SourceLocation location, ImmutableArray <TreeReference> elements, bool mutable) : base(context, location) { Elements = elements; IsMutable = mutable; }
public TreeReceiveNode(TreeContext context, SourceLocation location, ImmutableArray <TreePatternArm> arms, TreeReference? @else) : base(context, location) { Arms = arms; Else = @else; }
public EasyTree GetById(int id) { using (TreeContext db = new TreeContext()) { return(db.EasyTrees.SingleOrDefault(a => a.id == id)); } }
public TreeMapNode(TreeContext context, SourceLocation location, ImmutableArray <TreeMapPair> pairs, bool mutable) : base(context, location) { Pairs = pairs; IsMutable = mutable; }
private DecisionTreeStatus TargetLowHP(long TickTime, TreeContext context) { bool sucees = false; Character LowerHP = null; foreach (Character c in context.enemies) { if (c.Health <= (c.MaxHealth * 0.25f)) { sucees = true; if (LowerHP && LowerHP.Health > c.Health) { LowerHP = c; } else { LowerHP = c; } } } context.target = LowerHP; return(sucees ? DecisionTreeStatus.Success : DecisionTreeStatus.Failure); }
public TreeMatchNode(TreeContext context, SourceLocation location, TreeReference operand, ImmutableArray <TreePatternArm> arms) : base(context, location) { Operand = operand; Arms = arms; }
internal Test(Module module, TestDeclarationNode node) : base(module, node) { Tree = new TreeContext(module.Loader, this, ImmutableArray <TreeParameter> .Empty, null, ImmutableArray <TreeUpvalue> .Empty); _lowerer = new SyntaxTreeLowerer(module.Loader, Tree, node.Body, node.GetAnnotation <ImmutableHashSet <SyntaxSymbol> >("Freezes")); }
public TreeBinaryNode(TreeContext context, SourceLocation location, TreeReference left, string @operator, TreeReference right) : base(context, location) { Left = left; Operator = @operator; Right = right; }
private static IEnumerable <INode> GetDependencyNodes(this TreeContext context, IDependency dep1) { return(dep1.Type == DependencyType.Single ? new[] { context.Tree.Nodes[dep1.Token] } : context.Tree.GetNode(dep1.Token) .Provider.Dependencies .SelectMany(context.GetDependencyNodes)); }
private static IFilter GetFinalFilter(this TreeContext context, IFilter filter) { var inversionDiag = context.IsCvFilter(filter) ? context.Store.CollectionInversions.SafeGet(filter.Dependencies.First().Token) : context.Store.FilterInversions.SafeGet(filter.FilterInfo.FilterToken); return(inversionDiag != null ? new Inverter(filter, new FilterInfo(context.Store.NextId, inversionDiag)) : filter); }
public TreeRelationalNode(TreeContext context, SourceLocation location, TreeReference left, TreeRelationalOperator @operator, TreeReference right) : base(context, location) { Left = left; Operator = @operator; Right = right; }
private DecisionTreeStatus UseAttack(long TickTime, TreeContext context) { if (context.attack != null) { CombatSystem.Instance.AttackCharacter(context.attack, new Character[] { context.target }); } return(DecisionTreeStatus.Success); }
private DecisionTreeStatus NeedHealing(long TickTime, TreeContext context) { if ((context.self.MaxHealth - context.self.Health) < (context.self.MaxHealth * 0.3f)) { return(DecisionTreeStatus.Success); } return(DecisionTreeStatus.Failure); }
private static bool DependencyIsAbsorbed(this TreeContext context, IDependency dependency, INode node) { if (dependency.Type == DependencyType.Single && dependency.Token == node.Token) { return(true); } return(context.IsParent(dependency.Token, node.Token)); }
private static HashSet<IToken> FindParents(TreeContext context, IToken token) { if (token == context.Store.RootToken) { return new HashSet<IToken>(); } var dependencies = context.Tree.Nodes[token].Provider.Dependencies.Select(x => x.Token).ToList(); return new HashSet<IToken>(dependencies.SelectMany(context.GetParents).Concat(dependencies)); }
private static void SetNodeWeights(TreeContext context, IDependency dependency, IDependency dep2) { if (context.IsParent(dependency.Token, dep2.Token) || context.IsParent(dep2.Token, dependency.Token)) { return; } SetNodeWeights(context, dependency); SetNodeWeights(context, dep2); }
public static IEnumerable<IDependency> GetGroupDependencies(TreeContext context, IFilterGroup filterGroup) { var inGroupTokens = context.GetInGroupTokens(filterGroup); var groupDependencies = inGroupTokens .SelectMany(x => context.Store.Providers[x].Dependencies) .Concat(context.GetInGroupFilters(filterGroup).SelectMany(x => x.Dependencies)) .Concat(filterGroup.GroupDependencies) .Where(dependency => !inGroupTokens.Contains(dependency.Token)) .DistinctDependencies() .ToList(); return groupDependencies; }
private static void SetNodeWeights(TreeContext context, IDependency dependency) { if (context.WeightedDependencies.Contains(dependency)) { return; } context.WeightedDependencies.Add(dependency); context.GetDependencyNodes(dependency) .OrderByDescending(x => x.Weight) .First() .Weight++; }
public static TreeContext CreateTreeContext(this TokenStore store, Tree tree) { var context = new TreeContext { Tree = tree, Store = store, Filters = store.GetTreeFilters() }; context.Groups = context.Filters.OfType<IFilterGroup>().ToDictionary(x => x.FilterInfo.FilterToken); context.FiltersInGroup = context .Filters .Where(x => x.ParentGroupToken != null) .GroupBy(x => x.ParentGroupToken) .ToDictionary(x => x.Key, x => x.ToList()); context.ProviderTokensInGroup = store .Providers .Where(x => x.Value.ParentGroupToken != null) .GroupBy(x => x.Value.ParentGroupToken) .ToDictionary(x => x.Key, x => x.Select(y => y.Key).ToList()); return context; }
private static void SetNodeWeights(TreeContext context, INode node) { node.Provider.ForDependencies((dep1, dep2) => SetNodeWeights(context, dep1, dep2)); }
public static void ReorderNodesForFilters(TreeContext context) { context.Filters .ToList() .ForEach(x => x.ForDependencies((dep1, dep2) => context.ReorderNodes(x, dep1, dep2))); }
private static void AddGroupDependency(this IFilterGroup parentGroup, TreeContext context, List<INode> dependencies) { dependencies.Add(context.Tree.GetNode(parentGroup.NodeToken)); }
private static INode CreateNode(IToken token, IProvider provider, TreeContext context) { var isNegative = provider.IsNegative || context.Store.CollectionInversions.ContainsKey(token); return Node.CreateNode(token, provider, isNegative, context); }