In this lab exercise you will add functionality to the OOP Implementation of Nim in C++ discussed in a web presentation. (See the menu at left.)

Download this zipped folder of code files to your machine: files.zip.

These code files need to be moved to your disk space on the Computer Science server named janus. (See Using C++ at UMD on the menu to the left for how to transfer, compile, and run programs.)

Run the program:

  1. In NetBeans, click File and select New Project....
  2. In the New Project dialog,
    • Select category C/C++
    • Select project C/C++ Application.
    • Click Next.
  3. In the New C/C++ Application dialog,
    • Name the project "CS 1581 Nim C++"
    • Uncheck the Create Main File box.
    • Click Finish.
  4. Right click Header Files under the newly created project and select Add Existing Item...
  5. In the Select Item dialog,
    • browse to the files folder and select all ten files with the ".H" extension.
    • Click Select to add them to the project.
  6. Right click Source Files under the project and select Add Existing Item...
  7. In the Select Item dialog,
    • browse to the files folder and select all ten files with the ".cpp" extension.
    • Click Select to add them to the project.
Right click the CS 1581 Nim C++ project node and choose Clean and Build.

You should see a number of messages and compiler invocations ending with "BUILD SUCCESSFUL".

Right click the CS 1581 Nim C++ project node and choose Run.

If you uncomment the "testGame()" call (see main function at right) and run the program you will observe one game set up and played to completion, followed by a program exit.

Your job is to implement a ScoreKeeperInfo object that:

The script below shows one possible result of running the testScoreKeeper() method.

For full credit your lab must exhibit the same functionality.

User input is shown in red.

Welcome to the Game of Nim.

What is your name? Ralph
I will flip a coin to start.
heads or tails? 1
heads or tails? tailsq
heads or tails? tails
It is heads
HAL 9000 will go first.

    Pile 1: 11
    Pile 2: 8
    Pile 3: 10

HAL 9000 takes 1 coin(s) from pile 1

    Pile 1: 10
    Pile 2: 8
    Pile 3: 10

Which pile will you remove from? 
2
How many coins do you want to remove? 
8
Ralph takes 8 coin(s) from pile 2

    Pile 1: 10
    Pile 2: 0
    Pile 3: 10

HAL 9000 takes 1 coin(s) from pile 1

    Pile 1: 9
    Pile 2: 0
    Pile 3: 10

Which pile will you remove from? 
3
How many coins do you want to remove? 
10
Ralph takes 10 coin(s) from pile 3

    Pile 1: 9
    Pile 2: 0
    Pile 3: 0

HAL 9000 takes 9 coin(s) from pile 1

    Pile 1: 0
    Pile 2: 0
    Pile 3: 0

HAL 9000 wins. Score:
     Ralph: 0
  HAL 9000: 1
Another game (yes or no)? sure
Another game (yes or no)? you bet
Another game (yes or no)? yes
Ralph will go first.

    Pile 1: 10
    Pile 2: 11
    Pile 3: 9

Which pile will you remove from? 
3
How many coins do you want to remove? 
1
Ralph takes 1 coin(s) from pile 3

    Pile 1: 10
    Pile 2: 11
    Pile 3: 8

HAL 9000 takes 1 coin(s) from pile 1

    Pile 1: 9
    Pile 2: 11
    Pile 3: 8

Which pile will you remove from? 
2
How many coins do you want to remove? 
10
Ralph takes 10 coin(s) from pile 2

    Pile 1: 9
    Pile 2: 1
    Pile 3: 8

HAL 9000 takes 1 coin(s) from pile 1

    Pile 1: 8
    Pile 2: 1
    Pile 3: 8

Which pile will you remove from? 
1
How many coins do you want to remove? 
8
Ralph takes 8 coin(s) from pile 1

    Pile 1: 0
    Pile 2: 1
    Pile 3: 8

HAL 9000 takes 7 coin(s) from pile 3

    Pile 1: 0
    Pile 2: 1
    Pile 3: 1

Which pile will you remove from? 
3
How many coins do you want to remove? 
1
Ralph takes 1 coin(s) from pile 3

    Pile 1: 0
    Pile 2: 1
    Pile 3: 0

HAL 9000 takes 1 coin(s) from pile 2

    Pile 1: 0
    Pile 2: 0
    Pile 3: 0

HAL 9000 wins. Score:
     Ralph: 0
  HAL 9000: 2
Another game (yes or no)? no
All tests succeeded.

The ScoreKeeperInfo class is tested with the following:

The only public method in ScoreKeeperInfo should be start(). Here is ScoreKeeperInfo.H:

Here is ScoreKeeperInfo.cpp:

ScoreKeeperInfo should have instance variables that store:

You should develop and test ScoreKeeperInfo incrementally. For example, here is a suggested implementation of the start() method:

welcome, flipCoin, and playRepeatedly are private methods that can be developed and tested separately in order.