I am trying to improve my AI knowledge by attempting problems on hackerrank.
One of the problem is:
Princess Peach is trapped in one of the four corners of a square grid. You are in the center of the grid and can move one step at a time in any of the four directions. Can you rescue the princess?
Details are here.
I needed a hint to go about this problem in a systematic way. Is it the case of the shortest route problem? Or which algorithms/concepts of AI can be used to solve this problem?
Thanks.
This is shortest path problem, where nodes are cells in the grid, and edges are possible moves from cell to cell.
Simplest solution to it is using a BFS (since the graph is unweighted). An improvement is using a bi-directional BFS.
An AI oriented improvement is to use an informed algorithm such as A*. You are going to need an admissible heuristic function to use it, can you think of any? (There is a classic well known one, but I'll let you figure it out on your own).