Tamed ZoG (Part 4: watch out — mines!)

Today I want to continue the story about the language features of descriptions of games ZRF used Zillions of Games. In the previous articles series, I showed how to describe the moves of the pieces, but there is another important kind of progress, the rest are not considered. In addition to moving figures across the Board (perhaps with the capture of the opponent's pieces), the player (if he's allowed), can add new shapes on the field. This type of stroke is called a reset (drops).
In addition, in today's article, I will talk about how ZoG is the generation of random moves. This functionality is necessary, for example, the implementation of games use throws of dice to perform moves such as Ludo or Chaturanga.

As an example, I suggest, based on classic Chess, to implement a game based on one of the missions of the story campaign Battle vs Chess. Most missions in the campaign are played by the changed rules. Missions vary in difficulty, some to win, enough to hold one of the pawns to a Queen, the other is to checkmate for a limited number of moves. I propose to consider the fourth mission of the campaign of Chaos called the "Point of no return."

This mission is part of the Central squares on the chessboard "mined." Figure staying on this pitch disappears (along with mine). At the same time, mines are only visible to the player, who plays for Black. The computer is playing White "thinks" that plays by the usual rules that allows you to lure his figures on the "bomb" position. 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 this mission) this is a kind of "handicap", allowing even very strong chess player to beat a fairly strong chess engine Fritzused Battle vs Chess.

Of course, in the described form, to implement the game in ZoG will fail. Because of its versatility, game kernel ZoG will take into account the presence of mines in performing the moves. The course on "mined" the cage is obviously not beneficial because it simply leads to the loss figure. Try to change the rules so that do undermine the "min" is beneficial, even with the loss of their figures.

Let the explosion is lost is not only the figure standing on the mined cell, but all the figures appeared beside her. Also, to make the game more fluid, will detonate the mine, found themselves near the source, removing from the field of figures, trapped, and near them too. Further, the chain of explosions won't spread, because it is connected with some technical difficulties. In addition, the possible undermining of the chain of "min" the greater part of the figures positioned on the Board, bring the game too much element of chance and can make it interesting.

We start development, based on the description of traditional Chess (Chess.zrf), included in the package ZoG. From it we take the description of the Board and moves of chess pieces. Any graphic resource "bombs" can take, for example, from the game Bombalot.

let's Start with the description of a bomb explosion
(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 here is familiar to us. If the figure stood on a bomb, blow up all around. If there was another bomb, blow her too (her neighbors do not touch). This is how it is used:

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

Just add our macro before the end of each turn. Now, don't allow the kings to end the game by suicide:

the
+(define check_safe
+ (verify (not (piece? Bomb) ) )
+)

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

Here the macro check-bomb may not apply, because we specifically check for not standing on a bomb.

Set bomb
+(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 notice that we added a third player, named ?Init. The question mark at the beginning of the name of the player means that he will make random moves (in accordance with what he is allowed). In addition, this player will not appear in the list of players (this means that to play for it would be impossible). A new player makes two moves every 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 draw attention to the keyword off in this description. It therefore needs to describe shapes that are available for relief on the field. Also describes the figures in games starting with an empty Board, for example in the implementation of the TIC TAC toe.

In the description of figure Bomb is allowed only one kind of turn — reset shape on the empty field of the Board, provided that the neighboring field vertically and horizontally is also empty. Bombs can coexist with other figures (including bombs) on the diagonal, which in my opinion makes the game more interesting.

note
you Can see that graphic resources Board and all figures described twice. This approach allows multiple design options, toggle which can be in the game. As our bomb in all variants will look the same, just specify the path twice to the same file.

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

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

The first means that the player (?Init) may pass the course, provided that he cannot do in accordance with the rules (if you do not enable this option, the game may end if a ?Init you will not find a place to drop the bomb). The second disables the animation captures of pieces (it looked too unnatural). To see a list of all available options in the documentation for Zillions of Games.

Game ready. You can see how it looks:


Overall, we can say that ZoG is playing by the new rules quite adequately, but sometimes it moves puzzle me. For example, he is undermining his Queens on a lonely standing bombs. To explain this I can't. Apparently the core of ZoG believes the bomb is so dangerous figure, that her "exchange" on the Queen is profitable.

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





This position is considered matte. Can't the king eat the Queen, so as not to come to the bombs as they attacked the Queen. Unfortunately, this behavior cannot be changed, because the demand for care by the king out of check "nailed" to the condition of the loss:

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

If you have a permit kings and replace the condition of the loss on the loss of a King:

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

... the Queen will be safely eaten. But I noticed that in this mode, ZoG plays in the endgame is significantly worse. In particular, I could not wait for the classic mate with rook and king the lonely king. When you use the terms checkmated, the Mat is placed very quickly.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

ODBC Firebird, Postgresql, executing queries in Powershell

garage48 for the first time in Kiev!

The Ministry of communications wants to ban phones without GLONASS