Exemple #1
0
 private LinkedList<Vector2f> astar(Field2D field, boolean flag) {
   for (; pathes.size() > 0; ) {
     ScoredPath spath = pathes.remove(0);
     Vector2f current = spath.path.get(spath.path.size() - 1);
     if (current.equals(goal)) {
       return spath.path;
     }
     ArrayList<Vector2f> list = field.neighbors(current, flag);
     int size = list.size();
     for (int i = 0; i < size; i++) {
       Vector2f next = list.get(i);
       if (visitedCache.contains(next)) {
         continue;
       }
       visitedCache.add(next);
       if (!field.isHit(next) && !flying) {
         continue;
       }
       LinkedList<Vector2f> path = new LinkedList<Vector2f>(spath.path);
       path.add(next);
       int score = spath.score + field.score(goal, next);
       insert(score, path);
     }
   }
   return null;
 }
Exemple #2
0
 public void convert(Field2D field, int in, int out) {
   for (int xp = 0; xp < this.width; xp++) {
     for (int yp = 0; yp < this.height; yp++) {
       if (field.getType(this.x + xp, this.y + yp) == in) {
         field.setType(this.x + xp, this.y + yp, out);
       }
     }
   }
 }
Exemple #3
0
 public static LinkedList<Vector2f> find(
     int[][] maps, Vector2f start, Vector2f goal, boolean flag) {
   if (astar == null) {
     astar = new AStarFinder();
   }
   if (fieldMap == null) {
     fieldMap = new Field2D(maps);
   } else {
     fieldMap.setMap(maps);
   }
   return astar.calc(fieldMap, start, goal, flag);
 }