@SuppressWarnings("unchecked")
	private void updateShadow(Point2D mousePosition) {
		if (mousePosition == null) {
			getCanvas().setShadow(null);
			return;
		}

		Board board = getBoard();

		if (board.isGameOver()) {
			return;
		}

		List<Move> moves = new LinkedList<Move>();

		// Are we trying to jump?
		int x = (int) Math.round(mousePosition.getX() * 2);
		int y = (int) Math.round(mousePosition.getY() * 2);
		boolean jump = x % 2 == 1 && y % 2 == 1;
		if (jump) {
			Position pos = new Position(x / 2, y / 2);
			Move move = new Jump(pos);
			if (move.isLegal(board)) {
				getCanvas().setShadow(move);
			}
			return;
		}

		// Determine whether we're trying to place a horizontal or a vertical
		// wall. Thanks to John Farrell (friendless.farrell@gmail.com), 18
		// January 2007.
		double rx = (mousePosition.getX() + .5) % 1;
		double ry = (mousePosition.getY() + .5) % 1;
		Wall wall = (ry < rx) ^ (ry < 1 - rx) ? Wall.HORIZONTAL : Wall.VERTICAL;

		x = (int) Math.round(mousePosition.getX()) - 1;
		y = (int) Math.round(mousePosition.getY()) - 1;
		Position pos = new Position(x, y);

		moves.add(new PutWall(pos, wall));
		moves.add(new PutWall(pos, wall.flip()));

		for (Move move : moves) {
			if (move.isLegal(board)) {
				getCanvas().setShadow(move);
				return;
			}
		}

		// No valid move found for the current mouse position.
		getCanvas().setShadow(null);
	}