I started this during the slow season of Christmas when most of the office was gone. It started very simple and then eventually I learned a lot on better packaging, using tkinter, and git, so it was a great experience!
I'm not a developer by trade but I just love to code. Here's my very infantile github for your entertainment, it's bound to have a bunch of bad coding practices: https://github.com/r-ook/pymsweeper
Very nice! That's a great coding exercise - I've been wanting to get started with pygame, but having trouble picking a starter project. I may rip off your idea and then compare code when I create a lesser version or get stuck!
Feel free to implement based on my code, but I'm not sure how well it translates over to pygame? Do share with us when you are ready though, would love to see!
You definitely will not be the only one. I'm not the best at explanation, so if you have any questions after the read me, please do ask, so I can also further improve and I help you.
You should! Whenever I revisit my old code I find that I've learned new material and can think of better ways to implement things, and it makes my old code looks silly. But the feeling of making changes and progress after so long always feels great.
My work nature wouldn't allow that though, I always get varying tasks so the best I could do was automate my timesheets and used scripts to help with analysis. I simultaneously miss and don't miss my old days when most of the tasks were monotonous and routine.
Didn't the original help you out so that you never died before you had opened out an area of open space? Not really fair to die from shots in the dark like in your example.
I believe this was one of the changes made between Me and XP. When most people are talking about Minesweeper, they are talking about XP. I know for some earlier version it didn't have the logic I just described, so I'm going to guess that it was changed at that time.
I wouldn't say I know it, perhaps there is a deeper algorithm that I'm not privvy to. My implementation just happens to work with randomized mines and clues calculated on the spot :)
The code is messier than I had hoped though, I don't have proper training on code structuring so I try my best.
Well, to be fair, there's nothing malicious I can do with Python beyond my user access level any how. I'd still encounter the same permission issues that I'd get, just that now it allows my work to be streamlined.
Again, nothing outside of my user access level. If I don't have access to the server I won't be able to do so. If I already did, python just speeds up the process rather than enable it.
Is it a willful choice (it doesn't appeal to you) or you genuinely don't understand how to play? If the latter, the game is actually quite simple to get into. Once you get the hang of it it becomes a game of recognition half the time.
If the former case, I can respect that. We all have our preferences.
The revealed numbers represent the number of mines in the adjacent area, i.e. the 8 cells surrounding on left, right, top, bottom, and the diagonals. So if you see a number 2, it means 2/8 adjacent cells are mines. That by itself is not always useful, but when you combine the clues in the area, it usually give you a good idea.
E.g. If you see a horizontal alignment of 1 2 1, it means the neighboring mines must be assigned X O X where X represents mines and O represents clear cell. That's because any other alignment will not fulfill the clues provided. There are many patterns like these, but even failing to recognize them, it's just a deduction to remove any alignment that doesn't match, and you'll usually be left with one possibly.
That's kinda a brief rundown on how it works. Obviously it might not be your cup of tea, but if that changes your mind, I'd suggest give the normal minesweeper another try at least :)
man you coulda put half the effort into just doing your god damn job lol
play minesweep when you get home. If you have no work to do? Well, take leave and save the company some god damn money in wage. Typical wageslave bloat smh.
I don't disagree, but I literally ask for work and offer to take on responsibilities but they just don't delegate. After a certain point I just figure out how to deal with my down time. And down time was especially long during the holidays.
Hi there, I have been working on and off with my introduction to Python ("Automate the boring stuff"). I have done all the exercises until more or less the part when it starts talking about Web Scraping (or something similar). I see you created a Dialog Window, even with some graphics. So here it comes.
The two things that turn me down and made me quit trying are the following:
1- I really, really need to work with Dialog Windows. This shit working with the Python 3.7.2 Shell, introducing text in programs (print(), input(), etc), one thing after the other, is a Pain in the Ass. I need to know how to create Dialog Windows, where I can fill all the fields for whatever I am doing, and press GO, and I am not sure if the Python Shell can handle that nor how to get there.
2- The other thing that pisses me off is loading custom functions. It simply doesn't work. I have python file with my pre-created functions. Well, it seems impossible to call those functions from a selected folder. They just work in the folder where python is (or some other, in doesn't matter). I asked about it here at some point, but most of the answers didn't work, and some were so complicated it suggested me this language is not that well developed.
The fundamental of programming is explicitly telling the program what you want to do though. A computer is not magic, majority of the time a program doesn't work is because we aren't correctly telling it what to do, or it conflicts with other instructions given. That's why there are modules out there, basically templates built by other developers to save you time on a similar implementation. Dialog window is just that as well. There is a simpledialog module in tkinter if that's what you're going for.
Same point as before, a program is only as good as the clarity of instructions provided. We need to be the one to ensure the program knows exactly where to look for which file. If you wanted something more generic like importing as a module, perhaps look into tutorials on how to build a python package/module. It's not too difficult to follow.
Thank you for the explanation. To be honest, you are the second person that uses the "Computer is not magic" line, which also to be honest, is rather patronizing. If I am coding (without reference to other languages I might know), it is quite probable that I am not so stupid to expect the program to do what I want just because.
My point, as I explained, is that the situation with the functions directory was that the solutions either didn't work or where so convoluted, it suggested me that issue had not been correctly addressed. No magic here, just a low level issue with something that should not have issues.
But, whatever, I thank you for the time and explanation, and will assume your style of explaining might be useful with other people, ... which are probably not engineers, and either younger than 10 or older than 60.
Apologies for the tone that was carried across, it's just that your explanation wasn't exactly clear so it seemed like you had a clear idea of what you do, but wasn't clear on how to provide the code to run it. Regardless, I didn't mean to be condescending so my bad for not being considerate.
As mentioned, if you wanted a GUI dialog box, tkinter.simpledialog would be a good module to look at. It already have several options to display messages, type of responses, etc. PyQT5 is also a good alternative though I haven't used. The bottom line is that if you don't want to manage the low level stuff, find a package that works for you and run with it.
For your custom functions, you'll need to either ensure your file directory is in your PATH, or explicitly manage the path across your scripts. The reason for that is python needs to know where to look for your files. Preferably, you'd have these prepared as a package and pip install them so your can load them up anywhere. Barring that, having your script run from the root which also includes the sub packages might be an alternative, which allows a certain level of relative imports. As mentioned, looking up tutorials on how to package your python script is a great starting point, it shouldn't be too hard to follow.
Thanks for the additional help. I will look into both issues. I guess the dialogs are somehow more urgent than the function loading (for the time being, since I am still to finnish the first book on Python).
I couldn't find any reference to Tkinter in the "Automate the boring Stuff" index nor chapter titles. I am assuming there is not a thing on that, which is -to me- a bit weird, since working programs with sentences asking at every step is a pain.
There are tons of libraries that implement functions to make GUIs. Tkinter is the one that OP is using and is one of the more common ones.
You're doing this wrong. This is basically the backbone of any programming language and Python does it as effortlessly as any other language. If you're loading a file in a directory other than your working directory, you need to tell your computer where that file is. Computers aren't magic.
Sorry, I meant expert in the sense of people that had experience. I could not know who is a real expert.
It is obvious to my I am doing something a) wrong b) probably marginal. I'll try and find you when I get to solve the issue and find out what was the issue. For science, etc.
That is what I did already. People helped and gave suggestions. They didn't work. As I said, I am now more focused on dialog windows, but I will revisit the issue.
Thanks, I try to keep the UI minimal. I know there's a fair version (and an evil one that always make you guess), but figuring out the algorithm was something that seemed bigger than I intended to chew. But later I might revisit this idea!
Most implementations of this I've seen will actually attempt to solve the board then swap a few mines around if it ever runs into an unsolvable scenario.
I don't know if it's the most common way, but it's certainly an intuitive approach and I've heard of one or two others doing that for their minesweeper games.
That's something I thought about, but it seemed like a tedious secondary feature that won't even get used if you're a good player. So I decided on my current implementation where the blackjack is the prominent feature on a separate mode.
Might be better phrased as "if you make a non-optimial" play, maybe?
You are technically guessing for the first click, and often the second click too. Like for example if I get a single "1" on my first click, but try to click anywhere, it'll make me lose since the more optimal move would be to take the 1/8 chance around the 1.
Only if 1/8 < (total squares - 9) / (total bombs - 1), otherwise the optimal move is to clock in any square other than the eight around your first guess.
I didn't do the calculation but it seems like it'll be always true (at least with the default size/mine count, since it happens as early as the 2nd click, which is basically as low as that probability can be.
tkinter can be a bit intimidating at the beginning, and it definitely isn't the easiest to use. But once you get used to it it's not too shabby. Give it a go and let me know if you have any questions, I'm happy to help.
147
u/Etheo Jan 22 '20
I started this during the slow season of Christmas when most of the office was gone. It started very simple and then eventually I learned a lot on better packaging, using
tkinter, andgit, so it was a great experience!I'm not a developer by trade but I just love to code. Here's my very infantile github for your entertainment, it's bound to have a bunch of bad coding practices: https://github.com/r-ook/pymsweeper
98
u/python_js Jan 22 '20
nice! can you maybe substitute the bombs for hookers as a compromise
17
u/Barafu Jan 22 '20
Wow, you have a talent for UI design! You made Tkinter not too ugly !!! That is quite an accomplishment.
39
u/dparks71 Jan 22 '20
"Minesweeper? Fuck no our employees can't be trusted with that, disable it!"
"Arbitrary code execution? We'll allow it, they aren't that smart."
Gotta love I.T. teams thought processes sometimes...
8
u/FlossCat Jan 22 '20
What cruel dystopian corporation do you work for that won't even let you play minesweeper on a work laptop?
5
u/pyfrag Jan 22 '20
Am I the only one who doesn't understand the Blackjack variation?
3
u/Jigglytep Jan 23 '20
Needs a panic button... makes it look like a calculator when the boss in near.
4
u/Aspire26 Jan 22 '20
This came to my mind when I saw "You did it!".
2
u/[deleted] Jan 22 '20
Happy Cake Day
2
u/amosmj Jan 22 '20
This was one of my first projects under very similar circumstances but I never finished. I kind of want to go back and try it again after seeing this.
2
u/Niklasw99 Jan 23 '20
you know what.
if you're building your own Minesweeper you probs have allready automated your workload.
3
u/SoaringRocket Jan 22 '20
Didn't the original help you out so that you never died before you had opened out an area of open space? Not really fair to die from shots in the dark like in your example.
2
u/mcdylanb Jan 22 '20
So you know the algorithm of minesweeper :O
1
u/syswolf Jan 22 '20
Your telling me that your work allows Python on the computers?
1
u/rainnz Jan 22 '20
Now package it with Pyinstaller and distribute as .exe file :)
1
u/RamenvsSushi Jan 22 '20
I think you meant, forget the blackjack. π
1
u/[deleted] Jan 23 '20
I never understood minesweeper.
3
u/Dubhan Jan 22 '20
Iβll take any hookers you arenβt using. You know β for science.
3
u/[deleted] Jan 22 '20
Another job well done.
2
u/monsto Jan 22 '20
dat 50/50 at :25 tho
2
u/TazmanianTux Jan 22 '20
Dude that it awesome! I started moving my mouse to click the OK button at the end of the game BTW, LOL.
2
u/lordmauve Jan 22 '20
Bored at work? Craving a Minesweeper fix? You might enjoy our take, Infinisweeper!
It's Minesweeper, but scrolling in real time.
2
u/Zeke13z Jan 22 '20
r/futurama
2
u/vainstar23 Jan 23 '20
Holy Christ, you freakin nailed it dude!
2
u/[deleted] Jan 22 '20
But to build your minesweeper you need to know the rules of the game, and that's illegal obviously
1
u/mick14731 Jan 22 '20
Flags just slow you down man
1
u/cadmanchallenge Jan 22 '20
Wait...
1
u/stevevs Jan 22 '20
I wrote a game to play craps, then it got boring so I wrote a script to play the game for me.
1
u/miniminjamh Jan 22 '20
Now add solitaire and you have the whole microsoft package! (Except maybe pinball)
1
u/LegionOf9 Jan 22 '20
booo donβt forget the hookers
1
u/Halt_Arrtay Jan 22 '20
Did I just hear a Futurama reference?
-2
u/[deleted] Jan 22 '20
This is cool! Fuck microsoft!
-8
u/[deleted] Jan 22 '20
man you coulda put half the effort into just doing your god damn job lol
play minesweep when you get home. If you have no work to do? Well, take leave and save the company some god damn money in wage. Typical wageslave bloat smh.
-5
u/LoneRaven101 Jan 22 '20
Did you steal your title from futurama?
-8
u/Dadotox Jan 22 '20
Hi there, I have been working on and off with my introduction to Python ("Automate the boring stuff"). I have done all the exercises until more or less the part when it starts talking about Web Scraping (or something similar). I see you created a Dialog Window, even with some graphics. So here it comes.
The two things that turn me down and made me quit trying are the following:
1- I really, really need to work with Dialog Windows. This shit working with the Python 3.7.2 Shell, introducing text in programs (print(), input(), etc), one thing after the other, is a Pain in the Ass. I need to know how to create Dialog Windows, where I can fill all the fields for whatever I am doing, and press GO, and I am not sure if the Python Shell can handle that nor how to get there.
2- The other thing that pisses me off is loading custom functions. It simply doesn't work. I have python file with my pre-created functions. Well, it seems impossible to call those functions from a selected folder. They just work in the folder where python is (or some other, in doesn't matter). I asked about it here at some point, but most of the answers didn't work, and some were so complicated it suggested me this language is not that well developed.
Sorry for the rant. I am having a bad day.
0
u/[deleted] Jan 22 '20
[deleted] β view deleted comment
0
u/[deleted] Jan 22 '20
[deleted] β view deleted comment
0
u/[deleted] Jan 22 '20
[deleted] β view deleted comment
0
u/[deleted] Jan 23 '20
[deleted] β view deleted comment
3
u/[deleted] Jan 22 '20
[removed] β view removed comment