| Author |
Message |
Michael Strickland (Michael)
| | Posted on Monday, December 15, 2003 - 3:16 pm: | |
I am trying to script a piece that captures all the pieces lying in one direction along a file or row. The only condition for capture is that the first piece must not be a friendly. The capture must take all the pieces both friendly or not that lie along the remainder of the file or row. My several attempts to script this have been failures. I would welcome any suggestions. I have tried modeling my script after the Mad Elephant in Mad Elephant Chess and the Robber Bishop in Robber Chess, both on this site. Thanks! |
Sean Duggan (Dream)
| | Posted on Monday, December 15, 2003 - 4:57 pm: | |
Probably a bit crude, but the following will work. (define slide ($1 (verify not-friend?) (while (on-board? $1) capture $1) add)) ; non-capturing (define slide2 ($1 (while empty? add $1))) ; For each slide, do both "(slide n) (slide2 n)" |
Michael Strickland (Michael)
| | Posted on Monday, December 15, 2003 - 9:28 pm: | |
That was helpful, thank you! I neglected to mention in the first post that the piece may not capture through a block (dummy-piece). Also, if a king is captured, I need to kill a dummy piece on a dummy square to keep track of dead royal pieces for the win condition. I thought of using this macro: (define slide ($1 (verify not-friend?) (verify (not-piece? block)) (while (on-board? $1) (if (piece? King) capture dummy-square else capture $1)) add)) This did not allow me to capture the King, except when it was at the edge of the board; and when it did capture the King, it did not capture the dummy square. Neither did this prevent the piece from capturing through a block. |
Jeff Mallett (Jeffm)
| | Posted on Tuesday, December 16, 2003 - 2:53 am: | |
It's easy to see why a King captured on the edge of the board doesn't capture the dummy-square. If the King's square is on the edge, then (on-board? $1) is false, so it doesn't go through the logic inside the loop. Instead the loop terminates and a simple "add" is done for the King. When the King isn't on the edge you then jump to the dummy-square and continue looping from there. Is this really what you want, or do you want to continue capturing pieces past the King? If the latter, the code can be changed as follows: $1 (verify (and not-friend? (not-piece? block))) (while (on-board? $1) (if (piece? King) (capture dummy-square)) capture $1) (if (piece? King) capture dummy-square)) add Two more things: I'm assuming that when you say you can't capture through a block you mean that the block can't be the very first piece, since that's how your code is written. If you mean that the block affects the capturing if it appears anywhere in the line of pieces, then you've got to put the block test inside the while loop. Also, it wasn't clear to me where the capturing piece should end up. This code always moves the capturing piece to the end of the rank/file. |
Michael Strickland (Michael)
| | Posted on Tuesday, December 16, 2003 - 6:07 pm: | |
Thanks! That did it! |
|