Results 1 to 5 of 5
  1. #1
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default MineSweeper algorithm?

    I decided to make minesweeper and I'm having a little trouble with the algorithm used when you select a tile with 0 surrounding bombs, you know, how it fans out and uncovers all of the tiles with no surrounding bombs. Can someone explain to me how this works? If I knew how it worked I could convert it to code.

    This is what I currently have:
    MineSweeper algorithm?-capture.png

    I have bombs visible (red X) for debugging.

    It works otherwise though. It's pretty cool.
    MineSweeper algorithm?-capture.png
    Last edited by zFollette; 12-31-2013 at 06:15 AM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: MineSweeper algorithm?

    The algorithm resembles a 'flood fill' algorithm and is quite simple if implemented recursively: if a cell contains no neighbouring mines, you can open all neighbouring cells (if not open yet). For each neighbour cell, if it contains no neighbouring mines, you can recursively do the same. If it does contain neighbouring mines, show the number of mines and stop the recursion for that cell (otherwise the algorithm would solve the entire puzzle for you)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,860
    Rep Power
    5

    Default Re: MineSweeper algorithm?

    Slightly off-topic: that's an excellent idea for a game to use as a study help, especially because of this one really nasty tiny little game element to implement. I'm actually curious what people who don't apply recursion can come up with to hack it together anyway, it might actually open up some really creative thinking. I'm going to add it to the list of projects to torture interns with :)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: MineSweeper algorithm?

    Sounds good. Ill take a whack at it.

    Update: Got it to recursively uncover the whole board. Now setting restrictions.

    I think I just about have it, can someone verify this?

    MineSweeper algorithm?-capture.png

    My flood fill starts from the poorly drawn blue X
    Last edited by zFollette; 12-31-2013 at 06:25 PM.

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,928
    Rep Power
    8

    Default Re: MineSweeper algorithm?

    Quote Originally Posted by gimbal2 View Post
    Slightly off-topic: that's an excellent idea for a game to use as a study help, especially because of this one really nasty tiny little game element to implement. I'm actually curious what people who don't apply recursion can come up with to hack it together anyway, it might actually open up some really creative thinking. I'm going to add it to the list of projects to torture interns with :)
    Your interns get to write minesweeper?

    ...are you hiring? :p
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Minesweeper Game Need Help!
    By Punkymedic in forum New To Java
    Replies: 18
    Last Post: 11-14-2013, 10:27 AM
  2. I badly need help on this minesweeper game
    By Shin in forum New To Java
    Replies: 5
    Last Post: 10-14-2012, 08:42 PM
  3. [suggestions] minesweeper
    By temyong in forum New To Java
    Replies: 7
    Last Post: 12-30-2010, 03:10 AM
  4. MineSweeper!
    By CrushOverwrite in forum New To Java
    Replies: 17
    Last Post: 02-24-2010, 02:34 PM
  5. Minesweeper problem! need help!
    By jeffrey in forum New To Java
    Replies: 1
    Last Post: 10-02-2009, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •