What is wrong w/ this code? Log Out | Topics | Search
Moderators | Register | Edit Profile

Zillions of Games Discussion Forum » Designing Games for Zillions » What is wrong w/ this code? « Previous Next »

Author Message
Alexander Domagalsky (Alexander)
New member
Username: Alexander

Post Number: 1
Registered: 2-2018
Posted on Sunday, February 11, 2018 - 4:06 pm:   

Hello
I would like to write move code that will do the following:
Once piece white Guard moves north, all pieces on the bottom rank should be captured.
The following code does not add direction n to the move list. Why?

(piece
(image White "pawnW.bmp")
(name Guard)
(moves
(n to A1 (while on-board? capture e) add)
(w add)
(e add)
)
)
Sean Duggan (Dream)
New member
Username: Dream

Post Number: 122
Registered: 9-2000
Posted on Sunday, February 11, 2018 - 4:58 pm:   

Offhand, the "add" establishes where the move is considered to "end". Right now, your guy moves n, the marker goes to A1, all of the pieces are captured, then the spot on the far right, one a little to the left, and then back again are added. None of the added spots are at "n".
Sean Duggan (Dream)
New member
Username: Dream

Post Number: 123
Registered: 9-2000
Posted on Sunday, February 11, 2018 - 5:06 pm:   

Ah, and I was wrong. What's happening is that your while loop is terminating early. Because it moves east before checking for on-board, it goes off the board and halts the loop. Try changing it to the following:

Try
(n to A1 capture (while (on-board? e) e capture) add)
Alexander Domagalsky (Alexander)
New member
Username: Alexander

Post Number: 2
Registered: 2-2018
Posted on Tuesday, February 13, 2018 - 8:22 pm:   

Hello Sean
Thanks for your answer. Your code does the trick.

I kind of cannot understand the spirit of this ZoG scripting language.
Sean Duggan (Dream)
New member
Username: Dream

Post Number: 124
Registered: 9-2000
Posted on Tuesday, February 13, 2018 - 9:02 pm:   

It can be tricky. I am unfortunately a bit rusty at it myself, but this is a pretty common error. Basically, any move which takes you to an invalid place halts evaluation of that move. For loops, that's why you always check to see if you can move to a location before moving to it (which makes "on-board?" by itself less than useful). That's always something to double-check when it seems like a move isn't getting added at all.

The other thing to do is to try to isolate problems by removing parts of the code until it works, and then adding them back in one by one.

And, well, feel free to ask questions. :-)
Alexander Domagalsky (Alexander)
New member
Username: Alexander

Post Number: 3
Registered: 2-2018
Posted on Wednesday, February 14, 2018 - 4:39 pm:   

I still have one question on the simple code.

I need code for Pawn that can move north, west and east.
- If Pawn moves north, allow him to make another move.
- Pawn can pass his partial move.

This part I know how to implement, see my code below:

I need to extend the code so that:
- Once Pawn moves to position D5, he CANNOT pass his partial move and he MUST make another move north, west or east.

Heeelp, is that possible?


(option "pass partial" true)
...
(piece
(image White "wPpawn.bmp")
(name Pawn)
(moves
(n add-partial)
(w add)
(e add)
)
)
Sean Duggan (Dream)
New member
Username: Dream

Post Number: 125
Registered: 9-2000
Posted on Wednesday, February 14, 2018 - 6:39 pm:   

I don't think you can do it using "pass partial". I have seen some games implement a "pass move" using another piece off the board to allow for more complicated logic. If you did that, you could establish a "pass move" that checks either for the active piece being at that position or for a flag predicated on the same to decide whether passing is valid.
Mats Winther (M_winther)
New member
Username: M_winther

Post Number: 8
Registered: 5-2017
Posted on Friday, February 16, 2018 - 2:00 pm:   

You can create a new move type D5move. If the pawn is on D5, you make (add-partial D5move). D5move goes east, north and west.

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: