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
3 answers

Minesweeper Action Events

Is there a way to make certain event actions specific to left and right mouse clicks? I'm creating a minesweeper gui, so when a square is left-clicked it will be uncovered, & when it's right-clicked it will be flagged. I wasn't sure how to…
mdegges
  • 963
  • 3
  • 18
  • 39
2
votes
4 answers

Stackoverflow exception in java minesweeper game

I was trying to make a minesweeper game in Java, but I keep running into this error. This function sets the current square to clicked and any adjacent squares to be clicked and continues recursively. It should stop when it runs out of squares, but…
Jim
  • 21
  • 2
2
votes
1 answer

algorithm to calculate the difficulty of randomly generated minesweeper map with fixed number of mines

I'm making a minesweeper game in minecraft (never mind). I created a code that randomly places mines, displays the number of bombs around each block, detects clear and fail of the game. Even if the same number of mines were placed on a map of the…
recu
  • 31
  • 3
2
votes
2 answers

Strange bug. For loop code works fine for most values, but then appends 4 times with certain values

I am recreating the popular game minesweeper. Bombs are hidden in a grid, and where grids do not contain bombs, contain numbers of how many (if any ) bombs are connected to the grid. In order to achieve this in python, I have created a list of list…
Pyson
  • 57
  • 7
2
votes
1 answer

while loop is either crashing or not performing the desired actions - very confused

I am building a Minesweeper game with vanilla JavaScript. I have a Grid class that handles logic on the grid, a Space class that acts basically as a container for space properties, and a Game class that handles game logic. In the Grid class, I have…
2
votes
1 answer

Minesweeper board labels (beginner level)

We were given a homework, where we get a sample minesweeper-like board, with blank spaces instead of numbers (board is in [String] form) and already placed mines. What we need is to create a function, that replaces all blank spaces with numbers,…
2
votes
2 answers

JTextField appears in 2 locations when created inside paintComponent()

I am creating a minesweeper game, and what I want to do is to have a JTextField where the user inputs his name in order for his score to be saved in a file. My problem is that when I create a JTextField and add it to my Jpanel it appears in 2…
2
votes
1 answer

Minesweeper code opening the zero boxes without max recursion depth

I am making Minesweeper in Python. I have all of the code done and working, but one feature I would like to add is that when you open a tile with zero mines nearby, it opens all of the squares around it. The problem stems from the fact that if any…
Logan Holmes
  • 89
  • 1
  • 1
  • 9
2
votes
1 answer

Python Minesweeper Recursion Algorithm Exceeding Recursion Limit

I am trying to make Minesweeper with Python arrays and have successfully generated the board and the bombs. However, I am having difficulty with Minesweeper's "zero recursion". If you select a 0 in Minesweeper, it will reveal all adjacent tiles and…
2
votes
1 answer

NumPy Array: Minesweeper - substituting random items

I am at the beginning of an attempt to make a "minesweeper" game. I have an 8 x 8 array of 0's. I would like to substitute 8 random 0's within the array with the value 1 (to represent "mines"). I have no clue where to begin. Here is my code: import…
acgf
  • 136
  • 6
2
votes
2 answers

Grid Generation for minesweeper

Hi so I am making a minesweeper game and I am a bit stuck with the grid generation part. This is my code so far: from random import randint import pygame def MineGen(): mineamount = 100 grid_across = 40 grid_up = 25 mine_list = [] …
crazy_angel
  • 65
  • 1
  • 10
2
votes
1 answer

Python find closest turtle via mouse click

I'm in the process of creating a minesweeper style game using a turtle-based grid setup. I need to find the closest cell within the grid and reveal the icon located under it whether that be a bomb or a number icons. I'm not looking to make it exact,…
ruen125
  • 35
  • 4
2
votes
6 answers

How to create a minesweeper board in javascript?

I am using div elements to create minesweeper board (8 x 8 or whatever). I used 2 for loops to create the board of divs window.onload = function () { var container = document.getElementById('container'); for (var i = 0; i < 8; i++) { …
Edgar
  • 25
  • 7
2
votes
1 answer

2d-array error with the length

I am having some truble in this part of the code cols = input[0].length() ; it says to me that 1) cannot invoke length of the primitive type of int 2)length cannot be resolved or is not field. i am doning a code for minesweeper game and here i…
jay
  • 23
  • 2
2
votes
1 answer

Minesweaper algorithm solution

this is a question about this codefight callenge. The contestant is asked to check if a minesweeper field, represented as a 2D-Array is valid. Details: Each cell of Minesweeper gameboard can be: a mine (appears as 9) or a number representing the…
User12547645
  • 6,955
  • 3
  • 38
  • 69
1 2
3
27 28