Hi, I'm new to this forum and was wondering if anyone could help me out with a code i'm working on requiring 2D arrays and recursion (the later which I have difficulties understanding).

In a nut shell I have to make a program that generates either a random maze or reads a maze from a file. Then I have to have the program find a path from point a to point b and output the path using "+"s

The maze would look something like this:

BBBBBB

BOOOBB

BSBOBB

BOOOOB

BBBBXB

B = barrier

O= open path

X = exit

S = start

The main area of concern is my Solve method which would solve a given array.

Here is what I have so far.

I'm getting out of bounds errors that I'm not sure how to fix :( Could anyone help me out? Also, would I have to search the array for "S" for it to start? My teacher says I would not but I don't understand why o.0Code:

public static int Solve (int row, int col)

{

int check = 1;

//check squares for O

if ((col - 1) >= 0) //check for left border

{

if (array [row] [col - 1] == "O")

{

if (Solve (row, col + 1) == check)

{

array [row] [col] = "+";

return check;

}

}

}

if ((col + 1) < MAXCOL) //check for right border

{

if (array [row] [col + 1] == "O")

{

if (Solve (row, col + 1) == check)

{

array [row] [col] = "+";

return check;

}

}

}

if ((row - 1) < MAXROW) //check for down border

{

if (array [row - 1] [col] == "O")

{

if (Solve (row - 1, col) == check)

{

array [row] [col] = "+";

return check;

}

}

}

if ((row + 1) >= 0) //check for up border

{

if (array [row + 1] [col] == "O")

{

if (Solve (row + 1, col) == check)

{

array [row] [col] = "+";

return check;

}

}

}

c.println ("No Solution.");

return 0;

}

}

Any help would be greatly appreciated :)