finding a way for a car in a maze using DFS algorithm (C programming)
hello everyone can anybody help me with the DFS algorithm : Path* agent_DFS (void* arg1,...); which is written on C program and is about Artificial intelligence which I have to find a way for a car to his goal ..?开发者_StackOverflow? it returns an array of type path I got absoloutely no idea about that ... please help me
Recursion is useful for implementing this.
Remembering if a location is on your current path as you traverse it will help you not to go in circles. You may also want to remember which addresses that you have not yet been to (interesting paths) and addresses you have already decided were dead ends (or at least not helpful in reaching your goal).
If you are looking for the optimal path then remembering how far (through the maze) each address on a path is from both the beginning and the end (on the shortest path discovered that goes through that address) is also helpful. The sum of both of these distances should be the same for all addresses along the shortest paths (paths because their could be more than one path with the same distance), by the way.
In order to know where the car is in the maze with respect to where it came from, it keeps track of all moves made (north, east, west, south). Whenever you backpedal, it doesn't add to the path, but rather removes from it (what point is there to know that you've been to a dead-end and come back for example?).
精彩评论