Minesweeper AI (Playing on Massive Games)

  Рет қаралды 15,608

Coding Channel

Coding Channel

Күн бұрын

In this video I show off a minesweeper AI that I built which can solve accurately very large games, using a significant improvement to backtracking.
github.com/yujinwunz/minesolver2
Not mentioned in the video due to how long and complicated it was:
Another thing to consider when it comes to combinations and probabilities, was that the probability of a combination depends on how many mines it includes. Combinations with mine density closer to the rest of the board are more likely. So all the calculations and algorithms are basically run many times over, with different mine count assumptions, so that this aspect could be done accurately.

Пікірлер: 46
@sammyskye9498
@sammyskye9498 3 жыл бұрын
Besides the low volume, this was actually a very good video!
@saro9359
@saro9359 3 ай бұрын
I hope you come back and do more this is a really great video and I'd love to see more AI playing games videos
@acidangel162
@acidangel162 3 жыл бұрын
Oh my GOD!!! This is some beautiful content. Great first video.
@theodorhar4767
@theodorhar4767 3 жыл бұрын
Clear explanation, and interesting analysis
@Noobificado
@Noobificado 2 жыл бұрын
Wow, amazing I wonder if this could help us discover patterns that are not obvious at first sight for speedrunning or something.
@childax7284
@childax7284 2 жыл бұрын
This video is great! It interesting for someone who plans to take CS after highschool. The only thing to improve is probably the volume since it''s a little hard to hear sometimes even at max volume.
@suuuken4977
@suuuken4977 2 жыл бұрын
Very interesting man! good work
@iquisitivemusic8757
@iquisitivemusic8757 2 жыл бұрын
This is great work
@dylangreen6027
@dylangreen6027 3 жыл бұрын
Great video!
@cheeseburgerinvr
@cheeseburgerinvr Жыл бұрын
highly underrated.
@abangfarhan1
@abangfarhan1 2 жыл бұрын
Nice work. In the final program, does the AI try to use the basic algorithm first? Or is it faster to always immediately use your algorithm?
@codingchannel4422
@codingchannel4422 2 жыл бұрын
Good question, It actually does basic algorithm for a couple of rounds and then does the full algorithm once, then basic a couple of times, then full once etc. The basic algorithm unlocks a lot of squares quickly, but it happens that doing it too much (even when it's not stuck) leads to jagged edges and thus very long frontiers (bad!). So actually the "smart" algorithm is run for 2 reasons: to solve ambiguous cases accurately when the basic algorithm is inevitably stuck, and to "smooth" the frontier/perimeter every now and then to keep it short.
@GeorgeO714
@GeorgeO714 Жыл бұрын
This is a very interesting video
@jonsnow7844
@jonsnow7844 3 жыл бұрын
RE UPLOAD WITH NORMALIZED AUDIO
@codingchannel4422
@codingchannel4422 3 жыл бұрын
Ok will do
@doublepmcl6391
@doublepmcl6391 2 жыл бұрын
Very NOICE!
@AlphaPizzadog
@AlphaPizzadog Жыл бұрын
In order to further optimize the AI, does it also check for the remaining number of mines when looking for potential solutions, or do your maps not have a given number of mines?
@nerdy8644
@nerdy8644 Жыл бұрын
What coding language did you use to make this AI? How do you make a backtracking algorithm?
@Daniel-fv1ff
@Daniel-fv1ff Жыл бұрын
Awesome
@huggjgfjughj
@huggjgfjughj Жыл бұрын
for advanded patterns I designed and algorithm so It searched only one cell instead of calculate all closed cells. I based It in neighbours of a number.
@madhukartemba2987
@madhukartemba2987 3 жыл бұрын
The percentage of winning at 16x30 with 99 mines is 50%?! How are you able to get 50% ?
@codingchannel4422
@codingchannel4422 3 жыл бұрын
Theres a couple of tricks! 0. Making random guesses at any uncertain juncture yields abysmal winrates, maybe 5%. 1. As explained in the video, when no mines are certain, we click on the least likely square to be a mine. (Sometimes, this isn't the best choice as there are cases that the least likely square doesn't reveal on average as much information as another slightly riskier square which would have given more clarity. But this is not implemented here.) This gets the bot to about 49-50%. 2. Not explained in the video, (but is in the code), to more accurately calculate probabilities, the total number of mines in the minefield actually make a difference. In general, perimeters with fewer mines are more probable, since they have more mines left over and therefore more arrangements of remaining mines in the remaining squares. More care needs to be taken with calculating the probability of an arrangement when there are multiple perimeters - the number of mines in each perimeter affect each other and needs to be taken care of. Doing this careful combinatorial work improves the accuracy by about 1.5-2%. In fact the average accuracy is about 52%, the video's 50% is a below-average run.
@madhukartemba2987
@madhukartemba2987 3 жыл бұрын
@@codingchannel4422 Nice!, I have actually implemented your method in C++ but was able to get only 30% accuracy. Is there a particular function for arranging the mines in the start? Currently I am using rand() to arrange the mines is it correct or the minesweeper board has a different arrangement?. And also the world record is around 40%! (PSEQ - D256 is the method name). You should publish your work as a research paper!
@codingchannel4422
@codingchannel4422 3 жыл бұрын
@@madhukartemba2987 Very nice paper you linked! I think for my accuracy it is using different rules to the paper. In mine it is mimicking windows minesweeper where the first move is guaranteed to expand (have 0 neighbours), not just safe. It does this by randomizing the grid until it finds one where the point you clicked can expand. Well done in implementing it in C++, For your implementation, I think (barring any other bugs) it will be of similar accuracy once you have the same rules about the initial click. The paper already references using the method of choosing a mine with least probability (not sure if they calculated them accurately or not) and they added heuristics on top of that, no doubt it is going to be more accurate than mine with the same rules. I think that paper is interesting! The entropy heuristic is something I though of doing but alas didn't have time. I thnk it would be interesting to use deep neural nets for large unsolved areas (when the remaining game is still too big for an optimal game tree analysis). It did wonders in chess/go, minesweeper could be next :P The decisions of the neural net could be evaluated against all possible choices with monte carlo during training, where the remainder of the game would be done with a different algorithm (faster) or the DNN itself.
@madhukartemba2987
@madhukartemba2987 3 жыл бұрын
​@@codingchannel4422 Thank you coding channel for this video, it has helped me a lot in my project! I have also implemented the 0 neighbor part but still get accuracy around 35% (must be some other bug). Anyways thanks again for the video! Please check my implemented game here! madhukartemba.itch.io/minesweeper-ai Please reply if you find any obvious bugs/mistakes!
@codingchannel4422
@codingchannel4422 2 жыл бұрын
Oh awesome! Only just saw this, I'm checking it out that's cool!
@idlowii7670
@idlowii7670 2 жыл бұрын
Nice
@jp4109
@jp4109 3 жыл бұрын
Hey man, This is super intriguing, I'm starting to do some CS passion projects for my own. Would love to learn anything I can from you. Any way I can contact you, an email?
@codingchannel4422
@codingchannel4422 3 жыл бұрын
Really appreciate your comment, and I'm glad you found this interesting! I have added my contact on my about section, it is maxwucoder@gmail.com. We can continue via email!
@sky_hawk0811
@sky_hawk0811 2 жыл бұрын
What do I run to make this work on the github?
@mekkler
@mekkler 2 жыл бұрын
Just out of curiosity, what if you set up an large array where all prime numbers are mines. How long would it take to calculate the? Probably the same, I bet.
@GambinoTheGoat
@GambinoTheGoat Жыл бұрын
noice
@jcbahr
@jcbahr 2 жыл бұрын
I'm not sure your account of the probabilities is completely accurate. We're looking for the probability of the mines being in a certain place *given* the current arrangement of the board. We can't assume the possible mine positions are equally likely. Technically we'd need Bayes' law but that might be impractical (since knowing the likelihood of the current board state might not be easy. Perhaps you could just look at the likelihood of the board state in the region though, idk.
@TmOnlineMapper
@TmOnlineMapper 2 жыл бұрын
And this also beatifully shows why Minesweeper is a bad game (in a sense). As there are boards (the bigger the board, the more likely) where you have to make a random choice. And for me this always takes away a lot of the fun of the game, knowing that no matter how good I play, there are many boards I just cannot win, due to me having to guess.
@Jacky_Lin_9487
@Jacky_Lin_9487 Жыл бұрын
Guessing is also part of the fun.
@JasonMitchellofcompsci
@JasonMitchellofcompsci 2 жыл бұрын
Have you thought about simply adding more rules to a more basic AI. Your stitching method is close to what humans do intuitively. Most things can be solved locally. When they can't a bit of near context can help. On a big board the level of complexity goes down because the probability of seeing something that can be solved locally to advance the game goes up. An example of "additional simple rules" are that on a straight run with one two in the middle of it, the mines will be to either side of the two. Knowing just three or so of those kinds of rules plus the basic strategy is enough for most humans to win the game. Storing even more of them than most humans are willing to memorize is enough to win a very significant majority of solvable games in non-exponential time. Having additional rules that produce ambiguous results produce results that are worth logging so that you can look at neighboring areas that may resolve the ambiguity (what humans do). Another thing to note is there are "firewalls" in minesweeper. Basically areas in which what is occurring in one area cannot impact another. Having the computer able to recognize those may help reduce processing.
@neopalm2050
@neopalm2050 Жыл бұрын
You can't reach perfection like that. If you looked into how minesweeper is NP-complete, you'd know how far away from the tile you are considering you may actually have to check.
@semnet3217
@semnet3217 2 жыл бұрын
2:25 this is wrong there are 12 arrangements, not 13 in the second one you listed, the upper "3" has only 2 bombs around it, so its not a possible solution
@thinkbolt
@thinkbolt 2 жыл бұрын
No more videos?
@eranbroide3003
@eranbroide3003 Жыл бұрын
Great, but in many cases you could do much better to just use a little more advanced logic rules than the basic minesweeper logic. There will still be the odd occasion where you can't apply logic rules though.
@staribusevibgd
@staribusevibgd Жыл бұрын
were there 8s?
@jiawenzhu5915
@jiawenzhu5915 Жыл бұрын
So, how to use it.
@SumBoy0nline
@SumBoy0nline 2 жыл бұрын
clickbait sussy
Minesweeper Opening Strategy: The Classical
11:51
Mine Buoy
Рет қаралды 241 М.
4D Minesweeper (and a Python bot that beats it)
10:15
Games Computers Play
Рет қаралды 64 М.
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 35 МЛН
She ruined my dominos! 😭 Cool train tool helps me #gadget
00:40
Go Gizmo!
Рет қаралды 52 МЛН
Sprinting with More and More Money
00:29
MrBeast
Рет қаралды 181 МЛН
How do you solve Minesweeper?
12:41
Apple Maths
Рет қаралды 220 М.
A Brief Introduction to Esoteric Programming Languages
21:35
Hillel Wayne
Рет қаралды 332 М.
I Made a Neural Network with just Redstone!
17:23
mattbatwings
Рет қаралды 577 М.
How Ray Tracing (Modern CGI) Works And How To Do It 600x Faster
32:06
Josh's Channel
Рет қаралды 559 М.
*SEIZURE WARNING* Pushing Sorts to their Limits
59:06
Musicombo
Рет қаралды 5 МЛН
AIs learn to WALK
20:21
Pezzza's Work
Рет қаралды 52 М.
Python script beats Minesweeper in seconds (30+% success on expert)
13:22
Games Computers Play
Рет қаралды 27 М.
I programmed some creatures. They Evolved.
56:10
davidrandallmiller
Рет қаралды 4 МЛН
How to get faster at Minesweeper
17:19
Dard
Рет қаралды 73 М.
сюрприз
1:00
Capex0
Рет қаралды 1,4 МЛН
Iphone or nokia
0:15
rishton vines😇
Рет қаралды 1,7 МЛН
🔥Идеальный чехол для iPhone! 📱 #apple #iphone
0:36
TOP-18 ФИШЕК iOS 18
17:09
Wylsacom
Рет қаралды 771 М.
iPhone 15 Pro vs Samsung s24🤣 #shorts
0:10
Tech Tonics
Рет қаралды 14 МЛН