Dagaz: Kicks to Common Sense (Part 3)

    image“Ah, you scoundrel,” Woland said thoughtfully.
    “Messir, I turn to logic again,” the cat spoke, clutching his paws to his chest, “if a player declares a check to the king, and yet the king is no longer on the board, the check is invalid.

                              Mikhail Bulgakov “Master and Margarita”

    “Mat to the king!” - many of us absorbed these words with mother’s milk. The very concept of the shah (and mat) seems obvious to people familiar with Chess since childhood, but is it really so simple? After an easy warm-up with the transformations of the figures, I propose to tackle really complex issues.

    8. Checkmate

    The main difference between chess games (in addition to the characteristic way of taking pieces) is the presence on the board of the “main” piece - the king. If a player loses a king, he loses, regardless of how many other pieces he has left on the board. Such a rule of "sudden death" significantly enriches the game tactically. The game becomes more combinational, players are trying to lure each other into a trap.

    Ending a game by the “sudden death” rule is not a chess invention. In one form or another, this principle is used in many games. In all the familiar " Tic-tac-toe", для победы, необходимо выстроить свои фигуры «в линию» (и помешать сделать это сопернику). Игра стала бы совсем скучной без этого правила. Просто представьте себе «крестики-нолики» продолжающиеся до тех пор, пока остаётся возможность хода (есть пустые позиции на доске)…

    Пример кажется странным, поскольку сама суть «крестиков-ноликов» заключается в выстраивании линий? Вот вам менее очевидный пример: в Hasami Shogi фигуры могут двигаться и «поедать» друг друга. Для того, чтобы убрать фигуру противника с доски, её необходимо «взять в клещи», окружив своими фигурами с двух сторон (на самом деле, правила взятия в Hasami Shogi более сложные, но об этом я расскажу как-нибудь в другой раз). Это правило роднит Hasami Shogi с древнейшими игровыми системами «окружных шашек», такими как Seega.

    It is logical to assume that, like in Seega, in Hasami Shogi, to win, you need to “eat” all the pieces. Indeed, such a variant of the game exists, but it is sufficient to take not everything in it, but only a limited number (usually 5) of figures. The fact is that the method of capture used (by clamping “in pincers”) is very slow. In order to take the opponent’s piece, you need to properly place your two pieces (of course, this does not negate the fact that you can take several pieces at once with one move). In Seega, the situation is saved by the limited mobility of the pieces, but in Hasami Shogi, the pieces are long-range and the enemy can almost always avoid the threat.

    The rule of "sudden death" is very helpful. In most variants of Hasami Shogi, victory is achieved by aligning 5 of your figures “in a row” (outside their original location, otherwise it would not be interesting). Taking enemy pieces in them is not the goal of the game, but only a tactical technique that helps to win. Here, as in Tic Tac Toe, the condition for victory is the relative arrangement of the figures.

    The relative arrangement of the figures does not have to be simple. For example, in the game “ Hex ”, for victory, you need to connect two opposite sides of the board with a continuous chain of figures of your color (not necessarily straight), but in “ Rhythmachy", in order to achieve a" glorious victory ", the figures (ours and the adversary) must also be connected with arithmetic relations (in addition to their mutual arrangement).

    The condition of “sudden death” may also be associated with the absolute arrangement of the figures. So, in the Chinese game Dou-shu-qi (Jungle) , to win, you must bring any of your pieces to the “Lair” of the opponent (marked spot on the board). A similar rule brings tactical diversity to the Japanese game of Doubutsu Shogi . In it, for victory, it is enough to lead your king to the last horizontal of the board (at the same time, the loss of the king means defeat). Similar rules apply in games of the Tufle family , but only one side has a royal figure there (these are asymmetric games).

    As I said above, the most familiar interpretation of the "rules of sudden death" is associated with the loss of the main figure or group of figures. It was 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 (“exposing” 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 such an 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 implementation of Yonin Shogi was related to this.(variant of Japanese chess for four players). In addition to adapting the game to an earlier version of Zillions of Games 1.0, he changed the winning condition. Now the game does not end with the capture of one of the enemy kings. To win, you must "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 fourth version of Chaturanji with the capture of kings, everything is also not simple. Often this game was played “pair by pair”. The players sitting opposite each other made up a coalition. The player who took the king from them skipped moves (his pieces seemed to “freeze” on the spot), but his partner could return the captured king by taking one of the opponent’s kings and “exchanging prisoners”! Even more, this principle was developed in Enochian Chess . In this game, a player could “take control” of an army left without a king, taking his king “throne” (initial position) of the latter.

    Another component of the concept of shah (and mat) is forced moves. It is also not a chess invention. Without the concept of forced moves, there would be no drafts familiar to us. In this family of games, a player who has the opportunity to take an opponent’s piece must do so. It is this rule that makes the game interesting. Substituting his figure under attack, the player limits the number of possible reciprocal moves of the enemy. He can build complex tactical combinations by changing the position on the board with the help of victims.

    The honor of inventing a (almost) modern chess game belongs to the Persians. Apparently, it was in Chaterange that the concepts of the “main figure” and forced moves were combined. So the concept of the shah- the king should not remain under attack upon completion of the turn of the player to whom he belongs. The move that saves the king from the threat is forced (it does not matter whether it is taking a menacing figure or simply leaving for a more peaceful place).

    The concept of mat is a natural logical continuation. If the player cannot get rid of the threat to his king after completing the move, he loses. Another new concept has appeared - a stalemate , the position in which the king is not under attack, but the player cannot make a single move, due to the threat of the check. In Shatrange, unlike modern Chess, such a position (as well as the "exposure" of the king) also led to defeat.

    So far, everything has looked quite logical, but what will happen if the rules are complicated? For example, how to checkmate several kings? In “ Tamerlane Chess ”, a player can get up to three kings by completing the transformation of a royal pawn and the double transformation of a “pawn pawn”. In “ Tyu Shogi ” the situation is similar - “Drunken Elephant” can turn into “Crown Prince” (actually the second king).

    The Japanese, in this situation, did not become wise. Kings in "Tyu Shogi" can (and should) be "eaten." In Tamerlane Chess, things are a little more complicated. In this game, to win you need to checkmate. Matting the three kings at the same time is theoretically possible, but in practice hardly feasible. As long as there are two or more kings of the same color on the board, the kings are allowed to “take” (the order of capture is not important, since all the kings are interchangeable), as soon as the last king remains on the board, he needs to checkmate. In fact, this means that kings are allowed to be under the check while their “deputies” are on the board.

    No less interesting are the metamorphoses of the concept of check with a game of more than two players. I already mentioned above about Yonin Shogi. Its only difference from traditional Shogi- participation in the game of four players (and, as a result, another initial arrangement of figures). The result of this “small” difference was the completely inadequate processing of checkers in the Zillions of Games version:

    And this is more than just a bug of one particular implementation! Let's think a little bit. Suppose the player “South” puts his king under the blow of one of the figures of the player “East”, but until the turn comes (clockwise), the threat can be eliminated by the “West” or “North” (most likely the last if the game is “couple” for a couple "). Therefore, there was no threat and the “South” had the right to make such a move! And if the "North" and "West" did not begin to do anything about this threat? As you can see, in such a game, the concepts of check and check have little meaning.

    There may be other rules that affect the ability of matting. For example, there is a variant of Shogi that differs from the original game only in that the player cannot hold more than 5 pieces “in hand”. This means that he cannot take any piece if there are already five in the reserve (he must first drop one of the reserve pieces onto the board). This rule leads to completely anecdotal obscene situations. Even if the threat to the king is considered absolute (independent of filling in the reserve), it can interfere with 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, then now the berries will begin. In the “ Belarusian Chess " checkmate can be put a king! The fact is that in addition to chess pieces, checkers also work in this game. All pieces are played according to the usual rules, that is, taking drafts is mandatory! Moreover, even more necessary than saving his king from the Shah! So it turns out that if the enemy has the opportunity to take one of his pieces, you can safely approach your king and mat him! Very funny game.

    The game may introduce additional restrictions on the mat. So in Shogi you cannot checkmate by dropping a pawnfrom the reserve (at the same time, it is not forbidden to check the pawn with a reset and checkmate in the usual way too). Even further in terms of prohibitions is the Mongolian version of chess (Shatar). In this game it is not enough to checkmate, it is important to do it ideologically correctly (the result of the game depends on it)! Let me give you a small quote :

    The following different forms of check are distinguished: shack - given by the queen, rook or horse, knock - by the elephant, tsod - by pawn.
    Matting can only be with a shack (i.e. a queen or a rook), or with a continuous series of checkers, including at least
    one shack, and if the shack is declared last, then it should not be a check knight.
    For example, if the next series of checkers is given (the last checkmate) - with a knight, pawn and bishop, then this is a win.
    If the checkmate is placed only by an elephant / bishops and / or a pawn / pawns, then this is a draw - null.
    If one player has only one king (the “naked king"), then this is also a draw - robado.

    Uff ... This is not easy to figure out, not to realize. By the way, with the implementation of checkers and mats in ZoG, everything is pretty sad. At the end of the game (victory, draw or defeat), only the following predicates may apply:

    • stalemated - Inability to move
    • repetition - Repeat a position three times
    • captured - Capture a piece of a certain type (e.g. king)
    • checkmated - Mat to a shape of a given type
    • absolute-config - The absolute location of the figures (for example, reaching a given position)
    • relative-config - The relative arrangement of the shapes (for example, “5 in a row”)
    • pieces-remaining - The remaining number of pieces (for example, in the " Mill " - the two remaining pieces indicate defeat)
    • total-piece-count - Similar to the previous one, but excluding player ownership

    All this is firmly “wired” into the kernel of the program and 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 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 a single checkmated keyword is completely insufficient to adequately handle all kinds of opaque situations described in the article. Part of the problems can be solved by adding additional checks in the "manual" mode. Here, for example, looks like a check on the mat by resetting a pawn to Shogi:

    Utifuzume Manually
    (define safe 
       (and (on-board? $1) 
            (not-defended? $1) 
            (not-enemy? $1)
    (define no-mate 
       (or (not-piece? Gyokusho n) 
           (not-enemy? n) 
           not-defended? (attacked? no-king) 
           (safe e) 
           (safe w) 
           (safe ne) 
           (safe nw) 
           (safe nne) 
           (safe nn) 
           (safe nnw)
    (define drop-Fu (
     (verify-first Fu)
      END next
      (while on-board?
        (set-flag friendly-Fu false)
        (while (and (not-flag? friendly-Fu) (on-board? n))
          (if (and friend? (piece? Fu)) (set-flag friendly-Fu true))
        (if (not-flag? friendly-Fu)
    	(while (on-board? n)
    	  (if (and empty? (no-mate)) add)

    This works, but understanding what this code does is extremely difficult. At the same time, the fact is used that the pawn in Shogi attacks closely, only one field. It is impossible to close from its check, but you can only move away or "eat" a pawn. I have absolutely no idea how a similar set of “manual” checks would have looked if the Shatar had been implemented. To implement forced moves, a priority mechanism is used (either hard-coded “magic” when using the checkmated predicate ).

        (move-type noncapture-type)
        (man-shift ne)
        (man-shift nw)
        (move-type capture-type)
        (man-jump ne)
        (man-jump nw)
        (man-jump se)
        (man-jump sw)
        (move-type nomove-type)
    (move-priorities capture-type noncapture-type)

    Thus, the “compulsory” capture is realized in checkers. If it is possible to execute a move taking the opponent’s piece, it is necessary to execute it, and not a “silent” move. This mechanism also does not seem to me flexible enough. And the priority moves and actions under the 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 under the check, why not just say so?

    Realization of checks on a check in Dagaz
    (define invariant
             (check is-friend?)
             (check (is-piece? King))
             (check is-attacked?)
    (define goals
       (check-loss no-moves?)
       (pre  goals)
       (post invariant)

    By the way
    Is prediction calculation is-attacked? - quite a time-consuming operation (which is why it is performed at the end of the checklist). The fact is that not all games attack those fields on which the pieces end their turn. An example is the well-known Checkers, in which the attacked field "jumps".

    In more complex cases, is the result of the calculation is-attacked? depends on what type of shape is being attacked. For example, the "Chameleon" in the Ultima game attacks each figure according to the rules by which she walks. If castling was provided for in such a game, I would have to specify for what type of piece the check is performed (to check for the check this is not required, since the piece is already installed on the board, and not just passes through the field):

    Castling in Dagaz
    (define O-O
       (check (not is-moved?))
       (check not-attacked?)
       (take-piece-to-head current-pieces)
       (check w)
       (check is-empty?)
       (check (not-attacked? King))
       (check w)
       (check is-empty?)
       (check (not-attacked? King))
       (drop-pieces current-pieces)
       (check w)
       (check (not is-moved?))
       (set! is-moved? true)
       (take-piece-to-head current-pieces)
       e e
       (drop-pieces current-pieces)

    It's a little longer than a simple checkmated , but also incredibly flexible! If all possible moves violate the invariant, the list of generated moves is empty. Does the no-moves predicate work in this situation ? defines the condition for ending the game (defeat).

    Little hack
    No-moves predicate calculation ? It can also be time-consuming (to check you need to fully generate at least one move), but here you can cheat. Before starting the generation of moves, you can register a pending check. If many moves, upon completion of generation, are empty, the check is triggered and the defeat is recorded.

    The invariants, as defined in this article, do not seem to be some kind of "rocket science", but we have not yet allowed them to unfold in full force. In the next chapter, we will try to squeeze out of them the maximum of what they are capable of.

    Also popular now: