A different kind of reproducing piece Log Out | Topics | Search
Moderators | Register | Edit Profile

Zillions of Games Discussion Forum » Designing Games for Zillions » A different kind of reproducing piece « Previous Next »

Author Message
Chris Weimer (Cweimer)
Posted on Sunday, March 04, 2001 - 2:17 am:   

I want to have a piece that 'reproduces' by leaving pieces of a different kind behind it when it moves.

I am (obviously) new to this board and to Z programming, so I hope this isn't too easy, but after a couple of hours of trying different things, looking at code, and then reading the other postings, it sure does't seem like it.
Dan Troyka (Dtroyka)
Posted on Sunday, March 04, 2001 - 8:28 am:   

You can do this by using change-type on the "from" square to create the piece left behind, and add-copy for the "to" square. If you replace the slide macro in the chess rules file with the following, the Queen will always leave behind a Rook after moving.

(define slide ((change-type Rook) $1
(while empty? mark (go from) (change-type Rook) back add-copy $1)
(verify not-friend?) mark (go from) (change-type Rook) back add-copy))

The downside of using add-copy is that you can only move by selecting the "to" square. If you select the piece to be moved, Zillions will tell you that it cannot move. This is awkward and has to be explained to the player.

Note that if the move definition for the piece contains multiple adds in a single move generation block, the change-type code has to be inserted before each add or, if there is a while statement, within the loop, because Zillions resets change-type commands after each add.

A more elaborate (but probably worth it) solution is to create a store of pieces off the board and cascade them into the from square when the principal piece moves. As a not-quite-complete example, consider the following code:

(define slide
($1 (verify empty?) to back cascade a1
(while (not-piece? Rook) e) from back add))

If you use this in the chess rules file, the Queen can move one space in any direction and will leave behind a Rook when moving. The Rook is drawn from its array position. The movement is more natural in this case because the Queen can be selected. A few points: If you use this idea, you will need to define the principal piece separately for each player and create an off-board line of pieces-to-be-inserted that is long enough to last the entire game. The code above only allows the Queen to move twice (because then there are no more Rooks) and allows the Black Queen to leave behind a White Rook, which can only be avoided by separately defining the Queens. Second, if the principal piece can move more than one space in a turn (e.g., like a Queen, Bishop, or Rook), you will need to define each possible distance (one space, two spaces, etc.) as a separate move-generation block. Third, I'm not sure how the AI would react to this coding. I think it would probably handle it well because it would recognize the advantage of having a Rook in play instead of locked in place off-board. All things considered, however, the first suggestion would probably make for a better computer opponent. Finally, you would need to disable the off-board pieces while off-board. This could be accomplished by adding a (verify (not-in-zone? off-board)) statement to their move definitions.

Good luck!
Karl Scherer (Karl)
Posted on Sunday, March 04, 2001 - 10:38 pm:   

Reproducing pieces using INVISIBLE pieces:

Another easy way to "reproduce" a piece is
to have ALL "EMPTY" BOARD LOCATIONS filled with
invisible pieces.
When you move a piece from one position to another
you have to move the invisible piece to the original position abnd then change its type
and ownership.

Here an example for chess:
Say ranks 3 to 6 in chess are filled with an
invisible (= coloured green)piece "dot".

Then the following version of the opening move
d2 - d4 creates a rook at d2:

(move for piece Pawn):
(
from mark n n to
cascade
from back to
(change-type Rook)
add
)

Advantage of this method:
- you select the piece, not the target square
as in add-copy.
- No definitions of extra off-board pieces
necessary

Note that you have to change the ownership of
the new Rook as well with code like

(
from mark n n to
cascade
from back to
(change-type Rook)

(if (am-White?)
(change-owner White)
else
(change-owner Black)
)

add
)

Of course you have to declare (am-White?)
as usual:

(define am-White? (in-zone? promotion-zone a8))

Add Your Message Here
Post:
Username: Posting Information:
This is a private posting area. Only registered users and moderators may post messages here.
Password:
Options: Enable HTML code in message
Automatically activate URLs in message
Action: