Exemplo n.º 1
0
 private List <Vector2f> Astar(Field2D field_0, bool flag_1)
 {
     for (; pathes.Count > 0;)
     {
         AStarFinder.ScoredPath spath_2 = (AStarFinder.ScoredPath)CollectionUtils.RemoveAt(pathes, 0);
         Vector2f current = spath_2.path[spath_2.path.Count - 1];
         if (current.Equals(goal))
         {
             return(spath_2.path);
         }
         List <Vector2f> list = field_0.Neighbors(current, flag_1);
         int             size = list.Count;
         for (int i = 0; i < size; i++)
         {
             Vector2f next = list[i];
             if (CollectionUtils.Contains(next, visitedCache))
             {
                 continue;
             }
             CollectionUtils.Add(visitedCache, next);
             if (!field_0.IsHit(next) && !flying)
             {
                 continue;
             }
             List <Vector2f> path_3 = new List <Vector2f>(spath_2.path);
             CollectionUtils.Add(path_3, next);
             float score = spath_2.score
                           + findHeuristic
                           .GetScore(goal.x, goal.y, next.x, next.y);
             Insert(score, path_3);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        private void Insert(float score, List <Vector2f> path_0)
        {
            int size = pathes.Count;

            for (int i = 0; i < size; i += 1)
            {
                AStarFinder.ScoredPath spath_1 = pathes[i];
                if (spath_1.score >= score)
                {
                    pathes.Insert(i, new AStarFinder.ScoredPath(score, path_0));
                    return;
                }
            }
            CollectionUtils.Add(pathes, new AStarFinder.ScoredPath(score, path_0));
        }
Exemplo n.º 3
0
 private List <Vector2f> Calc(Field2D field_0, Vector2f start,
                              Vector2f goal_1, bool flag_2)
 {
     if (start.Equals(goal_1))
     {
         List <Vector2f> v = new List <Vector2f>();
         CollectionUtils.Add(v, start);
         return(v);
     }
     this.goal = goal_1;
     if (visitedCache == null)
     {
         visitedCache = new HashedSet();
     }
     else
     {
         CollectionUtils.Clear(visitedCache);
     }
     if (pathes == null)
     {
         pathes = new List <ScoredPath>();
     }
     else
     {
         CollectionUtils.Clear(pathes);
     }
     CollectionUtils.Add(visitedCache, start);
     if (path == null)
     {
         path = new List <Vector2f>();
     }
     else
     {
         CollectionUtils.Clear(path);
     }
     CollectionUtils.Add(path, start);
     if (spath == null)
     {
         spath = new AStarFinder.ScoredPath(0, path);
     }
     else
     {
         spath.score = 0;
         spath.path  = path;
     }
     CollectionUtils.Add(pathes, spath);
     return(Astar(field_0, flag_2));
 }
Exemplo n.º 4
0
 private List <Vector2f> Calc(Field2D field, Vector2f start,
                              Vector2f goal, bool flag)
 {
     if (start.Equals(goal))
     {
         List <Vector2f> v = new List <Vector2f>();
         v.Add(start);
         return(v);
     }
     this.goal = goal;
     if (visitedCache == null)
     {
         visitedCache = new HashedSet();
     }
     else
     {
         visitedCache.Clear();
     }
     if (pathes == null)
     {
         pathes = new List <ScoredPath>();
     }
     else
     {
         pathes.Clear();
     }
     visitedCache.Add(start);
     if (path == null)
     {
         path = new List <Vector2f>();
     }
     else
     {
         path.Clear();
     }
     path.Add(start);
     if (spath == null)
     {
         spath = new ScoredPath(0, path);
     }
     else
     {
         spath.score = 0;
         spath.path  = path;
     }
     pathes.Add(spath);
     return(Astar(field, flag));
 }
Exemplo n.º 5
0
 public virtual void Dispose()
 {
     if (path == null)
     {
         CollectionUtils.Clear(path);
         path = null;
     }
     if (pathes != null)
     {
         CollectionUtils.Clear(pathes);
         pathes = null;
     }
     if (visitedCache != null)
     {
         CollectionUtils.Clear(visitedCache);
         visitedCache = null;
     }
     spath = null;
     goal  = null;
 }
Exemplo n.º 6
0
 public virtual void Dispose()
 {
     if (path == null)
     {
         CollectionUtils.Clear(path);
         path = null;
     }
     if (pathes != null)
     {
         CollectionUtils.Clear(pathes);
         pathes = null;
     }
     if (visitedCache != null)
     {
         CollectionUtils.Clear(visitedCache);
         visitedCache = null;
     }
     spath = null;
     goal = null;
 }
Exemplo n.º 7
0
 private List<Vector2f> Calc(Field2D field_0, Vector2f start,
         Vector2f goal_1, bool flag_2)
 {
     if (start.Equals(goal_1))
     {
         List<Vector2f> v = new List<Vector2f>();
         CollectionUtils.Add(v, start);
         return v;
     }
     this.goal = goal_1;
     if (visitedCache == null)
     {
         visitedCache = new HashedSet();
     }
     else
     {
         CollectionUtils.Clear(visitedCache);
     }
     if (pathes == null)
     {
         pathes = new List<ScoredPath>();
     }
     else
     {
         CollectionUtils.Clear(pathes);
     }
     CollectionUtils.Add(visitedCache, start);
     if (path == null)
     {
         path = new List<Vector2f>();
     }
     else
     {
         CollectionUtils.Clear(path);
     }
     CollectionUtils.Add(path, start);
     if (spath == null)
     {
         spath = new AStarFinder.ScoredPath(0, path);
     }
     else
     {
         spath.score = 0;
         spath.path = path;
     }
     CollectionUtils.Add(pathes, spath);
     return Astar(field_0, flag_2);
 }
Exemplo n.º 8
0
 private List<Vector2f> Calc(Field2D field, Vector2f start,
         Vector2f goal, bool flag)
 {
     if (start.Equals(goal))
     {
         List<Vector2f> v = new List<Vector2f>();
         v.Add(start);
         return v;
     }
     this.goal = goal;
     if (visitedCache == null)
     {
         visitedCache = new HashedSet();
     }
     else
     {
         visitedCache.Clear();
     }
     if (pathes == null)
     {
         pathes = new List<ScoredPath>();
     }
     else
     {
         pathes.Clear();
     }
     visitedCache.Add(start);
     if (path == null)
     {
         path = new List<Vector2f>();
     }
     else
     {
         path.Clear();
     }
     path.Add(start);
     if (spath == null)
     {
         spath = new ScoredPath(0, path);
     }
     else
     {
         spath.score = 0;
         spath.path = path;
     }
     pathes.Add(spath);
     return Astar(field, flag);
 }