A state is winning if the current player can force a win from it. A state is losing if every move leads to a winning state for the opponent. Here's the pattern: a state is winning if there exists at least one move to a losing state.
You just need one good move. A state is losing only if all moves lead to winning states for the opponent. Base case: whoever faces an empty pile, finished array, or "no moves left" position loses (or wins, depending on the game rules). Build backwards from there.