ID:261601
Aug 20 2002, 2:51 pm
|
|
Ok, I have a var called piece, and its under a mob. Whenever the person's turn comes up, and they click on a piece the "peice" var gets set to the thing he/she clicked on. Now here is where the error is. The person is only allowed to move the peice diagonnaly how would I check to see if they only moved the peice diagonallY?
|
Aug 20 2002, 3:17 pm
|
|
Add all the acceptable moved they could make with that piece (all the turfs it could be moved to) to a list, and check and see if the location they try to move the piece to is in the list. If it is, move it, if not, fail.
|
In response to Foomer
|
|
Ya that would be easy except there is like 12 different pieces they could select from
|
In response to DBZ Kidd
|
|
It's still easy. Only calculate the possible locations when they try to move the piece.
|
In response to Foomer
|
|
Even easier. When you select the place to move the piece to, subtract it's x and y coordinates from the x and y coordinates of where the piece actually is. If the remaining x and y are equal, remove the piece.
|
In response to Garthor
|
|
Well, my way was actually something I thought up for a "how to make chess pieces move properly" puzzle, so it was intended to support general movement types, not just that specific one.
|
DBZ Kidd wrote:
Ok, I have a var called piece, and its under a mob. Whenever the person's turn comes up, and they click on a piece the "peice" var gets set to the thing he/she clicked on. Now here is where the error is. The person is only allowed to move the peice diagonnaly how would I check to see if they only moved the peice diagonallY? Assuming you're going for a chess-like solution, basically what you want to do is keep track of the new and old x,y values. If they match completely, of course, then no move has been made. But if they don't: obj/chesspiece Pawns and kings have a more complicated movement structure, because of the special moves of castling, en passant, and en passant capture. Note, however, that the IsValidMove() proc doesn't take into account whether your king will be put in check; that's something that has to be handled separately. king The movelist part might need a little explaining. Assume you have a datum set up to track moves: chessmove After each move is made, details about the move are added to the list. This gives you the benefit of having a move history available, while also allowing en passant capture (which is only valid when the last move was en passant) to work. Lummox JR |