Chapter 15.2.3

The Game of Nim - Step 3

AmazonLet’s apply the 3rd step of the Four-Step Programming Model to solve the game of Nim!

Four Step Programming Model: Step 3Interrelation: All variables are independent of one another.

State: max and min are determined by the programmer and shouldn’t change throughout the program; size is the current number of marbles and is always decreasing; whoseTurn should switch back and forth between player and computer; compTakeOff and youTakeOff should be legal number of marbles to draw; mode should not change once it is determined.

Scope: Out of these variables, we can make max and min global constants because their values do not change throughout the program.