I have to find the shortest path from point D to R. These are fixed points. This is an example of a situation:
The box also contains walls, through which you cannot pass across them, unless you break them. Each wall break costs you, let's say "a" points, where "a" is a positive integer. Each move which doesn't involve a wall, costs you 1 point.
The mission is to find out of all the paths of minimum cost, the one with the least number of broken walls.
Since, the width of the box can go up to 100 cells, it's irrelevant to use backtracking. It's too slow. The only solution I came up is this one:
- Go east or south if there are no walls
- If south has a wall, check if west has wall. If west has wall, break south wall. If west doesn't have wall, go west, until you find a south cell without wall. Repeat this process with south and east until you exceed the cost of a broken wall in this order. If path from west goes into the same place as if I had broken the south wall and costs the same or less than "a" points, then use this path, else brake south wall.
- If nothing above encounters, brake a south or east wall, depending on the box boundary.
Repeat steps 1, 2, 3 till the "passenger" arrives in point R. Between these 3 steps, there are "else-if" relations.
Can you come up with a better problem algorithm? I program in C++.