path-finding

How do you use a Bidirectional BFS to find the shortest path?

五迷三道 提交于 2019-12-02 19:32:18
How do you use a Bidirectional BFS to find the shortest path? Let's say there is a 6x6 grid. The start point is in (0,5) and the end point is in (4,1). What is the shortest path using bidirectional bfs? There are no path costs. And it is undirected. amit How does Bi-directional BFS work? Simultaneously run two BFS's from both source and target vertices, terminating once a vertex common to both runs is discovered. This vertex will be halfway between the source and the target. Why is it better than BFS? Bi-directional BFS will yield much better results than simple BFS in most cases. Assume the

Efficient Path finding algorithm avoiding zigzag's [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-02 18:09:53
This question already has an answer here: Pathfinding - A* with least turns 2 answers I am developing a software which connects objects with wires. This wiring has a rule that these wires cannot pass on other objects and no diagonal move is accepted. All of the shortest path algorithms that i know (A*, dijkstra etc.) find this type of paths: I do not want the unnecessary zigzags in the second screenshot. How do i achive this goal? Note: Anyone who want to try the algorithms can use this application. Another Note: This is the exact situation that i do not want. It finds the zigzag path instead

Correct formulation of the A* algorithm

寵の児 提交于 2019-12-02 16:50:18
I'm looking at definitions of the A* path-finding algorithm, and it seems to be defined somewhat differently in different places. The difference is in the action performed when going through the successors of a node, and finding that a successor is on the closed list. One approach (suggested by Wikipedia , and this article ) says: if the successor is on the closed list, just ignore it Another approach (suggested here and here , for example) says: if the successor is on the closed list, examine its cost. If it's higher than the currently computed score, remove the item from the closed list for

Pacman: how do the eyes find their way back to the monster hole?

跟風遠走 提交于 2019-12-02 13:48:40
I found a lot of references to the AI of the ghosts in Pacman, but none of them mentioned how the eyes find their way back to the central ghost hole after a ghost is eaten by Pacman. In my implementation I implemented a simple but awful solution. I just hard coded on every corner which direction should be taken. Are there any better/or the best solution? Maybe a generic one that works with different level designs? Kylotan Actually, I'd say your approach is a pretty awesome solution, with almost zero-run time cost compared to any sort of pathfinding. If you need it to generalise to arbitrary

Calculating distance between non directly-connected nodes in matrix

谁都会走 提交于 2019-12-02 04:41:39
I made a adjacency matrix for cities and connecting between them. And for example A-B, B-C, C-D. Now I am wonder if I can calculate distance between cities that aren't connected. Is it possible to calculate distance in matrix between non connected nodes and find path? Cities class import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class GraphCities { private List<String> cities; private int[][] matrix; Scanner s = new Scanner(System.in); public GraphCities() { this.cities = new LinkedList<String>(); } public void addCity(String name) { if (!cities.contains

Find all simple path from node A to node B in direct weighted graph with the sum of weighs less a certain value?

心已入冬 提交于 2019-12-01 14:13:08
I have a directed weighted graph G=(V,E), which may have loops . I am trying to determine the best time efficient algorithm to accomplish task: t o find all simple path in G between source and target node with total weight of edges in this path less than certain value (for convenience we denote this value as PATH_WEIGHT_LIMIT) All weights is positive and can be float. So, a prototype of my function will be: def find_paths(G, source, target, path_weight_limit) Result paths may overlap, its fine. Much like those discussed here, e.g.: algorithm for finding NUMBER of distinct paths from A to B in

Prevent Location Offset With SpriteKit Camera Node

*爱你&永不变心* 提交于 2019-12-01 12:02:09
I have noticed that the centerOnNode: method as shown, - (void)centerOnNode:(SKNode *)node { cameraOffset = [node.scene convertPoint:node.position fromNode:node.parent]; node.parent.position = CGPointMake(node.parent.position.x - cameraOffset.x, node.parent.position.y - cameraOffset.y); } greatly impacts the relative positioning of child nodes. As soon as this method runs, the child nodes do in fact seem to be impacted. The following image show the logic of NO movement then with moving left and slightly down: I drew a light blue box to estimate the physics body that it seems the paths are

Prevent Location Offset With SpriteKit Camera Node

拜拜、爱过 提交于 2019-12-01 11:21:39
问题 I have noticed that the centerOnNode: method as shown, - (void)centerOnNode:(SKNode *)node { cameraOffset = [node.scene convertPoint:node.position fromNode:node.parent]; node.parent.position = CGPointMake(node.parent.position.x - cameraOffset.x, node.parent.position.y - cameraOffset.y); } greatly impacts the relative positioning of child nodes. As soon as this method runs, the child nodes do in fact seem to be impacted. The following image show the logic of NO movement then with moving left

How to obtain the state of grid cells based on a specific location on a 2D array

北城余情 提交于 2019-12-01 01:04:16
Consider a 2D grid with n rows and n columns (here 75x75). The symbols (tokens) are drawn in each cell on mouse click. The code below is used to draw grid lines and symbols within cells: class DrawCanvas extends JPanel{ @Override public void paintComponent(Graphics g){ super.paintComponent(g); setBackground(Color.WHITE); //Lines g.setColor(Color.BLACK); for(int ligne = 1; ligne < ROWS; ++ligne){ g.fillRoundRect(0, cellSize * ligne - halfGridWidth, canvasWidth - 1, gridWidth, gridWidth, gridWidth); } for(int colonne = 1; colonne < COLS; ++colonne){ g.fillRoundRect(cellSize * colonne -

Unable to implement A Star in java

一笑奈何 提交于 2019-11-30 14:49:52
I've been trying all day to get this algorithm up and running, but I cant for the life of me. I've read many tutorials on the net, and source code in AS3, javascript, and C++; but I cannot adapt what I am seeing to my own code. I have created an AStar class that has a nested class named Node. The map is a 2D array named MAP. The biggest problem that I am having is pulling the F value in the pathfind function. I have implemented the F = G + H, my problem is the actual AStar algorithm. Can someone please help, this is how far I've got as of yet: import java.util.ArrayList; public class AStar {