CS 261 Lab J - Mind Reading

Due Wed Apr 17 at 9:00am

Overview

In this lab, you will program the computer to read the user's mind. (Why didn't software developers do this a long time ago?) Your program will guess in advance whether the user will choose heads or tails, then get the actual response from the user. If your program guesses correctly, it gets a point; otherwise the user gets a point. The first one to 15 points wins. The interface should look something like this:

Welcome to MindReader.
****************************
I've made my prediction about what you will enter. Input 'h' or 't' below. 
Enter 'h' or 't': h
Drat. My prediction was wrong.
Score is now human 1, computer 0
****************************
I've made my prediction about what you will enter. Input 'h' or 't' below. 
Enter 'h' or 't': t
I was right!
Score is now human 1, computer 1
****************************
I've made my prediction about what you will enter. Input 'h' or 't' below. 
Enter 'h' or 't': t
I was right!
Score is now human 1, computer 2

Underneath the hood, your program will be using a hashmap to track the user's responses and use that to predict its guesses The "mind reading" will be implemented by remembering the last four responses and the last response that followed such a "response history". Humans are not very good at producing genuinely random output, and this simple method is surprisingly effective considering how simple it is.

This lab will be completed in pairs. Review the pair programming guidelines!

Objectives

Necessary Files

None! You are on your own here.

Details

You will be making three classes for this program:

Submitting

Submit all of your classes to the LabJ submission folder on hedwig. Make sure you upload your work to the correct folder! The lab is due at the start of class on the day after the lab.

Remember to fill out your lab partner evaluation!

Extensions

Right now, you just record the user's last response and use that in the hashmap. Make this a bit more sophisticated: Record a pair of values that represent the number of times the user followed that history with 'h', and the number of times the user followed that history with 't'. So your hashmap might have entries like:

"hthh": (3, 5)
which says that "hthh" was followed by 'h' three times, and 't' five times. So you would return 'h' as the computer's guess with probability 3/8, and 't' with probability 5/8.

You can use a Point, a two-element array, or another private class with two instance variables to store this pair of responses. You could even store the pair of values as a hashmap with keys 'h' and 't', and with the counts as values. So you would have a HashMap whose values are HashMaps. The idea here is to track the distribution of responses that followed a given history, instead of just the last response, and to make guesses according to that distribution.

Further refinements may be possible. How accurate can you make your mind reader?

Grading

This assignment will be graded based on approximately the following criteria: