wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes I cant find the mistake Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I cant find the mistake" Watch "I cant find the mistake" New topic
Author

I cant find the mistake

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello to the forum,

I have a 2D array with JButtons.
Im trying to build a method that starting from a square on last row by clicking another square will check if those both are connected or not (path of specific ImageIcon). Squares that you can stand on called Stones and squares that connect Stones called Bridge. Here is my method so far:



Cordinate is a class that takes two integers (x,y) and add(Cordinate c) takes the current Cordinate element and add it on x and y variables (So if found bridge move to the next square)


Now, my problem. If there is a Bridge element in front (Cordinate(-1,0)) everything working excelent, but if is not then trying to scan others and here something going wrong and never move on. Look System.out debugging i have to understand



If anyone find what going on....then is Mastermind :P
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

You have the definition


Current is the same variable throughout the entire execution of your pathConnected method, it never changes. So inside your loop when you call

you will always get (6,6) because current is not changing.

Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello Hunter, thank you for quick reply. I just check what you told me but current position changed anytime player moves to new Stones. Add some more System.out to debug and noticed that if function when doing scanning detect (Bridge) object before the (Bridge) object that connect the current with the destination then start doing what i have above in Console.
For example, if scanning goes UP-LEFT-RIGHT-DOWN and im standing on a Stones that has at the LEFT and DOWN side Bridge and select to go DOWN. Function check UP = no Bridge, then LEFT = there is a Bridge BUT not included in destination's Bridge and here function start acting like crazy. As you can see from above, start scanning again from begining many times
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

hmm well I'm having trouble understanding what your question is. So the application you are creating searches for a path between a start position and an end? and then uses Bridge objects to cross Stones? is that right?


Hunter
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Yes thats right
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

You are storing visiting positions in a list so your code shouldn't be rechecking positions. Try printing out visitedStump every iteration to see what gets added to the list.

Hunter
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

I am afraid that without seeing any other code, it will be very hard for any of us to help. What Hunter mentioned was correct though: the method you listed seems to always get a Stones object called current with the same values for getColumn() and getRow().

Maybe upload the code to some public svn repository?

Cheers
Wim
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Prints out Stones that already visited. You think so that i have to clear the list each time? Noticed also that my destination Stone always remain the same
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Wim suggestion is a good idea, that way we can see the entire code. Also you might consider looking up depth-first search and breadth-first search algorithms, to classic ways to find paths from start to finish.

Hunter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I cant find the mistake
 
Similar Threads
How to implement the wall follower algorithm in java?
operator && cannot be applied to boolean,int - error
Reading data from files and other classes
Problem with for-each loop
Boggle search algorithm - How this works?