c++ - with Pathfinding Algorithm
I am working on a project which, at least, will generate 2D matrix of numbers, "empty" space With each number submitted by 0 is linked to the list of nodes. Due to the algorithm, there is a list of number values in the nodes, the position of the number of x and y, and all the locations around it (its "neighbors"), which occurs with the exception of the quartz space near the point, Only allows fault, bottom, left and right I have the issue that, as the title suggests, I have some stack overflow problems. I will post my code below, if any I can help, so I appreciate most.
CoordiaList * Puzzle :: GeneratePath (Coordist's List * Path, Int Gooylx, It Goyal) {int quarks; Int'l Currie; CurrX = path- & gt; Neighbors; CurrY = path-> Neighbors; If (currx == golfes and curie == round) {return (path); } Else {int NewX; Int NewY; Double new distance; Int Oldx; Int Old; Double Priorism; CoordList * PointNeighbors = NULL; CoordList * Best Choice = Faucet; For (int i = 0; i & lt; NumDirections; i ++) {CoordList * NewNeighbor = new CoordList; Newx = curse x + directives x [ii]; New = curie + directives [i]; If (IsPossible (NewX, New)) {New Nebor- & gt; Neighbor X = Newx; New Nieber- & gt; Neighborhood = New; If (PointNeighbors == faucet) {NewNeighbor-> Next = null; Point Nieberbers = New Neubre; } And {NewEnghiber-> Next = Point Neighbors; Point Nieberbers = New Neubre; }} // Delete Nulliger; } While (Point Nibbers! = Null) {if (Best Choice == Faucet) {CoordList * AChoice = new CoordList; Aqua-> Next = null; NewX = Point Neighbors- & gt; Neighborhood; New = Point Nibbers- & gt; Neighbors; Access-> NegberX = New X; Aqua-> Neighborhood = New; Best Choice = Echnow; Point Nibberbos = Point Nibberbors-> Next; // Deleted Action; } And {NewX = Point Neighbors-> Neighborhoods; New = Point Nibbers- & gt; Neighbors; NewDistance = Determine (NewX, New, Goyleax, Goal); Oldx = Best Choice- & gt; Nebroob X; Old = Best option- & gt; Neighbors; OldDistance = Determine (old, old, goal, round); If (New Destination; OldDistance) {Best Option-> Nebrar = new; Best Choice- & gt; Neighborhood = New; } PointNeighbors = PointNeighbors-> next; }} BestChoice-> Next = path; Path = best option; Return (Generated Path (Path, Goyleax, Goyal)); }} I was asked to provide my fixed distance function. This traditional point is just a simple implementation of the distance formula. Has been given below.
Dual puzzle: fixation (int onex, int vaniwie, int twox, int dual) {int dfx; Int difference; Double point sum; Dtx = (tox - one x); Dify = (two YY - OneY); Dtx = (dxx * dtx); Dify = (Dify * Dify); Point sum = (dxx + dfi); Return (sqrt (pointsusum)); } The following isPossible function, which determines whether the X and Y values are within the possible grid space.
bool puzzle :: isPossible (int x, int y) {if (x + 1> size - 1 || x - 1 & lt; 0} y + 1> size - 1 | | Y - 1 & lt; 0) {return false; } Back true; }
You may have an infinite recurrence loop which causes stack overflow , As you make new local variables with each repetition, especially the behavior of your convulsions. I think you do not have problems with small matrix. It's just a shot in the dark: -)
The oscillation problem indicates that you do not check whether you are already in a place or not?
Anyway, maybe you would like to reconsider the use of another pathfinding algorithm I would suggest an agent based solution. I used the following solution to solve the maze of similar structures: I started an agent with the "positionist" of a spot, where the beginning was started, so in the beginning only with the starting point. After this, he kept copying himself in every unrecognized position in the status list, destroying himself by adding a new situation to that list. Repeat the pattern with all new agents until the first agent reaches the goal. In this way you are guaranteed to find the optimal path. But this can be very heavy for large matrix, especially when there are many different ways to get the goal and there are many possible directions in every situation! But there are so many other very good pathfinding algorithms. Perhaps one of them suits you well: -)
Good luck!
Comments
Post a Comment