Fundamentals of Computer Science I

Assignment 8

Chat Bot

The Loebner Prize Competition is held every year to evaluate artificial intelligence chat programs using the Turing Test. In 1950, Alan Turing proposed a test to measure the intelligence of computers. In the Turing, test a subject has a text chat with either a person in another room or with a computer (the subject does not know which). There are no limits to what the subject can chat about, but when done chatting the subject must choose whether they think they were talking to a real person or to a computer. The more frequently a the computer computer is labeled as human, the more intelligent the computer is, according to the test. (Whether the Turing test is actually a measure of intelligence is debatable, but one interesting thing to consider is, what if a computer was labeled as human more than an actual human?) One simple artificial intelligence chat algorithm is to just repeat what other people have said previously in the same context.


This assignment is to be done individually. You will not work with a partner for this assignment.

Write a simple artificial intelligence chat program. The program should use a dictionary to associate phrases with responses. When a user types a phrase into a prompt the program should check if there is an entry for the phrase. If there is an entry it should print it, if there is not, then it should print a response for a random phrase in the dictionary. Note, the dictionary must be initialized with at least one phrase and response or else it will not be able to select a random phrase. After printing the response the program should repeat. The program should repeat a large fixed number of times and it should inform that user that pressing ctl-c will quit the program.

The chat will be very boring unless the program’s response dictionary is updated. The program should add the users input as a new response to the last phrase the program printed. That is, the program’s last output is the new key, and the user’s last input is the new value. The key should be converted to lowercase and stripped of all non-alphabetic characters to prevent capitalization and punctuation from affecting the look-up. If the key is already in the dictionary, the value should be overwritten with the new response.


It's time to put your thinking caps on! We will run our own version of the Loebner competition in class. During the competition, you will get paired with either another student in the class, or one of your fellow classmates chatbot program. Your goal in class is to discover as many chatbots as possible. Your goal when writing the assignment is to fool as many of your peers as possible. The program which fools the most people will be awarded additional bonus points.


Submit your code before class on Friday November 22nd.

Your code should conform to the course's code conventions. Create a tar file of your assignment8 directory by navigating to your assignments directory, using the cd command. Then, issue the following command.

    tar czf tarfilename.tgz assignment8/

To verify that the tgz file contains your code run the following command. It should list all of your .py files.

    tar tzf tarfilename.tgz

To submit your activity, go to cseval.roanoke.edu. You should see an available assignment called Assignment 8. Click the submit button and choose the tgz file you created to upload. Only one person per group needs to submit.

Be sure to also copy or email the tgz file to your partner. To extract the files in a tgz file from the terminal use the following command:

    tar xzf tarfilename.tgz