#include #include #include #include "CPstring.h" #include "vector.h" #include "prompt.h" #include "player.h" // don't forget to include your header file here, e.g., "olaplayer.h" void ReadWords(istream & input, Vector & words, int & numWords) // precondition: input open // postcondition: each line of input read, stored one line per entry // of words, numWords = # of lines read { string word; while (getline(input,word)) // read one line { word = word.substr(0,Player::SIZE); // truncate # letters if (isalpha(word[0])) // begins with alphabetic char? { if (numWords >= words.length()) { words.resize(words.length() * 2); } words[numWords] = word; numWords++; } } } 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); } if (common != 6) { cout << "You are a cheater!!!" << endl; } } int main() { ifstream input; string filename; string answer; Vector words(6000); int count = 0; cout << "file name: "; cin >> filename; input.open(filename); ReadWords(input,words,count); // replace line below with your Player * p = new CompPlayer("owen",words,count); do { Play(p); answer = PromptString("play again? [y/n]"); p->makeNewSecret(); } while (tolower(answer[0]) == 'y'); }