I need help troubleshooting this code... Log Out | Topics | Search
Moderators | Register | Edit Profile

Zillions of Games Discussion Forum » Designing Games for Zillions » I need help troubleshooting this code. Please help « Previous Next »

Author Message
Richard Hutnik (Richardhutnik)
New member
Username: Richardhutnik

Post Number: 44
Registered: 12-2002
Posted on Tuesday, April 22, 2008 - 11:44 pm:   

What this move is supposed to do is, when a piece moves out from the first rank it is in, whether to capture or not, it is supposed to pull in piece $2 onto the space it just left, from i1, i2, i3, i4 OR j1, j2, j3, j4

What the code is doing here is allowing this to happen if a piece captures, not if it moves into empty space.

I am stumped.

Please review below, and let me know what you see is the answer.

(define gate_kslide
(
(verify
(and never_moved?
(in-zone? first_rank)
(or
(and (friend? i1)(piece? $2 i1))
(and (friend? i2)(piece? $2 i2))
(and (friend? i3)(piece? $2 i3))
(and (friend? i4)(piece? $2 i4))
(and (friend? j1)(piece? $2 j1))
(and (friend? j2)(piece? $2 j2))
(and (friend? j3)(piece? $2 j3))
(and (friend? j4)(piece? $2 j4))
)
)
)
mark
$1
(while empty?
(set-attribute never_moved? false)
add-partial
$1
)
cascade
(verify not-friend?) ;edit here
(set-attribute never_moved? false) ;edit here
to
(if (and (friend? i1)(piece? $2 i1)) i1 from back to)
(if (and (friend? i2)(piece? $2 i2)) i2 from back to)
(if (and (friend? i3)(piece? $2 i3)) i3 from back to)
(if (and (friend? i4)(piece? $2 i4)) i4 from back to)
(if (and (friend? j1)(piece? $2 j1)) j1 from back to)
(if (and (friend? j2)(piece? $2 j2)) j2 from back to)
(if (and (friend? j3)(piece? $2 j3)) j3 from back to)
(if (and (friend? j4)(piece? $2 j4)) j4 from back to)
(set-attribute never_moved? false)
add
)
)
M Winther (Kalroten)
New member
Username: Kalroten

Post Number: 56
Registered: 1-2007
Posted on Thursday, April 24, 2008 - 1:33 pm:   

(You have an "add-partial" where it should be an "add", I suppose.) It's better to talk about principles. In principle the code should look like this, I suppose:

(define move-and-drag1 (
$1 (verify not-friend?)
cascade
i1 (verify not-empty?)
from back to
add
))


So you will have to use a "cascade" if you want the piece to drag the other piece automatically onto the board. Otherwise you can use a double-move (add-partial).

But if you decide to use cascade then you must place the "add" last. In your code you make add-partial, which functions like add and finalizes the move. It does not work to put an add before a cascade.

The reason you must use a while loop is because you use sliding pieces. If a sliding piece is going to automatically drag a piece onto the board then you must make separate calls from the move block. Imagine that we have a piece that can slide one or two steps orthogonally. Then we can use my previous function for the first move in the move block. And for the second step we call another function that looks almost the same but makes two steps, like this.

(define move-and-drag2 (
$1 (empty?)
$1 (verify not-friend?)
cascade
i1 (verify not-empty?)
from back to
add
))



In the move block we write

(moves
(move-and-drag1 n)
(move-and-drag1 s)
(move-and-drag1 e)
(move-and-drag1 w)
(move-and-drag2 n)
(move-and-drag2 s)
(move-and-drag2 e)
(move-and-drag2 w)
)


So now we have a piece that can slide two steps and is able to drag a piece from i1. If you want it to slide three steps then you must write yet another function.

Mats Winther
M Winther (Kalroten)
New member
Username: Kalroten

Post Number: 57
Registered: 1-2007
Posted on Thursday, April 24, 2008 - 2:03 pm:   

Furthermore, as only unmoved pieces can drag, you can promote to standard piece when first moving. E.g., a "_bishop" is on the first rank, but after it has moved it is promoted to "bishop". Regular bishops cannot drag so they use standard code which is faster than my previous drag-sliding code. This also means that you don't always have to check the attributes and first rank. The code for the "_bishop" would use my code above, but instead of "add" there would be an "(add bishop)".

Mats

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: