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
1 answer

c# how to reveal the empty fields in minesweeper

I'm currently working on creating a playable minesweeper and the basics are ready but I want to make it perfect. My problem is that now if you click on any field it reveals its content even if its an empty one and it feels kind of annoying to click…
1
vote
1 answer

Mine Sweeper: Improve mine random locate algorithm?

Here is my code to create a grid with randomly generate mines. Problem is the mines is so diffuse, so when I count the mines for non-mine cells, it mainly have value 1, 2 and nearly don't have value 4, 5 , 6, 7. How to improve this algorithm? Assume…
NoName
  • 7,940
  • 13
  • 56
  • 108
1
vote
1 answer

Strange behavior with Python flood-fill algorithm

I'm implementing a flood-fill algorithm for python minesweeper. Before I show you the algorithm, let me define some things that are important: BOARD, when pretty printed, looks like this: X 1 1 1 3 X 2 1 2 X 2 2 3 X 2 X X 3 1 2 1 1 2 2 1 2 X 3…
JavascriptLoser
  • 1,853
  • 5
  • 34
  • 61
1
vote
1 answer

MineSweeper in Python (With tkinter)

I just debugged most of my MineSweeper Code in Python, but there is an issue with the game functions that determine a win or loss. If I win, it does not show the desired message box and confirm a win. If I lose, it will show an error message that…
Lionblaze16
  • 23
  • 1
  • 7
1
vote
2 answers

Minesweeper stackoverflowerror

Im writing a method for minesweeper that opens a cell if there is no mine there. If there are no adjacent cells next to mines, it opens the cells around it that do not have mines. I regularly have this error: Exception in thread "AWT-EventQueue-0"…
user3015224
  • 27
  • 2
  • 5
1
vote
2 answers

Creation 2D array for Mine game

Hello I am trying to create emulation of "Mine game" suppose we have matrix 0 0 0 0 0 0 -1 0 0 0 0 -1 0 -1 0 -1 now each cell that not equal -1 should be represent numbers of mines here code for(int…
Leo
  • 131
  • 1
  • 3
  • 9
1
vote
1 answer

hiding a widget according to x, y coordinates

I'm quite a newbie when it comes to programming, and in our programming excercise in school I'm making a minesweeper game in python using TKinter as GUI. The game works, except my "floodfill" algorithm, to clear any adjacent blank spaces. I have…
feil
  • 33
  • 5
1
vote
1 answer

Applet wont initialize, but needs to be abstract

Trying to get minesweeper to work with right clicks, everything worked up to this point; Discovered that i needed to use MouseListener....which seems to be fine but my main error is I cannot get the applet to initialize and dont understand why. I…
1
vote
2 answers

How to reset JFrame (restart game) using a JMenuItem?

I am making a minesweeper, using actionPerformed method (I know how to use it) at any time, I want to reset the game, make a whole new JFrame of the game and closing the old one. (the map is generated in JuegoBuca(), by an object from another…
Mac
  • 111
  • 7
  • 14
1
vote
1 answer

Minesweeper Mines wont place or appear

Why will this code not load buttons when run? The question is very vague I know but I'm very new to Java and trying to understand lots of things at once. This code is based off of my two previous successful attempts to code TicTacToe and Connect…
1
vote
3 answers

JFrame freezes after calling getContentPane().removeAll()

The title of this quesiton speaks for itself. I am making a clone of minesweeper using a JFrame and have just finished the starting screen where the player selects a game size. When a button is clicked, the Frame is supposed to clear ready for the…
imulsion
  • 8,820
  • 20
  • 54
  • 84
1
vote
1 answer

Creating minesweeper, how do i reset the board when changing the difficulty.

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.ActionListener; public class Minesweeper extends…
1
vote
7 answers

How to properly use recursion in this function?

ok, i have this function that needs to use recursion, to search in a mineswepper(int[][] m) given a coordinate(i, j) by the user, a zero. The zero means there is no mines near that localition. If it is a zero, then my function should show this zero…
Mac
  • 111
  • 7
  • 14
1
vote
2 answers

Java programming - nested for loops for minesweeper game

Currently making a minesweeper game and stuck on being able to loop through the 8 surrounding cells to find the number of surrounding bombs. I have a helper method that I believe works fine that is used to check if the cell (passed by…
1
vote
6 answers

How to get all classes of squares around

I have a table and it looks like this: | 1.1 | 1.2 | 1.3 | ___________________ | 2.1 | 2.2 | 2.3 | ___________________ | 3.1 | 3.2 | 3.3 | And for example if I click on 2.2 what's the best way to get all squares around?
Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103