I think that the wavefront algorithm might be a little bit too complicated to use for this problem, thus in my answer I'll be looking at the other two graph searching algorithms.
The first step you would need to take is to yield a graph representation of the maze. I think that the easiest way would be to:
- Have each square (tile) in your map represented as a node in a graph.
- If there is no edge between any two given adjacent squares, then, there is an edge between the two nodes representing those squares.
Once that you will have that done, you would need to assign weights. Since in your case you do not seem to have any preference over one edge or another, giving each edge a cost of 1 should be fine.
After that the weighted graph will be generated, you will need to search through it. I think that the two most popular algorithms are Dijkstra's Shortest Path Algorithm
and the A*
algorithm.
From what I am understanding, you have no information on where the cube will be placed, this, in my opinion means that you can't use A*
since A*
bases itself upon heuristics, which in this case could be the distance between the current node and the target node which is something you do not know.
Thus, the only option left is the Shortest Path Algorithm
. To do this however, you would need to slightly modify the stopping condition of the search since you will need to check the square each node represents for its contents. If you find what you are looking for, you stop.
If on the other hand, for some reason you will have to use negative weights, then the Shortest Path
will no longer work. For that, you will need to use the same approach however, use a Label Correcting Algorithm
or the Bellman-Ford Algorithm
.
Once that you will have the shortest path from the source node to the destination node, you could extract a series of vectors which will move you from one square to the next. After that you obtain these vectors, you should then be able to move the camera as explained in this MSDN tutorial.
EDIT: This line in your question: So, the goal: Now, I want the camera to find the location of the cube made me understand that you do not know where the cube is before hand. If this is not the case, then, as per @Gene's comment the A*
algorithm will be more suitable since (assuming you know where your goal it) it will be more efficient.
Manhattan distance
(see image below) should serve well as your heuristic section of your algorithm since it seems you can't traverse square blocks diagonally and thus, the most common way of calculating distances (Euclidean) will be less effective.