Huarong Road Game
Huarong Dao Game
The Huarong Dao game is an advanced version of the number puzzle problem explained in the BFS Algorithm Framework. The main differences are:
In the number puzzle, each digit occupies one cell. In the Huarong Dao game, each piece has a different shape and occupies a different number of cells. For example, Cao Cao occupies 4 cells, each of the Five Tiger Generals occupies 2 cells, and a soldier occupies 1 cell.
The number puzzle only requires you to record the minimum number of steps to complete the game. In the Huarong Dao game, you do not need to find the minimum steps, but you must record the specific sequence of moves. This way, you can call the
gameHandler.move
function to operate the board and complete 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 sequence of moves. Once a valid solution is found, we can call gameHandler.move
to operate the board and solve the game.
The game panel only supports running JavaScript code. However, the required solveHuarongRoad
function is meant to compute a sequence of moves, not to be part of the game's execution logic. Therefore, you can implement the algorithm in any programming language, as long as you print a sequence of moves like this:
gameHandler.move(10, 'left')
gameHandler.move(9, 'right')
gameHandler.move(5, 'down')
// ...
Then, copy this sequence into the solveHuarongRoad
function on the game panel to complete the game and check if your algorithm is correct.