Tuesday, August 24, 2021

Casual games part I: Minesweeper

Hello. Today I would like to post something about my favorite video games than can be found on the Internet.

My first favorite game is Minesweeper. I have been playing Minesweeper since High School. This is when I learnt how to play it quite fast. I am not a master, but I still can play quite fast. You can watch me play on my video channel. Click here to watch one of my videos. 

I like the Minesweeper game so much, that I made a bunch of JavaScript versions of this game and published them on the Internet. My first Minesweeper game was in Polish and Spanish and was unavailable in English. But my second game is available in English and can be found here.

So how my game differs from others? Well, the traditional Minesweeper game is of course a logical puzzle, but also depends a lot on luck, especially while playing on higher difficulties. Every expert player encountered a frustrating situation in which s/he has to pick randomly between two locations of a mine because it is impossible to figure out where the mine actually is using logic alone. This is especially frustrating if you made a considerable effort to solve almost the entire game and the lucky shot must occur at the end of the game. Though, I learnt later, some people actually like this feature. How strange.

Anyway, to get rid of this frustration I decided to add a feature to my Minesweeper games. This feature is called “Pure Logic” or “Pure Intellect.” With this feature on, the game always generates boards that are solvable by logic alone. That is, you will never encounter a situation in which you actually have to guess. To implement it in my code I used an optimized version of the Tank algorithm with some improvements. This algorithm ensures that the games are always solvable. The algorithm is also highly intelligent. I remember being asked if my algorithm is not too stupid. That is, whether it eliminates some configurations of mines which actually can be solved by a genius player but my algorithm is too stupid to figure them out. And the answer is no: my algorithm is ultimately intelligent, because at its core it boils down to checking all possible configurations of mines and eliminating those which yield contradictions.

A huge advantage of having deterministically-solvable (i.e. solvable without need of luck) Minesweeper boards is that with this feature boards can become quite huge. If the luck is involved, for huge boards, you will sooner or later run out of it. In other words, solving a huge Minesweeper board that depends on luck is like rolling dice 10 times and getting 6 every time. In theory possible, but in practice not so much.

And so my Minesweeper Pro game allows for really big boards, and offers two new predetermined difficulty levels. One is Superman with a board of 50 by 50 and 500 mines and the other is Alien (or Extraterrestrial) with a board of 100 by 100 and 2000 mines. Watch videos on my channel to see how I beat both these difficulty levels.

But that’s not all. The size of the board in my second Minesweeper is limited by the number of graphical elements a web browser can display. You can imagine it as a huge table. If the table is 100 by 100 it has 10000 cells. And many browsers cannot support tables much bigger than that. 

To solve this problem, I decided to use different technology and instead of using HTML elements I used Canvas. So, there are no more humongous tables but there is a picture instead. And I just paint over this picture. This is the technology I used to create my Third Minesweeper Game. This allowed me to add a new predetermined difficulty setting: God (or Godlike). God boards are 250 by 250 with 10000 mines. And believe it or not, I actually did solve it. My best time (as of 2021-08-24) with God difficulty is 4 hours 44 minutes and 30.05 seconds. I know there are at least two people who also solved this difficulty level with times 6:08:06 and 6:17:14. And more is coming – the game has not been popular too much yet, because it still does not rank well with Google.

Unfortunately, creating much larger boards or boards with higher mine density is hard. My algorithm is tuned so that it tries to create a board for a predetermined number of milliseconds, and if it fails to do it in the allotted time, it just stops and spits out an error. Larger boards and boards with higher mine density are generally harder to create and take more time. The 250 by 250 monster with 10000 mines is close to the limit, beyond which reliable board generation is no longer possible.

Eventually, I also decided to create my Fourth Minesweeper game. This is just a simple game based on an old engine which is suitable for people who like nostalgia and do not mind having to use luck from time to time.

I hope you will find your favorite Minesweeper game among my creations ;)