A Minesweeper Probability Calculator

  Рет қаралды 8,161

Merrick Huang

Merrick Huang

2 жыл бұрын

This is a free browser-based minesweeper game where players can see the probabilities of cells being mines given the current information.
Link to website:
s3.us-east-2.amazonaws.com/ww...
Source code:
github.com/EmZeeAech/Mineswee...

Пікірлер: 41
@gungunpanda8135
@gungunpanda8135 2 жыл бұрын
nice video. can u elaborate on how to programmatically enumerate all mines patterns given limited information, like u did around 2:00? maybe share a web describe how to do it?
@Mewok
@Mewok 2 жыл бұрын
Of course! I'll try my best to explain the process in steps: First, I wrote a function that will find all of the "edge" cells (aka the cells that border a revealed number) and stored them in an array with their row and column index and a mine status equal to null. Next we loop through the edge array and recursively run another function called "generateArrangements" which determines if a cell can contain a mine or if it can not contain a mine as determined by the neighboring numbers and other already placed mines. See below for more details. generateArrangements function logic: For each cell, if a mine can be placed in that cell, then we make a copy of the edge array and set that cell to a mine status equal to true. Then we re-run the generateArrangements function on the newly copied edge array with a new mine status. Also, if a cell has the possibility to not contain a mine, then we also make a copy of that edge array and set that cell mine status to false. Then we re-run generateArrangements on this new array as well. Finally, when generateArrangements reaches the last edge cell, then it will store the array as a possible arrangement. Overall, this will create an array of all possible arrangements for the edge cells. If this is still confusing here is a crude graphic representation with an edge array of 3 cells: Edge Cell # Possibility Tree (Y = mine) (N = not a mine) 1 Y N / \ / \ 2 Y N Y N | / \ / \ | 3 N Y N Y N Y Often times a previously placed mine or unplaced mine will cause the next cell to only have one possible mine status. In this hypothetical case, there would be 6 possible mine arrangements: Y Y N Y N Y Y N N N Y Y N Y N N N Y Hope this helps!
@ollllj
@ollllj 3 ай бұрын
@@Mewok given that minesweeper is turing-complete, larger maps may use a lot of memory for all the trees?
@Mewok
@Mewok 24 күн бұрын
@@ollllj Yes, you're probably right.Was just a challenge to see if I could code something. Definitely more efficiently ways to do it though.
@matthewisabella8145
@matthewisabella8145 15 күн бұрын
This is a great video! I recently watched a video by Code Bullet where he made an optimal Minesweeper solver using probability, and I wanted to attempt to code something similar, but I didn't understand the math he used. This video explained the math very clearly for me to understand, so thank you!
@Mewok
@Mewok 13 күн бұрын
Thanks for watching! Glad you found it helpful.
@wendyzhang2249
@wendyzhang2249 2 жыл бұрын
The probability is so useful. After playing this version, I can’t play without it anymore.
@Mewok
@Mewok 2 жыл бұрын
I hope it can help you improve your game!
@vincentkim4494
@vincentkim4494 2 жыл бұрын
This video will make me a professional minesweeper player.
@Mewok
@Mewok 2 жыл бұрын
I hope it does!
@vincentkim4494
@vincentkim4494 2 жыл бұрын
WOW VERY HELPFUL VIDEO! Thank you! You are one talented student. I think you will be famous one day.
@Mewok
@Mewok 2 жыл бұрын
I'm glad you found it helpful!
@Theooolone
@Theooolone 8 ай бұрын
Awesome video! Really clearly explained
@Mewok
@Mewok 5 ай бұрын
Thank you! I'm glad you enjoyed it.
@ThePuzzleExpert
@ThePuzzleExpert 2 жыл бұрын
This is so cool, I love Minesweeper and I love having this probability laid out right in front of me! Can I ask for an increased limit to the board parameters? I've been trying to beat a 99x99 grid with 2450 mines for ages, and this tool would be a massive QoL update!
@Mewok
@Mewok 2 жыл бұрын
Unfortunately, minesweeper is NP complete, meaning that the larger the board (and the larger the mine density), the longer the program will take to calculate the probability. You may even have already noticed some delays on the 16x30 board due to this fact. Since my code is by no means completely optimized, it will struggle with larger boards, so I decided to limit the size of the grid. Nevertheless, I think that playing around with probabilities on a smaller scale may still be helpful to improve your best guess intuition which can be translated to larger boards. If I were to recommend a substitute probability calculator, I would direct you to check out one of the following other sites: davidnhill.github.io/JSMinesweeper/ mrgris.com/projects/minesweepr/demo/player/
@pranayranjan8591
@pranayranjan8591 2 жыл бұрын
Great job...
@Mewok
@Mewok 2 жыл бұрын
Thanks!
@ollllj
@ollllj 3 ай бұрын
excellent
@Mewok
@Mewok 2 ай бұрын
Hope you got some use out of it.
@lforlight
@lforlight 3 ай бұрын
I always wondered how probability worked for cells that on one side are 1 of 2, but on the other side are 1 of 3. I guess that answers that. Cheers.
@Mewok
@Mewok 2 ай бұрын
Yes, that conundrum is what made me want to figure it out!
@mrswag2874
@mrswag2874 2 жыл бұрын
This is so cool
@Mewok
@Mewok 2 жыл бұрын
Thanks, I'm glad you think so!
@pedrokrause7553
@pedrokrause7553 Жыл бұрын
Recently, I've become very interested in coding minesweeper and a solver. After watching this and other videos I've developed a very efficient solver that you could maybe implement! Essentially, I first apply common algorithms, such as "if the number of surrounding unknown squares is the same number of the square, then all of them are mines" and other ones cited in this video: kzfaq.info/get/bejne/btBnlc5_vbTcZIE.html. After that I noticed that the game can be put into a linear system of equations. Suppose the number of a square is n=3 and it is surrounded by 4 unknown squares a1,a2,a3 and a4, then a1+a2+a3+a4=n (ak is 1 if it has a bomb and 0 if not). And this can be applied to all number squares to get a large matrix. Solving this system (which I did using SymPy), the solution is given in a parametric form. Testing all possible values of the parameters (each can be 0 or 1, because each square either has or doesn't have a mine) and filtering out only those which satisfy the system gives all the possible combinations of mines. Note that this gets really efficient also because the majority of border squares is already decided to have or not a mine by the first algorithms. I am currently trying to think of ways to improve even more my solver. I believe that it would be better to break the set of border squares into groups that are not connected than to consider all of them at once, for example. Edit: I've uploaded it to github! github.com/PedroKKr/Minesweeper-probabilty-calculator
@Mewok
@Mewok Жыл бұрын
Thanks for sharing Pedro! That sounds really cool. Is there a way for people to try it?
@pedrokrause7553
@pedrokrause7553 Жыл бұрын
@@Mewok I've created a repository for it on GitHub today. I've edited my comment to include a link for it.
@kurdistanindependance5471
@kurdistanindependance5471 11 ай бұрын
2:50 how did you get the grand total number of arrangements?
@Mewok
@Mewok 9 ай бұрын
Hey, sorry for the late response. I explained it briefly at 1:34 in the video, but to expand: You calculate all possible mine arrangements around the revealed region of the board. Then, with each mine arrangement, you subtract the number of mines that that specific arrangement used from the total number of remaining mines. Then, you do a combinations probability calculation between the total number of unrevealed cells and number of remaining mines not used by that mine arrangement. Lastly, you add up all of the combinations calcuations to get the grand total.
@user-do7lb3ip9d
@user-do7lb3ip9d 8 ай бұрын
Can you make a board on which you can input data (mine and number) on a partially played game so that you an calculate probabilities at that point?
@Mewok
@Mewok 8 ай бұрын
I could... but that sounds like a lot of work. Here's a good website that does it already! mzrg.com/js/mine/probability.html
@health_doc
@health_doc 7 ай бұрын
Nice
@Mewok
@Mewok 5 ай бұрын
Thank you thank you!
@scorpiobtw.
@scorpiobtw. 25 күн бұрын
nice
@Mewok
@Mewok 24 күн бұрын
thanks!
@sisioosbisioos4483
@sisioosbisioos4483 Жыл бұрын
Which algorithm did you use?
@Mewok
@Mewok Жыл бұрын
Hi! If you mean what algorithm I used to generate the probabilities, I wrote my own. You can see a rough logic explanation in the pinned comment on how it works.
@gabrielluna6049
@gabrielluna6049 8 ай бұрын
1:49 - how did you know that it has 8 possibilities on that case?
@Mewok
@Mewok 8 ай бұрын
Well I just manual, systematically tried out different possibilities and found out that only eight of them were possible. I don't know if that answered your question tho. Did it?
@DeltaruneRalsei
@DeltaruneRalsei 2 ай бұрын
8.1 GOOGOL??
@Mewok
@Mewok 2 ай бұрын
Craaaaaaaaaazy right?
How do you solve Minesweeper?
12:41
Apple Maths
Рет қаралды 220 М.
Hacking Minesweeper to be IMPOSSIBLE
10:47
MattKC
Рет қаралды 629 М.
La revancha 😱
00:55
Juan De Dios Pantoja 2
Рет қаралды 63 МЛН
Which one is the best? #katebrush #shorts
00:12
Kate Brush
Рет қаралды 23 МЛН
The Noodle Picture Secret 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 29 МЛН
We Got Expelled From Scholl After This...
00:10
Jojo Sim
Рет қаралды 47 МЛН
4D Minesweeper (and a Python bot that beats it)
10:15
Games Computers Play
Рет қаралды 64 М.
Calculator Gaming: Minecraft
11:53
James Channel
Рет қаралды 540 М.
I Made a Neural Network with just Redstone!
17:23
mattbatwings
Рет қаралды 592 М.
Why this puzzle is impossible
19:37
3Blue1Brown
Рет қаралды 3,1 МЛН
How the Heck Do You Speedrun Minesweeper?
15:28
i am error
Рет қаралды 130 М.
minesweeper variants that get more cursed
12:03
Icely Puzzles
Рет қаралды 472 М.
Python script beats Minesweeper in seconds (30+% success on expert)
13:22
Games Computers Play
Рет қаралды 27 М.
The rarest move in chess
17:01
Paralogical
Рет қаралды 1,1 МЛН
Minesweeper Opening Strategy: Obelus' Principle
9:53
Mine Buoy
Рет қаралды 12 М.
Реальнее чем в жизни ( Bodycam )
14:10
JOHAN
Рет қаралды 768 М.