本文整理汇总了C++中AI::getMostOccuring方法的典型用法代码示例。如果您正苦于以下问题:C++ AI::getMostOccuring方法的具体用法?C++ AI::getMostOccuring怎么用?C++ AI::getMostOccuring使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AI
的用法示例。
在下文中一共展示了AI::getMostOccuring方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runGameLoop
void Hangman::runGameLoop(AI my_ai){
//loop this
while (true){
//print out the progress the user has made in guessing
printVector(blanked_out);
cout << "\n";
//uses the common words string to get the most popular characters
guess = my_ai.getMostOccuring();
in_wrong_guesses = false;
for (int i = 0; i < wrong_guesses.size(); ++i){
if (guess == wrong_guesses[i]){
in_wrong_guesses = true;
}
}
//if the user has already tried this letter before
if (in_wrong_guesses){
cout << "\nYou already guessed that letter silly goose!" << endl;
cout << "You have " << (max_wrong - wrong_answers) << " wrong guesses left until you lose" << endl;
}
else{//this is a new letter attempt
//add that char to vector<char>guessed
wrong_guesses.push_back(guess);
//check if that is in answer
if (contains()){
//cout << "Your guess '" << guess << "' IS contained in the answer!" << endl;
cout << "'" << guess << "' IS in the answer!" << endl;
//cout << "You have guessed correctly " << num_correct << " times" << endl;
cout << "You have " << (max_wrong - wrong_answers) << " wrong guesses left until you lose" << endl;
// printVector(blanked_out);
//user has won!
if (num_correct == len_guess){
//print victory information
cout << "____________________________________________" << endl;
cout << "\nYOU WON!" << endl;
cout << "The final word was: ";
printVector(blanked_out);
cout << "\n\n\n";
return;
}
}
else //the user guessed a wrong letter
{
//print failure message
cout << "'" << guess << "' is NOT in the answer!" << endl;
++wrong_answers;//increment the wrong answer counter
cout << "You have " << (max_wrong - wrong_answers) << " wrong guesses left until you lose" << endl;
//if the user ran out of guesses display error message
if (wrong_answers >= max_wrong){
cout << "You used up all of your guesses!" << endl;
cout << "GAME OVER" << endl;
cout << "The word was: " << answer << endl;
return;//quit the loop and function
}
}
}
}
}