To implement the maze, I used a two-dimensional array, where the element of the array shows which side of the maze is open. The element of the array is a string of length four and contains only zero and one. Zero means the side is open and 1 means it is blocked. The first, second, third and fourth digits shows the state of the top, left, bottom and right side of one cell respectively. Please see the following example that shows how the maze is created. The left picture shows the maze, while the right shows the content of the array that represent the maze.
-
Task 4:
The first problem that you solve recursively is to implement enoughGate() to check if the dogMaze has at least two gates (one for the entrance and one for the exit). This problem must be solved recursively, however there is no limitation on what type of recursion (i.e., direct or indirect recursion) you use .
As a reminder, a direct recursion refers to the function that calls itself to solve the given problem. However, by indirect recursion, more than one function involves in solving the problem. It is possible that a non-recursive function solves a small part of the problem and then calls the recursive function to finish the job.
/**
* This method returns true if the number of
* gates in dogMaze >= 2.
* @return it returns true, if enough gate exists (at least 2), otherwise false.
*/
publicboolean enoughGate (){
// insert your code here. Change the return value to fit your purpose.
return true;
}


Step by step
Solved in 4 steps with 3 images









