private ArrayList<ChessMove> getLegalMoves(ChessPiece piece) {
		ChessPosition from = piece.getPosition();
		ArrayList<ChessPosition> legalDestinations = getLegalDestinationsOnBoard(piece);
		ArrayList<ChessMove> legalMoves = new ArrayList<ChessMove>();
		for (ChessPosition destination : legalDestinations) {
			if (piece.isKing()
					&& Math.abs(from.getX() - destination.getX()) == 2) {
				// this is a castling move;
				if ((destination.getX() - from.getX()) < 0) {
					legalMoves.add(new ChessMove(piece, from,
							ChessMove.MoveType.LONG_CASTLE, destination,
							getPieceOnBoard(destination)));
				} else {
					legalMoves.add(new ChessMove(piece, from,
							ChessMove.MoveType.SHORT_CASTLE, destination,
							getPieceOnBoard(destination)));
				}
			} else if (piece.isPawn()
					&& Math.abs(from.getX() - destination.getX()) == 1
					&& getPieceOnBoard(destination) == null) {
				// this is en passant
				if (piece.getOwner().equals(getPlayer1())) {
					legalMoves.add(new ChessMove(piece, from,
							ChessMove.MoveType.EN_PASSANT, destination,
							getPieceOnBoard(new ChessPosition(destination
									.getX(), destination.getY() - 1))));
				} else {
					legalMoves.add(new ChessMove(piece, from,
							ChessMove.MoveType.EN_PASSANT, destination,
							getPieceOnBoard(new ChessPosition(destination
									.getX(), destination.getY() + 1))));
				}

			} else {
				legalMoves.add(new ChessMove(piece, from, destination,
						getPieceOnBoard(destination)));
			}
		}
		return legalMoves;
	}