Taming ZoG (Part 4: Caution - Mines!)

  • Tutorial
Today I want to continue the story about the possibilities of the ZRF game description language used by Zillions of Games . In the previous articles of the series, 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 taking the opponent’s pieces), the player (if allowed to do so) can add new pieces to the field. This kind of move is called drops .
In addition, in today's article, I will talk about how random moves are generated in ZoG. This functionality is necessary, for example, when implementing games using dice rolls to complete moves such as Ludo or Chaturanga .

As an example, I propose, based on the classic Chess, to realize the game based on one of the missions of the Battle vs Chess story campaign . Most missions in the campaign are played according to the changed rules. Missions vary in complexity, in some, to win, it is enough to hold one of the pawns in the queens, in others - to checkmate for a limited number of moves. I propose to consider the fourth mission of the Chaos campaign, called the Point of No Return.

In this mission, part of the central fields of the board is “mined”. A figure stopped at such a field disappears (along with a mine). At the same time, “mines” are visible only to the player playing for the Blacks. A computer playing for Belykh “thinks” that he is playing by the usual rules, which allows him to lure his pieces to “mined” positions. I must say that a similar approach is used in most of the campaign missions. One of the players in them has incomplete information. In some cases (for example, 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” 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 profitable, since it simply leads to the loss of a figure. Let's try to change the rules in such a way as to make the detonation of “mines” profitable, even taking into account the loss of your figure.

Suppose that during the explosion, not only the figure standing on the mined cell is lost, but also all the figures that are next to it. Also, to make the game more combinational, we will detonate mines that are close to the original, removing figures from the field that are also close to them. We will not distribute the chain of explosions further, since this is due to some technical difficulties. In addition, a possible undermining of the “mines” chain of most of the pieces located on the board will bring into the game too much element of chance and may make it not interesting.

We start development by taking as a basis the description of traditional Chess ( Chess.zrf ) included in the ZoG package. From it we take a description of the chessboard and moves of chess pieces. A suitable graphic resource for a “bomb” can be taken, for example, from a gameBombalot .

Let's start with the 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
  )
)


Everything is familiar to us here. If the figure stood on the bomb, we explode everything around. If another bomb was near, we explode it too (we don’t touch its neighbors). Here's how it is used:

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

Just add our macro before completing each move. Now, let the kings end 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 verify that we are not standing on the bomb.

Arrange the 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 added a third player, named ? Init . The question mark at the beginning of the player’s name means that he will make random moves (in accordance with what he is allowed to). In addition, this player will not appear in the list of players (this means that it will be impossible to play for him). The new player makes two moves each time before White's move. What moves can he do?

In the board-setup, he was given 8 bombs, which he can put on the field. I want to pay attention to the off keyword in this description. This is how the figures available for resetting on the field should be described. The figures in games starting with an empty board are also described, for example, in the implementation of Tic-Tac-Toe .

In the description of the Bomb figure , only one variation of the move is allowed - resetting the figure to an empty board field, provided that the neighboring fields vertically and horizontally are also empty. Bombs can be adjacent to 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 shapes 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 cases, we simply indicate twice the path to the same file.

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

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

The first one means that the 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 can end if ? Init does not find a place to drop a bomb) . The second disables the shape-taking animation (it looked too unnatural). See a 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, it can be said that ZoG plays according to the new rules quite adequately, but sometimes its moves confuse me. For example, he undermines his queens on 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 the queen becomes profitable.

I found another interesting effect that can be observed in the following video (the white king was moved to the third horizontal manually):


By highlighting the fields during the course of the King, it is noticeable that the presence of bombs in 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 enemy figures cannot “undermine” them. As soon as the bombs are attacked, the King is obliged to move away from them as if he were leaving the shah. In general, this is a completely logical behavior, if you do not consider a small nuance:



This position is considered matte. The king cannot eat the queen, as he cannot approach the bombs, because the queen attacks them. Unfortunately, this behavior cannot be corrected, since the requirement for the king to leave the check is “nailed” to the loss condition:

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

If allowed to eat Kings and replace the loss condition 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 mate with the rook and the king of the lonely king. When using the checkmated condition , the mat is put up very quickly.

Also popular now: