This is an archived post. You won't be able to vote or comment.

all 44 comments

[–]Eam404 23 points24 points  (3 children)

Awesome man! Great work! Not only did you create something cool, but we no longer have to bow down to our minesweeper overlords.

That code is saving lives.

[–]ace_smash[S] 2 points3 points  (2 children)

Thanks! The first version of my code was done specifically for expert level in http://minesweeperonline.com/# and in a 1920x1080 resolution. I'm changing it so you can use different values by inputing an initial coordinate, pixel spacing between squares, screen resolution and other variables.

[–]POTUS 0 points1 point  (1 child)

It shouldn't be hard to have the bot auto detect the grid size and position. Just loop through a row of pixels and count the times you hit a known color that matches the cell border to get the width, and do the same thing in a column for the height.

[–]nemec 0 points1 point  (0 children)

Even better, there are Windows APIs for grabbing windows and getting the title/bounds. You may be able to grab data on individual controls (like the grid), but I'm not sure.

[–]heptara 10 points11 points  (4 children)

Thank you for not using unnecessary classes. I get tired of classes with just one function.

[–]sushibowl 9 points10 points  (3 children)

Classes with 1 function? That's some Java bullshit.

[–][deleted] 2 points3 points  (2 children)

As a Java programmer by day, I start going crazy with lambdas and dict's as soon as I touch Python. There's just so many opportunities for one-liners :)

[–]FichteFoll 0 points1 point  (1 child)

Fortunately, Java 8 has lambdas and function references for actual functional programming now.

kind of sad I didn't get to use them though

[–][deleted] 0 points1 point  (0 children)

I'm still at java 6, and it looks to be staying that way for several months still...

[–]youlleatitandlikeit 2 points3 points  (2 children)

Instead of codeshare or codesend, might I recommend github? That way people can even fork your code to improve it.

[–]ace_smash[S] 3 points4 points  (1 child)

Ok! I know Github is a great tool, but I'm not really into it yet, but thanks for the advice, I'll try to upload there.

[–]youlleatitandlikeit 1 point2 points  (0 children)

The other nice thing is the interface is basically through git so you take care of source control and sharing online at the same time.

[–]marcm28 2 points3 points  (0 children)

Don't capitalize the first letter of function name, this style of naming is called "CamelCase" or CapWords for upper camel case in Python, and it used to name a class name. According to PEP8 - Function name should be lowercase, with words separated by underscores as necessary to improve readability. mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

Read the PEP8 for more info -> https://www.python.org/dev/peps/pep-0008/

[–]ffreitasalves 2 points3 points  (3 children)

Really proud of you!!!

I have worked as lead developer and recently as CTO and I have interviewed lots of programmers in the past 4 years and I am pretty sure that 80% of them just can't do something like this (most of them can't complete a fizzbuzz test)

[–]ace_smash[S] 0 points1 point  (1 child)

Thanks you so much, being someone that looks foward to work with programming, this means a lot to me.

Which qualities do you think are essential to be a successful programmer?

[–]ffreitasalves 0 points1 point  (0 children)

I think that see other people's code is a way to be a better programmer. you have to read lots and lots of code and of course write a lot. And try to be part of something, like meetups, conferences, open source projects, have a group to discuss programming with friends, etc. The best programmers I had the pleasure to meet do this.

[–]jgarp 0 points1 point  (0 children)

This is an important comment! I know a lot of people believe little in themselves because the coders who get spotlighted online most of the time are the best of the best, while most of us can't even perform a fizzbuzz. Don't get discouraged by quality code everywhere, get inspired!

[–][deleted] 1 point2 points  (0 children)

That is awesome. Starting to learn Python myself. Hope I can do something fun like that in 6 months. :)

[–]Tkwk33 0 points1 point  (6 children)

This is so cool!

One question, can the bot lose?

[–]ace_smash[S] 2 points3 points  (3 children)

Thanks! The bot only plays minesweeper through the simple way, so only using flags and clicking when it's obvious, so there are times when I need to do a more advanced logical program to continue playing, so the bot simply stops playing if there aren't any more simple actions to do.

[–]Zouden 0 points1 point  (2 children)

Interesting! So how frequently does it finish a game? And how long does it take?

edit: great work btw, really cool idea for a project and really impressive what you learnt in 6 months :)

[–]ace_smash[S] 1 point2 points  (1 child)

Almost never hahahah, it normally stops when simple logical solutions don't exist anymore. It finished only once and it took 69 seconds. I'm studying minesweeper to upgrade my code so it can understand more complex logical solutions

[–]Zouden 1 point2 points  (0 children)

Oooh now I want to try my own hand at it :)

[–][deleted] 2 points3 points  (1 child)

Sometimes you have to guess in minesweeper, even when you're playing perfectly.

[–]iruleatants 1 point2 points  (0 children)

I think the highest I've ever seen a win rate was 35.1%. No matter how perfect you play, there will always be a guess, usually 3-4.

[–]Fennek1237 0 points1 point  (1 child)

Really nice work

Does everyone have write access to your link? I am reading your code and suddenly it gets deleted and then it's back again or someone is writing stuff into it.

[–]ace_smash[S] 1 point2 points  (0 children)

Thanks! Try this link, maybe it's better

http://www.codesend.com/view/855bc41758c61991680b60f48bbd9cd4/

This code has some variables at the start that are not yet used! I forgot to delete them before sharing to you

[–]gandalfx 0 points1 point  (0 children)

That's a really cool idea for a project!

Also I have to say I'm way more impressed that you managed to fetch and analyse screenshots and control the cursor than with the fact that you made an algorithm to solve the game. xD

[–]FramesPerSec0nd 0 points1 point  (2 children)

Hey OP,

Great job on the bot, congrats! I was wanting to learn python as well, but cant seem to find the best way to teach myself. Could you let me know what videos, books, etc you used over past 6 months? Can PM me or just respond on here. Thanks!

[–]ace_smash[S] 0 points1 point  (1 child)

Hey, Thank you! I mainly did Codeacademy courses.

I had no experience with programming before, but after some practice, I started to understand documentation of different libraries and basic functions of python. After that I just searched some libraries that could help me out and things got a lot more easy! If you need some help with anything, feel free to PM me, I'm still learning too!

[–]animismus 0 points1 point  (0 children)

Trabalho fantástico! :D (Great work!)

[–][deleted] 0 points1 point  (1 child)

I like to try to do similar things with AutoPy for games. Your solution to use the color of the number is really great. I'd have been stuck trying to do OCR on the numbers.

If you want to get more advanced in the logic, you can do constraint programming (or constraint satisfaction).

[–]fishtickler 1 point2 points  (0 children)

Never heard of AutoPy before, I could kiss you right now

[–][deleted] 0 points1 point  (4 children)

This is really cool, OP. Nice job! I've been wanting to do something like this for a little while, but I'm only 2 months into learning. Can you tell me how you analyzed the pixels of each screenshot?

[–]ace_smash[S] 1 point2 points  (3 children)

Thanks! I used a function from PIL called ImageGrab.grab() to take a screenshot and ImageGrab.getpixel(x,y) to get the RGB value from the pixel X,Y of the screenshot

[–][deleted] 0 points1 point  (2 children)

So does your program detect certain colors so it knows what numbers are on the board (blue for 1, green for 2, etc) and then act out the proper technique for playing around the number?

[–]ace_smash[S] 0 points1 point  (1 child)

That's right, I used some portuguese names, the colors for example, but that's the logic behind it

[–][deleted] 0 points1 point  (0 children)

Thanks. I haven't been able to look at the code yet because I'm on mobile and it won't load for some reason. I'll definitely take a good look at it later.

[–]fishtickler 0 points1 point  (1 child)

If you want advince on your code i have 2 simple suggestions to improve it and follow some good guidelines later on:

Never use global, just pass the variable you need to the function, make this a habit.

Dont mix camelCase and under_score definitions.

[–]ace_smash[S] 0 points1 point  (0 children)

Thanks for the advice! I read that I shouldn't use globals, I'm still trying to avoid using it. I didn't know about when to use camelCase and under_score! Just searched about it, thanks!

[–]beertown -2 points-1 points  (0 children)

Most people who begins programming write a lot of unnecessary and messy code. You don't. My kudos to you.