[Community Puzzle] Minesweeper

https://www.codingame.com/training/medium/minesweeper-1

Send your feedback or ask for help here!

Created by @eulerscheZahl,validated by @JBM,@Marchete and @Djoums.
If you have any issues, feel free to ping them.

2 Likes

This retro viewer is simply priceless!!!
Can we vote for your next puzzle?
+1 for a FreeCell solver, aber natürlich in Win 3.x style… :slight_smile:

2 Likes

FreeCell is an interesting puzzle and should be doable as a weekend project. I’ll put it on my list.
Usually I try to learn something new in these contributions. E.g. this one has a system clock which shows the real time and a debug view that re-scales a part of the screen instead of changing visibility. None of those is possible if you stick to the Java part of the SDK.

I have another project in mind but that’s going to be a complicated one and I’m not sure if I have the passion to do it. So FreeCell seems a nice filler when the other project frustrates me too much.

Cool!
According to this article FreeCell problem has enough depth for multiple possible approaches, including GA, heuristics, etc. And most likely not brute-forceable in CG’s available solving timeframe.

Your puzzle made it in the last CG mailing, congratulations :grinning:

Mmm. I had a FreeCell implementation in the works.

Ok, FreeCell is all yours then.

Well, here’s a start: https://www.codingame.com/contribute/view/56162cb1ae8743fbda12c6b2eb519b8055a7

1 Like

someway a stupid question for sure … is there a way to put some flags or is it has to be memorized ?

sorry i just understood :smiley:

extremely funny !!! i got giggles during simulation specially for the hazardous heuristic strategy when no one of my real strategies occur… cheers ! *****

Got it at try 31 with the laziest AI ever :rofl:

I can assure you that success rates above 50% are possible :wink:

Yes when I look at the games that failed there were obvious moves to be done but my algorithm goes like this:

  • identify very obvious mines
  • deduce very obvious non mines and play one
  • if no obvious non mine, calculate probabilities of being a mine in the neighbourhoods of digit tiles, and play the tile with the lowest probability
  • if no digit tile with unknown tiles in their neighbourhood, play a random tile that is not a identified as mine

I think the structure is okay but the problem is the first part, I identify a mine only when the neighboors match exactly the digit, but there are many other ways to identify a mine/non mine.
Example:
|???
|111
|…
Here obviously the third ? is not a mine cause there is a mine among the first two ?s so the midle 1 cannot refer to the third ?.
My algorithm doesn’t detect this kind of stuff at all, that’s why I called it lazy.

2 Likes

Spoiler Alert: If you want to solve some of the situations you mentioned, you may want to check out this video https://youtu.be/cGUHehFGqBc?t=146

It’s no longer completley lazy, but not too much effort either.

1 Like

The hour displayed in the UI stays up to date ! :heart_eyes::heart_eyes:

4 Likes

Thanks for noticing, I spent more time on this little detail than I should have.

5 Likes

Hi guys!
It is a really nice challenge and I really enjoyed writing a code. But, does all challenges has a solution? For example, for this one Coding Games and Programming Challenges to Code Better I don’t know what the next move should be. If I’m not mistaken, every adjacent cell could contain a mine.

I don’t know but I guess they’re not guaranteed to have a logical solution, as in real minesweeper (it’s actually frequent that you have to guess once or twice in a game).

As for your example, it’s not as locked as it seems.
Let’s label tiles around your hole like this:

abcde
f...g
h...i
j...k
lmnop

g and i cannot both have a mine cause if they do, c, d, e can’t have a mine so the top-center 2 has only one neighbour left (b).
So it means that k has a mine and g/i share one.
For similar reasons, b has a mine and c/d share one.
Therefore, e has no mine.

1 Like

It took me the entire night to 100% it from scratch.

This should be an optimization game with scoring to compare our algorithms! :smiley:

Since Minesweeper is NP-complete, the best algorithm should be a SAT solver, which is sort of what I’ve done. Each slot of the board is a boolean variable which is true if there is provably a mine, and false if there is provably none. Each slot with a number of adjacent mines gives a set of clauses restricting the variables around. The goal is to prove that there is no mine (prove that a variable is false) before selecting the slot, or figure out some probability in the worst case.

The hardest part of course, was optimizing the data structure to avoid timeouts.

I can improve my algorithm further to win more often, maybe I will do it just for the solution contest.

1 Like