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.

enter image description here

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top