Example #1
0
 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;
 }
Example #2
0
 public OrNode(string name, int duration, int cost, IADTreeNode left = null, IADTreeNode right = null)
 {
     Name     = name;
     Duration = duration;
     Cost     = cost;
     Left     = left;
     Right    = right;
 }
Example #3
0
 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;
 }
Example #5
0
 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;
 }
Example #6
0
        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)));
        }
Example #8
0
 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();
            }
        }
Example #10
0
        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);
        }
Example #11
0
 public int GetValue(IADTreeNode node, IVisitor <int> visitor, ADTreeContext context)
 {
     return(node.Accept(this, context));
 }
Example #12
0
 public ORNode(IADTreeNode left, IADTreeNode right, string name, int duration, int cost) : base(left, right, name, duration, cost)
 {
 }
Example #13
0
 public IADTreeNode insertChild(IADTreeNode child)
 {
     childs.Add(child);
     return(this);
 }
Example #14
0
 public IADTreeNode insertChild(IADTreeNode child)
 {
     return(this);
 }