Question: Java: Whenever I test this code and try to put a value of 6 or more for the rows and columns it gives me a

Java:

Whenever I test this code and try to put a value of 6 or more for the rows and columns it gives me a StackOverflow Error. How would I be able to change this to include values of 6 or more?

import java.util.Random; import java.util.Scanner; public class MouseMaze2 {

static final int INVALID_LOC = -10000; static final int neighX[] = {-1, -1, -1, 0, 0, 1, 1, 1}; static final int neighY[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int counter = 0; int catCaught = 0; int totalBadMoves = 0; int fellOverTheEdge = 0; Random random = new Random(); public boolean isLegal(int maze[][], int totRows, int totCols, int destRow, int destCol, int curRow, int curCol, int visited [][], int catX, int catY){ if (destRow >= totRows || destCol >= totCols || destRow < 0 || destCol < 0) { fellOverTheEdge++; totalBadMoves++; return false; } if ((destRow+destCol) < (curRow+curCol) || visited[destRow][destCol] == 1) { totalBadMoves++; return false; } if ((destRow==catX && destCol==catY) || (destRow==catX && destCol==catY+1) || (destRow==catX+1 && destCol==catY) || (destRow==catX+1 && destCol==catY+1)) { catCaught++; totalBadMoves++; return false; } return true; } public void resetAll(int maze[][], int[][] visited, int totRows, int totCols) { for (int i=0; i

void printStatistics(int[][] maze, int totRows, int totCols, int catX, int catY) { System.out.println("It took " + totalBadMoves + " attempts to find a path"); System.out.println("The mouse fell off the maze " + fellOverTheEdge + " times"); System.out.println("The cat got the mouse " + catCaught + " times"); for (int i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!