| Author |
Message |
David Cannon (Davidcannon)
New member Username: Davidcannon
Post Number: 1 Registered: 2-2009
| | Posted on Sunday, February 15, 2009 - 7:29 am: | |
I'm working on a chess variant in which one piece (the King) has to move before all other pieces. I'm new to Zillions programming, so can you tell me how to prevent all other pieces from moving until the King has made his initial move? |
Greg Schmidt (Gschmidt2)
New member Username: Gschmidt2
Post Number: 93 Registered: 1-2007
| | Posted on Sunday, February 15, 2009 - 4:16 pm: | |
Probably the best way to accomplish your goal is to use an attribute. Take a look at Chess.zrf which comes with Zillions and search for "never-moved?". I believe this is used to determine if a castling move is legal. You can use the same technique, except expand it to all piece moves. Also see the help file for "set-attribute", there is mention of an attribute being used in a "never-moved?" case there too. -- Greg |
David Cannon (Davidcannon)
New member Username: Davidcannon
Post Number: 2 Registered: 2-2009
| | Posted on Sunday, February 15, 2009 - 4:49 pm: | |
Thanks for that, Greg. I tried it a moment ago but the whole thing crashes. Excuse my ignorance, but I'm a zillions novice. Castling : yes, the king and rook must never have moved. Wouldn't expanding the "never moved?" attribute to all pieces simply mean that the King can move only if the other pieces haven't? That's a little different from what I'm trying to do : I want the King to move first (specifically, to "merge" with another piece, thereby making the other piece royal - I know how to do that); no other piece can move until after the king has done this. That's what I'm finding difficult to understand. |
Greg Schmidt (Gschmidt2)
New member Username: Gschmidt2
Post Number: 94 Registered: 1-2007
| | Posted on Sunday, February 15, 2009 - 6:15 pm: | |
David - Now that I think about it, I don't think an attribute is the right solution, as an attribute is specific to a piece. That means that one piece can't directly affect another piece's attribute. What I think is needed is a global attribute and the only way I know how to do that is to use a dummy position. So here's the basic idea: 1) Define a dummy position, call it something like "king-can-move". Initially, the dummy position is empty. 2) Define a dummy piece, call it something like "yes" or perhaps "marker". 3) As part of each non-king move, create the dummy piece (above) on the "king-can-move" position. 4) As a pre-condition to generating the king move, check to make sure that the "king-can-move" position is not empty. -- Greg |
David Cannon (Davidcannon)
New member Username: Davidcannon
Post Number: 3 Registered: 2-2009
| | Posted on Monday, February 16, 2009 - 3:34 am: | |
I'm trying to do that, but I'm finding it incredibly tricky. I'm just a novice :-( I've come up with another idea, but I don't know whether it will work: prohibiting all pieces from moving unless the King's home cell is empty (thereby permanently disabling the cell, which I can create "off the board"). Would that work? And if so, how could I encode that? Thanks! |
Greg Schmidt (Gschmidt2)
New member Username: Gschmidt2
Post Number: 95 Registered: 1-2007
| | Posted on Monday, February 16, 2009 - 12:43 pm: | |
It seems like that might involve changing the rules or at least the starting location of the king. That would work and isn't much different than the previous suggestion. Creating a dummy location to hold king movement status isn't really that hard, so I would advocate that approach. 1) Under "(board..." create a dummy position: (dummy king-moved) 2) Create a piece called "marker" and make it a dummy piece by including the following underneath it: (dummy) 3) As part of the king move (just before you do the "add"), include: (create marker king-moved) This will store the dummy piece "marker" on the dummy position "king-moved". 4) At the beginning of the move generation for all of the other pieces include: (verify (not-empty? king-moved)) This will ensure that the move doesn't get generated until the king has moved. -- Greg |
David Cannon (Davidcannon)
New member Username: Davidcannon
Post Number: 4 Registered: 2-2009
| | Posted on Monday, February 16, 2009 - 3:11 pm: | |
It works! Thanks Greg! I'll finish the game in the next couple of days and go live with it - thanks to your help! |
Keith Carter (Keithc)
New member Username: Keithc
Post Number: 169 Registered: 8-2000
| | Posted on Tuesday, February 17, 2009 - 5:39 pm: | |
I am late to the party and I see there is already an working solution. So I will phrase this as a general question\alternative. Couldn't this be done with move priorities and the turn order? Give the king a move type called initial and it's regular move. Have the move order be: white initial, black initial, repeat white black. |
Greg Schmidt (Gschmidt2)
New member Username: Gschmidt2
Post Number: 96 Registered: 1-2007
| | Posted on Tuesday, February 17, 2009 - 6:05 pm: | |
I think your suggestion is even better. In fact, I don't think you even need move priorities. Just use the turn order you suggest and specify a "king-move" move type for the first two moves in the turn order, e.g. (turn-order (white king-move) (black king-move) repeat white black ) I can't fathom why it didn't occur to me! -- Greg |
Greg Schmidt (Gschmidt2)
New member Username: Gschmidt2
Post Number: 97 Registered: 1-2007
| | Posted on Wednesday, February 18, 2009 - 7:24 am: | |
David, If you would like to send me your game, I would be happy to make the change discussed above and send it back to you. -- Greg gschmidt958@yahoo.com |
David Cannon (Davidcannon)
New member Username: Davidcannon
Post Number: 5 Registered: 2-2009
| | Posted on Sunday, February 22, 2009 - 6:00 pm: | |
Thank you so much for all your helpful suggestions. I tried out a lot of things, and eventually found a way to do it that satisfied me. But without your suggestions, I would not have been able to get started. I completed the game (CHESS ON A SOCCER BALL) yesterday, and emailed it to Zillions today, so you can see it soon. Enjoy! |