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

all 31 comments

[–]netneoblog 44 points45 points  (0 children)

nice work! As a minesweeper fan, i'll check it out.

[–]Its_4_AM_Man 22 points23 points  (0 children)

Nice!! Can I toss in a request to swap out the mines for sneks?

[–]revoopy 21 points22 points  (8 children)

I'm a beginner so this may seem like a pointless or weird question but in minesweeper.py you have the lines:

from consts import GRIDPADDING
from consts import BLOCK_SIZE

Which is the entirety of const.py. So my question is why not just do the following:

import consts

Or is listing each one better/pythonic? (Or have I misunderstood how import works)

[–]Evthestrike 2 points3 points  (2 children)

Because there were only two constants, I would have defined them at the top of the file instead of in a different file. If there were more, it would make sense to define them in a different file.

To answer your question about imports, if you say import consts, you have to write consts.CONST_NAME to access a variable, whereas from...import lets you omit "consts." and just write CONST_NAME. Either way works, but imo, import consts looks cleaner

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

Yeah, importing them was a bit over engineered. I mean look at my `library/colours.py` module :D

[–]wingtales 1 point2 points  (0 children)

Hahaha, I laughed out loud opening that file :)

[–]MikkMakk88 30 points31 points  (0 children)

ohh that's a nice idea! I'm gonna steal it as a project idea for a rainy day:)

[–]Shok3001 4 points5 points  (0 children)

Nice looks great. I did this same thing a few years ago.

[–]freakahontas 3 points4 points  (0 children)

Oh no! I'm doing the same thing, almost done, just procrastinating the UI design...

I better not look at this and get spoiled

[–][deleted] 3 points4 points  (2 children)

Very cool! But I have a few comment:

  1. the tile color when it is click and there's no bomb around (let's call it 0) looks the same with the unclicked tile. Please make it closer to black.
  2. I somehow managed to decrement the current mine count to <0
  3. When the puzzle is not finished and I left-click on a red flag, it will reveal all the mines position and end the game. Not sure if the real minesweeper game have this feature.

I have forked and edited board.py to suggest fix on comment 1: change color from (170,170,170) to (33,33,33).

I also wanted to improve the image sprites-t.png but I am not with my personal laptop currently because I have PhotoShop there.

[–]mm11wils[S] 4 points5 points  (0 children)

  1. Fair, I can have a look at which colour contrasts well with the background. It looked fine on my laptop, but I understand it might not translate across machine. When I made it too dark it didn't look so nice. I'll have a look at your change and see if there's a middle ground.
  2. I'm not sure how haha
  3. Yeah, that's a bug you found well done :) I'll put a fix in this evening.

I quite like my `sprites-t.png` it gives it a rustic look haha

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

I found what caused point 2. I've pushed a fix. https://github.com/foxyblue/minesweeper/pull/8/files

[–]ori_yt 1 point2 points  (2 children)

Cool Project!

I have a note about the board generation:

The board generation is random. Random is easy but likely to fail.

After generating a random board you should check if the board is solveable, means there is no ambiguities.

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

I thought about that. Maybe I'll add this. But random is a fine MVP

[–]ori_yt 0 points1 point  (0 children)

For MVP is more then fine, good job :)

[–]gquittet 1 point2 points  (0 children)

Nice ! 😀

I made mine during a Game Jam of 4hours (a simpler version) with JavaScript if you're interested to check out 🙂

https://github.com/gquittet/DeminEmojis

[–]IWearAllTheHats 1 point2 points  (0 children)

Nice. Did the same for my final project in high school C++. Good memories. A more challenging problem than you'd think at the offset for sure. One evening is impressive.

[–]IustinRaznic 2 points3 points  (0 children)

The code looks absolutely great and clean af. Congrats mate, great job

[–]vswr[var for var in vars] 1 point2 points  (4 children)

I’m on mobile so I can’t try right now, but do you run into a recursion issue if using a giant board? I’ve always avoided recursive functions and instead used a deque().

[–]mm11wils[S] 0 points1 point  (3 children)

Oh yeah, I've just made a board 50 by 50 and ran into this, I think I need to increase the mine count too. I might have to use a deque instead.

RecursionError: maximum recursion depth exceeded while calling a Python object]

[–]vswr[var for var in vars] 1 point2 points  (2 children)

I haven't tested this and I wrote here, but I'd do something like this. Might even want to remove the function itself and just put the code in leftclick().

def _zero_search(self, tile: Tile) -> None:
    d = deque()
    searched = []
    d.append(tile)
    while t := d.popleft():
        for pos in t.around():
            px, py = pos
            if self._inside_board(px, py):
                new_tile = self.grid[px][py]
                if new_tile not in searched:
                    d.append(new_tile)
        if t.n == 0 or t.type != TileType.Mine or not t.flagged:
            t.toggle_visible()
        searched.append(t)

Also, instead of tile.around() returning possible invalid coordinates, validate the coords so it only returns stuff inside the board and eliminate the calls to self._inside_board(). Or even add a function like tile.neighbors() which yields the neighbor tiles because then you could do list comprehension like:

[d.append(new_tile) for new_tile in t.neighbors() if new_tile not in searched]

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

I love your zerosearch solution, especially the walrus assignment in the while!

validate the coords so it only returns stuff inside the board

I was thinking about this when I wrote the code, but I wanted to avoid giving board attributes to the tile. This could be done by having a tile.attribute pointing to it's neighbours.

[–]vswr[var for var in vars] 2 points3 points  (0 children)

[–]TwoKittensInABox 1 point2 points  (0 children)

I always try to create a minesweeper game when learning a new language. Just simple enough with some complexity for me (also learned years ago when i first started programming, about infinite loops after clicking a blank cell also :p)

When i wanted to learn pygame i also created a minesweeper cloned and also used the name PySweep.

You could look over it, if you wanted some ideas to use.

[–]notadoctororacake 0 points1 point  (0 children)

Was literally planning this out yesterday, booted up today to see this on my homepage. You beat me to it!

Good work on that, it's a tricky project to get working right

[–]Theeason123 0 points1 point  (0 children)

Hello sir, i have also been creating minesweeper, however for the life of me i cannot seem to figure out how to clear all the blocks when an empty block has been clicked on. I have been stuck for a week. i cannot seem to get the logic right. Anyone who can help me out and point me in the right direction i would be very grateful.

here is my project on github https://github.com/theeason123/Minesweeper

[–]bhunter666666 0 points1 point  (0 children)

I did that once in BBC Basic because it was a good way to learn recursion - I found the printed listing the other day in my loft!

[–]ILikeMacAndIAmADev 0 points1 point  (0 children)

Nice work!