CPS 100, Spring 1997, Jotto

The word game Jotto is similar to mastermind, but played with five-letter words instead of colored pegs. Two players each pick a secret word that is not revealed. Players than take turns guessing five letter words. For each guessed word the opponent tells how many letters are in common with the secret word. For example, if player A picks "flops" as the secret word, and player B guesses "spore", then Player A responds that "spore" has 3 letters in common with his secret word. The player who determines the oponent's secret word with the fewest guesses wins.

Files accessible for use in this program are:

You are to implement a class so that the computer plays Jotto. You must subclass the abstract class Player whose interface is given below. You can add more functions, but you must implement those declared in the base class Player from player.h.

class Player { public: virtual string getSecretWord() = 0; // returns secret word virtual string getGuess() = 0; // player's guess virtual void makeNewSecret(); // create a new secret word // process the guess word, which has common letters // with oponents word. isSecret = true if word is // opponent's word virtual void processGuess(const string & word, int common, bool isSecret) = 0; virtual void debug() = 0; // useful for debugging static const int SIZE; static const string ALL_DONE; }; // lines below are actually in player.cc const string Player::ALL_DONE = "hopeless"; const int Player::SIZE = 5; For example, here is a small function that shows how a computer player might interact with a human player typing at the keyboard (see testjotto.cc). void Play(Player * p) { string guess = ""; int common; while (guess != Player::ALL_DONE) { p->debug(); guess = p->getGuess(); cout << "guess = " << guess << endl; common = PromptRange("# in common (6 for done): ",0,6); if (common == 6) break; p->processGuess(guess,common,false); // ignore last param. for now } if (common != 6) { cout << "You are a cheater!!!" << endl; } }

You should submit three files. The first two are a .h file and a .cc file in which you declare and implement a class derived from Player. For example, you might start with:

class OlaPlayer : public Player { // put stuff here }; You'll want to write a program to test your player class. You can use the routines in testjotto.cc to read the file of five letter words knuth.dat in the data directory and as a start, but you'll want to get the bugs out of your JottoPlayer class or write a program that lets the computer play with a person.

In any case, you must also submit a third file modeled after the program jfactory.cc shown below.

#include "olaplayer.h" Player * jFactory(const Vector<string> & dictionary, int numWords, const string & name) // precondition: dictionary = list of numWords valid words, // dictionary is sorted { return new OlaPlayer(dictionary, numWords,name); } You can substitute any header file for "olaplayer.h" and you may substitute any class name (e.g., something other than OlaPlayer). You can also call functions from jFactory, but the parameters to jFactory cannot change. This function will be used to create players for each submission.

When all classes are submitted, there will be a tournament in which all classes try to guess a sequence of words. The player/classes requiring the fewest guesses wins. The top three classes will receive bonus points of +8, +4, +2, respectively. The program itself is worth 12 points.

Submit using

submit100 jotto README ...
Owen L. Astrachan
Last modified: Thu May 1 16:36:30 EDT