Prog 1: Guess01

Addition made on 9/4: Sample output shown for Stage 0

Clarification made on 9/9 shown in blue.

Can you write a program that can outsmart you?  You might be surprised!  Write a program to play a 0/1 number guessing game against the computer.  

At each move first the computer makes a forecast of 0 or 1, then you make your guess.  The score starts at 0.  If the computer correctly forecasts (matches) your choice, we subtract 1 from the score.  If the computer doesn't match your move, we add 1 to the score.  The computer wins if the score reaches -10.  You win if the score reaches +10.

A sample of this game (written in Scratch) is shown below.  For the best experience play it here.

Our version will not be graphical but will be text-based, and should be written in stages.  While generally poor form, we will be extensively allowing the use of global variables for this first program. If you know how and prefer not to use global variables for this program, you can do so, but don't have to.   Of the 55 points available for execution, different numbers of points will be awarded depending on how far you get.

Stage 0 (0 points)

Create a Qt Creator project in C, as demonstrated in class on 8/31. (Watch the class video through Echo 360 on Blackboard if you don't remember this.)  The name of your project should be your netid.  Add the code to:

Program #1: 0 or 1 number guessing game 

Author: Dale Reed

Lab: Tues 8am

Instructions:

For each move the computer will forecast what it thinks you will enter.  

When prompted you then enter 0 or 1.  The computer forecast and your

input will be compared.  If the computer got it right, the score is

decremented.  If the computer got it wrong, the score is incremented.  

The score starts at 0.  If it reaches -10 the computer wins.  

If it reaches 10, the human wins!  Good luck, you'll need it!

1. Score is: 0

Computer has made forecast.

What is your input (0 or 1): 1

Computer's forecast was 1.  

Final score is: -1

Exiting program...

Note that if the user input instead of 1 was 0, the score would have gone up to 1 instead.

Stage 1 (5 points)

Use a random number generator to make the computer forecast.  Do the following:

Stage 2 (15 points)

Use the possible values from the single previous user move to make the computer forecast.  

Stage 3 (15 points)

Store and use the previous two moves to make the computer forecast.  You should create two global variables for these previous two moves.   There are 4 combinations of the previous two moves, leading now to 4 table rows.  For each of these 4 combinations store how many times 0 was chosen by the user in that situation, and store how many times 1 was chosen by the user in that situation.  Each of these will again be a global variable, for a total of 8 variables.  Consider the following table to represent these values:

Initialize Move 2 and Move 1 to both be 0.  Create a variable to store the user input.  When the user makes a move, "shift these values left" by storing the old Move 1 value "left" into Move 2, and the new user input into Move 1.  Use the Move 2 and Move 1 values to determine which row in the table you care about.  As in the previous stage, then compare the variables that store the history for that row, identifying the largest of the two to make the computer forecast.

Stage 4 (20 points)

Store and use the previous three moves to make the computer forecast.  There are 8 combinations of the previous three moves, leading now to 8 table rows and 16 variables.  Follow the same approach as in the previous stages, but this time filling in the table information for all 16 variables.

Turning In Your Program

Remember that the name of your project should be your netid.  Zip up your entire project and turn it in to Blackboard into the Program 1 assignment.  Be sure to review the grading criteria on the course syllabus, particularly regarding variable names and comments.