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
1
vote
2 answers

"Minesweeper" in C, trouble on counting surrounding mines are near a certain spot in the board

I have to recreate a simple version of the game "Minefield" in C, but I'm having trouble on counting how many mines are near a certain spot in the board. My piece of code runs throughout the array (board) searching for mines. When it finds a mine,…
1
vote
0 answers

Opening ToggleButtons in Java for MineSweeper

So I would have asked this in the Java chat, but my new overflow account does not have 20 rep yet so I would like to ask it here. So basically my problem is sometimes when I open one of the JToggleButtons in my minesweeper application, it opens but…
Michi
  • 13
  • 4
1
vote
1 answer

I cant figure out the minesweeper recursive algorithm

I cannot figure out the algorithm for revealing empty cells in minesweeper. revealCells is supposed to take a cell, and then check the surrounding cells and reveal them until it finds a mine cell, but for some reason I keep getting an…
Jack
  • 21
  • 1
  • 3
1
vote
3 answers

Creating simple Minesweeper application using 2D vector

I'm trying to build a simple Minesweeper application using a 2D vector. First I fill the squares with 1's and 0's (1's meaning mines and 0's meaning clear). srand(time(NULL)); for (int i = 0; i < battlefield.size(); i++) { for (int j = 0; j <…
Chris
  • 73
  • 1
  • 2
  • 8
1
vote
1 answer

Minesweeper recursion, stackoverflow

So, I've been working on some code for java for minesweeper. I'm working on trying to get the cells that are empty to reveal the coinciding cells next to them recursively. Here is the function that does this. The "cell" is a button that I'm using…
pianoman102
  • 541
  • 8
  • 22
1
vote
3 answers

How to count true values in a bool[,] around a given index?

I turned up a simple MineSweeper program i wrote several years ago and got intersted if you could optimize the following code, because that doesn't look good at all. The following method is for checking if the indexes aren't out of range and returns…
Martin Niederl
  • 649
  • 14
  • 32
1
vote
1 answer

Are there any downsides to changing a value of a JavaScript WeakMap key/value pair without using the WeakMap.set method?

I'm just beginning to learn the use cases for the ES6 WeakMap feature. I've read a lot about it, but I haven't been able to find an answer for this particular question. I'm implementing a Node.js Minesweeper game for the terminal - just for fun and…
1
vote
2 answers

Recursion error in GUI

I am creating a simple 9x9 grid for Minesweeper. One of the primary functions of this game is to have a recursion to check all the sides when the tile clicked has no bombs surrounding it. In the code attached below, I have been able to create a…
dont_me
  • 11
  • 2
1
vote
1 answer

return new int[]{randomHeight, randomWidth};

I want to code some basic stuff for a little minesweeper-game, that we do in university. Now I have the problem that my code . public class Minesweeper1 { public static int[][] makeRandomBoard(int s, int z, int n){ //creating the field…
user7180609
1
vote
1 answer

Discovering a region with no mines on minesweeper

I am new in this page, it hope get to some help, basically I am doing a minesweeper game on Java but it have a problem with a function: discover the region with no mines and no numbers like in the game on windows, when you click in one place and all…
Farengar
  • 33
  • 8
1
vote
0 answers

Minesweeper program in C trouble with numbers surrounding mines

So I need to write a program that creates the grid like in minesweeper, and then you input how many mines you want, and then the location of the mines. My program so far seems to work fine until I decide to put a mine on the same row as another…
1
vote
1 answer

C# MineSweeper project: Any simplier way to show adjacent mines?

I made a minesweeper WPF project as a practice to study object oriented programming. However, my method for showing how many mines the buttons "see" is kinda long and messy. The current grid is 6x6 and as you can see, it is a long list of lines.…
Daniel
  • 89
  • 1
  • 2
  • 8
1
vote
2 answers

Flagging Buttons for Minesweeper GUI Game

I have worked for hours on this code and finally gotten ver close to completion. I will be adding a Mine Counter and a timer once I figure out how to add the ability to flag mines with right clicking. I learned that JButtons do not recognize right…
baileyr12
  • 41
  • 6
1
vote
6 answers

How can I identify buttons, created in a loop?

I am trying to program a minesweeper game on python using tkinter. I started off by creating a grid of buttons using a two dimensional list of 10x10. Then I created each button using a loop just so I don't have to manually create every single button…
Chuan Li
  • 19
  • 1
  • 1
  • 3
1
vote
1 answer

Adding image to a Button in JavaFX after Button is created

I am working on coding a MineSweeper game using JavaFx. I am having an issue with changing the Buttons to just include an image and not have text. A portion of my code is as follows: ImageView bomb; Image bombImage = new…