Ejemplo n.º 1
0
 public virtual void AddChild(Node n, int index)
 {
     Children.Insert(index, n);
 }
Ejemplo n.º 2
0
 public void RemoveChild(Node n)
 {
     Children.Remove(n);
 }
Ejemplo n.º 3
0
 public virtual void AddChild(Node n)
 {
     Children.Add(n);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Randomly add this node to success or failure trees
 /// </summary>
 /// <param name="n"></param>
 /// <param name="index"></param>
 public override void AddChild(Node n, int index)
 {
     AddChild(n);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Randomly add this node to success or failure trees
 /// </summary>
 /// <param name="n"></param>
 /// <param name="index"></param>
 public override void AddChild(Node n)
 {
     if (new Random((int)DateTime.Now.Ticks % Int32.MaxValue).Next(100) > 50)
     {
         if (Success == null)
             Success = n;
         else
             Success.AddChild(n);
     }
     else
     {
         if (Failure == null)
             Failure = n;
         else
             Failure.AddChild(n);
     }
 }
Ejemplo n.º 6
0
 public Chromosome(Node Genome)
 {
     this.Genome = Genome;
     Random = new Random((int)(DateTime.Now.Ticks % Int32.MaxValue));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Recursive enumeration of actions using conditions considering current state
        /// </summary>
        /// <param name="State">
        /// A <see cref="Dictionary<System.Int32, System.Int32>"/>
        /// </param>
        /// <param name="node">
        /// A <see cref="Node"/>
        /// </param>
        /// <returns>
        /// A <see cref="IEnumerable<Node>"/>
        /// </returns>
        public IEnumerable<Node> Enumerate(Dictionary<int, int> State, Node node)
        {
            if (node as Action != null)
                yield return node as Action;

            if (node as Conditional != null && State == null) //only enumerate conditionals if this is a non-state-dependent enumeration
                yield return node as Conditional;

            foreach (var c in node.Children)
                foreach (var n in Enumerate(State, c))
                    yield return n;

            var cond = node as Conditional;
            if (cond != null)
            {
                if (cond.Success != null && ((State != null && cond.Evaluate(State)) || State == null))
                    foreach (var n in Enumerate(State, cond.Success))
                        yield return n;
                if (cond.Failure != null && ((State != null && !cond.Evaluate(State)) || State == null))
                    foreach (var n in Enumerate(State, cond.Failure))
                        yield return n;
            }
        }