CSCI 136 |
This is how the Mind Reader game should work. Prior to user input, the program is going to predict whether a user is going to input a “head” or a “tail”, as if a coin has been tossed. Without being told what the computer guessed, the user will then choose to enter “heads” or “tails”. The program’s guess and the user’s input will then be compared. If the program guessed correctly, it gets a point. If not, the user gets a point. The program continues until either the program or the user reaches 25 points.
The program will keep track of past behavior of the user, and over time, build a "history" of what the user has input. Each piece of user history will consist of four consecutive head/tail choices, as shown below. Let’s say the user has entered the following 10 choices:
H H T H T T T H T H
1 2 3 4 5 6 7 8 9 10
The first four times the program guesses what the user will input next, it has no history, and must make random guesses. After that, it may then start looking at past user behavior. In the above example, the computer has the following cases available by the 10th user input.
1. H H T H
2. H T H T
3. T H T T
4. H T T T
5. T T T H
6. T T H T
7. T H T H
For each unique set of entries, the computer can keep track of what choice the user makes next, either heads or tails, and how many times the user chose that particular choice. So, if the value we are storing for each is a 2-element integer array with the first element representing the number of times "H" was chosen, and the second the number of times "T" was chosen, the outcome would look like this:
1. H H T H 0 1
2. H T H T 0 1
3. T H T T 0 1
4. H T T T 1 0
5. T T T H 0 1
6. T T H T 1 0
7. T H T H 0 0
Thus, when the user has guessed a series of HHTH in the past, the next guess was T, so if the program sees this pattern again, it should guess the user will input an T next. Let's say that sequence did occur again, and the user entered a T again. The value stored should now be:
H H T H 0 2
If the user entered the same pattern again, but this time their next choice was H, the stored values would be:
H H T H 1 2
If the exact pattern isn’t available in the hash map, the program should simply make a random guess. This will happen before the computer has enough data (the first few rounds of play), or if a pattern has not yet been seen. The computer will also need to make a random guess if the number of times H or T was chosen is equal in the hash map.
You must use a hash map (dictionary) where the input patterns are the keys, and the value stored has two components to keep track of the number of times H and T were chosen by the user after that key pattern was used. I used a 2 element array of integers, but you can use whatever works for you. You will also have to think about what kind of structure would work best for keeping track of user choices as they are input. What you use is up to you. In this program, I am also leaving it up to you on how to structure your methods. In other words, I am not requiring that you use a pre-defined API. Unfortunately, with no API, this also means I cannot provide you with an autograder... :(
Part of an example run interaction and output is shown below:
Enter H for heads or T for tails: H
Computer predicted: H Player chose: H
Computer: 1 Player: 0
Enter H for heads or T for tails: T
Computer predicted: H Player chose: T
Computer: 1 Player: 1
...
Enter H for heads or T for tails: T
Computer predicted: T Player chose: T
Computer: 25 Player: 3
Computer WINS!!!
Grade Item | Points Possible | Points Earned |
---|---|---|
Program Compiles | 2 | |
Program Runs | 2 | |
Comments on All Classes and Methods | 6 | |
Hash map stores keys/values correctly | 6 | |
Computer prediction is based on patterns | 4 | |
Game operates correctly | 4 | |
Write Up of Results across10 Test Runs | 6 | |
Total | 30 |
Page last updated: January 06, 2022