Rush Hour - Solving the game

前端 未结 7 2062
太阳男子
太阳男子 2021-01-30 10:47

Rush Hour
if you\'re not familiar with it, the game consists of a collection of cars of varying sizes, set either horizontally or vertically, on a NxM grid

7条回答
  •  逝去的感伤
    2021-01-30 11:26

    Just finished writing my implementation and experimenting with it. I agree with polygenelubricants that the state space is really small for the classic game (6x6 board). However, I tried a clever search implementation (A* search). I was curious regarding the reduction of explored state space in comparison to a simple BFS.

    A* algorithm can be viewed as a generalization of BFS search. The decision of which path to explore next is determined by a score that combines both the path length (i.e. number of moves) and a lower bound on the remaining moves count. The way I chose to compute the latter, is to get the distance of the red car from the exit, and then add 1 for every vehicle in the way, since it has to be moved at least once in order to clear the way. When I replace the lower bound calculation with a constant 0, I get a regular BFS behavior.

    After inspecting four puzzles from this list, I found that A* search explores in average 16% less states than a regular BFS.

提交回复
热议问题