“Oh, you're a scoundrel,” said Woland thoughtfully. - Messire, I again appeal to logic, - the cat spoke, pressing his paws to his chest, - if a player declares a shah to the king, and the king, meanwhile, is no longer on the board, the shah is declared invalid.
Mikhail Bulgakov "Master and Margarita"
“Matt to the king!” - many of us absorbed these words with mother's milk. The concept of the shah (and the mat) seems obvious to people familiar with chess since childhood, but is it really that simple? After a light warm-up with the transformation of the figures, I propose to deal with really complex issues.
8. Checkmate
The main difference between chess games (in addition to the characteristic method of taking figures) is the presence of the "main" figure - the king on the board. If a player loses a king, he loses, no matter how many other pieces he has left on the board. Such a rule of "sudden death" significantly enriches the game in tactical terms. The game becomes more combinational, players try to trap each other. ')
Completing the game according to the rule of "sudden death" is not a chess invention. In one form or another, this principle is used in a variety of games. In all the familiar " Tic-tac-toe ", for victory, you need to line up your pieces "in line" (and prevent your opponent from making it). The game would be quite boring without this rule. Just imagine the “tic-tac-toe” continuing as long as the possibility of the move remains (there are empty positions on the board) ...
The example seems strange, since the very essence of the “tic-tac-toe” is to line up? Here's a less obvious example: in Hasami Shogi, the figures can move and “eat” each other. In order to remove an opponent's piece from the board, it must be “ticked off”, surrounded with figures from both sides (in fact, the rules for taking in Hasami Shogi are more complicated, but I will tell you about this some other time). This rule makes Hasami Shogi related to the most ancient gaming systems of "district checkers", such as Seega .
It is logical to assume that, as in Seega, in Hasami Shogi, to win, you need to "eat" all the figures. Indeed, this version of the game exists, but it is enough to take in it not all, but only a limited number (usually 5) of the figures. The fact is that the method of capture used (by clamping "into tongs") is very slow. In order to take a figure of the opponent, you must properly place two of your pieces (of course, this does not cancel the fact that you can take several pieces at once with one move). In Seega, the limited mobility of the figures saves the situation, but in Hasami Shogi the figures are long-range and the enemy can almost always avoid the threat.
The rule of "sudden death" turns out to be most welcome. In most variants of Hasami Shogi, victory is achieved by building 5 of his pieces “in a row” (outside their original location, otherwise it would not be interesting). Capturing enemy pieces in them is not the goal of the game, but merely a tactical device that helps to win. Here, as in "Tic-Tac-Toe", the condition for victory is the relative position of the pieces.
The relative position of the figures does not have to be simple. For example, in the game " Hex ", to win, you need to connect the two opposite sides of the board with a continuous chain of pieces of your color (not necessarily straight), and in " Ritmomachia ", to achieve a "glorious victory", the figure (your own and the opponent) must be tied and arithmetic relations (in addition to their mutual arrangement).
The condition of "sudden death" can be associated with the absolute location of the figures. So, in the Chinese game Dou-shu-chi (Jungle) , to win, you need to bring any of your pieces to the opponent's Lair (marked place on the board). A similar rule introduces tactical diversity to the Japanese game Doubutsu Shogi . In it, for, to win, it is enough to hold your king to the last horizontal of the board (at the same time, the loss of a king means defeat). Similar rules apply in the games of the Tafl family, but only one of the parties has a royal figure (these are asymmetric games).
As I said above, the most familiar interpretation of the “rule of sudden death” is associated with the loss of the main figure or group of figures. It is in this form that it was used in ancient chess games, such as Chaturanga . In this game, it was required to “eat” the enemy king (“uncovering” the king, that is, taking all the other pieces, was also considered a victory). If we talk about the version of the game for four players, then a similar interpretation of the rules for completing the game is perhaps the most reasonable. Before the victory of one of the players, playing is much more interesting than before the first loss.
One recent change that Howard McCay made to my realization of Yonin Shogi (a variant of Japanese chess for four players) was connected with this. In addition to adapting the game to an earlier version of Zillions of Games 1.0, he changed the victory condition. Now the game does not end with taking one of the enemy kings. To win, you need to "eat" them all! Moreover, taken kings can be put on the board as your pieces! In this form, the game has become much more interesting.
In the quadruple version of Chaturanji with the capture of kings, everything is also not easy. Often in this game played a pair of a couple. Players sitting opposite each other formed a coalition. The player from whom they took the king, missed the moves (his figures seemed to “freeze” on the spot), but his partner could return the taken king, taking one of the opponent's kings and “exchanging prisoners”! To a greater degree, this principle was developed in Enochian Chess . In this game, the player could “take control” over the army left without a king, taking his “throne” (initial position) of the latter with his king.
Another component of the notion of the Shah (and mate) are forced moves. It is also not a chess invention. Without the concept of forced moves there would be no familiar checkers . In this family of games, the player who has the opportunity to take the figure of the enemy, is obliged to do so. It is this rule that makes the game interesting. Substituting his figure in jeopardy, the player limits the number of possible counter moves of the opponent. He can build complex tactical combinations by changing the position on the board with the help of the victims.
The honor of the invention (almost) of the modern chess game belongs to the Persians. Apparently, it was in Shatrandzh that the concepts of the “main figure” and the forced moves were combined. So the notion of a shah appeared - the king should not remain under attack at the end of the turn of the player to whom he belongs. The move that saves the king from the threat is forced (it doesn't matter whether it is taking a threatening figure or just going to a quieter place).
The concept of mat is a natural logical continuation. If a player cannot get rid of the threat to his king after completing his turn, he lost. Another new concept has emerged - a stalemate , a situation in which the king is not under attack, but the player cannot make a single move, due to the threat of the Shah. In Shatranj, in contrast to modern Chess, such a position (like the "exposure" of the king) also led to defeat.
Until now, everything seemed quite logical, but what would happen if you complicate the rules? For example, how to checkmate several kings? In Tamerlan Chess , the player can get up to three kings by completing the transformation of the royal pawn and the double transformation of the pawn pawn. In " Chu Shogi " the situation is similar - a "Drunk Elephant" can turn into a "Crown Prince" (in fact, the second king).
The Japanese, in this situation, did not become wise. Kings in "Tyu Shogi" can (and should) "eat." In Tamerlan Chess, it's a bit more complicated. In this game, you must checkmate to win. Matting the three kings is theoretically possible at the same time, but in practice it is hardly feasible. As long as there are two or more kings on the board, kings are allowed to “take” (the order of capture is not important, since all kings are interchangeable), as soon as the last king remains on the board, he needs to checkmate. In fact, this means that the kings are allowed under the check while their “deputies” are on the board.
No less interesting is the metamorphosis of the notion of the Shah when playing more than two players. I already mentioned above about Yonin Shogi. Its only difference from the traditional Shogi is the participation of four players in the game (and, as a result, another initial arrangement of figures). The result of this "small" difference was a completely inadequate processing of the shahs in the Zillions of Games version:
And this is more than just the bug of one particular implementation! Let's think a bit. Suppose a player "South" puts his king at the blow of one of the figures of the player "East", but until the move reaches (clockwise), the threat can be eliminated by the "West" or "North" (most likely the last, if the game is played for a couple "). Consequently, there was no threat and the “South” had the right to make such a move! And if the "North" and "West" did not take anything against this threat? As you can see, in such a game, the concepts of shah and mate have little meaning.
There may be other rules that affect the possibility of mate. For example, there is a variant of Shogi, which differs from the original game only in that the player cannot hold more than 5 pieces “in his hand”. This means that he cannot take any figure if there are already five of them in reserve (he must first dump one of the reserve figures on the board). This rule leads to completely anecdotal dull situations. Even if the threat to the king is considered absolute (independent of the reserve filling), it can prevent you from defending against the shah, as in the position shown below (in the original Dobutsu Shogi there is no limit on the number of pieces in the reserve, but I decided to leave it to make the implementation more fun ):
If there were still flowers, now the berries will begin. In the " Belarusian chess " mate can be put king! The fact is that in addition to chess pieces, checkers are active in this game. All pieces play according to the usual rules, that is, it is necessary to take checkers! Moreover, even more necessary than the salvation of his king from the Shah! So it turns out that if the opponent has the ability to take one of his drafts, you can safely approach your king and mate him! Very fun game.
The game can introduce additional restrictions on the mat. So, in Shogi, you cannot checkmate a pawn from the reserve (in this case, it is not prohibited to shake a pawn and mate with a regular move, too). Further in terms of prohibitions goes the Mongolian version of chess (Shatar). In this game, it's not enough to checkmate, it is important to do it ideologically correctly (the result of the game depends on it)! Let me quote a little:
The following different forms of the shah are distinguished: a shak is given by a queen, a rook or a knight, a knock by an elephant, a tsod by a pawn. You can mate only with a shakom (that is, a queen or a rook), or a continuous series of checks, including at least one shak, and if the shak is declared last, then it should not be a check knight. For example, if the next series of shahs is given (the last check - mate) - with a knight, pawn and bishop, then this is a win. If the mate is placed only by the bishop / bishop and / or the pawn / pawns, then this is a draw - nel. If one player has only one king ("naked king"), then it is also a draw - robado.
Whew ... In this and it is not easy to understand, not something to implement. By the way, with the implementation of the shahs and mats in ZoG everything is pretty sad. In the conditions of the completion of the game (victory, draw or defeat), only the following predicates can be applied:
stalemated - no move opportunity
repetition - threefold repetition of the position
captured - Capture a piece of a certain type (for example, a king)
checkmated - Mat a specified type
absolute-config - Absolute location of figures (for example, reaching a given position)
relative-config - The relative position of the shapes (for example, "5 in a row")
pieces-remaining - The remaining number of pieces (for example, in Mill , the two remaining pieces signify defeat)
total-piece-count - Similar to the previous one, but not taking into account that the pieces belonged to the player
All this is hard-wired into the core of the program and is minimally controlled by another “hardcode” - the option command (available only in version 2.0). For example, using the " include off-pieces " option, you can make the system take into account in the pieces-remaining predicate not only the pieces placed on the board, but also those that are "in reserve". There is no system in the set of available options.
It is clear that one single checkmated keyword is completely inadequate for adequate handling of all sorts of matte situations described in the article. Some problems can be solved by adding additional checks in the "manual" mode. So, for example, checking for a mate is a reset of the pawn at Shogi:
It works, but it’s extremely difficult to understand what this code does. At the same time, the fact is used that the pawn in Shogi attacks closely, only one field. It is impossible to close from her check, but you can only move away or “eat” a pawn. I can’t imagine at all how such a set of “manual” inspections would look like in the case of Shatar. To implement forced moves, the priority mechanism is used (or hard-coded “magic”, using the checkmated predicate).
Thus, the "obligatory" capture is realized in checkers. If there is an opportunity to make a move, taking the opponent's piece, you need to make it, and not a “quiet” move. This mechanism also does not seem to me quite flexible. And priority moves and actions under check can be implemented using a single universal mechanism of invariants . If at the end of any of his moves the king should not be in check, why not say so?
Is the predicate calculation is attacked? - a rather laborious operation (which is why it is performed at the end of the list of checks). The fact is that not all games attack those fields where the pieces end their turn. An example is the well-known Checkers, in which the attacked field is “jumped over”.
In more complex cases, the result of the calculation is is-attacked? depends on what type of shape is being attacked. For example, the “Chameleon” in the game of Ultima attacks each piece according to the rules by which she walks. If there were a castling in such a game, we would have to specify for which type of figure the check is performed (to check for a check this is not required, since the figure is already installed on the board, and not just passes through the field):
It's a little longer than simple checkmated , but also incredibly more flexible! In case all possible moves violate the invariant, the list of generated moves is empty. The predicate no-moves? determines the condition of the end of the game (loss).
Little hack
Calculation of the no-moves predicate It can also be time consuming (to check it is necessary to fully generate at least one move), but here you can cheat. Before the generation of moves, you can register a pending check. If the set of moves, at the end of generation, is empty, the check is triggered and the defeat is fixed.
Invariants, as defined in this article, do not seem to be some kind of “rocket science”, but we have not yet allowed them to turn in full force. In the next chapter, we will try to squeeze out the maximum of what they are capable of.