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

Recursion Ending Too Soon in Javascript Function

I am currently learning JavaScript through remaking games from scratch, and my current project is Minesweeper. While trying to create the recursive function that reveals the spaces surrounding a clicked space I have run into the issue of it ending…
Zelkins
  • 723
  • 1
  • 5
  • 22
4
votes
1 answer

Minesweeper reveal nearby tiles function

I am trying to make the blank or "0" function of ms in a web page. The goal: what happens in mine: what should happen: the red square indicates the button that was clicked, and the green circles indicate its adjacent squares/tiles. My approach or…
Allicnam
  • 88
  • 1
  • 8
4
votes
2 answers

Minesweeper board "opening up"

I am designing a Minesweeper game, yet I can't find the algorithm on how to board "opens up". If you have ever played Minesweeper, the first click or so will display lots of the tiles. What is the algorithm behind it?
LazySloth13
  • 2,369
  • 8
  • 28
  • 37
4
votes
3 answers

javascript minesweeper placed unnecessary "1"

i wrote a minesweeper in JavaScript which was working fine for a while, and then randomly on 1 run (i was trying to improve the styling) it gave me this: note the "1" in the upper-right corner as well as 2 missing 1's two and three spaces below…
Math chiller
  • 4,123
  • 6
  • 28
  • 44
4
votes
3 answers

Placing 1's around "b" in grid in minesweeper

I have a grid that looks like this. I place one "b" randomly in the grid and put the number 1 surround the letter "b". This seems to work everywhere except when a 1 is supposed to be placed on the bottom row and the column all the way to the right.…
DHulse94
  • 67
  • 5
3
votes
1 answer

Trying to code a grid of squares that disappear when clicked, wrong squares disappear and I have no idea why

I am new to programming and I decided to code the game minesweeper as a way to exercise. To do this, I started by creating a code that makes a grid of 10 x 10 cells that disappear when clicked. However the squares when clicked sometimes make other…
Frlhy
  • 33
  • 3
3
votes
1 answer

Minesweeper algorithm that opens all the safe squares in contact with each other from the starting square

I am cooding a minesweeper and I have to make a function that will look through all the squares around the starting square. It should then open these squares and keep checking around the newly opened squares until there are no more safe squares in…
EK249
  • 29
  • 4
3
votes
2 answers

How do I reduce the cyclomatic complexity?

Thanks for reading my question. I am currently taking a Java class on Coursera, and was asked to write a program on minesweeper for the assignment. My code creates the correct result, but my grade was deducted greatly because my code is ”excessively…
3
votes
2 answers

Minesweeper: Reveal Surrounding Blocks Function Freezes

I'm trying to make a function for a minesweeper game I'm making. This function's purpose is to reveal an element given the x and y (where it is located). This is probably not the most elegant way to accomplish it, but I'm making a list of ['-'] for…
3
votes
1 answer

Codefights, minesweeper, python, code almost working

I'm doing codefight's challange: minesweeper. The description: My code is as follows: def minesweeper(matrix): for x in range(len(matrix)): matrix[x].insert(0, "x") #matrix[x].insert(len(matrix)+2, "x") frame = ["x" for i…
TCB
  • 61
  • 6
3
votes
2 answers

Very slow minesweeper recursive algorithm in Swift

I'm working with Swift 3 and Xcode. I'm creating an iOS game that is basically a Minesweeper, but there are no squares but hexagons, so each hexagon can have up to 6 mines in their surrounding. I created a recursive algorithm, so that when the…
Drakalex
  • 1,488
  • 3
  • 19
  • 39
3
votes
1 answer

How to initialize a table with tables in Lua?

A friend and I try to write a mine sweeper program in Lua using the Löve framework. So far the code needs to see if a box (a cell) is checked and then draw it. We are new to Lua, the program now has the flaw that it only works on the lower right…
user2609980
  • 10,264
  • 15
  • 74
  • 143
3
votes
1 answer

Minesweeper Clearing Algorithm

I'm attempting to recreate Minesweeper in flash for a project and I've gotten as far as placing mines and numbers. I can't seem to figure out the recursive algorithm for the expansion of clicking on a tile and clearing its neighbors. There are two…
3
votes
1 answer

How do I set a value as an Icon?

I have a problem. First I'll show you a small code excerpt from my Minesweeper game I'm making. lbl_grid[mineX, mineY].Text = "*"; Now, what this does is it sets a mine in my grid to look like a *. What I want instead is for lbl_grid[mineX,…
2
votes
3 answers

How Can i target one of my pictureboxes created on runtime? VB.NET

So basically, i have successfully randomized certain pictureboxes in a grid to contain mines, and show that mine, and for testing purposes, those mines are currently showing. What do you think I need to do to be able to say: If, you click this box…
Rick Bross
  • 1,060
  • 3
  • 16
  • 39
1
2
3
27 28