One approach to this problem whereby we can deduce the answer without any initial guessing is to calculate the nimber $f(n)$ of a game starting with $n$ pebbles in a single pile. This is helpful because our game has the property that, when we have two piles, its the same as if we had two games simultaneously, where each player chose to play in one, and the winner was the person who made the last legal move. That is to say, the nimber of a game with multiple piles is the nim-sum of the nimbers of each pile.
To calculate the $f(n)$, we compute the nimber of every position that can be moved to from a pile of $n$, then calculate the minimal nimber not achieved in that set - as is the standard method in impartial games. Given that a pile of $n$ may be replaced by piles $s_1,\ldots,s_k$ where all values of $s_i$ are less than $n$ and that all possible moves are of this form, we may write
$$f(n)=\operatorname{mex}(\{f(s_1)\oplus f(s_2)\oplus \ldots \oplus f(s_k):0<s_i<k\})$$
where $\oplus$ is the nim-sum. Using the above, we may inductively show that $f(n)=2^n$ for $n\geq 1$. This is because if we let $s_k$ be the position of the ones in the binary expansion of $n'$ for some $n'<2^n$, then the expression $f(s_1)\oplus\ldots\oplus f(s_k)$ will equal $n'$ by inductive hypothesis. Thus, starting from position $n$, one can move to a position with any nimber less than $2^n$. However, since $2^n$ has a $1$ in the binary expansion in a position where no smaller $2^k$ does, it is not such a nim-sum, and hence must be the mex of the set.
Knowing this, we can say that a losing position is one whose nimber is $0$. Given that $f(n)=2^n$ happen to be linearly independent with respect to the nim-sum, it follows that the only way for this to happen is if there are an even number of piles with $n$ rocks for all $n$. Knowing that these are exactly the losing positions, we find that a winning position is one where there is some - and the proper move is to move to a losing position, meaning you must take the largest $n$ such that there are an odd number of piles with $n$ rocks, remove it, and ensure that all $k<n$ have an even number of piles of $k$.