I have a board which is 6x6 see picture below. The black thing is a ball. The red block is where the ball needs to go. So my question is how do I find the shortest way to the red block. The ball can only be moved up, down, right and left. There are also obstacles. I have been thinking a lot but have no clue or idea on how the algorithm to find the shortest way should be. I need some advise on how I can solve the problem.
Asked
Active
Viewed 305 times
-7
-
looks like there are many shortest ways... but the easiest way would be just to move the ball to the same row and then the same column as the red block? ... assuming you can't move diagonally and (like the example) there are no obstacles or any sort of portals or whatever. – Smern May 12 '14 at 15:37
-
1You should try something before asking: show some effort and then we will help you. You only have to go up and then left (or left and then up) – Pablo Lozano May 12 '14 at 15:39
-
If you've been thinking a lot about the problem and not getting anywhere maybe you should just try playing the game and move the ball around. – MxLDevs May 12 '14 at 15:48
-
1You can use Astar algorithm – Anthony Raymond May 12 '14 at 15:52
1 Answers
3
If there are any obstacles, use breadth-first-search algorithm.
If there aren't, the task is even easier. Just get to the right column and then continue to the right row.

Danstahr
- 4,190
- 22
- 38