| Author |
Message |
Daniel Julian (A_grue)
New member Username: A_grue
Post Number: 1 Registered: 10-2020
| | Posted on Monday, October 19, 2020 - 4:41 pm: | |
I've been pulling my hair out searching through this message board trying to find a solution to my problem. I have decided to just ask anyone who cares. Basically, I need to detect when a piece is captured or if a piece isn't on the board, preferably the former. These are the only solutions I could think of: 1. A brute-force implementation where every other piece checks if they can capture the piece in question. If they can, the capture is simulated, the board state gets marked, then the capturing piece is returned. If the piece in question is captured on the next turn, the resulting board state would be one we have already marked, so we can detect that. This longwinded process is repeated for every piece which is threatening the piece in question, and I would have to implement this new capture check for every piece. Very inefficient. 2. Zones. Make the whole board a zone called "board". Check if the piece in question is still in the zone when it is your turn again (assuming you owned the piece in question). I have attempted to implement this, but I can't seem to find a good place to place the check, as I would need a point in the program that is always executed on your turn before you have moved anything. I don't think such a point exists. 3. Dummy boards and pieces. I feel this is the most likely solution to work, but one I am not fond of. Essentially, a dummy piece on a dummy board will act as a shadow of the piece in question; moving as it does. If the piece in question is captured, then the shadow piece can detect that. I am somewhat new to Zillions and have never needed to use dummies before, so I'd like to stick with what I know and keep things simple for the moment. I'll progress when I need to. That's basically the issue. If you have any solutions I didn't think of, please say so. Thanks. |
M Winther (Kalroten)
New member Username: Kalroten
Post Number: 176 Registered: 1-2007
| | Posted on Monday, October 19, 2020 - 7:05 pm: | |
It seems like a simple problem. When the piece is captured, you simply add a dummy piece to some dummy position. Then you can check whenever you want if the piece has been captured. |
Daniel Julian (A_grue)
New member Username: A_grue
Post Number: 2 Registered: 10-2020
| | Posted on Tuesday, October 20, 2020 - 12:12 am: | |
That would require an overhaul of the capture system (i.e. replacing zillions' existing capture system with your system) |
Daniel Julian (A_grue)
New member Username: A_grue
Post Number: 3 Registered: 10-2020
| | Posted on Tuesday, October 20, 2020 - 12:23 am: | |
It just seems like an inflexible system that will be difficult to implement again if I need to. |
Daniel Julian (A_grue)
New member Username: A_grue
Post Number: 4 Registered: 10-2020
| | Posted on Tuesday, October 20, 2020 - 1:32 am: | |
I think it might be helpful to clarify. I have a piece in this chess variant (the wizard) that should only be able to move after your queen is captured (assuming you own the wizard). Hence I am trying to detect whether or not the queen has been captured. When I discovered the pieces-remaining goal, I thought that meant I could use (pieces-remaining 0 Queen) to detect the presence of the queen, but I was disappointed after I discovered you could only use it inside a win-condition block. Surely there must be a way to detect pieces in a straightforward manner if zillions has things like pieces-remaining, since it clearly has the ability to detect the presence or absence of pieces without dummy piece shenanigans. If dummies are required to solve this, then fine, but a solution which doesn't require replacing the capture system entirely would be preferable. Is looping through all the board squares out of the question? I could have the loop run inside the wizard's move generation code since zillions will definitely run that at the start of the turn. Only issue then is that this loop will run every turn, which is quite slow. |
M Winther (Kalroten)
New member Username: Kalroten
Post Number: 177 Registered: 1-2007
| | Posted on Tuesday, October 20, 2020 - 5:02 am: | |
It's a trivial problem. This is all that is needed in the capture code of the pieces: (if (piece? Queen) (create dummyp Z1)) And this is all that is needed in the Wizard code: (verify (not-empty? Z1)) Of course, if each player has a Wizard, then you need to have two positions (e.g. Z1 and Z2). The easiest way to solve this is to already have a dummyp in Z1 and Z2. And you also define a dummy piece "queen_captured". At capture of the enemy queen the code is: (if (enemy? Z1) (change-type queen_captured Z1) else (change-type queen_captured Z2)) At the top of the Wizard code is: (if (friend? Z1) (verify (piece? q_captured Z1)) else (verify (piece? q_captured Z2))) |
Daniel Julian (A_grue)
New member Username: A_grue
Post Number: 5 Registered: 10-2020
| | Posted on Tuesday, October 20, 2020 - 5:32 am: | |
Sorry if the question was trivial, but there aren't many other places to go to learn about ZRF. The language reference only gets you so far, and honestly I don't quite get the description of dummies they have in there. Many thanks Kalroten! |
M Winther (Kalroten)
New member Username: Kalroten
Post Number: 178 Registered: 1-2007
| | Posted on Tuesday, October 20, 2020 - 7:30 am: | |
You don't need to define coordinates for dummy positions and you don't need to define images for dummy pieces. So defining dummy positions and pieces is much simpler that defining real pieces and positions. |
Daniel Julian (A_grue)
New member Username: A_grue
Post Number: 6 Registered: 10-2020
| | Posted on Tuesday, October 20, 2020 - 10:28 am: | |
I got that part, though the reference didn't give any examples of the practical usage of dummies. I suppose there's an example somewhere in the default games. |