I created a PERFECT minesweeper AI
Вставка
- Опубліковано 5 лют 2025
- Using the power of MATH and Probability, I was able to create what I believe to be a perfect minesweeper player
Become a patreon to support my future content as well as sneak peaks of whats to come.
/ codebullet
Check out my Discord server
/ discord
live QnA at 8:30 - 9:00pm every Sunday AEST
0:48
Dam, the ai found all the bombs in less than half a second. Thats really good
Not good at all. I can do the same thing faster than that.
@@puppergump4117 You mean that's not how you start the game?
Imagine code bullet making a bot that defeats captcha
its been done before but i dont remember who did it
*_DETROIT: BECOME HUMAN_*
Am I a joke to you?
Been done a tone of times, and that's usually just one of the steps for that bots task.
Mr Guest god TOO MUCH SCIENCE TO MUCH POWER
It's fun seeing how his channel went from explaining everything like a tutorial channel to half of his vocabulary being "I can't be fucked"
nahhh I just cant bc this video is so funny why is he why its so funny hes just being mr tutorial man the professional. its so funny it's so normal the editing is so average along with the dialogue and it cant be. did i just hear him say walla in the backgroung noooo
And now he has a good mic
I was gonna raply but I cant be fucked. Oh, wait...
I like how he drew Mr. Perfect Cell.
let's remember the one time he called an AI "perfect child" and not "abomination".
There's always a favorite
Road roller da
@@BravoTuneAlpha no u
He tryna get on their good side in case a revolution starts
Dude this is cool and I play minesweeper on my channel!
This guy turned minesweeper into mindsweeper
This comment is underrated
why is this comment under-rated
Ohhhhhhhhhhh good comment
Hate to burst, break, and bust your bubble, brick, and balls, but this comment is not underrated.
this comment is really good and i want to like it but it has 666 likes so i am sorry dude
Difficulty in minesweeper isn't determined by size, but by density.
Minesweeper*
@@manegar9990 effing autocorrect!!
Magnus Larsson yeah but a bigger board means more times you could mess up or get unlucky
@@aidenheiber8726, not really sure what you're referring to. If you mean 50/50 klick chances they also increase and decrease based on mine density and not size. If you look at the last example given, the large 64x36 it has less mine density than the original small one. But sure, with a larger board, the figurations can get more tricky. But it still less likely when as in the examples given the mines are miles apart.
Try 32x24 with 256 mines, I've been trying to beat it for half a year.
You just taught me how to play minesweeper. I never got past clicking and praying.
Ditto
@HeavenStito - ROBLOX cause mine didn't come with stupid instructions
@@AMPMASTER10 but... wouldnt you be able to understand how to play it if you play it long enough?
@@timtams_6 if I was really interested in it like a difficult but fun strategy game with a good story, then yes. But I thought it was wired n only played for a few min at a time before quitting
@@AMPMASTER10 heh... minesweeper as a strategy game with a story
One flaw in your ai
When it comes to a 50/50 situation, sometimes one of the guesses tells you more information.
true
That is true.
To clarify, let me give an example: a stranded few boxes in the middle of cleared squares, or a box in the middle of the main area of squares, both with the same odds of being a bomb.
The ai sees these as equal. However, the one in the main area is actually a much more valuable data point as it helps you to solve many more squares than the other if not a bomb.
I mean, a bigger tho related flaw is its search pattern is rather slow and often bounces between places rather than focus on an area to clear it and then move over to another area. It is wastin precious seconds even when certaintys are at 100% for many spaced.
Ofc, i am assumin speed is what matters; cuz thats all that shows up in high scores after all.
And if we're talkin speed then the time to beat is 31.133 seconds; on Expert.
@@SylviaRustyFae watch the follow up video, he slowed it down for the video, so we could see what the AI is doing.
@@DougSalad But its still jumpin all over the place even if it does it at near instant speed, those tiny amounts of time wasted do add up. Particularly when multiple squares have similar odds but it picks a square much further away.
Plot Twist:
Code Bullet can't code and is just really good at minesweeper
I feel like you are on every one of his videos like i swear i saw you on the piano tiles video eh
Have a good day
You actually do not need any skill to play Minesweeper. You just need to understand the rules.
@@damienbailey227 Yeah, i think so to
@@Linuxdirk Minesweep is a challenge of speed; it's not a game of success or failure.
Lol
I used to make 500 by 500 custom maps with only 10 bombs and win with one click
@Scarce-20 yes i agree
I'd like to see him try his AI on hard
Me: *clicks on a bomb on first move*
@@jackwoodhead its impossible, the game is coded so that the first click is never a bomb
i dont think so... if one-shot-died many times
k"CB: We're gonna have to use a little bit of maths and probabilities."
Me: "Oh yeah! I'm all about maths, and I especially love probabilities!"
CB: "Wait, don't click away! We can make things interesting."
Me: "I feel so attacked right now..."
ME
10/10 can relate
Same
I want to learn to like math but I’m not good at it so.
ye
Me: "Mom can we have AI?"
Mom: "No we already have AI at home"
The AI at home: 0:47
my ai at home 6:13
@@Kadencabs My AI at home: Litterally just terminator
my ai at home: 4 + 2 = 7
My AI at home:
0:57
ai:2+2=7
This guy is like mumbo jumbo but with actual coding
Nah, mumbo can't keep his logic straight, he always misses something
No mostly because "it's simple really"
Actually alirion Is right
More like Ceave Gaming
More like sethbling
When I was a kid I taught myself how to play Minesweeper (I didn't have internet don't judge me) by lowering the bomb count and increasing the grid. Then I increased and decreased both respectively as I got better and better at the game. Hell it beat playing solitaire for the umpteenth time
You are amazing
Did you get to the point where you could beat a regular expert field?
Doesn’t the game have a guide in the options to teach you?
Man same but i learnt solitaire after minesweeper
Code bullet: I hope you enjoyed watching my AI.
UA-cam’s Subtitle AI: I hope you enjoyed watching my eye.
Leo Sevilla my eye!
The subtitles don't use an AI
Onat Akosha The Third “auto generated” dumbass
@@Subscriberswithnovideos-en3lw Ah yes, AI stands for auto generated
Onat Akosha The Third but an ai progressively generates stuff
If:going-to-touch-bomb
Then:don’t+flag
CODED
If: game-started
Then: win
using System;
namespace l33tsweeper {
class Program {
static void Main(string[] args) {
while (true) {
flipTile();
if (touchingBomb) {
dont(); // Hire me Microsoft, i'm ready!
flag();
}
}
}
}
}
E
E
@@SoDamnMetal you forgot
if (!touchingBomb) {
click();
}
This video taught me how to play minesweeper at last!
How do you not know how to play minesweeper?
Same hahah
I knew before the video even. Really not that hard. Numbers mean how many bombs it is touching. Blanks are 0.
Out of all the specific guides to how to play minesweeper, this unintended guide is so far the best haha
You mean it taught you the math tricks it takes to win it, yeah? To the extent you can, of course. So many times I've played minesweeper to clear everything except a 50/50 pair, with no indication of how to play except to guess.
*That moment when you click bomb in the first move*
but you can't
Yes you can
@@dustincoon2032 no. First click is never a bomb. If you make a 10x10 with 99 bombs, and click randomly you always win. I learned that like 25 years ago
@@dustincoon2032 Only on certain apps/online versions that are not the original is that possible. The original minesweeper is hard coded to generate every tile 'after' the first click, and the first clicked tile can't be a bomb... HOWEVER, your first click CAN be a flag, then the tiles are all generated, and you can click a bomb without getting any tiles correct, but that's the only way in original minesweeper.
*insert "lion sleeps tonight" beginning*
Found a flaw. At 4:48 it randomly chose an edge piece. While mathematically the odds of it being a bomb are the same, the odds of it openning a gap of spaces is lower. Random selection should default to a space as far away from edges and known squares as possible.
Nice catch
John Richardson what
@@teoteoteoteote It was asserted to be "perfect" but at that point made a statistically poor random choice.
John Richardson oh ok
Well actually every game has a set amount of bombs, if it is the last square left but not all the bombs have been flagged then the space would be flagged as it would be the last bomb, if all the bombs have been previously flagged then it’s simply an empty space
It would be super cool to see the A.I. leave behind a little fraction on each square that he chose, so we could see the probability. If you then plot the percentages, you would have a nice little graph of how hard the game gets for your boy towards the end. 👍 Bravo man, you are awesome.
Next from codebullet an ai the does math homework perfectly =)
Try Wolfram Alpha.
Also, integral calculator
well that's easy
that's called a calculator
No, you need a human factor for you to not be spotted. A few 90s here and there at least.
“The perfect AI”
**AI immediately clicks on a bomb second turn**
Well yeah, because in that case there was no better option - mathematically speaking.
1st of all you're being sarcastic right?
If you ain't then, imagine this there are 2 cups upside down inside 1 of those is a chocolate bar and the one who arranged it was your mom they are placed on the table, now your mom asked you to come to the living room and guess where the chocolate bar is, now you have 50% chance of getting the bar, now imagine that with 10000 cups that's minesweeper, and btw the first box you click is a guessing game.
@@simonforsberg3757 I get what you are trying to say, but what you are saying is simply not true; i.e. there was a better option.
(Choosing your first box has nothing to do with math by the way. With no leads there is nothing to calculate)
The word 'perfect' is really the wrong word to use here. It implies there is no room for error, i.e. if the AI was 'perfect' it should win 100% of the time.
But a game of chance cannot be won 100% of the time, so there is no 'perfect AI'. It can still be a great AI though...
@@Rayzan1000 My definition of "Perfect Minesweeper AI" is simply: Make the best possible move with the information that you have. In which case, taking a bomb on the second move when the first field revealed was a 3 is perfectly acceptable.
Choosing your first box has a lot of things to do with math, you have to think "What if it is *not* a mine?" in which case one could argue that picking a corner is the best move as that has a higher probability to be a '0' and create a bigger open field.
*Directed by Robert B.Weidy* 😂
*M A T H* and _PROBABILITY.._ made it very interesting to watch.
How do u do slanted words
'Hi'
Brooke D
_I dunno_
_wow_
-dude-
I was today years old when I learned that the numbers actually mean something in minesweeper.
1980: I bet you there are going to be flying cars and a cure for Cancer!
2018: I created the perfect Minesweeper AI.
Speak for yourself, this video actually cured my cancer.
Ehh potato potahto.
In Canada, they have the cure but the government won’t release the cure because they’re afraid they won’t get any credit, do maybe if they release it then our population won’t be so low for our size, the population will grow at a better rate Atleast
2118: I bet that the earth was not dying!!
Im a disappointment
3:43
No, you.
No he is right
*Reverse card*
Gabriel Barbosa He said "your mom gay" instead of "ur mom gay" so I'm following the trend.
*MIC DROP*
you mum gay
6:13 when the minesweeper is sus!
😳😳😳😡👎👎👎👎🥺😟
A piece of code:
Coding Bullet: "Look, an AI"
Me: The perfect minesweeper AI doesn't exis-. The Video:
Jesus Rodriguez no likes? let me help you :)
Me: There is no most unoriginal comme-.
Me: I regained my faith in humanit-. tHiS ComMEnT:
Me: Ah there will be Normal Commen- These Comments
Me: the perfect meme-killing comment doesn’t exis-
I once created a game called Gossip that was a cross between Clue and House Party. Five guys and five girls all hooked up with somebody at a party in five different rooms, but the morning after, nobody could remember who they were with. Like, Clue, everybody had one random bit of information about who somebody was not with. "Emma was not with Alex", or "Alice was not in the Closet". etc. The challenge was to fill in all the blanks based on interrogations of things everybody is sure didn't happen. If Emma was not with Alex, Billy, Chris, or Danny, then she must have been with Eddy. If Eddy was with Emma, then he was not with Alice, Beth, Cathy, or Dana. And so on. Process of elimination.
So then I had to code the computer AI to try to beat you to the punch on their turn. Oh, man. It nearly broke my brain. But I got it done based on a few rules of inductive reasoning. Then, when I added a recursive function to loop back through the logic tree after every new bit of information was uncovered, I found the AIs were way smarter than any hungover college student could ever be. Some of them cracked the case with only six or seven clues. So then the problem was not how to get them to solve the problem, but to get them to believably fail sometimes so there could be a "Easy" difficulty.
I never did release the game because of issues around alcohol and consent, but it was fun to build.
so many things wrong here.. like what made you think it would be difficult to be smarter than a hungover college student ?! and what did you put in their drinks to make them forget who they hooked up with ?! and most importantly... who the fuck tried to put alice in the closet?!?!?!
This is the challenge most AI devs have to deal with. Making the AI is challenging enough, but staging it in different tiers is the really challenging bit.
How do you dumb an AI down? Well, that's different for each situation.
And it is often far easier to make the "perfect" AI than to make a challengingly easy AI.
Orgy
Imo it's OK to a game/piece of enternainment be a little fucked up if it itself realizes it (and warns about it) and doesn't fantasise it. (In most cases the purpose would be comedic):
For an example Monopoly pedo edition would be fine. (Adults only of course)
@@metawarp7446 makes sense.. but in the current politcal climate, context isn't ever taken into account
One day he will upload a video titled: "Creating Skynet"
Minesweeper. How to win
Width: max
Height: max
Bombs: 10
Weak. Prove yourself with 1600 x 900. 1,439,999 mines.
@@RFDN0 It's unable in classic minesweeper from windows 3.1-xp
@@justarchive789 Honestly last played minesweeper as a kid on windows 95 and lost many times with a set up like that.
@@RFDN0 that would completely fill my old laptop's screen pixel for pixel, interesting if that could work
I never even figured out how that game worked.
I still don't understand. Even after watching this video
If there is a 1 it means there is only one bomb around the piece. If there is 2 it means two bombs and so on
look it up on wiki
it'll tell you all you need to know
+1
minesweeper, aside from the occasional 50/50 chances you have to take, is the easiest video game
plot twist: the recordings shown are actually ones of him playing sped up
double plot twist: the recordings are him playing at his actual speed without any modification
Triple twist: It's slowed down footage of him playing subconsciously and he really believes it was his program doing it.
quadruple plot twist: This has been the case for all videos on this channel.
quintuple twist: all his videos are made up in your mind and your dreaming while watching the videos
Algorithms like these don't take a lot of processing time. The only reason it takes so long is because he deliberately set a mouse speed limit to make it easier to follow.
You can make a better AI: To make choices of equal risk: (like the first few moves) have it prioritize the move that will give it the *most information* about the rest of the board. I wrote an AI very similar to this one to solve the "Thrill Digger" minigame in Skyward's Sword, and increased it's win rate significantly by giving it this secondary priority. (It had the Third priority of picking the square that netted you the most points in situations where they were equally risky and equally informative; but moves aren't assigned point values in minesweeper)
I like this! But also I feel the programing should incentivize clicking on the nearest certain safe spot to speed up the process. There were several times in the video where the computer would go back and forth across the board/field to click on knowingly safe spots.
I'm talking about the situation where you get two places where you have two equally safe moves. Obviously if there are two places it knows are safe then it will eventually click both of them-- so it wouldn't matter. But lets say there are two (or more) places that each have a 20% chance of blowing up AND those are the spaces with the lowest chance of blowing up. It's better to pick the spot that gives us a higher chance of winning in the long run. We can both agree that emulating an entire game in this fractal manner would be incredibly slow, (unless you're on a super computer) but what we can do is choose the move that is most likely to reveal the highest number of safe spots, as one way of implementing this idea of "information". There are other ways to implement this but they take longer to explain.
This matters the most during the 2nd through when it gets its momentum. As said in the video, once it gets its momentum it's good. The goal is to get momentum faster, so it spends less time in the dangerous state, where it has a very real chance of losing.
Sorry I like explaining things and get a little excited when I get to.
DoomMustard I get what you are saying and I agree with you. I was saying that in addition to that, having it clear out one section of absolutely safe spots before moving on would also speed it up. It spent most its time moving the mouse needlessly back and forth across the field.
Daniel Copeland: I realized that after I finished typing it, but I spent so much time typing it.
Hense the "sorry" right after
LOL I used to play minesweeper as a kid in the 90s
You just progressively made it easier for the bot by increasing the size of the grid
with the same number of mines
I don't know that many people know this, but did you know that clicking the left and right mouse buttons at the same time has a unique action in Minesweeper? If you click on a number and that many mines are already flagged around it, all remaining unflagged squares are simultaneously clicked. This may speed up your AI a bit.
No one will care or believe me, but I genuinely believe my brother is faster then this AI and this being a big part of it. On the largest size with easiest settings from memory he used to average less then 8 seconds, with 3 seconds being his fastest.
He used to play so much minesweeper, its actually ridiculous haha.
Trent 88
3 seconds??? You gotta show us one dude!
It's called chording, and the best minesweeper players strategically use this function only when it is quicker to do so, otherwise they just don't flag the mine at all and just click to reveal. Because the win condition is not to flag all mines, it is to reveal all non-mines. Also note that there's a trick you can do where you hold down the flag click and drag to the chording tile and then finish the chord click. It saves you almost no time, but since you don't have to let go of the right click and then click it down again, it is marginally faster for incredibly fast players. And for these fast players the only thing slowing them down is the speed that they can click and move the mouse, so it's totally worth it.
World record is 32 seconds on expert > www.minesweeper.info/wiki/World_Record_History , 8 seconds is likely impossible for any human being.
Edit: unless of course you meant that its restarted game with known position of the mines, that might be doable..
"largest size with easiest settings" sounds like custom game size and mine count to me. If you do the max size and minimum bomb count you can win in 1 click if you're lucky. I don't think they really know what they're talking about when they say 3 seconds is the fastest.
This AI still isn't very fast though, for an AI. It's easy to see how inefficient it is just by how much bounces back and forth between the right half and left half instead of sweeping across it, or even just staying on one side until it's done.
This one is fast: ua-cam.com/video/ON7rc-koLfM/v-deo.html but doesn't win 100%. It wins an expert game in 2 seconds, so watch that and imagine this dude's brother being able to click that fast lol (he runs it at "human speed" first and then speeds it up at like 1:15)
Am I the only one who keeps on getting recommended old videos from him?
Even when you think you binged them all somehow there is a new old one which you have never seen.
... Has Code Bullet hacked time???
He did that a few years ago
...or is it a few years from now? I can never keep things straight with time travel
Same
Since you liked the newer ones, you get the older and thus more irrelevant ones
And also, they are probably just not exactly fitting for you from the AI algorithm. It's a robot, ya can't blame it that much.
Meeting too, watched all of the new ones then these just pop up lol
Man, this channel really evolved over time.
(5:20) Technically, you don't have to divide it by the number of probabilities there are. You don't need a percentage. - After checking all the probabilities, you then click on all squares with a total number of 0 boms on them. Then do the calculation again, and if there are no squares with 0, you click on one with 1, then do the check again. Repeat and always click on one of the lowest numbers, unless it's 0, then you can click them all. - Dividing by the number of probabilities checked does gives you a percentage, but percentages requires float values, compared to integers who only requires integers. Floats are slower than integers (but processors are made to handle floats faster, because people overuse floats), and floats also have rounding issues, and doing the division is an unnecessary processing step.
Addendum: by also marking all the squares that got the same number of probabilities with bombs in them as probabilities checked; that is, a square that has value 83 and there were 83 boards checked, that means the square has a bomb guaranteed, and can be flagged. Still no need for division here. This means you have much less squares to test for the next time, increasing the processing power. So after an _n_ amount of tests done, click on all squares with value 0 and flag all squares with value _n_ and for all squares with values of 1 to _n_ - 1 are ignored. If there are no squares with 0, click just one random one with a value of 1 and run the code again.
Can you explain the formula to me? I understand what you're saying but I couldn't understand what formula CB or you used
@@DezXereanas he basically just counts how many possible layouts of bombs have a bomb on a certain tile. If you divide that by the total number of possible layouts you get the probability of a bomb being on that tile in decimals.
@@DezXereanas (Sorry for being late). I'm not sure what formula CB is using. I'm just commenting on the fact that he said division. You don't need to divide, to figure out that the probability of something that already has 0 as its value. So you simulate all possible bomb placements, then for all squares that never could have a bomb are guaranteed safe.
the difference in speed from floats and integers is so minuscule and circumstantial that its basically hardly a point
Same with dividing numbers: basically almost no processing power needed. The biggest clog in speed of this program is gaurenteed to be inputting the results as mouse movement and clicks
@@Liggliluff Yeah sure, but then you're forgetting that there are times where it isn't guaranteed, and then you need probability
Funny story. All the way into my teenage years, I didn't know how to play minesweeper; I didn't know what the numbers were for. I just thought it was a game where you randomly revealed squares and sometimes there were mines underneath. I hated it since I thought it was based on pure luck and was practically unwinnable... One day it hit me that I might have a few misconceptions about the game, and I was able to logic out how to actually play it.
somebody should make a film of your story.
Same, I thought it was the worst game ever, never really thought too much about it, it was just a free shitty game that came with Windows lol
0000 Huh,that's funny
Press f1
Same i hated it because it looked unbeatable but then i figured out.
3:48 bottom left
Pokerxs it kinda looks like a face is that what your saying
Sonofwolf628 lol it says your mum gay
No u
Pokerxs no u
fuck you guys lmao
Code Bullet: Here's my perfect AI
Also Code Bullet : *Gives an hardcoded solver*
this comment is underappreciated.
@@matteoar ikr
But it is an AI.
@@sea81793 Well, no.
An AI would learn by itself how to do this, the ability to autonomously learn from data and improve without having to change its program code defines an Artificial Intelligence after all, while he wrote every possibility and the best way to solve it.
It's, as said, an hardcoded solver, a really good one at that, but it does not define as AI.
Matteo A. I understand what you’re getting at, but your point is a product of “machine learning”. Machine learning is a form of Artificial Intelligence. It is capable of learning on its own(within parameters). Code’s minesweeper program is also a form of Artificial Intelligence. While it may not be self-learning...it is still able to achieve its goal through the knowledge it has been provided.
medium.com/axiomzenteam/what-most-people-dont-understand-about-ai-and-the-the-state-of-machine-learning-ed007a987108
lmao that audio quality. I'm glad it's here for prosperity, and I'm glad his mic improved over the years.
Who’s talking to me through the washing machine
Dude someone is talking through a toaster
hahahahahha 🤣🤣🤣
Maybe it can get better, if by better you mean "completing more games per hour". You can probably optimize and make it faster, but in terms of changing the logic, you could look at situations where it at some point HAS to take a chance, like if there is an island that can't be completed unless you pick a square with less than a 100% chance of not being a bomb. In that case you would be better off taking the chance right away and fail fast if you have to fail at all, rather than putting it off until the last moment.
well actually it could end in a situation where there are more/fewer bombs on the board and therefore the chance changes - if it waits longer it has the best idea
There are such cases where you already know how many bombs are in the island, so the rest of the board truly can't give you any more information.
This is likely slowed down so it's visible for us to see. The computer probably can complete it in milliseconds.
(From a former addict.) It is a simple matter to play perfectly logically, so the game really is about racing the clock. The trouble, when it arises, is in clearing out the last of areas, when you can arrive finally at 50/50 gambles. So the most efficient play is always to try to finish areas completely so that if you are going to lose on a forced gamble, you find that out before wasting time doing the rest of the board.
This flaw in the game is why I kicked the habit - as opposed to rewarding the player for getting better, the game ultimately punishes you. It always bothered me that it would have been a simple matter for the game to be programmed to check after the random mine placement, and scrub matches that could only be won by chance.
For probabilistic minesweeper complexity, see: arxiv.org/abs/1204.4659
The short of it: it's extremely hard, harder than solving np problems or simulating quantum computers. Widely believed to be impossible to do perfectly, but perhaps it could be approximated closely.
I lose 99% of my mindsweeper games cause I misclick WAY to much
No one realized that he said mindsweeper instead of minesweeper
*minesweeper
*misclick
*too
Oh yeah, a typo will get you blowed up quicker than anything
@@keenankersh7944 Thanks! English is not my native language, always happy to learn new things.
I'm the same
You should revisit this. Room for improvement include having the ai focus on one area at a time to reduce travel time and the utilizing the double click trick: if you left click and right click at the same time on a number that has all its bombs flagged it clears all remaining squares that are touching it.
It’s 3:00 am. Who needs sleep when I can listen to that soothing voice.
2 am here, I agree
Cola BotelsOVA 3:11, I’m closer
Wilson Liang Funny thing is, it’s 3:00 over here as I’m writing this
i love how it's only been a year and your editing skills and mic quality have improved 100 fold
You should have added more bombs.
every single square are bomn and left one space square so no one can win it
Tom Tang: Actually, that'd be a instant win. The first tile you click on is guaranteed not to be a mine, so if there was only one square that wasn't a mine you would've already clicked it.
Mu'izz Siddique, that's not true.
Load up Minesweeper on Windows (most people are ever only talking about the Windows XP/Vista/7 version, there's one on the Windows Store by Microsoft) and make a custom game of 10x10 field with 99 mines. Try it.
Don't play shoddy ports made by first time developers who are still learning to code.
Mu'izz Siddique, maybe you're right on the newest version. In Windows 3.11/95 it was possible to hit a bomb on the first try.
It's so weird not seeing the talking tv head man.
Sometines Minesweeper generates maps which just can't be solved with all of these rules. So your AI would just rely solely on probability. I'd recommend adding another rule: If we solved everything that we were 100% sure in and now we're left with space which can't be solved with our rules => calculate where the bombs that are left have to be.
We got the exact number of bombs left and the "unsolvable" space. Yea, in some cases even this wouldn't work, but solvability percentage will rise and the AI will be even more PERFECT.
P.S. well... it would be kinda hard to implement this I guess...
Would've been a bit more interesting if for the larger maps there were more bombs, good video!
jeez, coming back to OG code bullet is a trip.
Maybe in the year 2560 humanity will invent a robot that can beat the I’m not a robot check
What if you _combined_ hard-coded rules *with* neural networks and genetic algorithms, not only so that it can never lose on increasingly large boards, but also play at an increasingly faster pace.
So it wouldn't just be a perfect Minesweeper player, but a Minesweeper _speedrunner._
One useful technique to teach it would be "1.5-clicking" as well as some no-flags techniques.
And maybe throw some raycasting in there just for the sake of over-engineering it~
over-engineering sounds like the last thing Evan would ever do
theres no way to get better than polynomial time anyways since its a NP complete problem. Best implementations (without any mistakes possibly occuring) is sub exponential at best.
You should make it check the squares closest to the cursor at any given time that way it would reduce the time taken
Im a disappointment
It should avoid clicking any box unless it has a 0% chance of being a bomb. Clear an area, no 0%s, move onto a different area. Odds are, it'll attack that area at a different angle, or eventually work its way back to that area and clear some tiles that adjust the initial probabilities.
Best of both worlds.
@@AnaseSkyrider it would never get past the first few clicks if that was implemented
@@AnaseSkyrider It already does that
ENXJ then just click the square with the lowest possibility of a bomb if not zero
pause at 3:44 and look towards the bottom left of the screen
MushyCrabs no u
No u
ToMany Knifes
Yes, because we can't see it witout pausing.
No u.
Look at the righr side
This has been sitting in my "Watch Later" playlist for TWO YEARS, ever since it came out! I'm so glad I finally watched it
it's really really good but it's not perfect.
the first move shouldn't be completely random, even though all the squares have the same probability of containing a bomb. The corner for example would be a bad move, because in the case that it isnt a bomb, you wouldn't gain as much information about other squares. I imagine that similar but more complicated decisions issues would exist once the game is in progress where multiple squares both have equal probability of being a bomb, but one would give you more information, and therefore give you a higher probability of winning the game.
it's really good though.
Underrated comment! I like your way of thinking :)
Thomas Ritter Thanks, Thomas!
Actually I always start with the corner in minesweeper. You have a much higher chance of opening a patch with useful information as opposed to a single number which doesn't tell you anything.
That's an interesting point! Is there any data about that or are you judging from experience?
how many games of minesweeper does it take for experience to become data?...the first square you click will never be a bomb, so starting the game on a corner both ensures there is no bomb there, and solves one of the corner squares which has a high chance of a 50/50 choice since there are at most 3 squares providing clues about its status...that being said, you will not likely be able to solve the whole board without having to make subsequent guesses elsewhere, hopefully opening a patch to end the guess work for a moment
Hey Code Bullet,
I'd like to hear more about how you calculated the bomb arrangements for the probabilities. I made a Minesweeper AI myself a little while ago (no video, just a personal project) and I found that part to be extremely difficult, especially considering that the number of arrangements can reach into the hundreds of thousands even on a normal expert level board. I'm curious if our methods of solving that problem are similar since the math can get kinda tricky.
Same I'm writing and report on it. Also what version he is using? Here is a presentation explaining what MathAndCarnage is talking about. It is written by the guy who proved it is impossible to find the perfect algorithm. web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf
My suggestion would be that all squares with no information about them are equal. So if you have a 1 as first you know there is a 1/8 chance for those, and the rest have (m-1)/(x*y-9). m i mines, x,y are the size of the field.
if m is sufficiently high, this is more than 1/8 and we can pick any of the adjacent squares.
But, the tricky part here is this:
Does it matter if we pick a corner or a side?
---
And what about the first move, should that be a corner, a side or in the middle of the field?
They all have the same probability for a mine, but if they do not, what are the odds we gain useful information?
And I have a suspicion this solver does not take those things into account, and thus I have proven that it is possible to create a better solver for mine sweeper.
One standard size in timing for the minesweepers world records is 16x30 with 99 mines.
This means the base odds for a mine is about 1/5.
For a central position, there is a 1/5 risk of a mine at each of the nine positions, however, strictly speeking they are _not_ independent. If there is a mine on the top left, there is a 98/480 chance for one in the next, if not, the chance is 99/480. But if we ignore these small changes (thus making our solver worse) there is a 13% chance to get a 0 (which automatically expands, or we can expand with no further thinking).
For a corner, there are only 4 squares to consider, so the odds of getting a 0 is about 40%. Of course, a 1 means the surrounding spaces has 1/3 of having a mine, sp we are much worse off in that case.
What are you guys coding it with? C++/Js?
I'm coding in Java using Javafx.
Also @57thorns first click does matter check out this www.minesweeper.info/wiki/Strategy#First_Click
Yeah I know that code and math on a screen may not be the most mesmerizing visual but it is certainly fascinating stuff and I was very disappointed when the video just kinda skimmed over what I thought would be the interesting stuff.
Also would be kinda neat if it could be optimized to win as many games as possible as fast as possible by taking into account how much information is revealed with each click. Sometimes taking a risk just doesn't tell you anything about an area making even a low bomb probability a bad choice over a slightly higher risk but much more informative choice.
The idea of doing it through probability is actually genius
I picture the Super Saiyan 3 transformation dialogue going on during the end "crushing." :)
And this is to go even further beyond!
On my deployment I spent the majority of my free time playing it. I got really good at it. I found every time on the largest scale though, there is always a 50/50 click that determines your win or not, at least on the original.
Honestly I didn't know you could flag bombs in minesweeper so this video happens to be very educational for me.
Geez did you just mark the bombs?
Pi no i just tried to remember where they were located
@@herohuntr same i never knew you could flag them, i just click and avoid bombs haha
Hero Huntr I’m not the only one.
if u use linux like i do, then [sudo apt-get install xbomb] installs minesweeper
"It's simple really"
I knew it CeaveGaming is Code Bullet!
Devon Rogers yes
Hooray!
ITs actually, surprisingly simple... *goes on for a full video.*
Your code helped me out on the spots that cause me the most problems. I obviously can't do the probability solving your code can but you taught me how to treat two squares as one which is something I never considered before.
Title should be "I created a minesweeper algorithm."
Textbook definition from wikipedia: "Leading AI textbooks define the field as the study of "intelligent agents": any device that perceives its environment and takes actions that maximize its chance of successfully achieving its goals." The agent in this video certainly qualifies. Also, every talk I've gone to about machine learning has clearly made this point: the modern self-learning neural stuff is called "machine learning", the term "artificial intelligence" is a much broader concept that includes hard-coded algorithms. That should be enough, but I'll also point out that in most computer games where you playing against "an AI" or "the AI", as is very commonly said, those AIs are almost always hard-coded. Very few computer games having neural-net-based AIs. So as much as you might want to argue that Code Bullet's bot is not AI, you're at odds with the definition used across most academic literature as well as common vernacular, which is about as close to being "wrong" as possible.
Finally my uncle who is bored with his office job every 1 hour before leaving hour can now see the end of minesweeper
the difference between this and current vids are insane
As someone who can't even solve a 10x8 grid, seeing an AI of all things solve a 64x36 grid makes me kinda contemplate life.
4:48 for the skip
thanks
Whats the song thats playing at 4:48 ?
Well it's not AI then, it's an algorihm.
LocatingGoku That’s your opinion.
Vulcan not even an opinion lmao, that's fact
If that isn't an ai, then what exactly are enemies in video games? They don't learn and get better...so if those aren't ai, when what are they?
A.I. Stands for Artificial intelligence. The term was specifically created to help search for "a computer program that was more than just an algorithm or list of instructions." So LocatingGoku is correct.
and it's not perfect
still a more accurate title than Trump tweets tho
Today: A.I. becomes a perfect Minesweeper.
Tomorrow: A.I. becomes a perfect *_Populationsweeper_*
i dont even know how to play minesweeper normally
Spirited Spy Basically the numbers mean how many bombs that square is touching. A bomb can be up, down, left, right, and diagonal. If there is no number there are no bombs around it.
don’t click the bombs
@@pewpewsalote8802 ok then what are the flags
@@petelee2477 they mark bombs, i think
Wait it can be more funny :
*When you don’t even know how to play mind sweeper in the first place*
The best minesweeper player ever?
*Kamil Muranski:* Hold my beer
It's funny how many people here claim that this is not an AI algorithm. But the fact is that search Algorithms which use heuristics like A* are already called AIs. This program is clearly not machine learning, a minmax-Algorithm, a sat-solver or a neural network but even those are just fields of the discipline which is called AI.
The only reason why I would disagree with that being an AI - if I had to (which alot of peope seem to do, lol) - is that it is very specialized and doesn't use a general AI algorithm. This weak argument is the strongest argument against that being an AI. So why disagree?
THANK YOU. I’m getting triggered reading all of these “that’s not an AI” comments with tons of likes 🙄
I once worked on AI for a console game. Compared to this video, the algorithms we used were simpler mathematically, and slightly more complicated software wise.
The bots were not too intelligent. In some edge cases they were quite stupid actually. However, the “AI” term is widely used for algorithms controlling NPCs in videogames. Just search “AI programmer” and you’ll see half of the links are related to game development. Videogames don’t do deep learning. One reason is games have better things to do with the GPUs. Another reason is game designers want to design player experience, so they want to control AI behavior for that. Deep learning kind of AI essentially does whatever it pleases; it’s hard to design good player experience on top of that.
AI is learning hence the term ML, this doesnt. The whole idea is no or utility only hard coding. As Geohot said: if statements kill ppl. Now it might b that in Unity or Game maker u find a* pathfinding under AI tab, but its not actually it, AI is ML, in game development u mostly simulate an itelligence, thats why u all r so confused.
Its an awesome program but think about this, if this is AI then so is any modern fusebox.
As John McCarthy, who coined the term “Artificial Intelligence” in 1956 said: “as soon as it works, no one calls it AI anymore".
If a intelligent person stops learning, is that person no longer intelligent?
Machine learning is just a subfield of artificial intelligence, but indeed a crucial one.
0:38 dang cell not only stole piccolos regeneration, but his minesweeper app as well
4:47 is when it starts.
Daniel Gonzalez thanks bro
Thanks bro.
u r lifesaver.
Thank You!!! When I saw skip to ??? I knew my savoir would be in the comments
0:00 is when it starts if you have an attention span longer than a gold fish's
Maybe a revised version might help soldiers in the field... Or not...
the minesweeper game needs to know where the bombs are, a critical bit of information not available in the war zone
If you can find the solution in polynomial time, it might. (Well, and you'd be filthy rich.)
Because Minesweeper is NP complete. sed.free.fr/complex/mines.html
What? You mean in actual war zones, the dirt you're standing on doesn't tell you how many mines are around you?
At 5:35 to 5:45 it leaves a big line at the bottom, which it later solves. What is the reasoning behind this?
Is it just always doing rule one until no more rule one is possible and so rule 2 and eventually rule 3???
xchiltonx
Those lines have no tiles with a 0% chance of not being a bomb.
I just realised that my last sentence is kind of triple negative.
"generate all possible bomb arrangements" - doesn't that lead to a combinatoric explosion?
There are many ways to get around generating all combos for the the entire map at once. You would have to be insane to do that. It's simple: only generate all possible combinations for 5 tiles at a time
@@gabe8168 Could you elaborate a bit more?
@@dennisrkb One way to mitigate the explosion is to notice that in untouched squares (squares with no clues touching it), all combinations within those squares have the same probability, so you'll only have to consider touched squares.
As a math person myself, I've also realized that if you add all the probabilities of there being a mine within all the squares touching a certain clue, it must sum to that clue. I'm not sure how much that helps, but there may be techniques to minimize that chance.
One last thing: this probably never applies until near the end where the only squares left are those where you have to guess, so there would be no combinatorial explosion.
6:10 I could just imagine him also coding in the minesweeper to play an "oooooooooh" sound as it moved the mouse across to the final corner.
You could speed this up by having the AI finish a section before making a big mouse movement to a different section in the field.
You could achieve this by taking the product of (-2 * abs(0.50 - the probability of this square being a bomb) + 1) and (the distance the cursor has to travel), and then travel to the smallest product of all calculated squares.
This will minimize travel time
This will not minimise travel time - what you've described is just a heuristic. Minimising the total move distance requires solving the Travelling Saleman Problem, but it's actually a bit worse than TSP since each click can create new places that need to be clicked and you don't know in advance where those will be.
If you use SendMessage() function (windows only), you don't need to move the mouse
This is a function I commonly use in my recent projects as I am learning how to reverse engineer games, and lately was writing a simple bot for it:
It's from C project, but I'm 99% sure that this would compile with C++ compiler as is with no changes needed.
void mouse_left_click(HWND window, int x, int y) {
SendMessage(window, WM_LBUTTONDOWN, 0, (y
I agree, for the best possible path this would require solving a variant of the TSP. My solution was simply something I had quickly thought of to counter the apparent problem of inefficient travelling. For a simple speedup, I think my solution would be fitting.
Awesome stuff! However, I feel like speed could be improved a bit. Sometimes it goes from one place to another for no good reason. If two or more squares have the same (highest) probability, it should go for whichever is the closest to the cursor right now.
A minor fix: prioritize marking fields by % and then by proximity to previously opened field to avoid unnecessary jumps all over the place.
its just for visualization. the AI can be much faster than that.
it doesnt matter where its moving. its slowed down for visual effect in the video on purpose limiting the AI's speed so we can see it. otherwise the whole 64x36 grid would be completed within a second
4:20 - Love that white board. Instead of making it bigger, just make that little bit big enough for the word to fit within xD
Genious!
Lmao true
But can you use it on Minesweeper.io to wreck some noobs? :D
Holy frick, that would be overpowered.
But, then, there would be Gohan on there to save us all...
DO IT, Code Bullet!
Now we are talking!!
YUSSSSSSSSS
IIRC they rate-limit uncovered squares to deter bots, though.
This AI is definitely effective, but sounds pretty inefficient. On a grid as big as that one, it may not be able to keep up. I know from experience that you can (or at least used to be able to; people might be better now) pretty consistently get first place by just using the first logical rule mentioned here, though.
4:47 is where it begins
np
No it begins at 0:00
It begins at 7:46 my friends
No. I want to see the programming. I am a proud nerd.
thx m8
CodeBullet: if x we do y
Me: clicks randomly and then pray for the next click
Code bullet in 2018: im a badass AI programmer
Code Bullet in 2020: im a badass AI programmer
1:25 Skip to ??? ?
yes. obey the rules
xxZ0MB1E Ended up tearing space-time fabric, sewing it back together right now
crap
He probably meant to fill that in in editing
Koos Naamloos 4:47
I think your algorithm is not perfect since whenever it has to take a chance it should take into account the value of information of uncovering a square so that the risk is "worth it". E.g. in the first move all squares are valued equally but the center might have a higher value of information than a corner.
You are right, it seems to be much more challenging to build an alghorytm for that
A corner actually is more likely to have useful information, since there are only 3 neighbors which could have a bomb, meaning it if more likely to expand. Knowing how many bombs are around a single square isn't useful information, knowing how many bombs are around a grouping of squares is.
@@PaulBurg having less neighbours means a lower chance to expand, not a higher one - each square has the same probability to have a bomb at the very start, since it is not 100%, the more squares, the less chance there is that all of them (surrounding the original pick) are a bomb
Although if the AI was truly perfect, it would take in the probability of a blind guess compared to a logical guess of squares which do not currently have a definitive answer
@@PJOZeus along with that, there is also the possibility of a 50/50 guess occurring
Your Bayesian method is mathematically perfect for one move, but it only minimizes the chance of boom for one turn. The “best”algorithm would minimize it for the sum of all future turns, which may (may not) mean different choice.
Jim Geary can you explain it further? Since I don’t think one move would matter for the future, it’s just whether the bomb is there or not, no? I do want to know what you mean by “taking future turns into account”
SulfurRingROKer The goal isn’t to minimize stepping on a bomber this turn. It is to minimize stepping on a bomb for this and all future turns, so there may be paths that “go around” a second hazard if they work out, whereas perhaps some choices only delay a sure future death lotto ticket.
But do those options even exist in minesweepers? Each turn is a clear cut, just being successful if you don’t click on a bomb and unsuccessful if you do, and I doubt having a “successful turn” can ever backfire in minesweepers as every square clicked on without a bomb is a positive hint for future turns
Jim, thank you. I was trawling through the comments to see if anyone else had noticed this; it's sad how far I had to scroll :-(
@@jihwan990706 One simple example is that you may have a situation in the top right corner of the board where you can fit either 1 or 2 mines, but can't tell which configuration it is. Meanwhile, there's more solving to be done at the bottom left. If the AI solves the bottom left, such that only the top right corner is left, it can use the readout of the number of mines remaining to infer which of those two configurations is correct. However, if the probability of death at the top right is initially lower, the AI will take a totally pointless and worthless risk doing the top-right first, and will then still have the gauntlet of the bottom left to contend with, which has an overall higher chance of death than taking on the gauntlet first and then taking advantage of the extra info to get a free win at the top right.
However, as much as I enjoyed contriving this example, the reality is that it's not on me or Jim to provide a specific clear-cut example. The idea that you have the overall highest probability of success by always picking the option that has the immediately lowest probability of killing you, without considering the knock-on effects, is obviously short-sighted. Such an algorithm is called a greedy algorithm (yes, this is a actual technical term you can look up), and the onus is actually on you or CodeBullet to *prove* that the greedy algorithm is actually optimal. Mathematically rigorously. (I mean, that would be the case in an academic scenario, I'm not saying every youtube video needs a peer-review worthy proof)
"I made a computer do math!" would have been a better title lmao
im joking of course, very interesting video!
Making a perfect ai is easy
Just make it so it can see all of the mines
That would technically be cheating because you would have to modify the game files to remove the tile filter over squares, something that could be done.
Never said the AI couldn’t cheat
fair point
I don't think so... I see little issue... The problem is that the first move is random and if there is number '1' chance that you click at the bomb is 1:8, but
chance that bomb is any where else is (30*16-1)/99:1 = about 1:4,48 that means its safer to click any where around the '1' but your AI had '1', but then clicked randomly else.
My math is correct only if I consider that you use standrart Expert mode 30×16 with 99 mines.
(I might be wrong just please someone tell me something)
sorry for gramma and I love your videos :)
windows_x_seven yes that is how minesweeper works
Unless the AI stores data from prior games, this is the best the AI can do, barring calculating the probability of each guessed click opening a large pocket.
@windows_x_seven Hmm after reading your answer and the others I think the first click is always an empty square and it moves the mine if there would have been one there maybe?
@windows_x_seven i think the first square is always safe and after your first click its then randomised , at least thats what i did in my mine sweeper
windows_x_seven The original comment is talking about the second click not the first
I used to play by starting with the lowest density of bombs allowed and increasing by one each time I won a game.
I had an excel spreadsheet which did all of the calculations you describe here.
My one reason why your game is not perfect:
The first move should always be a corner because corners have the greatest chance of having zero bombs and allowing you to start your actual logic.
Sometimes the second, third, and fourth moves should also be corners depending on the density of bombs and outcomes of previous moves.
Sides also preferable to random squares for the same reason.
All that said, when you get a very dense board, there is nothing like clicking somewhere at random and seeing an 8.
"The first move should always be a corner"
Wrong. In a corner you're opening up the field only to 2 sides, on the walls you're opening up the field only to 3 sides, while starting in the middle of the board, you're opening up the field to all 4 sides. Starting in a corner or wall limits your possibilities.
@@Metatr0n Perhaps your argument is valid for low density maps.
You want to maximize your chance of the first square to be a zero, thus the corner.
I'm sure one could tweak the program to run at various density maps and with a random first move vs a corner first move and see which leads to the lowest expected value of moves on squares with a nonzero probability of being a bomb over the course of a game. Or the highest actual winning percentage. Or the highest likelihood to win defined as the product of the odds of a square being safe for each move made. Or some other reasonable success metric.
@@gregorykrajeski6255 Even in high density map, there's still an equal chance that the edge have 2 bombs near it thus locking you too. In fact a higher chance since it only need 2 bomb to lock it in higher density.
@@idontido6303 In a high density map, you know that your first move will never be a bomb.
So if there is a 60% chance of any cell being a bomb, then the chance that an interior square gives you any information is low. Mostly you will be surrounded by 3's, 4's, 5's, and 6's.
A corner only has three adjacent cells, so you have a 36% chance of only having one bomb adjacent, giving you a 67% chance of surviving the second move.
Lower the density of bombs and you will get a 0 far more often on a corner than anywhere else, again maximizing your chance of surviving the second move.
@@gregorykrajeski6255 You're supposed to start in the center. The center squares never have mines. If you get a bad start and get locked into the center, then you can apply this logic.
The numbers looked so nice. I always thought that how many big numbers you can get. Kind of like a lottery.
First time play showing:
*loses*
Bot:BUT I AM PERFECT!!!!