Modifying the Program for Strategies: Exercise 6.14, p. 159
Exercise 6.14 adds a strategy parameter to the computer-move
procedure.
A strategy is simply a procedure that takes a game state and
returns a move instruction. For example, here is the familiar simple-minded
one currently used by the computer:
(define simple-strategy
(lambda (game-state)
(if (> (size-of-pile game-state 1) 0)
(make-move-instruction 1 1) ; remove one coin from pile 1
(make-move-instruction 1 2)))) ; remove one coin from pile 2
The computer will apply the strategy to the
current game state and receive a move instruction, from which the number of
coins and pile number can be extracted through the ADT selectors.
Note that play-with-turns will need to be modified to
accept a strategy parameter to be passed to computer-move,
and nim will need to be modified to pass simple-strategy
to play-with-turns.
When you
finish this exercise the program will still behave as it did before.