• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

I cant find the mistake

 
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes thats right
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic