Background
This is a small codebase related to mazes. It has some basic utilities to parse a maze from a string representation, print out a maze, and attempt basic maze solving. However, an intern from summers past wrote the code, so there might be some bugs. They also didn’t quite finish their summer project, so let’s:
- uncomment the tests
- fix any bugs
- finish any functionality they hadn’t done yet
Completing the Question
Check out the unit tests. There are four files:
p1_test_maze_printerp2_test_maze_solverp3_test_maze_solve_hardp4_test_maze_solver_with_key
You can go in order, p1 to p4, to complete the question. Make sure to uncomment the tests to complete each part.
TODO: Uncomment the following code as you implement the proper logic for MazePrinter.
Uncomment to test solving the big maze
@Test
public void testCanSolveWithChutes() {
/* Test that we can solve a maze with chutes. */
MazeSolver solver = new MazeSolver(mazeWithChutes);
assertTrue(solver.hasSolutionViaBFS());
}
@Test
public void testCanSolveWithImpossible() {
/* Test that can't solve a maze with impossible chutes. */
MazeSolver solver = new MazeSolver(mazeWithImpossibleChutes);
assertFalse(solver.hasSolutionViaBFS());
}
这道 Meta VO 题本质上是一个迷宫求解与代码补全任务:你需要先补齐被注释掉的单元测试,再修复 MazePrinter 和 MazeSolver 中的缺失或错误逻辑。核心思路通常是把迷宫抽象成图,用 BFS 判断从起点到终点是否可达;如果题目里包含 chute、key 等特殊格子,则在搜索时把它们当作状态转移规则的一部分,必要时将“当前位置 + 是否持有钥匙”等信息一起作为访问状态,避免重复搜索和错误判定。