An optimal solver for the puzzle - Ricochet Robots.
This solver uses A* search algorithm to calculate the optimal path to the destination from the given source.
###Cost function:###
Here, the cost function consists of f(n) = g(n) + h(n)
Where,
g(n) - Total number of blocks visited so far.
h(n) - Manhattan distance between the given position and the goal position.
Since, the chosen h(n) is an admissible heuristic (never overestimates the goal) and repeated states are handled, A* algorithm is guaranteed to be complete as well as optimal.
###Example Format for the test file###
8 # Number of rows
8 # Number of columns
[(0, 4), (1, 1), (2, 5), (4, 4), (4, 7), (1, 0), (6, 2), (7, 6)] # List of block locations
(6, 4) # Where the ball starts
(2, 4) # Goal location
I have also uploaded a test file for a 50x50 board under the test folder. To use this new test file, replace the value for the variable path_to_file_containing_puzzle in Ricochet.pyde to the new test file name.
###Pre-reequisites:###
- Python 2.7
- Processing 3.2.3, which can be installed from https://processing.org
- Install python mode in Processing.
###Execution###
The solver can be executed using the Ricochet.pyde file via the Processing IDE.
An exception is raised if the solver detects a loop, i.e if no solution exists.