Exemplo n.º 1
0
        // Checks for collision between two nodes and their children
        public static bool CheckCollision(Node n1, Node n2, NodeProvider provider, SpaceState state, bool noisy = false, int deep = 0)
        {
            if (deep > 5)
                return false;
            int x = (n1.x + n2.x) / 2;
            int y = (n1.y + n2.y) / 2;
            int t = (n1.t + n2.t) / 2;
            Node n3 = provider.GetNode (t, x, y);

            // Noisy calculation
            if (state.enemies != null && ((Cell)n3.cell).noisy) {
                foreach (Enemy enemy in state.enemies) {
                    Vector3 dupe = enemy.positions [t];
                    dupe.x = (dupe.x - state.floorMin.x) / state.tileSize.x;
                    dupe.y = n3.t;
                    dupe.z = (dupe.z - state.floorMin.z) / state.tileSize.y;

                    // This distance is in number of cells size radius i.e. a 10 tilesize circle around the point
                    if (Vector3.Distance (dupe, n3.GetVector3 ()) < 10)
                        return true;
                }
            }

            return !(n3.cell.safe || !(n3.cell.blocked || n3.cell.seen)) || CheckCollision (n1, n3, provider, state, noisy, deep + 1) || CheckCollision (n2, n3, provider, state, noisy, deep + 1);
        }
Exemplo n.º 2
0
        public float DistanceFrom(Node n)
        {
            Vector2 v1, v2;
            v1 = new Vector2 (this.x, this.y);
            v2 = new Vector2 (n.x, n.y);

            return (v1 - v2).magnitude + Mathf.Abs (this.t - n.t);
        }
Exemplo n.º 3
0
        private static Common.Node CreateNodeRecord(string resourceName, TimeMeter.Integrator.NodeInfo info)
        {
            var res = new Common.Node();

            res.ResourceName   = resourceName;
            res.DNSName        = info.DNSName;
            res.CoresAvailable = info.NumberOfCores;
            res.CoresTotal     = info.NumberOfCores;
            res.Parameters[SummaryNodePerformance.CoresPerformance] = JsonConvert.SerializeObject(info.FrequencyOfCores.ToArray());
            return(res);
        }
Exemplo n.º 4
0
 public static bool SmoothNode(Node n, NodeProvider provider, SpaceState state, bool noisy = false)
 {
     if (n.parent != null && n.parent.parent != null) {
         if (CheckCollision (n, n.parent.parent, provider, state, noisy))
             return false;
         else {
             n.parent = n.parent.parent;
             return true;
         }
     } else
         return false;
 }
Exemplo n.º 5
0
 // current moving cost
 private float g(Node current)
 {
     if (current.parent == null)
         return 0;
     else
         return h (current, current.parent) + g (current.parent);
 }
Exemplo n.º 6
0
 private float h(Node current, Node to, ref double temp)
 {
     if (to == end){
         return getProb(current,ref temp)*Vector2.Distance (new Vector2 (to.x, to.y), new Vector2 (current.x, current.y));
     }
     return getProb(to, ref temp)*Vector2.Distance (new Vector2 (to.x, to.y), new Vector2 (current.x, current.y));
 }
Exemplo n.º 7
0
 public Node(Vector3 position, Vector3 size, bool verticalSplit, int nLeafCells, ref int leafCounter)
 {
     this.rectangle = new Common.Bounding.AABB(position, size);
     this.verticalSplit = verticalSplit;
     float weight = (float)(System.Math.Ceiling(nLeafCells / 2f) / nLeafCells);
     if (verticalSplit)
         split = position.X + weight * size.X;
     else
         split = position.Y + weight * size.Y;
     if (nLeafCells > 1)
     {
         children = new Node[2];
         if (verticalSplit)
         {
             children[0] = new Node(position, new Vector3(size.X / 2, size.Y, 0), false, (int)System.Math.Ceiling(nLeafCells / 2f), ref leafCounter);
             children[1] = new Node(new Vector3(position.X + size.X / 2, position.Y, 0),
                 new Vector3(size.X / 2, size.Y, 0), false, (int)System.Math.Floor(nLeafCells / 2f), ref leafCounter);
         }
         else
         {
             children[0] = new Node(position, new Vector3(size.X, size.Y / 2, 0), true, (int)System.Math.Ceiling(nLeafCells / 2f), ref leafCounter);
             children[1] = new Node(new Vector3(position.X, position.Y + size.Y / 2, 0),
                 new Vector3(size.X, size.Y / 2, 0), true, (int)System.Math.Floor(nLeafCells / 2f), ref leafCounter);
         }
     }
     else
         id = leafCounter++;
 }
Exemplo n.º 8
0
        // Creates a node with the specified coordinates, no matter if it already exists in the tree or not
        // This is mainly to create the connections between nodes that shouldn't be added to the tree
        // Like the nodes with combat in then
        // This avoids crashing exceptions collisions while retrieving nodes
        private Node NewNode(int t, int x, int y)
        {
            Node n = new Node ();

            n.x = x;
            n.y = y;
            n.t = t;
            n.enemyhp = new Dictionary<Enemy, float> ();
            n.fighting = new List<Enemy>();
            n.picked = new List<HealthPack>();
            n.cell = nodeMatrix [t] [x] [y];
            return n;
        }
Exemplo n.º 9
0
 // Gets the node at specified position from the NodeMap, or create the Node based on the Cell position for that Node
 public Node GetNode(int t, int x, int y)
 {
     object o = tree.search (new double[] {x, t, y});
     if (o == null) {
         Node n = new Node ();
         n.x = x;
         n.y = y;
         n.t = t;
         try {
             n.cell = nodeMatrix [t] [x] [y];
         } catch {
             Debug.Log (t + "-" + x + "-" + y);
             Debug.Log (n);
             Debug.Log (nodeMatrix [t]);
             Debug.Log (nodeMatrix.Length);
             Debug.Log (nodeMatrix [t].Length);
             Debug.Log (nodeMatrix [t] [x].Length);
             n.cell = nodeMatrix [t] [x] [y];
         }
         o = n;
     }
     return (Node)o;
 }
Exemplo n.º 10
0
 public Boolean equalTo(Node b)
 {
     if (this.x == b.x & this.y == b.y & this.t == b.t)
         return true;
     return false;
 }
Exemplo n.º 11
0
        public List<Node> Compute(int startX, int startY, int endX, int endY, Cell[][][] matrix, float playerSpeed)
        {
            this.speed = 1.0d / playerSpeed;
            try {
                Priority_Queue.IPriorityQueue<Node> heap2 = new Priority_Queue.HeapPriorityQueue<Node> (1000000);
                List<Node> closed = new List<Node> ();

                // Initialize our version of the matrix (can we skip this?)
                Node[][][] newMatrix = new Node[matrix.Length][][];
                for (int t=0; t<matrix.Length; t++) {
                    newMatrix [t] = new Node[matrix [t].Length][];
                    for (int x = 0; x < matrix [t].Length; x++) {
                        newMatrix [t] [x] = new Node[matrix [t] [x].Length];
                        for (int y = 0; y < matrix [t] [x].Length; y++) {
                            newMatrix [t] [x] [y] = new Node ();
                            newMatrix [t] [x] [y].parent = null;
                            newMatrix [t] [x] [y].cell = matrix [t] [x] [y];
                            newMatrix [t] [x] [y].x = x;
                            newMatrix [t] [x] [y].y = y;
                            newMatrix [t] [x] [y].t = t;
                        }
                    }
                }
                // Do the work for the first cell before firing the algorithm
                start = newMatrix [0] [startX] [startY];
                end = newMatrix [0] [endX] [endY];
                start.parent = null;
                start.visited = true;
                start.accSpeed = speed - Math.Floor(speed);
                foreach (Node n in getAdjacent(start, newMatrix)) {
                    n.parent = start;
                    float fVal = f (n);
                    n.Priority = fVal;
                    heap2.Enqueue (n, fVal);
                }
                while (heap2.Count != 0) {
                    Node first = heap2.Dequeue ();
                    if (first.x == end.x && first.y == end.y) {
                        end = newMatrix [first.t] [end.x] [end.y];
                        break;
                    }
                    first.visited = true;
                    foreach (Node m in getAdjacent(first, newMatrix)) {
                        float currentG = g (first) + h (m, first);
                        float gVal = g (m);
                        if (m.visited) {
                            if (gVal > currentG) {
                                m.parent = first;
                                acc(m);
                            }
                        } else {
                            if (!heap2.Contains (m)) {
                                m.parent = first;
                                m.Priority = f (m);
                                heap2.Enqueue (m, m.Priority);
                                acc(m);
                            } else {
                                if (gVal > currentG) {
                                    m.parent = first;
                                    m.Priority = f (m);
                                    heap2.UpdatePriority (m, m.Priority);
                                    acc(m);
                                }
                            }
                        }
                    }
                }
                // Creates the result list
                Node e = end;
                List<Node> points = new List<Node> ();
                while (e != null) {
                    points.Add (e);
                    e = e.parent;
                }
                points.Reverse ();

                // If we didn't find a path
                if (points.Count == 1)
                    points.Clear ();
                return points;
            } catch (System.Exception e) {
                Debug.Log (e.Message);
                Debug.Log (e.StackTrace);
                Debug.Log ("ERROR 2");
                return null;
            }
        }
Exemplo n.º 12
0
 public override string GetValue(Node node)
 {
     return GetPerfs(node).Sum().ToString(CultureInfo.InvariantCulture.NumberFormat);
 }
Exemplo n.º 13
0
 public override string GetValue(Node node)
 {
     try
     {
         return base.GetValue(node);
     }
     catch (NodeParameterException)
     {
         return false.ToString();
     }
 }
Exemplo n.º 14
0
        public static string GetValue(string parameterId, Node node)
        {
            if (node == null || !NodeParameterTypes.ContainsKey(parameterId))
            {
                throw new NodeParameterException(parameterId, node == null ? null : node.ResourceName, node == null ? null : node.DNSName);
            }

            return ((INodeHardwareParameter)NodeParameterTypes[parameterId].GetConstructor(Type.EmptyTypes).Invoke(null)).GetValue(node);
        }
Exemplo n.º 15
0
 public virtual string GetValue(Node node)
 {
     if (node.Parameters.ContainsKey(Key))
     {
         return node.Parameters[Key];
     }
     else
     {
         throw new NodeParameterException(Id, node.ResourceName, node.DNSName);
     }
 }
Exemplo n.º 16
0
        public List<Node> Compute(int startX, int startY, int endX, int endY, Cell[][] matrix, bool improve)
        {
            List<Node> opened = new List<Node> ();
            Priority_Queue.IPriorityQueue<Node> heap2 = new Priority_Queue.HeapPriorityQueue<Node> (600);

            List<Node> closed = new List<Node> ();

            // Initialize our version of the matrix (can we skip this?)
            Node[][] newMatrix = new Node[matrix.Length][];
            for (int x = 0; x < matrix.Length; x++) {
                newMatrix [x] = new Node[matrix [x].Length];
                for (int y = 0; y < matrix[x].Length; y++) {
                    newMatrix [x] [y] = new Node ();
                    newMatrix [x] [y].parent = null;
                    newMatrix [x] [y].cell = matrix [x] [y];
                    newMatrix [x] [y].x = x;
                    newMatrix [x] [y].y = y;
                }
            }

            // Do the work for the first cell before firing the algorithm
            start = newMatrix [startX] [startY];
            end = newMatrix [endX] [endY];

            closed.Add (start);

            foreach (Node c in getAdjacent(start, newMatrix)) {
                c.parent = start;
                if (improve)
                    heap2.Enqueue (c, f (c));
                else
                    opened.Add (c);
            }

            while ((improve && heap2.Count > 0) || (!improve && opened.Count > 0)) {

                // Pick the closest to the goal
                Node minF = null;
                if (improve) {
                    minF = heap2.Dequeue ();
                } else {
                    for (int i = 0; i < opened.Count; i++) {
                        if (minF == null || f (minF) > f (opened [i]))
                            minF = opened [i];
                    }
                    opened.Remove (minF);
                }

                closed.Add (minF);

                // Found it
                if (minF == end)
                    break;

                foreach (Node adj in getAdjacent(minF, newMatrix)) {

                    float soFar = g (minF) + h (adj, minF);

                    // Create the links between cells (picks the best path)
                    if (closed.Contains (adj)) {
                        if (g (adj) > soFar) {
                            adj.parent = minF;
                        }
                    } else {
                        if ((improve && heap2.Contains (adj)) || (!improve && opened.Contains (adj))) {
                            if (g (adj) > soFar) {
                                adj.parent = minF;
                            }
                        } else {
                            adj.parent = minF;
                            if (improve)
                                heap2.Enqueue (adj, f (adj));
                            else
                                opened.Add (adj);
                        }
                    }
                }
            }

            // Creates the result list
            Node n = end;
            List<Node> points = new List<Node> ();
            while (n != null) {
                points.Add (n);
                n = n.parent;
            }
            points.Reverse ();

            // If we didn't find a path
            if (points.Count == 1)
                points.Clear ();
            return points;
        }
Exemplo n.º 17
0
 // Gets all the adjancent cells from the current one
 private List<Node> getAdjacent(Node n, Node[][] matrix)
 {
     List<Node> adj = new List<Node> ();
     for (int xx = n.x - 1; xx <= n.x +1; xx++) {
         for (int yy = n.y - 1; yy <= n.y +1; yy++) {
             if (xx <= n.x + 1 && xx >= 0 && xx < matrix.Length && yy <= n.y + 1 && yy >= 0 && yy < matrix [0].Length) {
                 Node c = matrix [xx] [yy];
                 if (!((Cell)c.cell).blocked) {
                     adj.Add (c);
                 }
             }
         }
     }
     adj.Remove (n);
     return adj;
 }
Exemplo n.º 18
0
        public List<Node> Compute(int startX, int startY, int endX, int endY, Cell[][][] matrix, int time, bool prob)
        {
            try{
            Priority_Queue.IPriorityQueue<Node> heap2 = new Priority_Queue.HeapPriorityQueue<Node>(600);

            // Initialize our version of the matrix (can we skip this?)
            Node[][] newMatrix = new Node[matrix[0].Length][];
            for (int x = 0; x < matrix [0].Length; x++) {
                newMatrix [x] = new Node[matrix [0] [x].Length];
                for (int y = 0; y < matrix [0] [x].Length; y++) {
                    newMatrix [x] [y] = new Node ();
                    newMatrix [x] [y].parent = null;
                    newMatrix [x] [y].cell = matrix [0] [x] [y];
                    newMatrix [x] [y].x = x;
                    newMatrix [x] [y].y = y;
                }
            }
            enemyPathProb(newMatrix);
            // Do the work for the first cell before firing the algorithm
            start = newMatrix [startX] [startY];
            end = newMatrix [endX] [endY];
            start.parent=null;
            start.visited=true;

            foreach (Node n in getAdjacent(start, newMatrix)) {
                n.t=time;
                n.parent = start;
                float fVal = f (n);
                n.Priority = fVal;
                heap2.Enqueue(n,fVal);
            }
            while(heap2.Count != 0){

                Node first = heap2.Dequeue();
                if(first == end)
                    break;
                first.visited=true;
                double temprt = 1;
                List<Node> adjs = getAdjacent(first,newMatrix);

                foreach(Node m in adjs){
                    float currentG = (float)(g (first) + h (first,m, ref temprt));
                    if(m.visited){
                            if(g (m)>currentG){
                                m.parent=first;
                                m.t = first.t+time;
                            }
                        }
                    else{
                        if( !heap2.Contains(m)){
                            m.parent = first;
                            m.t= first.t +time;
                            m.Priority = (float)temprt*f(m);
                            heap2.Enqueue(m, m.Priority);
                        }
                        else
                        {
                            float gVal = g (m);
                            if(gVal>currentG){
                                m.parent= first;
                                m.t = first.t+time;
                                m.Priority= (float)temprt *f (m);
                                heap2.UpdatePriority(m, m.Priority);
                            }
                        }
                    }
                }
            }
                // Creates the result list
                Node l = end;
                List<Node> points = new List<Node> ();
                while (l != null) {
                    points.Add (l);
                    l = l.parent;
                }
                points.Reverse ();

                // If we didn't find a path
                if (points.Count == 1)
                points.Clear ();
                return points;
            }catch(System.Exception e){
                                Debug.Log (e.Message);
                                Debug.Log (e.StackTrace);
                                Debug.Log ("ERROR 2");
                                return null;
                        }
        }
Exemplo n.º 19
0
        private List<Node> getAdjacent(Node n, Node[][][] matrix)
        {
            List<Node> adj = new List<Node> ();
            int time = 0;

            var epsilon = new RealExtensions.Epsilon(1E-30);
            if (speed >= 1.0)
                time = (int) Math.Floor(speed);

            if (n.accSpeed.LE(1.0, epsilon))
                time++;

            if (n.t + time >= matrix.Length)
                return adj;
            for (int xx = n.x - 3; xx <= n.x +3; xx++) {
                for (int yy = n.y - 3; yy <= n.y +3; yy++) {
                    if (xx <= n.x + 3 && xx >= 0 && xx < matrix.Length && yy <= n.y + 3 && yy >= 0 && yy < matrix [0].Length) {
                        Node c = matrix [n.t + time] [xx] [yy];
                        //if (!((Cell)c.cell).blocked) {
                        if (c.cell.safe || !(c.cell.seen || c.cell.blocked)) {
                            adj.Add (c);
                        }
                    }
                }
            }
            //adj.Remove (n);
            return adj;
        }
Exemplo n.º 20
0
 private float h(Node current, Node to)
 {
     return Vector2.Distance (new Vector2 (to.x, to.y), new Vector2 (current.x, current.y));
 }
Exemplo n.º 21
0
 protected double[] GetPerfs(Node node)
 {
     var str = base.GetValue(node);
     return JsonConvert.DeserializeObject<double[]>(str);
 }
Exemplo n.º 22
0
 // current moving cost
 private float g(Node current)
 {
     double tmp = 1.0;
     if (current.parent == null)
         return 0;
     else
         return h (current.parent, current ,ref tmp) + g (current.parent);
 }
Exemplo n.º 23
0
 public override string GetValue(Node node)
 {
     return GetPerfs(node).Length.ToString(CultureInfo.InvariantCulture);
 }
Exemplo n.º 24
0
 public virtual void Handle(DhtEngine engine, Node node)
 {
     node.Seen();
 }
Exemplo n.º 25
0
 public override string GetValue(Node node)
 {
     return (Double.Parse(base.GetValue(node), CultureInfo.InvariantCulture.NumberFormat) / node.CoresTotal).ToString(CultureInfo.InvariantCulture.NumberFormat);
 }
Exemplo n.º 26
0
        private void copy(Node from, Node to)
        {
            to.playerhp = from.playerhp;

            foreach (Enemy e in enemies)
                to.enemyhp.Add (e, from.enemyhp[e]);

            to.fighting.AddRange(from.fighting);

            to.picked.AddRange(from.picked);
        }
Exemplo n.º 27
0
 private void acc(Node n)
 {
     var epsilon = new RealExtensions.Epsilon(1E-30);
     if (speed >= 1.0) {
         n.accSpeed = speed - Math.Abs(speed) + n.parent.accSpeed;
         if (n.parent.accSpeed.LE(1.0, epsilon))
             n.accSpeed -= 1.0;
     } else {
         n.accSpeed = n.parent.accSpeed + speed;
         if (n.parent.accSpeed.LE(1.0, epsilon))
             n.accSpeed -= 1.0;
     }
 }
Exemplo n.º 28
0
        // Returns the computed path by the RRT, and smooth it if that's the case
        private List<Node> ReturnPath(Node endNode, bool smooth)
        {
            Node n = endNode;
            List<Node> points = new List<Node> ();

            while (n != null) {
                points.Add (n);
                n = n.parent;
            }
            points.Reverse ();

            // If we didn't find a path
            if (points.Count == 1)
                points.Clear ();
            else if (smooth) {
                // Smooth out the path
                Node final = null;
                foreach (Node each in points) {
                    final = each;
                    while (Extra.Collision.SmoothNode(final, this, SpaceState.Editor, true)) {
                    }
                }

                points.Clear ();

                while (final != null) {
                    points.Add (final);
                    final = final.parent;
                }
                points.Reverse ();
            }

            return points;
        }
Exemplo n.º 29
0
 private float f(Node current)
 {
     return (g (current) + h (current, end));
 }
Exemplo n.º 30
0
 public CellBSP(float x, float y, float width, float height, int nLeafCells)
 {
     this.nLeafCells = nLeafCells;
     int leafCounter = 0;
     root = new Node(new Vector3(x, y, 0), new Vector3(width, height, 0), true, nLeafCells, ref leafCounter);
 }
Exemplo n.º 31
0
        private float getProb(Node current, ref double temperature)
        {
            return (float)probs[current.x, current.y];
            /*foreach (Enemy en in enemies){
                foreach (Vector2 v2 in en.cells[current.t]){
                    //if( Math.Abs(v2.x - current.x) <1 && Math.Abs(v2.y - current.y) <1){
                    if (v2.x == current.x && v2.y == current.y){
                        //Debug.Log ("collision");
                        temperature = temperature /1.5;
                        return 1000;
                    }

                }
            }
            return 1;*/
        }