All I can see from looking at your code is that you're not mainlining your state properly.
You have a method called moveToPosition()
but it's called for every node - and you end up adding every x/y
combination to the paths
List
.
To be honest a lot of this doesn't make sense, and I think you've got more than one problem. There are also a lot of poor programming techniques you'll lose marks for:
- not being OO - you're using static everywhere.
- no use of proper scope - everything is public
- no comments
- names of variables that don't explain what they contain.
- use of the same variable for different uses (holdx)
If I were you I would attempt to complete your profs example. It will teach you some decent transferable skills in OO design. I'd ignore the whole reading and writing from a file. Just mock up a quick Node[3][3] maze in a method and pass that into the initial method. You'll also need to track whether you've already visited a node, but that should be easy.
Sorry I can't help more - my solution would be very similar to your profs which you'd find equally difficult to understand, and I'm against doing homework for someone - one cant learn that way, and programming is very enjoyable once you get past the initial difficulties.
All the best
As a solution to your StackOverflowError
when setting your size > 100
, you'll need to increase the size of your stack
.
To increase the stack size, use the Java VM
argument -Xss
and set it to something bigger than the default.
-Xss64M
should do the trick.
As an explanation, as your increase the size
param, you're also increasing the amount of recursion you're doing which means putting more and more method calls onto your stack
(as seen by the very long stack printed when the error is thrown). To continue using your app with this much recursion requires you to increase the size of your stack.
See this SO question for details.