Hello,

I have a 300 lines program that should solve a maze made of a 2 dimensional array objects called Cell. The program is called FinalSolve and it makes use of

- findCellWithValue
- findNeighbors
- setTheValue

findCellWithValue returns an array made of Cell objects that have the value specified as an argument

setTheValue just sets the value given as arguement to a cell given as argumentCode:public Cell[] findCellWithValue(int theValue) { int currentNoOfCells = 0; Cell[] theCells = new Cell[INITIAL_ARRAY_SIZE]; for(int row = 0; row < HEIGHT; row++) { for(int column = 0; column < WIDTH; column++) { if(maze[column][row].value() == theValue) { if(currentNoOfCells == theCells.length) { Cell[] biggerArray = new Cell[theCells.length + ARRAY_RESIZE_FACTOR]; System.arraycopy(theCells, 0, biggerArray, 0, theCells.length); theCells = biggerArray; } theCells[currentNoOfCells] = maze[column][row]; currentNoOfCells++; } } } return theCells; }

findNeighbors is the most complicated method from this program I might say. Here it is

So there you go here are the main methods. I won't bother you with the constructor and with the toString since it doesn't matter I believeCode:public Cell[] findNeighbors(Cell theCell) { Cell[] neighborsCell = new Cell[1]; int neighbors = 0; int column = theCell.column(); int row = theCell.row(); if(column - 1 < 0) { } else { char someElse = maze[column-1][row].symbol(); if(someElse == ' ') { System.out.println("Good"); if(neighbors == neighborsCell.length) { Cell[] biggerArray = new Cell[neighborsCell.length + 1]; System.arraycopy(neighborsCell, 0, biggerArray, 0, neighbors - 1); neighborsCell = biggerArray; System.out.println("Once"); } neighborsCell[neighbors] = maze[column-1][row]; neighbors++; } } if(column + 1 >= 20 ) { } else { char someElse = maze[column+1][row].symbol(); if(someElse == ' ') { System.out.println("Good"); if(neighbors == neighborsCell.length) { Cell[] biggerArray = new Cell[neighborsCell.length + 1]; System.arraycopy(neighborsCell, 0, biggerArray, 0, neighbors - 1); neighborsCell = biggerArray; System.out.println("Once"); } neighborsCell[neighbors] = maze[column+1][row]; neighbors++; } } if(row - 1 < 0){} else { char someElse = maze[column][row-1].symbol(); if(someElse == ' ') { System.out.println("Good"); if(neighbors == neighborsCell.length) { Cell[] biggerArray = new Cell[neighborsCell.length + 1]; System.arraycopy(neighborsCell, 0, biggerArray, 0, neighbors - 1); neighborsCell = biggerArray; System.out.println("Once"); } neighborsCell[neighbors] = maze[column][row-1]; neighbors++; } } if(row + 1 >= 10){} else { char someElse = maze[column][row+1].symbol(); if(someElse == ' ') { System.out.println("Good"); if(neighbors == neighborsCell.length) { Cell[] biggerArray = new Cell[neighborsCell.length + 1]; System.arraycopy(neighborsCell, 0, biggerArray, 0, neighbors - 1); neighborsCell = biggerArray; System.out.println("Once"); } neighborsCell[neighbors] = maze[column][row+1]; neighbors++; } } return neighborsCell; }

Now the solve method combines all these methods together in the desperate try to solve it ( for 1 month )

Here it is:

public void solve()

{

Cell[] entrance = findCellWithValue(250);

Cell[] neighborsOf = findNeighbors(entrance[0]);

for(Cell neighbor : neighborsOf)

{

setTheValue(1, neighbor);

}

int moveCount = 1;

boolean foundExit = false;

while(!foundExit && moveCount <= 200)

{

Cell[] theCells = findCellWithValue(moveCount);

for(Cell justOne : theCells)

{

if(justOne != null){

if(justOne.symbol() == '!')

{

foundExit = true;

markPath();

break;

}

else

{

Cell[] moreNeighbors = findNeighbors(justOne);

for(Cell prostie : moreNeighbors)

{

if(prostie != null)

{

if(prostie.value() == 0)

{

System.out.println("" + moveCount);

setTheValue(moveCount+1, prostie);

}

}

}

}

}

}

moveCount++;

}

System.out.println("" + moveCount);

System.out.println(var_dump() + "");

}// solve

I also have a var_dump method ( yes inspired by the php function, however is nothing like it). This var_dump method prints the entire maze according to the values. So here is an image to how it actually looks. The top bit is var_dump the bottom is just the toString

http://imgur.com/R090YnS

So as you can see my maze does not want what so ever to turn left. It either goes right or down. Any ideas what might be causing this?

Thanks