Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Trouble with recursion in minesweeper

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 7624
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would help to know what you expected this method to do, and how its actual behavior deviates from that.
 
Angela Li
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 15703
367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic