Questions tagged [minesweeper]

Minesweeper game is an abstract puzzle, quite popular as a target of sample programs in different laguages.

Rules

The object of the game is to clear an abstract minefield without detonating a mine.

The game is played by revealing squares of the grid, typically by clicking them with a mouse. If a square containing a mine is revealed, the player loses the game. Otherwise, a digit is revealed in the square, indicating the number of adjacent squares (typically, out of the possible eight) that contain mines. In typical implementations, if this number is zero then the square appears blank, and the surrounding squares are automatically also revealed. By using logic, the player can in many instances use this information to deduce that certain other squares are mine-free, in which case they may be safely revealed, or mine-filled, in which they can be marked as such (which, in typical implementations, is effected by right-clicking the square and indicated by a flag graphic).

Popularity

The game has been written for many system platforms in use today. Versions of Minesweeper are frequently bundled with operating systems and GUIs, including Minesweeper for OS/2, Minesweeper in Windows, KMines in KDE (Unix-like OSes), Gnomine in GNOME and MineHunt in Palm OS. Apart from the bundled versions, a huge number of clones of all shapes and sizes can be found on the Internet.

Variants

Variants of the basic game generally have differently shaped mine fields in two and three dimensions, or various two-dimensional layouts, such as triangular or hexagonal grids, or possibly more than one mine per cell. For example, X11-based XBomb adds triangular and hexagonal gridsю

Complexity

In 2000, Richard Kaye published a proof that it is NP-complete to determine whether a given grid of uncovered, correctly flagged, and unknown squares, the labels of the foremost also given, has an arrangement of mines for which it is possible within the rules of the game. The argument is constructive, a method to quickly convert any Boolean circuit into such a grid that is possible if and only if the circuit is satisfiable; membership in NP is established by using the arrangement of mines as a certificate. This proof has been disputed, though.


Source: http://en.wikipedia.org/wiki/Minesweeper_(video_game)

410 questions
2
votes
1 answer

Improving my minesweeper algorithm c#

I'm making a minesweeper game, and so far it's completely playable and you can finish the game. However, my solving algorithm sucks. It's pretty messy and I'm looking for a cleaner way, perhaps with loops, but I can't think of anything. Here is what…
Anteara
  • 729
  • 3
  • 14
  • 33
2
votes
2 answers

Verify Position VB.NET

So I'm developing a minesweeper game and im assigning the mines, but i'm unable to create a algorithm to stop a mine to go to a place where there's already a mine, here's what i have so far: Public Sub initflags() Dim line, column As Integer …
joao
  • 133
  • 2
  • 2
  • 8
1
vote
3 answers

MineSweeper reveal neighbors help needed java

I am currently working on a minesweeper program and i need a little help on revealing neighbors in it. Currently what my program can do for reveals is the following The 1 would be the button that was selected and the lines are what i need to be…
Adam Jakiela
  • 2,188
  • 7
  • 30
  • 48
1
vote
1 answer

Capture simultaneous right and left click event triggers on label

I'm writing a simple minesweeper game over my Christmas break and I'm adding in the feature where you click with both mouse buttons on a number and it unveils the hidden boxes around it when it's safe to do so. ie the number is a 1 and you've…
jb.
  • 9,921
  • 12
  • 54
  • 90
1
vote
3 answers

Randomly placing items in a list of lists in Python

I'm a beginner at using Python and I've been trying to code a Minesweeper game. Basically, I'm a bit lost on how to set up my class so that it creates a 5x5 grid of cells using a list of lists, then randomly places 3 mines on this grid, and counts…
1
vote
1 answer

vb.net: Minesweeper clicking events

I've started making a Minesweeper game in vb.net using a dynamically created grid of buttons, which are stored in a 2D array. I have another 2D array (Boolean), that keeps track of whether a certain position is covered or uncovered. And I have an…
SiliconCelery
  • 185
  • 3
  • 12
1
vote
1 answer

Javascript recursion not working

I'm making a jquery minesweeper and am currently working on the revealing function for when you click a block with 0 adjacent mines. The intended result is to loop through all 8 adjacent blocks reveal those blocks, if they are also '0' blocks, it…
Korvin Szanto
  • 4,531
  • 4
  • 19
  • 49
1
vote
2 answers

How to detect a "win" in a Minesweeper game?

I am working on a Minesweeper which I have pretty much complete. The only thing missing is the detection of winning. What would be the best way to implement this? I know its going to be part of the actionlistener that detects clicks, at some point…
user541597
  • 4,247
  • 11
  • 59
  • 87
1
vote
1 answer

Outer grid in Mine Sweeper game bugged condition

I'm trying to replicate in Js the old Mine Sweeper game. But I'm stuck declaring conditions to the blue grid (that is distant 2 numbers from the bomb at the center of it); I have 2 bugged cells appearing on the other side when a bomb is on the grid…
1
vote
2 answers

minesweeper java

I am working on a minesweeper program in Java. I have my bombs distributed throughout the field, and I have my actionlisteners responding to clicks and mouselistener, responding to right clicks. I also have each square that is clicked check to see…
user541597
  • 4,247
  • 11
  • 59
  • 87
1
vote
1 answer

Minesweeper recursive dig function explanation

I am learning Python from scratch and went through the basics and now I started solving some online exercises for training and I came across the minesweeper game (coded by Kylie Ying: https://github.com/kying18/minesweeper). I am reading the code…
1
vote
0 answers

Why does mineCount return zero?

I wrote some code to count and reveal all adjacent tiles in minesweeper. However, when a tile is revealed and does not contain a mine, it displays zero. The adjacent mines do not get revealed. I'm certain that the issue is in my code. I'm trying to…
BJohn
  • 11
  • 3
1
vote
3 answers

How to randomly select divs from inside another div?

I am struggling to randomly select some divs (9 in this case) to place bombs/mines for those selected tiles. My code for this is: function place_mines() { if (document.getElementById("difficulty").selectedIndex == "2") { for (var u…
1
vote
1 answer

I am looking for a way to make my Minesweeper game add numbers around the bombs

Currently my code adds bombs through random x and y coordinates on my hidden grid. What would I have to add here in order for the code to add numbers if the grid space is touching a bomb? def addBombNum(bombs,gSize,hiddenGrid,bCount): fNum = "" …
1
vote
0 answers

Can't run function in button eventListener - Minesweeper Game

I want to generate random mines with a button ".btn" for my Minesweeper Game but I only managed to hide the tiles. I can't figure out why calling getMinePositions(boardSize, numberOfMines) doesn't work - mines are not generated after clicking the…
Bagnom
  • 21
  • 3