Wednesday, September 22, 2021

Casual games part III: Mahjong

Let us continue this mini-series on the casual video games I like. Today I would like to talk about Mahjong. Mahjong is a matching-pair game which uses game tiles from a traditional Chinese game with the same name. The original Mahjong was a game for four players which was often played for the purpose of gambling – not unlike poker. The game we play on our computers should probably be called Mahjong Solitaire, because it is played by only one player. Because of its popularity and because it uses the same game tiles, Mahjong Solitaire in the West is currently called just Mahjong which may sometimes be confusing. 

As with other solitaire games, I made my two versions of the game. The first Mahjong game I made was inspired by a popular Mahjong game, previously available free on the Internet which for some reason is no longer available. I tried to make visuals as similar to it as possible. And the effects are quite good, I think.

There are a number of interesting facts about Mahjong. Let’s say we want to find out whether the current deal is solvable or not. How many combinations of moves do we have to check? To calculate that we need to make a number of observations. The first observation is that the only way to get stuck is to remove the tiles of a particular category in a wrong order. Why is that?

The observation we can easily make is that once all four tiles of a certain category are available, we can remove all of them immediately without a fear that this is a mistake. This is quite obvious. Now let us assume that we have found out the correct pairing for each category. Is it possible to get stuck by removing the pairs in the wrong order? Assume that yes, indeed, it is possible and we got stuck. But, also by assumption, if we change the order of the moves we have made, we would not get stuck. But this is not possible, because in both orderings, we end up removing the same tiles. So, regardless of the order, the final outcome is the same, the pile we obtain after removing certain pairs is always the same no matter in which order we remove these pairs. Thus, since it cannot be simultaneously stuck and not stuck, we infer that the order of removal does not matter.

It turns out that the only thing that matters is which of the four tiles we match within each category. Let’s number tiles in each category from 1 to 4. How can we match these tiles? We can match 1 with 2 and 3 with 4. We can match 1 with 3 and 2 with 4. And we can match 1 with 4 and 2 with 3. There are no other possibilities. So, for every category, there are three ways we can pair its tiles. Since there are 36 categories, there are altogether 336 combinations. How much is that? It is 150,094,635,296,999,140. So, we have one hundred and fifty thousand trillion combinations to check if we want to know if a game is solvable. Unfortunately, it is not possible to run all of them on the computers we currently have. Maybe, if our computers were 1,000,000 faster, then finding out deterministically whether a Mahjong deal is solvable would be possible. Unless of course, somebody finds some algorithmic improvements which make it unnecessary to check all combinations. This may be possible although right now I am too lazy to think about it. 

And so, I recently made my second Mahjong game, which is very similar to the first one. As I was making it, I found that there is a problem with translating “Tiles” into other languages. A tile in English is something rectangular which is used to cover surfaces, especially in bathrooms or kitchens or on roofs. And so, if a low-quality translator translates a Mahjong game from English, s/he just uses the equivalent of ‘tile’ in his/her language. But this is a mistake. Many languages – and checking Wikipedia’s Mahjong’s page confirms it – use word ‘stone’ to denote Mahjong game pieces. This is true in languages as diverse as Dutch, Polish, and Romanian. 

Finally, as with Minesweeper, I wanted to give players an option to play games which are solvable. As you may know, some Mahjong deals are insolvable regardless of what you do. And so, I had to check which deals are solvable. But I did not check the thousands of trillions of combinations as described above. Instead, I just made the computer play every deal a number of times, every time using a different, randomized pairings. Then, I counted how many times a computer was able to solve the game. If the number was 0, then I treated the game as unsolvable. Of course, the game could still have been solvable – the computer just could have not found the correct pairings. But that did not matter – I wanted to have games which were proved to be solvable and false negatives were not really a problem. Moreover, the number of times the game was solved gave me an approximation for difficulty a human player could experience while playing a particular deal. And this is how I created various difficulty levels in my games. 

Well, that’s it. I hope you found some valuable information here :)


Wednesday, September 8, 2021

Casual games part II: Solitaire

Another game I like to play is Solitaire. Everyone knows Solitaire. Some of us even know how to play it with actual cards on a table. This is actually how I played the game for the first time. Oh, how fun were these days without computers :)

Klondike Solitaire, also known simply as Solitaire, is the most popular solitaire video game. This is because it was added to the Microsoft Windows operating system in the early nineties. From then on, people spent countless hours playing it instead of working on their computers.

So why is Solitaire so fun? Well, this is a game which allows you to relax. It has the right mix of strategy, perceptivity, and luck - with the strong emphasis on luck. It does not require you to think to much, it has a little of a gambling aspect, and makes you feel good when you win it – which actually does not happen too often, even with the lowest difficulty settings. The game actually does not allow you to win most of the time – even if you play perfectly.

So how to play Solitaire? You can watch my video with an example of gameplay, or you can visit one of the games I made. There just click on the “Help” in the menu up top and scroll down to the “Solving Example” section. This is actually the second version of the online Solitaire I made. The first one can be found here. So why do I have two versions? Well, the first is older and a bit worse – fonts are smaller, there are no tutorials etc. When I decided to make an upgrade, I figured it is not good to overwrite the old game with a new one. Many people are familiar with the old look and will be upset with the new one. And so, I made a new version and published it alongside the old one, despite being quite similar.

So the question is: is this all to Solitaire that there is? No. Solitaire in general is a genre of card games whose objective is to arrange originally disordered cards in nice stacks, starting with aces and ending with Kings. The fact the this particular game – Klondike Solitaire – uses the name assigned to the entire genre – Solitaire – may be confusing but it is a reflection of the game’s popularity.

So, what are other solitaire games? Currently my favorite solitaire game is Spider Solitaire. While Klondike Solitaire puts more emphasis on luck when it comes to the strategy vs. luck balance, Spider Solitaire puts much higher emphasis on Strategy. It has four difficulty levels. The easiest difficulty is played with only one suit (or color) of cards. That is, all 104 cards that you have on the board are, for example, Spades. The medium difficulty (2 Suit Spider Solitaire) uses two opposite colors. For example Diamonds and Spades or Hearts and Clubs. Or Diamonds and Clubs. Or Hearts and Spades. You get the idea.

Having more colors complicates the game, because of the game rules – you can move a stack of cards only if all the cards in he stack are of the same color. Obviously, it is the easiest if there is only a single color on the game board – you can move any stack you want. But with two colors things get more complicated. They get even more complicated if the player chooses hard difficulty setting, that is a game with four colors, otherwise known as 4 Suit Spider Solitaire. Now the player plays with two full decks. If you want to learn how to play Spider Solitaire you can watch my walkthrough video or read the tutorial on my second Spider Solitaire game site, which is in the “Help” section.

In my experience 1 Suit Spider Solitaire is quite easy to solve. 2 Suit Spider Solitaire is much harder, but apparently it is also almost always solvable. However, I solve it only in around 1/3 of times. 4 Suit Spider Solitaire is the hardest. I solved a few times in my live. And I made many more attempts. Apparently, it is supposed to be solvable in around 1/3 of cases, but I have no idea how to achieve that. And so, for now I concentrate on the 2 Suit Spider Solitaire.

I made and published two such solitaires on the Interent. Here you can find the first Spider Solitaire game I made. And here, you can find the second. The story is similar as with the traditional Klondike Solitaire. When I was creating the games, I wanted to make sure that the graphics are very user friendly and that the cards occupy as large portion of the screen as possible – many published games occupy a very small rectangle in the middle of the screen. This includes the game made by Google and it makes the game really annoying to play.

The third game I wanted to talk about is Freecell. Freecell is another simple solitaire game available on Windows since time immemorial. It is quite easy once you learn to play it. This game is almost always solvable and so it can be said that it does not require any luck, and your performance depends on logic alone. Freecell is not as popular as Klondike Solitaire or Spider Solitaire and I play it only occasionally. But it is always a lot of fun :) As with the two other games, I made my own versions of Freecell Solitaire which are available here and here. And if you want to learn how to play it, visit the second of these two links and click on “Help” or go to my YouTube walkthrough video.

Hopefully, at least some people will share my love for these games. As for which games I recommend? You can probably start with Klondike and then move on to Freecell and eventually to Spider. And I hope you will play with the games I made as they are (of course) the best available on the Internet :)