java,recursion,stack-overflow,path-finding

It's hard to say with the given code, but three things come to mind: Did you make sure to add C and all the other data? Are those extra spaces around " C" and "# " supposed to be there? Why did you convert [] to + and then to...

unity3d,unityscript,path-finding

The Update method run the code every frame, so if you have movement operations put your code in the update method. I have never heard about a NavMeshAgent. #1: The easiest way is to add an rigidbody object to your GameObject and use the method MovePosition(). #2: The second way...

graph,artificial-intelligence,path-finding

I hadn't explored the fringe search algorithm until seeing this post, so take this with a grain of salt. According to Wikipedia, Fringe Search is based off IDA*, which in turn is based off A*. pros/cons of IDA* over A*: IDA* was designed to decrease memory use at the cost...

I agree with Calumn: DFS is the simplest approach here. Here is a simple solution in python-like pseudocode. It will print the solution as a sequence of 'L','R',U','D' to indicate left,right,up, or down. def flood(x,y,story): if (visited[x][y] or map[x][y]=='0'): return; visited[x][y]=True; if (map[x][y]=='3'): print 'done. The path is: '+story return...

unity3d,artificial-intelligence,unityscript,path-finding

Here is a very basic snippet that I have used in enemy movement which I placed into the Update() function of a movement script (Mind the C#): Vector3 direction = Vector3.Normalize(transform.position - destination.position); transform.position = Vector3.MoveTowards(transform.position, destination.position, moveSpeed * Time.deltaTime); I hope it can help in getting your enemies to...

c++,pointers,vector,heap,path-finding

The second form of std::push_heap takes custom comparator as the third parameter, so you can give it the < overload: struct SPtrNodeLess { bool operator()(const std::shared_ptr<Node> &first, const std::shared_ptr<Node> &second) const { return *first < *second; } } std::push_heap(h.begin(), h.end(), SPtrNodeLess()) The std::find_if takes the unary predicate in similar fashion:...

algorithm,shortest-path,path-finding

Yes, your algorithm works but you can optimize it for the case when [number of food packets] << [number of squares in the grid]. eg. In the above graph. distances = new int[ROWS][COLS]; for each food-packet on the grid use a shortest path algorithm to find the distance to/from each...

c#,unity3d,artificial-intelligence,path-finding,a-star

I ended up using the C# Dictionary Data Structure in the end, and it's worked well, if anyone is interested.

java,algorithm,path,path-finding,a-star

Ok, so I've gone through your code and with the help of other's comments here I've managed to get it to work. I'm only posting the changed methods: Grid.getLowestFCostNodePos doesn't keep track of the X and Y values of the node with the lowest F: public int[] getLowestFCostNodePos(List<List<Integer>> openList, int...

Lets say there are at average 2.5 directions to choose from, then your algorithm will take 2.5^n steps to complete, where n is the number of squares. That will be an incredible large number, even for fairly small n. You need to look into Djikstra's algorithm This is assuming you...

java,android,multidimensional-array,adt,path-finding

wouldn't it be simpler to keep a list of all the rooms? – njzk2 Apr 30 at 16:10 Well, I followed this suggestion (made an ArrayList of a custom Pair class, and stored expected input-output in there), and this problem with the project, at least, is solved. I've still no...

r,algorithm,path-finding,a-star

There is e1071 and igraph. Not sure if they do A*, but they seem to have other shortest past algorithms.

The Answer is to use the A* (A Star) Algorithm

c#,path-finding,stack-overflow

A* does not have a recursive step. You should be pulling work items out of a priority queue. Your code is tail recursive. There is no need for recursion here. Just wrap the entire method in a while (true) loop: private void aStar(int x, int y) { while (true) {...

java,algorithm,code-review,graph-algorithm,path-finding

First of all, you are mostly on track. I strongly suspect the code you posted is still under development and has some problems. But, still your assumption of distance is positive is not correct in general. A* is a graph search algorithm and edges can have negative weights as well...

c#,xna,artificial-intelligence,path-finding

Not realy Q&A question, but hey... First of all, start with reorganizating your game to components (ist realy big topic to discuss here) Second, you can find distance with simple Pythagorean theorem, something like var x = WhiteBallRectangle.X - BlackBallRectangle.X; var y = WhiteBallRectangle.Y - BlackBallRectangle.Y; var distance = (decimal)Math.Sqrt((Math.Pow(x,...

java,algorithm,shortest-path,path-finding,a-star

Given your graph G=(V,E) where each v in V stands for a cell, and each edge (u,v) is possible move, you can create a new (weighted) graph G'=(V',E') as follows: V' = V_u U V_d U V_l U V_r - each group stands for the type of move you have...

algorithm,actionscript-3,flash,path-finding,a-star

I see a few potential things wrong. You are potentially overwriting values here: n.g = currentNode.g + cost; n.f=calculateCostOfNode(n); n.parentNode =currentNode; openNodes.push(n); It should be: if n.g > currentNode.g + cost: n.g = currentNode.g + cost; n.f=calculateCostOfNode(n); n.parentNode =currentNode; if n not already in openNodes: openNodes.push(n); With n.g initiated to...

The function would return a different result depending on which 1 you turn to 0 so "as far as possible" is relative to that. Just make it so that if the path is empty you fill it this way: currentX = startX; currentY = startY; path = []; while(grid[currentY][currentX] !=...

Directed graph data structures and algorithms are not included in the core .NET framework. You could use one of the community contributions, the best one is probably QuickGraph.

mysql,database,performance,algorithm,path-finding

Thanks to zebediah49, I have implemented the following algorithm: 0. Lookup tables First, I have created an ID on the trips table, that uniquely identifies it. It is based on the list of stops taken in sequence. So this ID guarantees that two trips with the same ID will take...

algorithm,shortest-path,path-finding

If I understood the problem correctly, you want to step on every block once and also step on all the blocks. So if you think of this as a graph, with every block being represented by a vertex (and every pair of adjacent blocks -horizontally, vertically or diagonally- consists and...

c++,path-finding,a-star,angelscript

for(int i = 0; i < openSet.length(); i++) { if(fScore[neighborTile.x][neighborTile.y] < lowestScore || i == 0) { lowestScore = fScore[neighborTile.x][neighborTile.y]; nextTile.x = neighborTile.x; nextTile.y = neighborTile.y; } } This loop just looks at neighborTile over and over. Did you mean to go over the elements of openSet?...

grid,2d,artificial-intelligence,path-finding,a-star

Do you mean they'd move diagonally on the grid? All you'd have to do is open up the node expanding code to also expand (+1, +1), (-1, -1), (+1, -1) and (-1, +1), turning it into orthogonal instead of cardinal. If your A* algorithm is correct, they will favour a...

c#,unity3d,path-finding,a-star

It looks like there could be some sort of circular logic where you're adding nodes to a list? Have you tried checking whether or not the list contains a node before you add it? while (node != null) { if (!list.Contains(node)) { list.Add(node); node = node.parent; } else { break;...

c++,algorithm,box2d,sfml,path-finding

You need to check whether the edge of the container1 is connected to container2 at any point of time if so then adjust the water level. I guess you are working on a image so you can use the connected components algorithm to check if any of the edge pixels...

As I can see it, you can split your problem into two parts: Get shortest reliable path - that can be done by removing all blue edges from the graph, and run any shortest path algorithm (such as Dijkstra's Algorithm). Get k shortest unreliable paths - this is the K...

c#,unity3d,path-finding,coroutine

You could eventually use threads as usual in C#. The point is that is not a convenient solution because you need to keep synchronized your thread with the engine loop. This might not be trivial. My understanding of coroutines is that they are better to use for sequential functions, not...

The number of diagonal moves you can make is limited to the number of either rows or columns you have to traverse to get to your destination. All other moves can be left/right or up/down and will preserve the shortest distance. That said, and assuming you know the row and...

Yes, it is possible. Transform your cells into a graph by modelling cells as nodes, and only connect two cells with an edge, if no wall separates them. However, Dijkstra is not the best algorithm to use, for such an easy example. If all edges in the graph have a...

algorithm,order,path-finding,circular-dependency

Supposing, than edges must alternate (every vertical to be followed by horizontal and vice versa), algorithm may be the following: P = input // collection of points EH = [] // collection of horizontal edges EV = [] // collection of vertical edges sort P by x, then y //...

javascript,unity3d,path-finding

Indeed it seems the problem is in the last 4 lines. Here is a couple of things that could be wrong: You are calculating the distance from the AI and the Target waypoint with Vector3, when you are using 2D coordinates. Make sure both items are working in the same...

c++,sorting,vector,path-finding

Note: You didn't include your error messages, so the following answer is more or less based on view compiling: sortF(), not sortF error: expected primary-expression before ‘)’ token std::sort(open.begin(), open.end(), sortF); ^ You need an instance of sortF, not the type struct sortF. Either use sortF() to create a temporary...

For a single query, A* is probably about as good as you can do. For many queries, you can convert your grid to an undirected, weighted graph consisting only of the hard-coded points where directly connected points have an edge between them and the edge weight is the distance between...

objective-c,ios7,sprite-kit,path-finding

This is a very interesting topic. There are algorithms for finding paths in continuous spaces. For example, you can use a potential based method with the objective having a very low potential and obstacles being "hills" (perhaps infinitely high, although this requires a bit of care). The downside of potential...

path-finding,adobe-illustrator,pathfinder

Step-by-step instruction (active layer = Layer 1): Draw a rounded rectangle on Layer 1. Name = Frame, Stroke = Black, Fill = None Create Layer below Layer 1. Name = Bg Draw a rectangle on Bg around Frame. Name = BgRect, Stroke = None, Fill = Yellow Lock Bg Draw...

We're going to solve this problem by searching a tree in three parts. First we will build a Tree representing the paths through the problem, with branches for each state. We'd like to find the shortest path to get to a state with a certain criteria, so we will write...

You may use a recursive procedure, e.g.: for (int i=0;i<Points.Count;i++) { // Paths[i] contains all paths from start to Point[i] Paths.Add(new List<List<list<int>>>()) ; } int startIndex= ... ; int targetIndex=... ; ProcessPoint(startIndex) ; That's all: you will get in Paths[startIndex] all possible paths. Select those ending at target. The recursive...

c++,dynamic,path-finding,unreal-engine4,d-star

UE4 comes with its own navigation system based on navmeshes. I do not think that tapping into that system will give you anything you can use for your D* algorithm. Plus, the navigation system is (in my opinion) very poorly documented and obscure. If you want to do this for...

There is an error with your code around here: var tmpStep: ShortestPathStep! = currentStep do { println(tmpStep.gScore) println(tmpStep.hScore) } while tmpStep != nil break As you are not changing the value of tmpStep at any point then you are never going to be able to determine it is null. Also,...

.net,unity3d,path-finding,a-star

You are right. The Serialization is just for Loading/Saving Graphs to/from Files so you can preprocess them before runtime. I don't know what implementation of A* you are using. But for performance optimisation you could take a look here and here...

algorithm,graph,graph-algorithm,path-finding,bellman-ford

Just reverse all the edges, and treated destination as start node. Problem solved.

algorithm,graph-theory,path-finding,a-star

It might be possible yes, but A* is a popular algorithm for finding shortest paths in grid like graphs. For graphs in general there are a lot of other algorithms for shortest path calculation which will match your case better. It depends on your setting which one to use. If...

I think it is not possible in O(n) time (see the comment). However you can save some time by solving this with backtracking, remembering the best solution and "cut" the solutions which you know that cant reach the solution better than the best found. This is backtracking solution with cutting...

artificial-intelligence,path-finding

In general, all shortest-path segments will have, as end-points, either polygon vertices or the start and goal points. If you build a graph that includes all those segments (from the start to each "visible" polygon vertex, from the goal to each "visible" polygon vertex, and from each polygon vertex to...

optimization,genetic-algorithm,path-finding

Genetic Algorithm as it is cannot be easily used for multi-objective optimisation directly. If you want to use the purest GA you have to combine the objectives into a single objective, e.g. by summing weighted values of each objective. But this often does not work very well, especially when there...

javascript,node.js,path-finding

What do you mean by "delay"? Like, it took longer to process a larger grid when nothing else was happening? Or, the processing "froze" while the path was calculated and then continued on? Taking longer to process is natural for a large processing space. More cells is more compute power...