File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Game Development and the fly likes Trouble with recursion in minesweeper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Trouble with recursion in minesweeper " Watch "Trouble with recursion in minesweeper " New topic
Author

Trouble with recursion in minesweeper

Angela Li
Greenhorn

Joined: Nov 04, 2011
Posts: 12
This is my code for inspecting a cell in minesweeper, and it is not working as I had expected but I can't quite figure out what is wrong. Some help would be appreciated.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
It would help to know what you expected this method to do, and how its actual behavior deviates from that.
Angela Li
Greenhorn

Joined: Nov 04, 2011
Posts: 12
So, I expected the method to open up just the cell (x,y) if it is next to a mine so its not zero. But if it is zero or no mines are adjacent to it then I expect it to recursively open the cells around it. But the method is failing to recursively open.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3370
    
    9
It looks like you are checking your loop variables wrongly. Shouldn't they be allowed to be equal to 0 as well? Anyway, you have a lot of clutter in that snippet of code. Here's a simpler version:
Angela Li
Greenhorn

Joined: Nov 04, 2011
Posts: 12
thanks for making my code more concise, i was getting confused myself with all the if statements. It works now that I took your suggestion, thanks so much. I spent so long on this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with recursion in minesweeper
 
Similar Threads
a doubt in hashcode program
program needs to be explained
HashMap Doubt
Grid Layout
Buttons not displaying till I mouseover them?