static int EvaluateCostAndPrint(IADTreeNode node, ADTreeContext context) { EvaluateCostVisitor v = new EvaluateCostVisitor(); var value = v.GetValue(node, v, context); Console.WriteLine("Minimum attack cost: " + value); return value; }
public OrNode(string name, int duration, int cost, IADTreeNode left = null, IADTreeNode right = null) { Name = name; Duration = duration; Cost = cost; Left = left; Right = right; }
public int GetValue(IADTreeNode node, IEvaluateVisitor <int> v, ADTreeContext context) { if (node.Left == null && node.Right == null) { return(node.Duration); } return(node.DurationProvider.GetDuration(v.GetValue(node.Left, v, context), v.GetValue(node.Right, v, context)) + node.Duration); }
public ADTreeNode(IADTreeNode left, IADTreeNode right, string name, int duration, int cost) { LeftChild = left; RightChild = right; Name = name; Duration = duration; Cost = cost; }
static bool EvaluateSuccessAndPrint(IADTreeNode node, ADTreeContext context) { EvaluateSuccessVisitor v = new EvaluateSuccessVisitor(); var value = v.GetValue(node, v, context); if (value) Console.WriteLine("Evaluated: true"); else Console.WriteLine("Evaluated: false"); return value; }
static int EvaluateDurationAndPrint(IADTreeNode node, ADTreeContext context) { EvaluateDurationVisitor v = new EvaluateDurationVisitor(); var value = v.GetValue(node, v, context); Console.WriteLine("Minimum attack time: " + value); Console.WriteLine(""); Console.WriteLine("----------------------------------------"); return value; }
public bool GetValue(IADTreeNode node, IEvaluateVisitor <bool> v, ADTreeContext context) { Random rnd = new Random(); if (node.Left == null && node.Right == null) { bool?nb = context.GetNodeOutcome(node.Name); return((nb.HasValue) ? nb.Value : Convert.ToBoolean(rnd.Next(1))); } return(node.StatusProvier.GetStatus(v.GetValue(node.Left, v, context), v.GetValue(node.Right, v, context))); }
public int GetValue(IADTreeNode a, EvaluateDurationVisitor b, ADTreeContext c) { if (a is LEAF) { return((int)a.Accept(this)); } else if (a is OR) { int v1 = GetValue(a.childs[0], b, c); int v2 = GetValue(a.childs[1], b, c); return(v1 > v2 ? v2 : v1); } else { return(GetValue(a.childs[0], b, c) + GetValue(a.childs[1], b, c)); } }
private IADTreeNode ParseNext(Stack <string> tokens) { if (tokens.Count == 0) { throw new SyntaxErrorException(); } string[] split = tokens.Pop().Split(','); if (split.Length != 4) { throw new SyntaxErrorException(); } string type = split[0]; string name = split[1]; int cost = int.Parse(split[2]); int time = int.Parse(split[3]); switch (type) { // TODO: complete parser implementation (build the ADTree corresponding to string input and return its root node). case "AND": { IADTreeNode left = ParseNext(tokens); IADTreeNode right = ParseNext(tokens); return(new ANDNode(left, right, name, time, cost)); } case "OR": { IADTreeNode left = ParseNext(tokens); IADTreeNode right = ParseNext(tokens); return(new ORNode(left, right, name, time, cost)); } case "LEAF": { return(new Leaf(name, time, cost)); } default: throw new SyntaxErrorException(); } }
public bool GetValue(IADTreeNode a, EvaluateSuccessVisitor b, ADTreeContext c) { if (a.childs.Count > 0) { if (a is AND) { return(GetValue(a.childs[0], b, c) && GetValue(a.childs[1], b, c)); } else { return(GetValue(a.childs[0], b, c) || GetValue(a.childs[1], b, c)); } } bool?outcome = c.GetNodeOutcome((string)a.Accept(b)); if (outcome == null) { return(new Random().Next(0, 100) > 50 ? true : false); } return(outcome.Value); }
public int GetValue(IADTreeNode node, IVisitor <int> visitor, ADTreeContext context) { return(node.Accept(this, context)); }
public ORNode(IADTreeNode left, IADTreeNode right, string name, int duration, int cost) : base(left, right, name, duration, cost) { }
public IADTreeNode insertChild(IADTreeNode child) { childs.Add(child); return(this); }
public IADTreeNode insertChild(IADTreeNode child) { return(this); }