~mc27/labs/nim/nim.scm
somewhere under your home directory, and then evaluate everything in it
in DrScheme. (Note: The easiest way to save the file is to go to
the link, and then do a Save As... under the File menu in
Netscape.) This file contains the Nim program and the game-state implementation
from the book, except that computer-move and human-move
are modified as indicated in exercise 6.13(c).
make-move-instruction and the two selectors
are called
num-coins and pile-number. You should write
them correctly by removing the error expressions which they currently
contain and replacing them with the actual procedure bodies.
Keep in mind that make-move-instruction just constructs
a move-instruction object, while next-game-state actually performs
the move.
Once you have implemented the move-instruction ADT, you can test your implementation in two ways. First, you could test the ADT in isolation with expressions such as:
(num-coins (make-move-instruction 4 2))Second, you can test the ADT in the context of the whole application by playing Nim games with the computer by evaluating, for example, the expression:
(play-with-turns (make-game-state 5 8) 'human)Both kinds of tests are critical in any large application, so be sure to do both kinds of tests throughout this lab.
Play a couple of games so that you get a hang of how the interaction works. (You needn't include transcripts of your game playing in the lab writeup.)
make-move-instruction, num-coins and
pile-number.
You'll be asked at the end of the lab to make sure your program works with
either implementation.
When working with the
random
procedure, keep in mind that each time you use it you may get a different
result; if you want to use the same randomly chosen integer twice, you
should hold onto it, for example by naming it with a let, as you
won't be able to regenerate it.
Again, as with the game-state ADT, be sure to test each
strategy in isolation as well as in the context of the whole application.
If you are unsure about how to test the strategies in isolation, ask!
As always, the code should be clear with names well chosen, and you may need to comment any code which is hard to understand. You may assume the reader knows your assignment.