public Pathway(Array<Tile> tiles, Owner owner) { start = new Array<>(); Map map = new Map(tiles.size, owner); pathFinder = new IndexedAStarPathFinder<>(map); heuristic = new EuclidianHeuristic(); graphPath = new DefaultGraphPath<>(); }
public PathFinder(final CachingIndexedGraph<TileCoordinate> graph) { this.graph = graph; pathFinder = new IndexedAStarPathFinder<TileCoordinate>(graph); heuristic = new Heuristic<TileCoordinate>() { @Override public float estimate(final TileCoordinate node, final TileCoordinate endNode) { return Math.abs(endNode.getX() - node.getX()) + Math.abs(endNode.getY() - node.getY()); } }; }
public static void main(String[] args) { // @off - disable libgdx formatter final String graphDrawing = ".....#....\n" + ".....#....\n" + ".....#...."; // @on - enable libgdx formatter final MyGraph graph = createGraphFromTextRepresentation(graphDrawing); final IndexedAStarPathFinder<MyNode> pathfinder = new IndexedAStarPathFinder<MyNode>(graph); final GraphPath<MyNode> outPath = new DefaultGraphPath<MyNode>(); // @off - disable libgdx formatter // 0123456789 // S....#...E 0 // .....#.... 10 // .....#.... 20 // @on - enable libgdx formatter final boolean searchResult = pathfinder.searchNodePath(graph.getNodes().get(0), graph.getNodes().get(20), new ManhattanDistance(), outPath); System.out.println(""+searchResult); System.out.println(""+outPath.getCount()); for(int i=0;i<outPath.getCount();i++){ System.out.println(""+outPath.get(i)); } }
@Override public void create() { mShapeRenderer = new ShapeRenderer(); mGraph = new TestGraph(20); mPath = new DefaultGraphPath<TestNode>(); mHeuristic = new ManhattanDistanceHeuristic(); // Initialize all the nodes that should be present. int index = 0; //Used to set index for every node. for (int x = 0; x < mMap.length; x++) { for (int y = 0; y < mMap[0].length; y++) { if (mMap[x][y] == 1) { mNodes[x][y] = new TestNode(x*TestNode.TILE_SIZE, y*TestNode.TILE_SIZE, index++); mGraph.addNode(mNodes[x][y]); } } } // Add connection to every neighbour of this node. for (int x = 0; x < mNodes.length; x++) { for (int y = 0; y < mNodes[0].length; y++) { if (null != mNodes[x][y]) { addNodeNeighbour(mNodes[x][y], x - 1, y); // Node to left addNodeNeighbour(mNodes[x][y], x + 1, y); // Node to right addNodeNeighbour(mNodes[x][y], x, y - 1); // Node below addNodeNeighbour(mNodes[x][y], x, y + 1); // Node above } } } mPathFinder = new IndexedAStarPathFinder<TestNode>(mGraph, true); calculatePath(); }
public AStartPathFinding(AStarMap map) { this.map = map; this.pathfinder = new IndexedAStarPathFinder<Node>(createGraph(map)); this.connectionPath = new DefaultGraphPath<Connection<Node>>(); this.heuristic = new Heuristic<Node>() { @Override public float estimate (Node node, Node endNode) { // Manhattan distance return Math.abs(endNode.x - node.x) + Math.abs(endNode.y - node.y); } }; }
public NavMesh(Model model) { btTriangleIndexVertexArray vertexArray = new btTriangleIndexVertexArray(model.meshParts); collisionShape = new btBvhTriangleMeshShape(vertexArray, true); raycastCallback = new NavMeshRaycastCallback(navMeshRayFrom, navMeshRayTo); raycastCallback.setFlags(btTriangleRaycastCallback.EFlags.kF_FilterBackfaces); graph = new NavMeshGraph(model); pathFinder = new IndexedAStarPathFinder<Triangle>(graph); heuristic = new NavMeshHeuristic(); }
public resolveRouteJob(IndexedAStarPathFinder<GridNode> finder, GridGraph graph, Entity a, Entity b, Team team) { this.finder = finder; this.graph = graph; this.a = a; this.b = b; this.team = team; }
public CalculatePreferredRoute(Team team, DefaultIndexedGraph<Routable> graph, Entity entityA, Entity entityB) { this.team = team; this.graph = graph; this.entityA = entityA; this.entityB = entityB; finder = new IndexedAStarPathFinder<>(graph); }
public void touchToMove(int screenX, int screenY) { Vector3 input = new Vector3(screenX, screenY, 0); camera.unproject(input); int x = MathUtils.floor(input.x / 32); int y = MathUtils.floor(input.y / 32); Gdx.app.debug(TAG, "clicked # (x:" + x + ",y:" + y + " )"); //we click not npc or block,set aim to move if (!isCollisionWithNpc(x, y) && !isCollisionWithBlock(x, y)) { //A* path finding path.clear(); Vector2 start = new Vector2(MathUtils.round(player.getX() / 32), MathUtils.round(player.getY() / 32)); //we need set exactly start position Vector2 end = new Vector2(x, y); int numCols = mapMgr.cols; int numRows = mapMgr.rows; Gdx.app.debug(TAG, "From:" + start + " to " + end + "|numCols:" + numCols + "|numRows:" + numRows); int s = (int) start.x + ((int) start.y) * numCols; int t = (int) end.x + ((int) (end.y)) * numCols; List<Sprite> temp = new ArrayList<Sprite>(); temp.addAll(mapMgr.npcs); temp.addAll(mapMgr.enemies); // temp.addAll(mapMgr.events); final MyGraph graph = GraphGenerator.generateGraph(mapMgr.getBlockLayer(), temp, numCols, numRows, 32, 32, start); final IndexedAStarPathFinder<MyNode> pathfinder = new IndexedAStarPathFinder<MyNode>(graph); final GraphPath<MyNode> outPath = new DefaultGraphPath<MyNode>(); final boolean searchResult = pathfinder.searchNodePath(graph.getNodes().get(s), graph.getNodes().get(t), new ManhattanDistance(), outPath); MyPathSmoother pathSmoother = new MyPathSmoother(new MyRaycastCollisionDetector(graph)); pathSmoother.smoothPath(outPath); StringBuilder sb = new StringBuilder(); for (int i = outPath.getCount() - 1; i >= 0; i--) { sb.append("(" + outPath.get(i).getX() + "," + outPath.get(i).getY() + ")|"); path.add(outPath.get(i)); } if (searchResult) { Gdx.app.debug(TAG, "Start Follow Path:" + sb.toString()); player.followPath(path); aim = new Aim(x, y); } } else { aim = null; } }
public List<IntPair> getPath(int levelID, IntPair from, IntPair to) { graph = new Graph(128); path = new DefaultGraphPath<Node>(); heuristic = new DistHeuristic(); Level level = Game_AI_TestBed.instance().getLevel(levelID); nodes = new Node[level.getTileSizeX()][level.getTileSizeY()]; int index = 0; for (int x = 0; x < level.getTileSizeX(); x++) { for (int y = 0; y < level.getTileSizeY(); y++) { if (level.isTilePassable(x, y)) { nodes[x][y] = new Node(x*Cst.TILESIZE, y*Cst.TILESIZE, index++); graph.addNode(nodes[x][y]); } } } for (int x = 0; x < nodes.length; x++) { for (int y = 0; y < nodes[0].length; y++) { if (null != nodes[x][y]) { addNodeNeighbour(nodes, nodes[x][y], x - 1, y); addNodeNeighbour(nodes, nodes[x][y], x + 1, y); addNodeNeighbour(nodes, nodes[x][y], x, y - 1); addNodeNeighbour(nodes, nodes[x][y], x, y + 1); } } } pathFinder = new IndexedAStarPathFinder<Node>(graph, true); return calcPath(from, to); }