Overview

In this lab, you will write a program that implements a simple game known as Bulls and Cows.

Game Rules

The computer selects a four digit number in which each digit is unique (e.g., 0274 or 3914 but not 3381). The object of the game is to correctly guess the number. After each guess, the user is given bovine hints. For each correct digit in the wrong position earns a cow, and each correct digit in the correct position earns a bull. When the user gets four bulls, (s)he wins.

The scoring is as follows:

Guesses: 1 2 3 4 5 6 7 8 9 10
Points: 1000 500 200 100 50 20 10 5 2 1

Sample Game Play

Here is an example running of the program:

Enter a guess: 0123
Bulls: 0, Cows: 2

Another guess: 4567
Bulls: 0, Cows: 2

Another guess: 6701
Bulls: 2, Cows: 0

Another guess: 6723
Bulls: 2, Cows: 2

Another guess: 6732
Bulls: 4, Cows: 0

Congratulations... you got it in 5 guesses.
Total score: 50

Would you like to play again (Y/N)?

You may chose implement your game through console I/O or as with a GUI. Note that your program must repeatly play the game until the user answers N to the question "Would you like to play again?" Also, you must implement at least two classes as part of your solution.

Just for Fun

The Bulls and Cows game is similar to Mastermind. The Wikipedia page for the game outlines a "Six guess algorithm" that solves the Mastermind game in fewer than seven guesses. If you have additional time/interest, you may wish to develop an algorithm for the Bulls and Cows game that minimizes the number of guesses required to win. You could implement the algorithm and watch the computer play against the computer. Have your algorithm run against the computer a few thousand times to determine the average number of guesses required.

Lab Report (due 4:00pm, Friday of week 10)

You should indicate how much time you spend on this assignment in the FAST system. You are encouraged to log your activity as you work on the project. At a minimum, you should log all of the time spent on this assignment before the due date given above. All time spent on this assignment should be entered into the week 9 and 10 columns.

This XML template can be used as a starting point for your reports.

Your report should include:

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost.

If you have any questions, consult your instructor.

Acknowledgment

This laboratory assignment was developed by Dr. Chris Taylor.