Stackoverflowerror on Breath Search algorithm
hey ppl, i need an algorithm that can detect the best path to get in an array from a to b. however,shortest path is not what i need,since there might be a path that goes backwards.anyway i wanted to test the complexity of the algorithm first, and i got an error. however, i don't know if it can be solved in a way. if i reduce the size of the array by half, it works.
thnx 4 replys in advance
publicclass CriticalPath
{
Spot[][] grid =new Spot[128][96];
publicstaticvoid main(String[] args)
{
CriticalPath cp =new CriticalPath();
cp.makeGrid();
cp.determineBestPath(0,0,62,46);
}
publicvoid makeGrid()
{
for(int i=0;i<grid.length;i++)
{
for(int j=0;j<grid[i].length;j++)
{
grid[i][j] =new Spot(i,j);
}
}
}
publicvoid determineBestPath(int x,int y,int eindX,int eindY)
{
if((x==eindX)&&(y==eindY))
{
System.out.println("Ik ben er!");
}
else
{
grid[x][y].setFree(false);
if((x>0&&y>0)&&(grid[x-1][y-1].getFree()))
{
determineBestPath(x-1,y-1,eindX,eindY);
}
if((y>0)&&grid[x][y-1].getFree())
{
determineBestPath(x,y-1,eindX,eindY);
}
if((x<grid.length-1)&&(y>0)&&grid[x+1][y-1].getFree())
{
determineBestPath(x+1,y-1,eindX,eindY);
}
if((x>0)&&grid[x-1][y].getFree())
{
determineBestPath(x-1,y,eindX,eindY);
}
if((x<grid.length-1)&&grid[x+1][y].getFree())
{
determineBestPath(x+1,y,eindX,eindY);
}
if((x>0)&&(y<grid[x].length-1)&&grid[x-1][y+1].getFree())
{
determineBestPath(x-1,y+1,eindX,eindY);
}
if((y><grid[x].length-1)&&grid[x][y+1].getFree())
{
determineBestPath(x,y+1,eindX,eindY);
}
if(((x><grid.length-1)&&(y><grid[x].length-1))&&grid[x+1][y+1].getFree())
{
determineBestPath(x+1,y+1,eindX,eindY);
}
}
}
>

