Esempio n. 1
0
 /// <summary>
 /// Any client can update their tracked list
 /// </summary>
 public void AddPositionRequest(int id, int connection, Vector3 position)
 {
     if (PositionBatch.ContainsKey(id))
     {
         if (connection <= PositionBatch[id].Priority)
         {
             PositionBatch[id] = new PriorityVector(connection, position);
         }
     }
     else
     {
         PositionBatch[id] = new PriorityVector(connection, position);
     }
 }
Esempio n. 2
0
    public List <Vector2> find_path(Vector2 A, Vector2 B)
    {
        PriorityVector        current  = new PriorityVector(A, 0, null);
        List <PriorityVector> to_open  = new List <PriorityVector>();
        List <Vector2>        to_openV = new List <Vector2>();

        to_open.Add(current);
        List <Vector2> opened = new List <Vector2>();

        while (to_open.Count != 0)
        {
            to_open = to_open.OrderBy(to => to.cost + heuristic(to.grid_pos, B)).ToList();
            current = to_open[0];
            if (current.grid_pos == B)
            {
                break;
            }
            to_open.RemoveAt(0);
            opened.Add(current.grid_pos);
            List <Vector2> neighbours = find_neighbours(current.grid_pos);

            foreach (Vector2 next in neighbours)
            {
                if (!opened.Contains(next) && !to_openV.Contains(next))
                {
                    to_open.Add(new PriorityVector(next, current.cost + 1f, current));
                    to_openV.Add(next);
                }
            }
        }
        List <Vector2> path = new List <Vector2>();

        path.Add(B);
        while (current.came_from != null)
        {
            path.Add(current.came_from.grid_pos);
            current = current.came_from;
        }
        path.Reverse();
        current = null;
        to_open = null;
        opened  = null;
        return(path);
    }
Esempio n. 3
0
 public PriorityVector(Vector2 grid_pos, float cost, PriorityVector came_from)
 {
     this.grid_pos  = grid_pos;
     this.cost      = cost;
     this.came_from = came_from;
 }