Example #1
0
        private static int MakeLazyKey(AStarFindHeuristic heuristic,
                                       int[][] map, int[] limits, int sx, int sy, int ex, int ey,
                                       bool flag)
        {
            int hashCode = 1;
            int w        = map.Length;
            int h        = map[0].Length;

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    hashCode = LSystem.Unite(hashCode, map[i][j]);
                }
            }
            if (limits != null)
            {
                for (int i = 0; i < limits.Length; i++)
                {
                    hashCode = LSystem.Unite(hashCode, limits[i]);
                }
            }
            hashCode = LSystem.Unite(hashCode, heuristic.GetType());
            hashCode = LSystem.Unite(hashCode, sx);
            hashCode = LSystem.Unite(hashCode, sy);
            hashCode = LSystem.Unite(hashCode, ex);
            hashCode = LSystem.Unite(hashCode, ey);
            hashCode = LSystem.Unite(hashCode, flag);
            return(hashCode);
        }
        public List<Vector2f> Search(AStarFindHeuristic heuristic,
				int startX, int startY, int endX, int endY, bool flying,
				bool flag)
        {
            return new AStarFinder(heuristic, field, startX, startY, endX, endY,
                    flying, flag).FindPath();
        }
Example #3
0
 private static int MakeLazyKey(AStarFindHeuristic heuristic,
         int[][] map, int[] limits, int sx, int sy, int ex, int ey,
         bool flag)
 {
     int hashCode = 1;
     int w = map.Length;
     int h = map[0].Length;
     for (int i = 0; i < w; i++)
     {
         for (int j = 0; j < h; j++)
         {
             hashCode = LSystem.Unite(hashCode, map[i][j]);
         }
     }
     if (limits != null)
     {
         for (int i = 0; i < limits.Length; i++)
         {
             hashCode = LSystem.Unite(hashCode, limits[i]);
         }
     }
     hashCode = LSystem.Unite(hashCode, heuristic.GetType());
     hashCode = LSystem.Unite(hashCode, sx);
     hashCode = LSystem.Unite(hashCode, sy);
     hashCode = LSystem.Unite(hashCode, ex);
     hashCode = LSystem.Unite(hashCode, ey);
     hashCode = LSystem.Unite(hashCode, flag);
     return hashCode;
 }
Example #4
0
 public List <Vector2f> Search(AStarFindHeuristic heuristic,
                               int startX, int startY, int endX, int endY, bool flying,
                               bool flag)
 {
     return(new AStarFinder(heuristic, field, startX, startY, endX, endY,
                            flying, flag).FindPath());
 }
Example #5
0
 public void Update(AStarFinder Find)
 {
     this.field         = Find.field;
     this.startX        = Find.startX;
     this.startY        = Find.startY;
     this.endX          = Find.endX;
     this.endY          = Find.endY;
     this.flying        = Find.flying;
     this.flag          = Find.flag;
     this.findHeuristic = Find.findHeuristic;
 }
Example #6
0
		public void Search(AStarFindHeuristic heuristic, int startx, int starty,
				int endx, int endy, bool flying, bool flag,
				AStarFinderListener callback) {
			AStarFinder pathfinderTask = new AStarFinder(heuristic, field, startx,
					starty, endx, endy, flying, flag, callback);
			AStarFinder existing = pathQueue.Contains(pathfinderTask);
			if (existing != null) {
				existing.Update(pathfinderTask);
			} else {
				pathQueue.Add(pathfinderTask);
			}
			pathfinderThread.Interrupt();
		}
Example #7
0
 public AStarFinder(AStarFindHeuristic heuristic, Field2D field_0, int startX_1,
                    int startY_2, int endX_3, int endY_4, bool flying_5, bool flag_6,
                    AStarFinderListener callback)
 {
     this.field             = field_0;
     this.startX            = startX_1;
     this.startY            = startY_2;
     this.endX              = endX_3;
     this.endY              = endY_4;
     this.flying            = flying_5;
     this.flag              = flag_6;
     this.pathFoundListener = callback;
     this.findHeuristic     = heuristic;
 }
Example #8
0
        public void Search(AStarFindHeuristic heuristic, int startx, int starty,
                           int endx, int endy, bool flying, bool flag,
                           AStarFinderListener callback)
        {
            AStarFinder pathfinderTask = new AStarFinder(heuristic, field, startx,
                                                         starty, endx, endy, flying, flag, callback);
            AStarFinder existing = pathQueue.Contains(pathfinderTask);

            if (existing != null)
            {
                existing.Update(pathfinderTask);
            }
            else
            {
                pathQueue.Add(pathfinderTask);
            }
            pathfinderThread.Interrupt();
        }
Example #9
0
 public static List <Vector2f> Find(AStarFindHeuristic heuristic,
                                    int[][] maps, int[] limits, int x1, int y1, int x2, int y2,
                                    bool flag)
 {
     heuristic = ((heuristic == null) ? ASTAR_MANHATTAN : heuristic);
     lock (finderLazy)
     {
         if (finderLazy.Count >= LSystem.DEFAULT_MAX_CACHE_SIZE * 10)
         {
             finderLazy.Clear();
         }
         int             key    = MakeLazyKey(heuristic, maps, limits, x1, y1, x2, y2, flag);
         List <Vector2f> result = (List <Vector2f>)CollectionUtils.Get(finderLazy, key);
         if (result == null)
         {
             AStarFinder astar    = new AStarFinder(heuristic);
             Field2D     fieldMap = new Field2D(maps);
             if (limits != null)
             {
                 fieldMap.SetLimit(limits);
             }
             Vector2f start = new Vector2f(x1, y1);
             Vector2f over  = new Vector2f(x2, y2);
             result = astar.Calc(fieldMap, start, over, flag);
             CollectionUtils.Put(finderLazy, key, result);
             astar.Dispose();
         }
         if (result != null)
         {
             List <Vector2f> newResult = new List <Vector2f>();
             CollectionUtils.AddAll(newResult, result);
             result = newResult;
         }
         return(result);
     }
 }
Example #10
0
 public static List<Vector2f> Find(AStarFindHeuristic heuristic,
         int[][] maps, int[] limits, int x1, int y1, int x2, int y2,
         bool flag)
 {
     heuristic = ((heuristic == null) ? ASTAR_MANHATTAN : heuristic);
     lock (finderLazy)
     {
         if (finderLazy.Count >= LSystem.DEFAULT_MAX_CACHE_SIZE * 10)
         {
             finderLazy.Clear();
         }
         int key = MakeLazyKey(heuristic, maps, limits, x1, y1, x2, y2, flag);
         List<Vector2f> result = (List<Vector2f>)CollectionUtils.Get(finderLazy, key);
         if (result == null)
         {
             AStarFinder astar = new AStarFinder(heuristic);
             Field2D fieldMap = new Field2D(maps);
             if (limits != null)
             {
                 fieldMap.SetLimit(limits);
             }
             Vector2f start = new Vector2f(x1, y1);
             Vector2f over = new Vector2f(x2, y2);
             result = astar.Calc(fieldMap, start, over, flag);
             CollectionUtils.Put(finderLazy, key, result);
             astar.Dispose();
         }
         if (result != null)
         {
             List<Vector2f> newResult = new List<Vector2f>();
             CollectionUtils.AddAll(newResult, result);
             result = newResult;
         }
         return result;
     }
 }
Example #11
0
 public AStarFinder(AStarFindHeuristic heuristic, bool flying_0)
 {
     this.flying        = flying_0;
     this.findHeuristic = heuristic;
 }
Example #12
0
 public AStarFinder(AStarFindHeuristic heuristic)
     : this(heuristic, false)
 {
 }
Example #13
0
 public static List <Vector2f> Find(AStarFindHeuristic heuristic,
                                    int[][] maps, Vector2f start, Vector2f goal, bool flag)
 {
     return(Find(heuristic, maps, start.X(), start.Y(), goal.X(), goal.Y(),
                 flag));
 }
Example #14
0
 public static List <Vector2f> Find(AStarFindHeuristic heuristic,
                                    Field2D maps, Vector2f start, Vector2f goal, bool flag)
 {
     return(Find(heuristic, maps.GetMap(), maps.GetLimit(), start.X(),
                 start.Y(), goal.X(), goal.Y(), flag));
 }
Example #15
0
 public static List <Vector2f> Find(AStarFindHeuristic heuristic,
                                    Field2D maps, int x1, int y1, int x2, int y2, bool flag)
 {
     return(Find(heuristic, maps.GetMap(), maps.GetLimit(), x1, y1, x2, y2,
                 flag));
 }
Example #16
0
 public static List <Vector2f> Find(AStarFindHeuristic heuristic,
                                    int[][] maps, int x1, int y1, int x2, int y2, bool flag)
 {
     return(Find(heuristic, maps, x1, y1, x2, y2, flag));
 }
Example #17
0
 public static List<Vector2f> Find(AStarFindHeuristic heuristic,
         int[][] maps, Vector2f start, Vector2f goal, bool flag)
 {
     return Find(heuristic, maps, start.X(), start.Y(), goal.X(), goal.Y(),
             flag);
 }
Example #18
0
 public static List<Vector2f> Find(AStarFindHeuristic heuristic,
         int[][] maps, int x1, int y1, int x2, int y2, bool flag)
 {
     return Find(heuristic, maps, x1, y1, x2, y2, flag);
 }
Example #19
0
 public void Search(AStarFindHeuristic heuristic, int startx, int starty,
                    int endx, int endy, bool flying, AStarFinderListener callback)
 {
     Search(heuristic, startx, starty, endx, endy, flying, false, callback);
 }
Example #20
0
 public static List<Vector2f> Find(AStarFindHeuristic heuristic,
         Field2D maps, int x1, int y1, int x2, int y2, bool flag)
 {
     return Find(heuristic, maps.GetMap(), maps.GetLimit(), x1, y1, x2, y2,
             flag);
 }
Example #21
0
 public AStarFinder(AStarFindHeuristic heuristic, Field2D field_0, int startX_1,
         int startY_2, int endX_3, int endY_4, bool flying_5, bool flag_6,
         AStarFinderListener callback)
 {
     this.field = field_0;
     this.startX = startX_1;
     this.startY = startY_2;
     this.endX = endX_3;
     this.endY = endY_4;
     this.flying = flying_5;
     this.flag = flag_6;
     this.pathFoundListener = callback;
     this.findHeuristic = heuristic;
 }
Example #22
0
 public AStarFinder(AStarFindHeuristic heuristic, bool flying_0)
 {
     this.flying = flying_0;
     this.findHeuristic = heuristic;
 }
Example #23
0
        public AStarFinder(AStarFindHeuristic heuristic)
            : this(heuristic, false)
        {

        }
Example #24
0
		public void Search(AStarFindHeuristic heuristic, int startx, int starty,
				int endx, int endy, bool flying, AStarFinderListener callback) {
			Search(heuristic, startx, starty, endx, endy, flying, false, callback);
		}
Example #25
0
 public AStarFinder(AStarFindHeuristic heuristic, Field2D field_0, int startX_1,
                    int startY_2, int endX_3, int endY_4, bool flying_5, bool flag_6)
     : this(heuristic, field_0, startX_1, startY_2, endX_3, endY_4, flying_5, flag_6, null)
 {
 }
Example #26
0
 public static List<Vector2f> Find(AStarFindHeuristic heuristic,
         Field2D maps, Vector2f start, Vector2f goal, bool flag)
 {
     return Find(heuristic, maps.GetMap(), maps.GetLimit(), start.X(),
             start.Y(), goal.X(), goal.Y(), flag);
 }
Example #27
0
        public AStarFinder(AStarFindHeuristic heuristic, Field2D field_0, int startX_1,
                int startY_2, int endX_3, int endY_4, bool flying_5, bool flag_6)
            : this(heuristic, field_0, startX_1, startY_2, endX_3, endY_4, flying_5, flag_6, null)
        {

        }
Example #28
0
 public void SetHeuristic(AStarFindHeuristic h)
 {
     this.heuristic = h;
 }
Example #29
0
 public void setHeuristic(AStarFindHeuristic heuristic)
 {
     this.heuristic = heuristic;
 }
Example #30
0
 public void Update(AStarFinder Find)
 {
     this.field = Find.field;
     this.startX = Find.startX;
     this.startY = Find.startY;
     this.endX = Find.endX;
     this.endY = Find.endY;
     this.flying = Find.flying;
     this.flag = Find.flag;
     this.findHeuristic = Find.findHeuristic;
 }