Tabnine Logo
AStarGraphProvider
Code IndexAdd Tabnine to your IDE (free)

How to use
AStarGraphProvider
in
ch.sahits.game.openpatrician.engine.sea

Best Java code snippets using ch.sahits.game.openpatrician.engine.sea.AStarGraphProvider (Showing top 10 results out of 315)

origin: ch.sahits.game/OpenPatricianEngine

/**
 * Add a new destination Node to the graph.
 * The new point is added to the heuristic as target and to the graph
 * together with edges to its nearest neighbors and they back to the new
 * node.
 * @param newPoint new location to add to the graph
 * @param isCity flag indicating if the new location is a city, which means the coordinates
 *               may not be located in the sea area.
 */
public void addDestinationPoint(Point2D newPoint, boolean isCity) {
  addDestinationPointInternal(newPoint, isCity);
}
@VisibleForTesting
origin: ch.sahits.game/OpenPatricianEngine

@PostConstruct
private void init(){
  clientServerEventBus.register(this);
  try {
    initImage();
  } catch (IOException e) {
    logger.error("Failed to create black and white image from the map", e);
  }
}
@Subscribe
origin: ch.sahits.game/OpenPatricianEngine

for (int y = 0; y < height; y += CHECK_DISTANCE) {
  Point2D p = getPoint(x, y);
  if (isOnSea(p)) {
    if (!graph.containsNode(p)) {
      graph.addNodeInternal(p);
      Point2D p2 = getPoint(x + CHECK_DISTANCE, y);
      addEdges(p, p2, false, false);
      Point2D p2 = getPoint(x, y + CHECK_DISTANCE);
      addEdges(p, p2, false, false);
      Point2D p2 = getPoint(x + CHECK_DISTANCE, y + CHECK_DISTANCE);
      addEdges(p, p2, false, false);
      Point2D p2 = getPoint(x + CHECK_DISTANCE, y - CHECK_DISTANCE);
      addEdges(p, p2, false, false);
      if (p.distance(city.getCoordinates()) < DIAG_CHECK_DISTANCE) {
        Point2D p2 = city.getCoordinates();
        addEdges(p, p2, true, false);
origin: ch.sahits.game/OpenPatricianEngine

private void addEdges(Point2D from, Point2D to, boolean isCity, boolean initial) {
  if (isCity || isOnSea(to)) {
    if (!graph.containsNode(to)) {
      if (initial) {
        graph.addNodeInternal(to);
      } else {
        graph.addNode(to, true);
      }
    }
    heuristicProvider.getHeuristic();
    double weight = calculateWeight(from, to);
    if (initial) {
      graph.addEdgeInternal(from, to, weight);
    } else {
      graph.addEdge(from, to, weight);
    }
    weight = calculateWeight(to, from);
    if (initial) {
      graph.addEdgeInternal(to, from, weight);
    } else {
      graph.addEdge(to, from, weight);
    }
  }
}
origin: ch.sahits.game/OpenPatricianEngine

@Override
protected double calculateWeight(Point2D from, Point2D to) {
  if (from.equals(to)) {
    return 0;
  }
  double distance = from.distance(to);
  try {
    int landPixels = imageService.countLandPixels(to, CHECK_DISTANCE*2, getSegments(from, to));
    int tangentialLandPixels = imageService.countLandPixels(to, (int) Math.round(DIAG_CHECK_DISTANCE), getTangentialSegments(from, to));
    double recastLandPixels =   landPixels/ (9.0 * 3);
    double recastTangentialPixels = tangentialLandPixels / (15.0);
    return distance + recastLandPixels + recastTangentialPixels;
  } catch (IOException e) {
    logger.error("Failed to count the land pixels near "+to, e);
  }
  return distance;
}
origin: ch.sahits.game/OpenPatricianEngine

  private void ensureSetup(Point2D source, Point2D destination) {
    if (!graph.containsNode(source)) {
      boolean isCity = false;
      for (ICity city : map.getCities()) {
        if (source.equals(city.getCoordinates())) {
          isCity = true;
          break;
        }
      }
//            graphProvider.addSourcePoint(source, isCity);
      graphProvider.addDestinationPoint(source, isCity);
    }
    if (!graph.containsNode(destination)) {
      boolean isCity = false;
      for (ICity city : map.getCities()) {
        if (destination.equals(city.getCoordinates())) {
          isCity = true;
          break;
        }
      }
      graphProvider.addDestinationPoint(destination, isCity);
    }
    graphProvider.getGraph();
  }

origin: ch.sahits.game/OpenPatricianDisplay

} else {
  final Point2D destination = new Point2D(unscaledX, unscaledY);
  if (aStarGraphService.isOnSea(destination)) {
    path = seafaringService.travelTo(vessel, destination);
origin: ch.sahits.game/OpenPatricianEngine

@VisibleForTesting
void addSourcePointInternal(Point2D source, boolean isCity) {
  synchronized (lock) {
    if (!heuristic.containsKey(source)) {
      heuristicProvider.addSourceNodeToHeuristic(source);
    }
    if (graph.containsNode(source)) {
      return;
    }
    List<Point2D> nearest = new ArrayList<>();
    for (Point2D node : graph) {
      double distance = node.distance(source);
      if (distance <= DIAG_CHECK_DISTANCE) {
        nearest.add(node);
      }
    }
    graph.addNode(source, false);
    for (Point2D point : nearest) {
      addEdges(source, point, isCity, false);
    }
  }
}
@Override
origin: ch.sahits.game/OpenPatricianEngine

graph = graphProvider.getGraph();
Thread.yield();
origin: ch.sahits.game/OpenPatricianEngine

@VisibleForTesting
void addDestinationPointInternal(Point2D newPoint, boolean isCity) {
  synchronized (lock) {
    if (!heuristic.containsKey(newPoint)) {
      heuristicProvider.addSourceNodeToHeuristic(newPoint); // once reached there we must leave again.
      heuristicProvider.addTargetNodeToHeuristic(newPoint);
      heuristicProvider.getHeuristic();
    }
    Preconditions.checkArgument(heuristic.containsKey(newPoint), "Destination not part of the heuristic: "+newPoint);
    if (graph.containsNode(newPoint)) {
      return;
    }
    List<Point2D> nearest = new ArrayList<>();
    for (Point2D node : graph) {
      double distance = node.distance(newPoint);
      if (distance <= DIAG_CHECK_DISTANCE) {
        nearest.add(node);
      }
    }
    graph.addNode(newPoint, true);
    for (Point2D point : nearest) {
      addEdges(newPoint, point, isCity, false);
    }
  }
}
@VisibleForTesting
ch.sahits.game.openpatrician.engine.seaAStarGraphProvider

Javadoc

Factory class to provide the graph for the AStar path finding calculation

Most used methods

  • isOnSea
  • addDestinationPoint
    Add a new destination Node to the graph. The new point is added to the heuristic as target and to th
  • addDestinationPointInternal
  • addEdges
  • calculateWeight
  • getGraph
  • getPoint
  • getSegments
  • getTangentialSegments
  • initImage

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getContentResolver (Context)
  • getSharedPreferences (Context)
  • findViewById (Activity)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Reference (javax.naming)
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now