| Author |
Message |
Mohamed El Mokhtar Messaoudi (Dumberbytheminute)
New member Username: Dumberbytheminute
Post Number: 8 Registered: 11-2008
| | Posted on Wednesday, December 16, 2009 - 3:23 pm: | |
Hi all. What would be the simplest code for a piece A to slide freely, and if bumping into an enemy piece B, to replace it with a piece C while putting an enemy piece D on the starting cell? (My head is dizzy with from, to, add-copy, cascade and what not. Please help. Thanks.) |
M Winther (Kalroten)
New member Username: Kalroten
Post Number: 134 Registered: 1-2007
| | Posted on Sunday, December 20, 2009 - 1:44 am: | |
How about this? (define slide-piece ($1 (while empty? add $1) (if not-friend? (if (not-piece? piece-B) add else cascade (change-type piece-C) back (create piece-D) flip add ) ) )) |
Mohamed El Mokhtar Messaoudi (Dumberbytheminute)
New member Username: Dumberbytheminute
Post Number: 9 Registered: 11-2008
| | Posted on Sunday, December 20, 2009 - 3:33 am: | |
Simple and to the point. Thanks, Mats. Unless I am abusing, could you tell me how to do random promotions in Chess (a pawn could promote to any piece of EITHER camp)? |
M Winther (Kalroten)
New member Username: Kalroten
Post Number: 135 Registered: 1-2007
| | Posted on Sunday, December 20, 2009 - 5:40 am: | |
I don't know if it's possible to implement random pawn promotion. But the following code could work. The random promotion move occurs first, at each move (move-order: random White move; normal White move; random Black move; normal Black move). If no pawn promotion is possible, then the same player moves again, and makes a normal move. However, if a pawn exists on the seventh rank, then the random procedure should also allow that the pawn is *not* promoted. That's why I have inserted ((verify (not-on-board? n) add) as a random alternative. The problem is that if a random promotion has occurred, then the player should not be allowed to move again. How to prevent this? One would have to verify before each move that a promotion has not occurred. One can check last-to and see whether this a friendly piece. Then a promotion has ocurred if it's positioned on the last rank. The code should look something like this: (players White Black ?Random1 ?Random2) (turn-order (?Random1 White promotiontype) White (?Random2 Black promotiontype) Black ) (define Pawn-move-promotion1 ( (verify (not-on-board? n) (add Bishop Knight Queen Rook) add ) ) (define Pawn-move-promotion2 ;this promotes to enemy piece ( (verify (not-on-board? n) (add Bishop Knight Queen Rook) flip add ) ) (piece (name Pawn) (moves (move-type promotiontype) (Pawn-move-promotion1) (Pawn-move-promotion2) ((verify (not-on-board? n) add) (...insert code for pawn movement and capture with promotion removed) )) /Mats |
Mohamed El Mokhtar Messaoudi (Dumberbytheminute)
New member Username: Dumberbytheminute
Post Number: 10 Registered: 11-2008
| | Posted on Sunday, December 20, 2009 - 2:20 pm: | |
Thanks again for bearing with me, mats. I will try to extricate all this. Your idea seems simpler than the scheme I had devised: An off-board zone (with suitable links) to be half-filled up in the first turn by a player (by some method- deterministic of course), then by the second player in the second turn, by standard promotion macros. The game proceeds normally from then on. Whenever a promotion occurs during the game, a piece is fetched and brought up from the off-board zone, and put into play. The glitch would then lie in the fact that if one knows about the method, he could predict the color of the n-th promotion, though not the piece type. (bearing in mind that a promoted piece can equally turn up to be Black or White, whatever the camp currently moving.) |
|