📜 ⬆️ ⬇️

Tame ZoG (Part 4: Beware of the Mines!)

Today I want to continue the story about the possibilities of the ZRF game description language used by Zillions of Games . In previous articles of the cycle, I showed how the moves of the pieces are described, but there is another important variation of the move that has not been considered. In addition to moving the pieces on the board (possibly with taking enemy pieces), the player (if allowed to him) can add new pieces to the field. This type of stroke is called a drop.
In addition, in today's article, I will talk about how random moves are generated in ZoG. This functionality is necessary, for example, in the implementation of games that use the rolls of game dice, to perform moves, such as Ludo or Chaturanga .

As an example, I propose, taking classic Chess as the basis, to implement the game based on one of the missions of the Battle vs Chess story campaign. Most campaign missions are played by modified rules. Missions differ in complexity, in some, to win, it is enough to hold one of the pawns to queens, in others - check mate for a limited number of moves. I propose to consider the fourth mission of the Chaos campaign called "Point of no return".

In this mission, part of the central fields of the board are “mined”. The figure, stopped on such a field, disappears (together with a mine). At the same time, "mines" are visible only to the player playing for Black. The computer that plays as White “thinks” that it plays by the usual rules, which allows you to lure his pieces to “mined” positions. I must say that this approach is used in most of the campaign missions. One of the players in them has incomplete information. In some cases (such as in the mission we are considering), this is a kind of “handicap” that allows even a not very strong chess player to beat the rather strong chess “engine” of Fritz used by Battle vs Chess.

Of course, in the described form, it will not be possible to implement the game in ZoG. Due to its versatility, the ZoG game core will take into account the presence of mines when performing moves. The move to the "mined" cell is obviously not beneficial, since it simply leads to the loss of a piece. Let's try to change the rules in such a way as to make the undermining of "min" profitable, even taking into account the loss of his figure.
')
Suppose that the explosion loses not only the figure that stands on the mined cell, but all the figures that are next to it. Also, in order to make the game more combinational, we will blow up the mines that are close to the original one, removing the figures from the field that are also close to them. Further, the chain of explosions will not be distributed, because it is associated with some technical difficulties. In addition, a possible undermining of the “min” chain of most of the pieces located on the board will introduce into the game too much randomness and may make it not interesting.

We will start the development, based on the description of the traditional Chess ( Chess.zrf ), which is included in the ZoG package. From it we take the description of the board and the moves of the chess pieces. A suitable graphic resource "bombs" can be taken, for example, from the game Bombalot .

Let's start by describing a bomb blast.
(define bomb-capture (if (not (piece? Bomb $1)) (capture $1) ) ) (define check-bomb-direction mark $1 (if (piece? Bomb) (bomb-capture n) (bomb-capture nw) (bomb-capture s) (bomb-capture sw) (bomb-capture e) (bomb-capture ne) (bomb-capture w) (bomb-capture se) ) capture back ) (define check-bomb (if (piece? Bomb) (check-bomb-direction n) (check-bomb-direction nw) (check-bomb-direction s) (check-bomb-direction sw) (check-bomb-direction e) (check-bomb-direction ne) (check-bomb-direction w) (check-bomb-direction se) capture ) ) 


Here everything is familiar to us. If the figure got on the bomb, we explode everything around. If another bomb is near, we explode it too (we don’t touch her neighbors). Here is how it is used:

 (define leap1 ($1 (verify not-friend?) + (check-bomb) add ) ) 

Just add our macro before completing each turn. Now, let's stop kings from completing the game with suicide:

 +(define check_safe + (verify (not (piece? Bomb) ) ) +) (define king-shift ($1 + (check_safe) (verify not-friend?) (set-attribute never-moved? false) add ) ) 

Here, the check-bomb macro can be omitted, since we specifically check that we do not get up on the bomb.

We will place bombs
 +(define drop-bomb + ( (verify (and empty? (empty? n) (empty? s) (empty? w) (empty? e) ) ) + add + ) +) (game (title "Chess") ... - (players White Black) + (players White Black ?Init) - (turn-order White Black) + (turn-order ?Init ?Init White Black) (board (Board-Definitions)) (board-setup + (?Init + (Bomb off 8) + ) (White (Pawn a2 b2 c2 d2 e2 f2 g2 h2) (Knight b1 g1) (Bishop c1 f1) (Rook a1 h1) (Queen d1) (King e1) ) (Black (Pawn a7 b7 c7 d7 e7 f7 g7 h7) (Knight b8 g8) (Bishop c8 f8) (Rook a8 h8) (Queen d8) (King e8) ) ) + (piece + (name Bomb) + (image ?Init "images\Bombalot\BlackBomb.bmp" "images\Bombalot\BlackBomb.bmp") + (drops + (drop-bomb) + ) + ) ... ) 


You may notice that we have added a third player, by the name ? Init . A question mark at the beginning of the player's name means that he will make random moves (in accordance with what is allowed to him). In addition, this player will not be displayed in the list of players (this means that it will be impossible to play for him). A new player makes two moves each time before White’s turn. What moves can he do?

In the board-setup he was given 8 bombs, which he can put on the field. I want to draw attention to the keyword off in this description. It is in this way that the figures available for discharge on the field should be described. It also describes the figures in games starting with an empty board, for example in the implementation of Tic-tac-toe .

In the description of the Bomb shape, only one kind of stroke is allowed - resetting the piece to the empty board field, provided that the neighboring fields along the vertical and horizontal lines are also empty. Bombs can coexist with other figures (including bombs) diagonally, which, in my opinion, makes the game more interesting.

Note
You may notice that the graphic resources of the board and all the figures are described twice. This approach allows you to use several design options, which can be switched during the game. Since our bomb will look the same in all variants, we simply specify the path to the same file twice.

It remains to make a couple of almost cosmetic changes. Add the following options to the game description:

 (option "pass turn" forced) (option "animate captures" false) 

The first one means that a player ( ? Init ) can skip a move, provided that he cannot make it in accordance with the rules (if you do not enable this option, the game may end if ? Init does not find a place to drop the bomb) . The second one turns off the capture animation (it looked too unnatural). See the list of all available options in the documentation for Zillions of Games.

The game is ready . You can see how it all looks:


In general, we can say that ZoG plays by the new rules quite adequately, but sometimes its moves put me at a dead end. For example, he undermines his queens in lonely standing bombs. I can't explain it. Apparently, the ZoG core considers the bomb to be such a dangerous figure that its “exchange” for a queen becomes profitable.

I found another interesting effect that can be seen in the following video (the white king is moved to the third rank manually):


By highlighting the fields during the King’s move, it is noticeable that the presence of bombs in the neighboring fields (I remind you that the King cannot walk on the field with the bomb) is not considered a threat to the King, provided that they cannot be "undermined" by enemy figures. As soon as the bombs are attacked, the King is obliged to move away from them as well, as if he were leaving the shah. In general, this is quite logical behavior, if you do not consider a small nuance:



This position is considered matte. The king cannot eat the queen, since he cannot approach the bombs, as the queen attacks them. Unfortunately, this behavior cannot be corrected, since the requirement of leaving the king from under the Shah is nailed to the loss condition:

 (loss-condition (White Black) (checkmated King) ) 

If allowed to have kings and replace the condition of loss with the loss of the King:

 (loss-condition (White Black) (pieces-remaining 0 King) ) 

... then the queen will be safely eaten. But I noticed that in this mode, ZoG plays in the endgame much worse. In particular, I could not wait for the classic rogue rook and the king of the lonely king. When using the checkmated condition, the mat is placed very quickly.

Source: https://habr.com/ru/post/213391/


All Articles