Huarong Road Game
The Huarong Pass game is an advanced version of the number puzzle problem explained in the BFS Algorithm Framework. There are some main differences:
In the number puzzle, each number takes up one square. In the Huarong Pass game, each piece has a different shape and takes up a different number of squares. Cao Cao takes up 4 squares, the five tigers take up 2 squares, and the soldiers take up 1 square.
In the number puzzle, we only need to record the minimum steps to finish the game. But in Huarong Pass, there is no requirement for the minimum steps. Instead, you must record the exact operation steps. Only then you can use the
gameHandler.move
function to move the pieces and finish the game.
We can use the BFS algorithm to try all possible moves on the board. At the same time, we use an extra data structure to record the operation steps. Once we find a solution, we call gameHandler.move
to operate the board and finish the game.
The game panel only supports running JavaScript code. But the solveHuarongRoad
function only needs to return an operation sequence, not the game logic itself. So you can use any programming language to write the algorithm, as long as you print out an operation sequence like this:
gameHandler.move(10, 'left')
gameHandler.move(9, 'right')
gameHandler.move(5, 'down')
...
Then copy this operation sequence into the solveHuarongRoad
function on the game panel. You can finish the game and check if your algorithm is correct.