How do I kill a certain piece or make... Log Out | Topics | Search
Moderators | Register | Edit Profile

Zillions of Games Discussion Forum » Designing Games for Zillions » How do I kill a certain piece or make a happen when a piece dies? « Previous Next »

Author Message
Tomas Forsman (Tomwolf)
Posted on Thursday, January 11, 2001 - 7:26 pm:   

The blacks Queen is nambed BQueen. If I want to kill her when a certain criteria is met, Like when the king has done 4 moves in the same direction, how do I write that in code?
(not the criteria but the killing of the piece)

And how do I make something happen when a certain piece is killed. Like if BQueen is killed I want the two BRooks to die with her.

With regards
Tomas
Karl Scherer (Karl)
Posted on Sunday, January 21, 2001 - 4:35 pm:   

Hi Tomas,

you kill a piece by scanning the board and capturing the piece where you find it.

Here an example for the chess board:

First (in the borad definition) you define a
dummy position
(dummy a0)

a direction 'x' to scan the board
(directions...
(x 1 0)
)

and some links to scan the board:
(links x (h1 a2)...(h7 a8))

Now here is the code to kill the black queen :

a0
(while (on-board x)
x
(if (piece? BQueen) capture)
)

To kill the rooks if the queen has been killed,
all you have to add is a flag and then execute a
similar routine for the rooks.
So here is the code for both activities:

(set-flag Queen-dead? false)
a0
(while (on-board x)
x
(if (piece? BQueen)
capture
(set-flag Queen-dead? true)
)
)

(if (flag? Queen-dead?)
a0
(while (on-board x)
x
(if (piece? BRook) capture)
)
)

Is that what you want?
Cheers, Karl
Karl Scherer (Karl)
Posted on Monday, January 22, 2001 - 4:25 pm:   

A few more remarks on your problem:

1.
My game "Spaghetti" deals with simple line-like pieces. The sequel "Spaghetti II" has even more complicated snake-like pieces.
Maybe it helps you to study the rules files
of these games.

2. Win-condition for complex multi-position pieces:

I solve this problem usually in the way that
I check on the piece with a while-loop
inside the move-code and if the appropriate
win-condition is fulfilled (a certain piece is on a certain place) then I set a "permanent flag" which the win-condition can check.

A "permanent flag" is a piece that is positioned
outside the board (negative coordinates) and serves purely as an indicator.

I will give you an example:
Say you want White to win whenever
the diagonal from a1 to h8 is occupied by pieces.

You have a subroutine "Check" that is called before any "add":

(define Kingshift (.....(Check) add)

(define Check
(set-flag diagonal-full? true)
(while (on-board? ne) ;loop over diagonal
ne ; go northeast
(if empty? (set-flag diagonal-full? false))
) ;end while
(if (flag? diagonal-full?)(change-type Win z0))
) ; end of Check

In the board-definition you define
(dummy a0)
(link ne (a0 a1))
(positions (z0 -1 -1 -1 -1))

In the piece-definitions you define
(piece (name Win).....
and associate it with any (small) image.

In the board-setup you initialize position z0
with any other piece. I usually use an
invisible (=green) piece 'dot':

(White (dot z0)...)

3.
In general, it is a good idea to study
other people's code.
You can learn a lot from it.

Cheers, Karl
Karl Scherer (Karl)
Posted on Monday, January 22, 2001 - 4:38 pm:   

Oops, I sent the last response to the wrong question.
Sorry.

A pity that the discussion board does not have a
DELETE, not even for your own messages...
Space for improvement!

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: