In the previous assignment, you defined a stub for a function myMagicSolver that searches for an
optimal solution to a Rush Hour puzzle. Your task in this assignment is to implement this function. In
principle, that’s it. Go!
I suspect it may help to break this task down a bit, to give you an idea of how you may structure your
solution.
As discussed in the previous assignment, the general strategy is to maintain a frontier, the list of
board states on the current level of your breadth-first search. The search is then a repetition of the
following process: Given the current frontier, check whether it contains a solution, a configuration
where the red car is free. If so, your search should return the path of moves you followed to reach this
configuration, so every state in your frontier also needs to store the path of moves you followed to reach
this configuration. If there is no solution in the current frontier, then you need to construct the next
frontier, the next level in your breadth-first search. To do this, you generate the list of configurations
reachable by moving a single car from each configuration in your current frontier. You need to remove
duplicates from the resulting list of configurations, and you need to remove all configurations you have
already seen on previous levels. The result is the next frontier. You call your function recursively on
this new frontier. To check which configurations you have seen already, the set of
configurations you have seen already as an argument to each recursive call. As I said in the previous
assignment, an efficient implementation should represent this as an actual set type from Data.Set.
You can use a list, but checking whether a list contains some element is slow if the list is big.
So here are some suggestions for functions you may need. You can structure your code differently or
choose to name these function whatever you like. I do not provide type signatures for these functions
because that’s part of what you need to figure out.
complete the haskell code

0 comments