|
You can't have the computer remove a random number of sticks in the range 1-3, always. You have remove a number in the range 1 to the lesser of 3 or the number of sticks left (if there are two left, you can't take 3).
You need a variable, sticksLeft. You need to compare sticksLeft to 3 and generate a random number in the range 1-3 or 1-sticksLeft, accordingly. When sticks are removed, you subtract that number from sticksLeft. When sticksLeft is zero, the game is over.
Obviously, after you've subtracted the player's number, it's the computer's turn. When the computer is through, it's the player's turn. That cycle gets broken by "game over".
|