上位 200 件のコメント全て表示する 412

[–]Keep_Phishing 846ポイント847ポイント  (16子コメント)

1:10AM, exactly what I expected

[–]root45 266ポイント267ポイント  (15子コメント)

Ah yes, the old, "just change this one line of code to make it work for this edge case" perpetual cycle. Feels good.

[–]MrSafety 111ポイント112ポイント  (14子コメント)

There are those rare times when you write a bunch of code from scratch and it works perfectly on the first try. Those times are awesome.

[–]ughduck 129ポイント130ポイント  (8子コメント)

Awesome for one brief moment. Then: "Well, I know I'm an idiot, so something must be wrong somewhere. This code just doesn't have the common decency to show me." And then extra-obsessive testing.

[–]computergroove 33ポイント34ポイント  (7子コメント)

Yes but if it works to complete the game then what other testing do you need? Setup a detection method for games won vs games lost and go to bed

[–]themooseexperience 40ポイント41ポイント  (0子コメント)

What do you think we are, sane?

[–]Mentally_ill_hippo 3ポイント4ポイント  (0子コメント)

That's when you start testing weird possibilities that may pop up but generally don't.

[–]won_vee_won_skrub 3ポイント4ポイント  (3子コメント)

I might not be understanding this but Minesweeper does force you to guess and you'll probably win less than 30% of the time.

[–]Savandor 2ポイント3ポイント  (2子コメント)

I don't think it would be less than 30% of the time. Assuming the bot functions perfectly, I would say in most hard level minesweeper games your going to only encounter one "guess" scenario, and rarely two. So it probably wins 45% of the time at least. Unless you know, its just awfully unlucky.

[–]RockLoi 1ポイント2ポイント  (1子コメント)

From what I can remember of playing I felt like I'd frequently have two or three in many expert games. Someone needs to research this!

[–]onioning 1ポイント2ポイント  (0子コメント)

I too want to see further research. I've been told that actual times that you need to guess are very rare, but that's not my experience at all. I keep staring at those times trying to figure out how I could possibly not guess. I'm wondering if I've been trolled...

[–]Dithinas 5ポイント6ポイント  (1子コメント)

I remember for my embedded systems class, I was bored one night/couldn't sleep so I wrote all the code for one of our labs in notepad++. I couldn't test the compilation because we had a special compiler on our lab computers or something. I think I missed one semi-colon and a bracket somewhere, but otherwise it worked perfectly first try. To be fair, it wasn't a huge amount of code. I think it was to break apart the fundamental frequencies of a DTMF keypad or something. Felt very good haha

[–]Seven-Three 1ポイント2ポイント  (0子コメント)

Bullshit. Those are the times you just haven't found the bugs yet.

[–]pFreak 479ポイント480ポイント  (74子コメント)

[–]BlackOdder 18ポイント19ポイント  (0子コメント)

As a programmer OPs code is not satisfying

[–]Artefact2 13ポイント14ポイント  (33子コメント)

[–]VefoCo 26ポイント27ポイント  (4子コメント)

Tabs are 8 characters

wat

[–]Fornax96 2ポイント3ポイント  (3子コメント)

My tabs are always 8 chars: http://pixeldra.in/u/642rQD and I never go over my margin. Linus would be so proud :)

Of course there are some things I don't agree with, but most of my code applies the Kernel coding style.

[–]VefoCo 7ポイント8ポイント  (2子コメント)

No, my point is that tabs are always one character. How big they appear is literally just a matter of rendering. Most IDEs I've used render as 4 by default, but the same code is rendered as 8 on Github. It's ridiculous to say that a tab is a fixed length. That's why I use spaces, because the code looks consistent everywhere.

Sorry, I'll get off my soapbox now.

[–]lozarian 4ポイント5ポイント  (0子コメント)

I use tab, autoreplaced by spaces with np++, because I'm a lazy bastard.

[–]ViperCodeGames 36ポイント37ポイント  (20子コメント)

No... Just no. There are lots of scenarios when my code goes beyond three indentations. Especially in HTML and php which this form validation is. He's not wrong but that's his style and I'll let him have that. It's just not for me.

Edit: shit what did I start

[–]o5mfiHTNsH748KVq 28ポイント29ポイント  (0子コメント)

HTML is a terrible comparison since nesting is part of the schema.

However, in java, the code this guy would make me vomit. Each loop should be it's own method with real variable names. I wouldn't be able debug this even if I wrote it.

[–]smallfried 12ポイント13ポイント  (1子コメント)

I wouldn't put the limit on 3 levels, but having very deep indentation is bad coding style as the readability suffers. Which is arguably the most important metric of code quality.

[–]ViperCodeGames 5ポイント6ポイント  (0子コメント)

Exactly, everything within reason.

[–]Artefact2 37ポイント38ポイント  (7子コメント)

Especially in HTML and php which this form validation is.

function register() {
    if(!$foo) {
        return 'test foo failed';
    }

    if(!$bar) {
        return 'test bar failed';
    }

    if(!$baz) {
        return 'test baz failed';
    }

    /* … */

    create_user();
    return 'ok';
}

[–]Fuckfencing 5ポイント6ポイント  (5子コメント)

It's all debatable, but this code is still really bad. I suspect the OP is very very new, because this could all be done much more simply recursively, and you could drop the 8 billion spaghetti conditionals here.

[–]sneeze_question 0ポイント1ポイント  (0子コメント)

You would hate ladder logic programming then.

[–]lucutzu33[S] 56ポイント57ポイント  (29子コメント)

Hey guys, thanks for the all the advice and good words I'm getting in the comments.

First of all I would like to say that the bot is only around 70% complete and there is still a lot left to do and a lot of bugs to solve. I just posted this GIF because it was satisfying for me to see the bot work for the first time. I know there are lots of nested if's, the naming of the variables is terrible and I could've done some things way more efficiently but the bot is in the "get it to work first" state and I really don't care about how pretty it looks.

The bot doesn't recognize all the patterns yet and very often gets stuck but if you're lucky you can get it to solve the puzzle. Also guessing when it gets stuck is the next thing on the to-do list.

Normally I wouldn't post the source code it this messy shape but if reddit asks you got to deliver.

Notes: !!! The bot only works 1366x768 resolution of windows 7.(you can change some values when reading the pixels and I think you can get it to work on any resolution but I just made it to work on my laptop which has a 1366x768 resolution.

Minesweeper has to be located in: "C:\Program Files\Microsoft Games\Minesweeper\MineSweeper.exe" but you can change that path in the source code.

It also only works on the expert difficulty. (Also easily changeable). When you run it make sure you create and empty class in your IDE and focus your mouse on that(like you were writing on it) then run the script because it sometimes messes up and changes focus to your IDE and it starts pressing arrow keys and enter inside your IDE instead of minesweeper.

If it gets stuck, it will stop and you will have to either close minesweeper or click Game>New Game>Quit and start a new game.

Again, this isn't finished, has lots of bugs, has a lot of "bad coding" in it, is very messy, not documented, I wouldn't normally post it anywhere and it's very hard to understand what it is doing because there are so many loops and ifs. I'm just sharing it for educational purposes and because reddit asked me for it. This is a throw-away project, nothing serious. I just challenged myself: "do a bot that can solve a expert minesweeper puzzle".

Link: http://www.mediafire.com/download/979p1jqjj8v7nr3/mine.rar

If you have any questions ask me and I will try to answer them.

Also I don't guarantee it will work on every computer and my laptop is the only computer I've tested it on.

[–]BritainRitten 4ポイント5ポイント  (7子コメント)

Why don't you just host it on Github?

[–]lucutzu33[S] 4ポイント5ポイント  (6子コメント)

Because it's still a mess and is not GitHub worthy yet.

[–]Yumipon 13ポイント14ポイント  (5子コメント)

Thats not how github works. But ok i guess.

[–]lucutzu33[S] 5ポイント6ポイント  (4子コメント)

I get what you're saying but that code is very hard to read for others. I have to make a lot of comments in the code first.

[–]nicholas818 6ポイント7ポイント  (3子コメント)

Are you at least tracking changes with git?

That'll make it easier to push to GitHub later. GitHub is not just a publishing platform: it is a place to track changes in your code and make it easy to pull data from old versions.

[–]spin81 5ポイント6ポイント  (2子コメント)

Actually you don't need Github for either of those things if you are using Git right.

[–]nicholas818 1ポイント2ポイント  (1子コメント)

True. But GitHub is probably the best place to host git repos.

[–]spin81 1ポイント2ポイント  (0子コメント)

You'll get no argument from me. They do what they do very well.

[–]Kazaxat[🍰] 1ポイント2ポイント  (2子コメント)

I'm guessing it still fails quite often? As I recall from a period when I played Minesweeper frequently when bored, you routinely get in situations where choosing the mine VS the safe spot ends up just being a 50/50 chance, with no amount of logical parsing able to help you. I can't imagine having a nifty program like this would help in that situation.

[–]lucutzu33[S] 3ポイント4ポイント  (0子コメント)

Yes, because of the randomness of minesweeper, it fails more often than not. Also because it still has lots of bugs in it.

[–]brygphilomena 2ポイント3ポイント  (0子コメント)

As someone who still plays minesweeper daily when he gets bored. I hate those moments.

[–]anothershittyalt 1ポイント2ポイント  (1子コメント)

Regarding the whole indentation thing that you seem to be getting a lot of flak for:

for (int i = y - 1; i <= y + 1; i++) {
    if (i >= 0 && i < 16) {
        for (int j = x - 1; j <= x + 1; j++) {
            if (j >= 0 && j < 30) {

I think this bit could be turned into

for (int i = Math.max(y - 1, 0); i <= Math.min(y + 1, 15); i++) {
    for (int j = Math.max(x - 1, 0); j <= Math.min(x + 1, 29); j++) {

and it seems to show up in Solver.java a couple times.

[–]lucutzu33[S] 1ポイント2ポイント  (0子コメント)

Thank you. That if statement only checks if the array is in bounds

[–]Weed_O_Whirler 1ポイント2ポイント  (0子コメント)

You know, there is a lot of people giving you shit, but the worst code that runs is still better than the best that doesn't. I mean, come on. This is a silly little side project, you don't have to follow "best practices" for something like this.

[–]Charand 157ポイント158ポイント  (99子コメント)

Really curious how you parse the game screen into numbers.

[–]lucutzu33[S] 304ポイント305ポイント  (87子コメント)

It takes the screenshot of the window, saves it as a buffered image then checks the RGB values of certain pixels in each square.

Source: https://www.reddit.com/r/oddlysatisfying/comments/3hb4am/minesweeper_bot/cu65m7j

[–]Synth3t1c 68ポイント69ポイント  (53子コメント)

Is this yours? I'd love to see the source!

[–]balducien 92ポイント93ポイント  (33子コメント)

Seeing the code in the gfycat, I'm not so sure if I want to read through all of it...

[–]BestSanchez 156ポイント157ポイント  (21子コメント)

if if if if if if if if if if

[–]Romanulus 15ポイント16ポイント  (0子コメント)

Came here to say this. /shudder

[–]esuma10 8ポイント9ポイント  (19子コメント)

Isn't that what all programming boils down to?

[–]PangolinRex 22ポイント23ポイント  (12子コメント)

I suppose you could say that, but you can find much more readable ways to structure your logic. That many nested if statements is almost certainly not the best way to proceed.

[–]esuma10 1ポイント2ポイント  (8子コメント)

Ahh gotcha. I've only ever taken a MATLAB course, and that was a few years back.

[–]josecuervo2107 8ポイント9ポイント  (3子コメント)

I hate MATLAB with a passion. I know it can be very useful but I just hated the damn language.

[–]Weed_O_Whirler 1ポイント2ポイント  (2子コメント)

MATLAB is a very useful language, but it is by no means a very broad language. I use it all day, everyday at work, and there is nothing else out there which would let me get my work done in even close to the same amount of time.

That being said, I never use MATLAB for anything but what it was designed to do. It's not a "do everything" language, and needs to be supplemented by other languages to actually build a program, but for straight up number crunching it can't be beat.

[–]PangolinRex 3ポイント4ポイント  (3子コメント)

MATLAB is...an interesting language. Not entirely sure I enjoy it, but it has some cool features. Just wish it were less proprietary, seems mostly like a way to grab huge amounts of money from researchers

[–]probably2high 1ポイント2ポイント  (0子コメント)

There are usually better ways to implement such nested logic.

[–]tonykodinov 3ポイント4ポイント  (0子コメント)

A lot is probably iterations of the same code with the variables changing for the colours of every new buffered image.

[–]stdTrancR 16ポイント17ポイント  (17子コメント)

I wrote something similar to bot the fuck out of some MMORPGS, you can do it pretty easily on AutoHotKey.

[–]Synth3t1c 15ポイント16ポイント  (12子コメント)

Yeah but I want to see it done in Java :P

[–]manikfox 25ポイント26ポイント  (11子コメント)

Robot r = new Robot(); r.cpature screen r.click etc...

Its all just the robot library, pretty simple.

I made $500 off diablo 3 with a java robot :)

[–]slowcom 6ポイント7ポイント  (10子コメント)

Is there a tutorial that you used to teach yourself this? I love watching bots play games and the challenge of setting it up correctly. I'd love to look into doing it myself!

[–]Revules 4ポイント5ポイント  (4子コメント)

You should probably just start with general programming tutorials, but I don't think you're going to be motivated enough if all you want to do is write game bots.

[–]TheLKL321 1ポイント2ポイント  (0子コメント)

The thing is that I can learn a lot by making a bot like this from scratch, even if I want to do normal programming

[–]slowcom 0ポイント1ポイント  (0子コメント)

In the early '00 I went to school for software engineering and I've written a few shitty iOS and Android apps. I've got the concepts down but my jobs/life has left me with little time to have it go past a hobby.

If I can just get pointed in the right direction. I wrote a bot for an old ass game back in High School (Ultima Online) but times have changed.

[–]PrivateCaboose 1ポイント2ポイント  (3子コメント)

Khan academy has some intro to coding courses for free, though I doubt they're in-depth enough to learn this sort of thing. They may be a good way to gauge your general interest in actually learning this stuff, though.

[–]slowcom 1ポイント2ポイント  (2子コメント)

Copy/Paste from a different reply.

In the early '00 I went to school for software engineering and I've written a few shitty iOS and Android apps. I've got the concepts down but my jobs/life has left me with little time to have it go past a hobby.

If I can just get pointed in the right direction. I wrote a bot for an old ass game back in High School (Ultima Online) but times have changed.

[–]PrivateCaboose 0ポイント1ポイント  (1子コメント)

Ah, you may be a bit out of Khan Academy's depth then. It may still be worth checking out as I've only looked at the very basic level courses, they may get a bit more in depth later on.

[–]KingSkeeze 0ポイント1ポイント  (0子コメント)

Interested in this as well.

[–]onlymadethis4porn 5ポイント6ポイント  (1子コメント)

Runescape?

[–]stdTrancR 1ポイント2ポイント  (0子コメント)

FFXI, unless that was a meme, in which case, well played.

[–]ThisIs_MyName 0ポイント1ポイント  (0子コメント)

Same here but I intercepted Direct3D function calls by replacing their DLLs with mine.

[–]rsxstock 6ポイント7ポイント  (2子コメント)

Would there be another way to do it other than take a screenshot?

[–]lucutzu33[S] 16ポイント17ポイント  (1子コメント)

Reading directly from it's memory but I haven't looked into that.

[–]PUSH_AX 5ポイント6ポイント  (0子コメント)

As optimal as it would be, you'll be there reversing the data structure and realise you have all the coordinates to the mines right there, at this point it would take a better man than me to continue :D Your implementation is a lot more interesting.

[–]samort7 16ポイント17ポイント  (11子コメント)

Wow! As someone just learning to program, that's really impressive!

[–]lucutzu33[S] 17ポイント18ポイント  (10子コメント)

It's been a year since I learned to print "Hello World". If you keep learning everything will get simple. The solver itself isn't really that complicated it's just bunch of for loops and if statements, the logic behind it is a little bit more tricky but nothing too hard.

[–]DoctorWaluigiTime 18ポイント19ポイント  (5子コメント)

How does the program handle 50/50 scenarios? Or is every Minesweeper board actually possible to solve without running into those situations?

[–]veryhandsome 10ポイント11ポイント  (2子コメント)

It depends — some versions of the game allow you to tick an option that guarantees a solvable board with no guessing. However I don't think that's default for most versions (the only extraneous rule is usually that your first click can't be a mine). I was wondering the same thing you asked..

[–]SmileyMan694 2ポイント3ポイント  (1子コメント)

Wait, what? I had no idea that was an option. So many games that were rigged to fail... I could have been spared the frustration.

[–]zugy 1ポイント2ポイント  (1子コメント)

Nope, you will definitely run into 50/50 scenarios that are unsolvable. It's a lot more likely at higher difficulties, it seems.

[–]adityapstar 8ポイント9ポイント  (1子コメント)

How do you get Eclipse to interact autonomously with the Minesweeper program?

[–]lucutzu33[S] 17ポイント18ポイント  (0子コメント)

When it opens minesweeper, windows automatically changes focus to the minesweeper window. Then I just use the Robot Class to simulate key presses. This bot uses the arrow keys and SHIFT + ENTER.

[–]KlicknKlack 2ポイント3ポイント  (0子コメント)

Now you need to code a bot that dominates that silly browser game, Agar.io

[–]CaptainStack 2ポイント3ポイント  (4子コメント)

I was afraid you'd say that. My desire to make this myself just dropped to 0 :(

[–]EnterDMZ 1ポイント2ポイント  (1子コメント)

What does it do when you get into one of those scenarios where there's only two blocks left and based on the numbers shown it could be in either one? Does it guess, idle forever, quit, or is there some secret minesweeper strategy that I haven't found out about for that scenario?

[–]lucutzu33[S] 2ポイント3ポイント  (0子コメント)

It just stays there but in the next version I'll make it click a random one.

[–]brainpostdoc 11ポイント12ポイント  (0子コメント)

Each number was a different colour iirc, probably easiest to use that

[–]qwertyslayer 6ポイント7ポイント  (6子コメント)

Probably one of two ways--either he found a java clone or wrote one himself, or he is reading the game state from memory and altering it (it's just an array of buttons, after all).

[–]open_door_policy 5ポイント6ポイント  (5子コメント)

I haven't checked to see how good the Accessibility Options are for Minesweeper, but frequently you can access those to get a fairly detailed description of every UI element.

It's one of the common ways for UI automation to be done in low intrusion environments.

[–]snailbotic 2ポイント3ポイント  (1子コメント)

Take a screen shot, find the window, chop out the cells into subimages, check for pixel differences that let you know which number it is

[–]lecherous_hump 0ポイント1ポイント  (0子コメント)

Me too. Would like to see the video.

[–]Nobody_epic 108ポイント109ポイント  (20子コメント)

What would happen if the game started and it had one of those bombs that you have to 50 50 guess to win? Would it be like asking to divide by zero?

[–]themeatbridge 71ポイント72ポイント  (18子コメント)

I didn't look at the code, but if it were my project, I would have it just guess and lose half the time. You figure it's going to pick a random starting point and occasionally lose.

[–]nukegod1990 31ポイント32ポイント  (17子コメント)

Actually the new minesweepers they made it impossible to lose on the first click. Very clever. ;)

[–]OneBodyBlade 16ポイント17ポイント  (5子コメント)

Thats always been like that, but they arent talking about the first click. When you have only 2 boxes left at the end of the game, they can be isolated in such a way that you cant tell from the given information where the bomb is. Like this

[–]Glen_The_Eskimo 3ポイント4ポイント  (0子コメント)

This was very rage inducing as a child.

[–]IllustratesYourShit 2ポイント3ポイント  (3子コメント)

This is why I never liked minesweeper, it's a puzzle game that's sometimes impossible to solve. Hexcells is way better.

[–]streampleas 11ポイント12ポイント  (0子コメント)

There are still times that you have a 50/50

[–]s1295 3ポイント4ポイント  (1子コメント)

Man, spoiled kids these days, they'll all grow up with false expectations.

[–]Ayjayz 1ポイント2ポイント  (0子コメント)

It was always like that, though, as far as I can remember at least and I think I've played Minesweeper ever since it was added to Windows.

[–]themeatbridge 2ポイント3ポイント  (0子コメント)

Huh, that's cool I guess. But you still might click next to a mine, and only get insufficient information to make any certain moves. Point is, the program has to guess eventually.

[–]WhoGivesACarvahna 41ポイント42ポイント  (35子コメント)

Is it possible to get a copy of that code? I've only done beginner's Java and the most I've done was make 75% of a Space Invaders clone using StdDraw.

[–]lucutzu33[S] 56ポイント57ポイント  (32子コメント)

I'm out right now, I'll post it when I get home but I've got to tell you it's still a mess. Edit: https://www.reddit.com/r/oddlysatisfying/comments/3hb4am/minesweeper_bot/cu65m7j

[–]SupermansOlderBro 33ポイント34ポイント  (14子コメント)

I've never seen clean Java code.

[–]Leeeoon 14ポイント15ポイント  (13子コメント)

Python taught me to be a better formatter because it forces you to indent or die.

EDIT: Err, as a result. I indent consistently in Java now because it would otherwise feel weird without me doing so.

[–]WhoGivesACarvahna 2ポイント3ポイント  (0子コメント)

It bugs the crap out of me when someone has Java code that isn't uniform. I don't care if someone brackets on the method line or on the line after, but they better mirror that at the method end. It's like seeing a picture frame that's mostly great but just slightly tilted and it slowly drives me insane.

[–]shplamana 0ポイント1ポイント  (1子コメント)

ctrl + alt + L will auto-format in most intellij IDEs.

[–]FUR10N 5ポイント6ポイント  (0子コメント)

I'm not OP, but here's mine for win8. Parser will probably only work for my screen though, but the solver is good.

https://www.youtube.com/watch?v=dsUoMh7vAKo

[–]LearnsSomethingNew 0ポイント1ポイント  (0子コメント)

It should be fairly straightforward to get started from the screengrab.

[–]qwertyslayer 15ポイント16ポイント  (1子コメント)

I'm more interested in what his two projects "Caaaine" and "Caiine" are for

[–]brews 6ポイント7ポイント  (0子コメント)

It's like the difference between "khan" and "KHAAAAAAN!", I think.

[–]MagnusRune 8ポイント9ポイント  (1子コメント)

should try it on the MMO of minesweeper.

http://mienfield.com/

[–]TheRealM_ 2ポイント3ポイント  (0子コメント)

A friend linked me that once and I just clicked a little bit around without any form of strategy since I honestly don't enjoy Minesweeper, until I realized this was MMO.

Now I ruined the game a little bit for everyone because I didn't pay attention :/

[–]Ixilary 9ポイント10ポイント  (2子コメント)

As someone studying programming, I don't think it would be too difficult for me to get all the logic for solving it figured out, I'm more curious how you got an external program to interact with the game, because I have absolutely no idea how you did that.

[–]yeowoh 9ポイント10ポイント  (0子コメント)

OP said it takes a screenshot of the window and compares RGB values.

[–]jlmbsoq 6ポイント7ポイント  (0子コメント)

You can control Windows Minesweeper using your keyboard. The Robot class in java can simulate keypresses.

[–]Edrondol 12ポイント13ポイント  (0子コメント)

It probably still fails about 1/2 the time. I can't remember the last game I played where I didn't have to guess on something at least once.

[–]BONER_PAROLE 3ポイント4ポイント  (0子コメント)

Now that's some cyclomatic complexity.

[–]vk0 3ポイント4ポイント  (0子コメント)

Here is a worse, uglier solver doing (I think) the same board.

http://imgur.com/SpRo9R3

The question marks are all the non-bombs it could detect in the current board layout, a single question mark usually means it guessed. Stars with red backgrounds are hit bombs, it hits a lot of bombs.

[–]matt420therose 16ポイント17ポイント  (11子コメント)

This belongs in /r/mildlyinfuriating... Those variable names are terrible.

[–]brews 15ポイント16ポイント  (9子コメント)

I was going to bitch about those nested "ifs" myself.

That being said. Everyone starts with poor code. It takes a few iterations to get it really nice. Keep it up!

[–]lucutzu33[S] 21ポイント22ポイント  (4子コメント)

I know I could've use && but I was way in over my head when I was coding it and I didn't care about how it looked I just wanted it to work.

[–]brews 3ポイント4ポイント  (1子コメント)

No sweat. Getting it to work is the important part. ;-)

[–]omrsafetyo 1ポイント2ポイント  (0子コメント)

It works! Now refactor.

[–]matt420therose 2ポイント3ポイント  (0子コメント)

Make it look pretty now that it works!

[–]deelowe 1ポイント2ポイント  (0子コメント)

I can't see the full source code, but I think most of the mess comes from not using recursion. This sort of problem lends itself well to recursive algorithms.

Are you familiar with tree structures, searching algorithms (e.g. binary search) and sorting (e.g. merge sort)?

If you'd like to take a stab at optimizing or cleaning up the code, those would give you a good foundation.

[–]zapitron 5ポイント6ポイント  (0子コメント)

Long, long ago (1980s on 65xx), I used a very crude C compiler that didn't short-circuit the && operator. It would always evaluate the whole expression.

Decades later, vastly different and better compilers, even totally different languages, I still tend to assume it might not work, and feel an urge to nest. Once you have been burned, trust is hard! Everyone says "if (a && b)" but my inner shitty-compiler-paranoia screams "if (a) if (b)" and nobody else hears the voices.

[–]JonasBrosSuck 4ポイント5ポイント  (0子コメント)

cut OP some slack, it's his intro course! i remember the code i wrote for the intro courses and they were not pretty

[–]Mightymushroom1 2ポイント3ポイント  (0子コメント)

I bet there is some somebody out there who is able to beat this, See you at AGDQ 2016 minesweeper

[–]joshually 2ポイント3ポイント  (0子コメント)

I just tried to press the red X inside the gif to try to close the minesweeper window as a gut reflex of years of endless frustration and fear while playing Minesweeper Advanced.

[–]IndsaetNavnHer 1ポイント2ポイント  (3子コメント)

What's limiting it to take 9 seconds to complete (that round of) the game and not faster?

[–]mosquit0 5ポイント6ポイント  (2子コメント)

Im guessing he put some delay to actually make the process visible.

[–]Duke_Jopper 5ポイント6ポイント  (1子コメント)

He also said that it was taking a screenshot then checking the RBG of each square. I've never tried taking screenshots but I think that could slow it down a bit

[–]Tripaway2013 4ポイント5ポイント  (0子コメント)

Also he's writing quite a lot to sys.out

[–]Ralph_Baconader 1ポイント2ポイント  (0子コメント)

I was hoping it would have to guess towards the end and lose.

[–]monkeymule 1ポイント2ポイント  (5子コメント)

If you comment out all the prints and it will run a lot faster.

Print is actually a pretty heavy function to call.

[–]lucutzu33[S] 0ポイント1ポイント  (4子コメント)

I know, plus the recording software eas using quite a lot of CPU power. I think if I run it on a better machine without recording I can get it to 4 - 5 seconds.

[–]monkeymule 0ポイント1ポイント  (3子コメント)

It's a really cool program though.

It actually looks cool to see the prints go by as it works.

I just know I've done some stuff going through images by pixel with really big loops and if I don't take every print out of those big loops it would take weeks instead of hours.

The thing I am most curious about is how you interfaced your code with the minesweeper program.

Is it an open source java minesweeper that you loaded up or is it parsing and sending commands to a separate program?

[–]lucutzu33[S] 1ポイント2ポイント  (2子コメント)

No, it's the original windows minesweeper. The bot changes focus to the minesweeper windows and the it uses the Robot class to simulate keystrokes as I found out you can control it through key presses.

[–]monkeymule 0ポイント1ポイント  (0子コメント)

Does that mean it's doing image recognition get the game state?

That is pretty bad-ass.

[–]Halolamer 1ポイント2ポイント  (7子コメント)

Very interesting. I don't know anything about programming but could you explain what the program does when it has to guess.

How often does it lose?

[–]pavetheatmosphere 1ポイント2ポイント  (2子コメント)

Does it ever get stuck? I find that on occasion there seems to be a corner that's not solveable except for by guessing.

[–]DooberBooberDoo 3ポイント4ポイント  (18子コメント)

Oh wow, this is making me really fear my last year of programming courses. I could never code something like that :(

[–]JBOYStaysUp 65ポイント66ポイント  (5子コメント)

Not with that attitude.

[–]DooberBooberDoo 26ポイント27ポイント  (4子コメント)

I guess you're right. I COULD code something like that! :D

[–]bambo758 11ポイント12ポイント  (2子コメント)

GO DO IT!

[–]tapodhar1991 18ポイント19ポイント  (1子コメント)

Don't let your dreams be dreams

[–]zirvis 3ポイント4ポイント  (0子コメント)

Yesterday, you said tomorrow.

[–]dJe781 15ポイント16ポイント  (3子コメント)

Don't forget that any solution to an engineering problem starts with breaking down a complex problem into smaller, less complicated, easy to tackle problems.

Last year, I wanted to automate a 5 clicks process on an Android mobile game because I'm a lazy fuck. I didn't know anything about Python or Android. I didn't know where to start. 4 months later I had an entire bot capable of handling every single use-case, every single process, doing character recognition and on screen verification, and ultimately able to loop for days (which got me banned for breaking the EULA, but that's another story). The limit became the battery. I wouldn't even have dared to think about pulling this off, but I did.

In the end, you can. It's just a matter of breaking it down to smaller challenges.

[–]DooberBooberDoo 2ポイント3ポイント  (0子コメント)

That's awesome, because my favorite programming professor has always said that a good programmer should always take complex problems and break them down into smaller ones. I'm an anxious guy and whenever I first look at a problem I always freak out because it seems too big to me.

[–]Primnu 0ポイント1ポイント  (1子コメント)

To avoid a ban with such apps, you need to add some human behaviours - like randomize the position of a tap and the time between actions, randomize a change in order that actions are performed, add random mistakes - anything to generally avoid creating patterns.

[–]dJe781 0ポイント1ポイント  (0子コメント)

That's what I thought but I thought about it too late. For a long while it wouldn't loop very well so I was safe because of the downtimes. When it really got effective, I had lost sight of the potential problem and stupidly kept it running as fast as possible without pause.

Won't make that mistake again ;)

[–]Primnu 4ポイント5ポイント  (0子コメント)

It's really quite simple.

To do something pretty similar to what OP has, all you need to know is:

Basic things like conditional statements, arrays, variables.

How to capture a window as bitmap.

How to get the RGB values of the bitmap (or rather areas within the bitmap for each square, 1 = blue, 2 = green, 3 = red, 4 = dark blue - you're basically just checking whether a square contains any of those colours). Could also instead do comparisons between predefined bitmaps of the numbers to get exact matching. When you've determined which colour it is, you add it to an array as its number value, if it doesn't contain any of the colours then it's a 'blank' square.

How to make the mouse move to a specific position and perform a click.

You also generally just need to know how Minesweeper works in order to determine what your application needs to do.

Start from the top of this list, ask Google if you're not sure on something, you can likely find bits of what you're trying to do on Stackoverflow, something like this for getting image of window.

The process will be:

1 Get bitmap from window

2 Check rgb value of each previously hidden square in that bitmap.

3 Add/update each square to array that keeps track of game progress.

4 Determine which currently hidden squares in the array are considered safe (do this by checking the value of non-hidden squares around hidden squares).

5 Click all safe squares, and go back to #1.

[–]Mavamaarten 3ポイント4ポイント  (1子コメント)

I once made something very similar to this (a bejeweled blitz bot) a few years ago. Really, I couldn't code for shit yet I managed to make something like that. The code is completely unreadable and breaks every good practice, but it worked.

You just need to divide the problem into smaller steps.

  1. Capture the minesweeper window
  2. "Read" the block grid and convert the image into a 2D array of blocks
  3. Calculate the next best move
  4. Profit :)

[–]DJSlambert 2ポイント3ポイント  (0子コメント)

Another thing to add to this: Once you break the big problem into easier steps, you can usually find existing solutions to these easier steps. For example, with the above list, you could google "how to capture a window using java" and find 4 stackoverflow postings, usually containing community-reviewed and upvoted solutions

[–]the_great_ganonderp 3ポイント4ポイント  (1子コメント)

The man who moves a mountain begins by carrying away small stones.

[–]Pidgey_OP 1ポイント2ポイント  (0子コメント)

I get your trepidation, but its not that bad. Ita really just logically laying out the steps that you follow when playing minesweeper and coupling them with some basic input code.

The hardest part is know how to play minesweeper (I learned this weekend that my girlfriend didn't know what the numbers meant and thought you just had to guess, lol)

[–]headbuster 1ポイント2ポイント  (0子コメント)

I can assure you that you can, you just don't know it yet.

[–]Veggieleezy 0ポイント1ポイント  (1子コメント)

It took me 1300 goes to finally win a game of Minesweeper on my old laptop. I am terrible at this game...

[–]makr28 1ポイント2ポイント  (0子コメント)

It took me a while to be able to figure out which number combos meant where a bomb was. But once you got those down they can get done pretty quickly and all youhave to worry about are the ones that force you to guess.

[–]thsuk 0ポイント1ポイント  (0子コメント)

Could you put out the source code? I'd like to mess around with it.

[–]MrBehnAm 1ポイント2ポイント  (0子コメント)

Nilesy should have used this.

[–]zirvis 0ポイント1ポイント  (2子コメント)

Is this on Github?

[–]lucutzu33[S] 2ポイント3ポイント  (1子コメント)

Not yet, right now it's a mess and I doubt anyone but me will understand how it works. I'll post it once I tidy it up.

[–]bury_the_boy 0ポイント1ポイント  (0子コメント)

What am i watching?

[–]Asimxo 0ポイント1ポイント  (0子コメント)

As a child I never really understood this game to be honest.. actually I still don't.

[–]ShowingErin 0ポイント1ポイント  (0子コメント)

I made one of these too. Then I used to to generate minewsweeper puzzles that are actually beatable without guessing. Don't know what microsoft hasn't figured this out yet...

[–]MystJake 0ポイント1ポイント  (0子コメント)

I thought about trying to build one of these when I was a freshman Computer Science major, but I never got around to it. Very neat to see that in action.

[–]ArkBird 0ポイント1ポイント  (0子コメント)

Awesome code! Do you have a github link?

[–]trevmex 0ポイント1ポイント  (0子コメント)

Oh man. The cyclomatic complexity. Refactor FTW!

[–]SrsSteel 0ポイント1ポイント  (0子コメント)

Aren't here spots where you just have to take a probability guessm

[–]silentfox13 0ポイント1ポイント  (0子コメント)

Wow, this really brings back memories from 2006. Another student and I made a similar program for a university project that solved the WinXP version of minesweeper. Of course, it had to guess periodically and only solved <40% of expert games, but man did it do it fast. I recall having all of my high scores as "0 seconds". The main speed limiting factor was having to read a few pixels from each tile to determine the game board state after each new click event was generated (much like OP's program).

Alternatively, the quick way is just to use XYZZY.

[–]PeppermintPattycakes 0ポイント1ポイント  (0子コメント)

I play minesweeper a bit differently. I don't use any flags and just hit the numbers around the bombs. It saves a lot more time for me at least especially when I just had a touchpad to use.

[–]robAtReddit 0ポイント1ポイント  (0子コメント)

I wish still have time to do side projects like this. I remember the text twist bot I made years ago..

[–]maggymooo 0ポイント1ポイント  (0子コメント)

You should get ride of those prints, make it a bit faster :P

[–]RealDarthVader 0ポイント1ポイント  (0子コメント)

Bro. Naming convention. Also, you put the whole thing in one package.

[–]Pedestrien 0ポイント1ポイント  (0子コメント)

Definitely just tried to close that box out by pressing the X on the gif.

[–]TwinSwords 0ポイント1ポイント  (0子コメント)

Why don't people who make gifs like this show the finished result for more than 1/10,000 of a second?

[–]MortisMortavius 0ポイント1ポイント  (0子コメント)

I would like someone to run this a few thousand games and tell me what percentage of games are solvable without guessing at some point.

[–]xfyre101 0ポイント1ポイント  (0子コメント)

i was half expecting it to hit a bomb.. kind of dissapointed

[–]woutske 0ポイント1ポイント  (0子コメント)

The code is not satisfying at all :c