コード例 #1
0
 public void testAddToPoint() {
   MapPoint point = new MapPoint(2637887.25, 6815777.50);
   Vector vector = new Vector(600, 800).setLength(1);
   MapPoint newPoint = vector.clone().multiply(0.1).addToPoint(point);
   assertEquals(2637887.31, newPoint.getX(), 0.001);
   assertEquals(6815777.58, newPoint.getY(), 0.001);
 }
コード例 #2
0
 @Test
 public void shouldUpdateDroneLocation() {
   Tracker tracker = new SimpleTrackerFactory().create("drone1", "my tracker");
   trackerData.register((Observer) tracker);
   Assert.assertEquals(1, trackerData.getTrackers().size());
   MapPoint oldPosition = tracker.getCurrentPosition();
   tracker.calculate();
   MapPoint newPosition = tracker.getCurrentPosition();
   System.out.println("........." + oldPosition.getLongitude());
   System.out.println("........." + newPosition.getLatitude());
   Assert.assertNotSame(newPosition, oldPosition);
   Assert.assertSame(oldPosition, tracker.getPositions().get(0));
 }
コード例 #3
0
 private static Iterable<MapPoint> getNeighbors(MapPoint point, BoxType dest, int keyCount) {
   Collection<MapPoint> neighbors = new HashSet<>(4);
   for (MapPoint neighbor : point.getNeighbors()) {
     BoxType type = neighbor.getType();
     if ((type == dest)
         || (type == BoxType.Open)
         || (type == BoxType.Door && keyCount > 0)
         || (type == BoxType.Key)) {
       neighbors.add(neighbor);
     }
   }
   return neighbors;
 }
コード例 #4
0
ファイル: MapItemPoint.java プロジェクト: Agetac/SITAC
 @Override
 public void render(Graphics2D g, JXMapViewer map) {
   if (isSelected()) g.setColor(selectedColor);
   else g.setColor(color);
   g.setFont(new Font("font", Font.BOLD, 12));
   Point2D p = map.getTileFactory().geoToPixel(pos.getPoint(), map.getZoom());
   g.translate(
       (int) p.getX() - shapes[0].getBounds().width / 2,
       (int) p.getY() - shapes[0].getBounds().height / 2);
   for (int i = 0; i < shapes.length; i++) {
     g.draw(shapes[i]);
     if (desc == null) g.fill(shapes[i]);
   }
   if (desc != null) g.drawString(desc, 5, 20);
   g.translate(
       -(int) p.getX() + shapes[0].getBounds().width / 2,
       -(int) p.getY() + shapes[0].getBounds().height / 2);
 }
コード例 #5
0
  /**
   * Searches for a {@code BoxType} from the given start point. The search algorithm used is a
   * Breath-first search (BFS) modified to use a past path-cost function g(x) to determine the next
   * point to evaluate.
   *
   * @param start the starting point
   * @param dest the {@code BoxType} to search for
   * @param hasKey
   * @return the set of solution MapPaths
   * @see <a href="http://en.wikipedia.org/wiki/Breadth-first_search">Breadth-first search -
   *     Wikipedia</a>
   */
  public static Set<MapPath> search(MapPoint start, BoxType dest, int keyCount) {
    PlayerMapDebugger debugger = SchoolPlayer.getLatestDebugger();

    Set<MapPoint> closed = new HashSet<>();
    Map<MapPath, MapPath> open = new HashMap<>();
    Map<MapPath, Integer> gScores = new HashMap<>();

    MapPath base = new MapPath(start);
    open.put(base, base);
    gScores.put(base, 0);

    Set<MapPath> found = new HashSet<>();
    Integer foundG = null;
    while (!open.isEmpty()) {
      Entry<MapPath, Integer> curEntry = getShortestPath(gScores);
      MapPath cur = curEntry.getKey();
      MapPoint curPoint = cur.getLastPoint();

      debugger.markPoint(curPoint, Color.MAGENTA);
      debugger.markPath(cur, Color.DARK_GRAY);
      debugger.waitForMarks(PATH_SEARCH_DELAY);

      if (curPoint.getType() == dest) {
        if (foundG == null || curEntry.getValue().compareTo(foundG) <= 0) {
          debugger.markPoint(curPoint, Color.GREEN);
          debugger.markPath(cur, Color.GREEN);
          debugger.waitForMarks(FOUND_DEST_MARK_DELAY);

          found.add(cur);
          foundG = curEntry.getValue();
        }
      }

      open.remove(cur);
      gScores.remove(cur);
      closed.add(curPoint);

      if (found.isEmpty()) {
        for (MapPoint neighbor : getNeighbors(curPoint, dest, keyCount)) {
          if (paused) {
            while (paused) {
              debugger.sleep(200);
            }
          }

          if (closed.contains(neighbor)) {
            continue;
          }

          MapPath subPath = cur.subPath(neighbor);

          MapPath samePath = open.get(subPath);
          int gScore = curEntry.getValue() + distanceTo(neighbor);
          if (samePath == null) {
            open.put(subPath, subPath);
            gScores.put(subPath, gScore);

            debugger.markPoint(neighbor, Color.PINK);
            debugger.waitForMarks(NEIGHBOR_SEARCH_DELAY);
          } else {
            if (subPath.getTurnCount() < samePath.getTurnCount()
                && gScore <= gScores.get(samePath)) {
              // samePath.equals(subPath)
              // so, need to explicitly remove samePath/subPath to re-map value
              open.remove(samePath);
              gScores.remove(samePath);
              open.put(subPath, subPath);
              gScores.put(subPath, gScore);

              debugger.markPoint(neighbor, Color.PINK);
              debugger.waitForMarks(NEIGHBOR_SEARCH_DELAY);
            }
          }
        }
      }

      if (curPoint.getType() != dest) {
        debugger.unmarkPath(cur);
        debugger.markPoint(curPoint, Color.LIGHT_GRAY);
      }
    }

    debugger.unmarkAllPoints();
    debugger.unmarkAllPaths();
    return found;
  }
コード例 #6
0
 private static int distanceTo(MapPoint point) {
   if (point.getType() == BoxType.Door) return 2;
   else return 1;
 }
コード例 #7
0
ファイル: MapItemPoint.java プロジェクト: Agetac/SITAC
 public boolean findItem(JXMapKit map, Point2D pt) {
   GeoPosition gp = pos.getPoint();
   Point2D pt1 = map.getMainMap().getTileFactory().geoToPixel(gp, map.getMainMap().getZoom());
   return pt1.distance(pt) < 20;
 }
コード例 #8
0
ファイル: MapItemPoint.java プロジェクト: Agetac/SITAC
 public List<MapPoint> getPoints() {
   List<MapPoint> p = new ArrayList<MapPoint>();
   p.add(new MapPoint(pos.getPoint()));
   return p;
 }
コード例 #9
0
ファイル: MapItemPoint.java プロジェクト: Agetac/SITAC
 public GeoPosition getPosition() {
   return pos.getPoint();
 }