
Hello, dear readers. I sincerely hope that among the readers of Habr there will be lovers of such a wonderful game as
"Minesweeper" .
If I remember correctly, for the first time this game appeared on the
Windows 3.1 operating system back in the 1994th year. At that time, this game was positioned as a means for teaching how to use a computer mouse and, in general, the OS graphical interface. She looked like this:
')

The principle of the game according to WikipediaA flat or volumetric playing field is divided into adjacent cells (squares, hexagons, cubes, etc.), some of which are “mined”; the number of “mined” cells is known. The goal of the game is to open all the cells that do not contain mines.
The player opens the cells, trying not to open the cell with a mine. Opening a cell with a mine, he loses. Mines are placed after the first move, so it’s impossible to lose on the first move. If there is no mine under the open cell, then a number appears in it, indicating how many cells adjacent to the just opened one are “mined” (in each game variant the neighborhood is defined in its own way); using these numbers, the player tries to calculate the location of the mines, but sometimes even in the middle and at the end of the game, some cells still have to be opened at random. If there are no mines under the neighboring cells too, then a certain “non-mined” area opens up to cells that contain numbers. The player can mark "mined" cells in order not to accidentally open them. Having opened all the “non-mined” cells, the player wins.
However, as time goes on, the popularity of the sapper falls, and I want to make a new life and colors in this game. That is how the multiplayer version of the game, called “
Russian Minesweeper ”, which is a browser-based online game, was born. Interested please under the cat.
Game Characteristics
Of course, in order for a certain number of players to play this game together, the rules will have to be somehow modernized and generally modified. However, the main rule is the essential principle to leave as in the original.
Thus, in fact, a set of rules was developed to allow several players to play simultaneously on the same field.
The basic rules of the game are as follows:
- The goal of the game is to be the first to mark all mines with flags.
- Each player has their own (local) flags.
- Players have the same (global) mine field.
- Players take turns ( however, the development of a "parallel" mode is underway ).
- If a player clicks on a mine, he will lose, and his opponent will win accordingly.
- The time for the player's turn is limited (~ 25 sec.) - it is necessary to walk as quickly as possible.
- If a player misses a move three times in a row, he loses, and his opponent wins accordingly.
- If a player misses six turns for the entire game, he loses, and his opponent wins accordingly.
- Draw is impossible. One of the players in any case will put the flags correctly faster than the other.
- The first move goes to a random player.
- The player can surrender at any point in the game.
A number of characteristics of the minefield for the game were also developed:
- Undermining the opening of the first cell at the beginning of the game is impossible.
- Mines are evenly distributed over the playing field.
- Properties of the "void", opened with the first click:
- Size A to B empty cells ( 0 min around ).
- Emptiness should not be a line of open cells only on one side of the orientation.
- The percentage of mine cells (the type of regulator is real ) and the size of the field are regulated in the application settings.
Thus, with the current configuration, with the first click, an “emptiness” from
3 to
12 “zero” cells opens, and a field of size
32x20 .
I apologize for the huge number of lists, however, I can not fail to mention that the game apart from this has the following functionality:
- Accord - the opening of more than one cell per turn. This is possible in the case of a click (LMB) on a digit in a cell on the playing field, and the number of flags around adjacent cells is equal to the target digit.
- Helping the opponent - by the middle mouse button, or [clicking on the opponent's nickname from the top + click on the desired cell]. Displayed in green:

- Chat - between players in real time.

- Nickname in the game.
- Sound in the game.
Technology
A complete list of technologies used in product development is as follows:
- C # .NET + ASP .NET - the foundation for a web server.
- HTML5 / CSS3 - for the development of the client-side interface.
- JavaScript - for dynamic work of the client part.
- JSON - for serialization / deserialization of client-server packets.
- WebSocket - the protocol is used as a client-server communication method.
- HTML Canvas is a minefield drawing technology.
- jQuery - effective and fast interaction between HTML and JS.
- JSON Newton is a library for easy work with JSON.
- Adobe Photoshop - for drawing graphic interface elements.
- GitHub - as a convenient platform for monitoring project versions.
- Microsoft Azure - to host a web server on the Internet.
- Yandex.Metrica - statistics and analysis of player behavior.
- CloudFlare - as a CDN proxy / SSL / Anti DDoS.
- Microsoft Visual Studio - as the main development environment.
- Sublime Text - as a JavaScript development tool.
- Microsoft IIS - to deploy ASP. NET

The most problematic places in the project were the following:
- Synchronize players with each other
- Problem : how to quickly notify players about changes on the field?
Options: long polling; websockets; cyclic polling; etc - Solution : use WebSocket
- Drawing a minefield and other elements of the game
- Problem : which tools will be optimal?
Options: HTML table / div; SVG; HTML5 Canvas; etc - Solution : HTML5 Canvas + JavaScript
Interesting numbers
- 23 people at least participated in the testing.
- 183 298 clicks made across the field during testing.
- From the 119th attempt, the minefield was completed.
- A 32x20 field is optimal for the game ( empirical observation ).
- From 3 to 12 "zero" cells are best opened with the first click ( empirical observation ).
And also I attach a click-through map from Yandex. Metrics, using it you can make a number of interesting conclusions. For example, it is obvious that the main area of ​​"battle" is the center of the field, and chat is popular.

Future plans
In the future, I want to finish the following functionality:
- Implement a room on N players.
- The possibility of creating a "friendly room" (playing with a friend on the link) and a single mode.
- Registration of players and leaderboard.
- "Skill Balance" (so that players play with their peers by experience).
- Optimization of the application for mobile devices.
- Transition to more powerful servers to implement the application to the masses.
- Creating a bug tracker.
- The implementation of user-friendly feedback from the players.
- More detailed statistics on the use of the application.
Conclusion

In conclusion I want to say the following - please be careful with the game server :)
It is received free of charge by a subscription from Microsoft Azure and its capacity is extremely modest.
I sincerely hope that after this article we will be able to enjoy this game together.
I remind you that it is available at
https://rmsweeper.com , and there is also a
community on VKontakte.
Thanks for attention,
Peter was with you.