ID:261601
 
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?
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
var/color
var/moved=0

// T is the intended destination
proc/IsValidMove(turf/T,list/movelist)

proc/FindFirstPiece(turf/stop,d) // first piece in path
if(stop) d=get_dir(src,stop)
var/turf/T=get_step(src,d)
var/obj/chesspiece/O
while(T && istype(T,/turf/board))
for(O in T) return O
if(T==stop) return null
T=get_step(T,d)
return null

bishop
IsValidMove(turf/T)
if(abs(T.x-x)!=abs(T.y-y)) return 0
var/obj/chesspiece/O=FindFirstPiece(T)
if(!O) return 1 // normal move
if(O.side==side || O.loc!=T) return 0 // blocked
return O // send back piece to indicate capture

rook
IsValidMove(turf/T)
if(T.x!=x && T.y!=y) return 0
var/obj/chesspiece/O=FindFirstPiece(T)
if(!O) return 1 // normal move
if(O.side==side || O.loc!=T) return 0 // blocked
return O // send back piece to indicate capture

queen
IsValidMove(turf/T)
if(T.x!=x && T.y!=y && abs(T.x-x)!=abs(T.y-y)) return 0
var/obj/chesspiece/O=FindFirstPiece(T)
if(!O) return 1 // normal move
if(O.side==side || O.loc!=T) return 0 // blocked
return O // send back piece to indicate capture

knight // with silly knees-bent running about advancing behavior
IsValidMove(turf/T)
if((T.x-x)*(T.x-x)+(T.y-y)*(T.y-y)!=5) return 0
var/obj/chesspiece/O
for(O in T)
if(O.side==side) return 0 // blocked
return O // return piece to indicate capture
return 1 // normal move

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
var/checked=0

IsValidMove(turf/T)
var/obj/chesspiece/O
if(get_dist(src,T)==1)
O=FindFirstPiece(T)
if(!O) return 1
if(O.side==side) return 0 // blocked
return O // return piece for capture
if(moved || checked || T.y!=y || abs(T.x-x)!=2) return 0
// check for castling
O=FindFirstPiece(null,get_dir(src,T))
if(!O || O.side!=side || O.moved || !istype(O,/obj/chesspiece/rook))
return 0
return O // return rook to indicate castling move

pawn
// By convention, any pawn with dir=NORTH can only move northwards
// likewise, dir=SOUTH can only move south
IsValidMove(turf/T,list/movelist)
if(!(get_dir(src,T)&dir)) return 0 // can't move backwards
// valid moves: en passant, forward, capture
if(abs(T.y-y)>(moved?1:2) || abs(T.x-x)>2-abs(T.y-y)) return 0
var/obj/chesspiece/O=FindFirstPiece(T)
if(T.x==x)
if(O) return 0 // blocked (by any piece)
var/turf/T2=get_step(T,dir)
if(!T2 || !istype(T2,/turf/board)) return 3 // promotion
return abs(T.y-y) // return 1 for normal move, 2 for en passant
if(O) // moving diagonally for capture
if(O.side==side) return 0 // blocked
return O // return piece for capture
// handle special case: en passant capture
// up to now, we know the pawn is moving diagonally and there's nothing
// on the destination square
var/chessmove/lastmove
if(!movelist.len) return 0 // no prior moves!
lastmove=movelist[movelist.len]
if(lastmove.piece && lastmove.movetype==2 && \
lastmove.dest.x==T.x && lastmove.dest.y==T.y)
return lastmove.piece // en passant capture
return 0

The movelist part might need a little explaining. Assume you have a datum set up to track moves:
chessmove
var/obj/chesspiece/piece
var/piecetype
var/movetype // the return value from IsValidMove()
var/turf/start // started at...
var/turf/dest // moved to...
var/check

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
Actually I'm making a checkers game. I'm trying to making the jump command, but I'm not exactly sure on how to tell if the piece other piece is there.