本文整理汇总了C++中Boggle类的典型用法代码示例。如果您正苦于以下问题:C++ Boggle类的具体用法?C++ Boggle怎么用?C++ Boggle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Boggle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SolveThread
DWORD WINAPI Boggle::SolveThread(void* arg)
#endif
{
Boggle* boggle = reinterpret_cast<Boggle*>(arg);
//set up a used letters bool array
unsigned int boardLen = boggle->m_BoardHeight * boggle->m_BoardWidth;
unsigned int* usedLetters = new unsigned int[(boardLen / (sizeof(unsigned int) * 8)) + 1];
char* wordSoFar = new char[boardLen + 1];
unsigned int boardPos = 0;
while (true)
{
boardPos = boggle->m_SolvedPositions.fetch_add(1);
if (boardPos >= boardLen)
break;
//make sure the usedLetters is blank
memset(usedLetters, 0, sizeof(unsigned int) * ((boardLen / 32) + 1));
boggle->SolveLetter(boardPos, boggle->m_Base, usedLetters, wordSoFar, 0);
}
delete[] usedLetters;
delete[] wordSoFar;
return 0;
}
示例2: computerTurn
/*
* Function: computerTurn
* --------------------
* This is the computer's turn. Find all of the remaining words using the boggles onj.
* Print this to the console and to the GUI.
*
* Preconditions:
*
* @param: word: the word to check
* @return: boolean true if valid word
*/
void computerTurn(Boggle& boggles) {
Set<string> humanWords;
string userInputW;
Set<string> computerSearch;
computerSearch = boggles.computerWordSearch();
cout << endl;
cout << "It's my turn!" << endl;
// Print out computer's words
cout << "My words (" << computerSearch.size()<<") "<< computerSearch.toString() << endl;
for(string i:computerSearch)
BoggleGUI::recordWord(i,BoggleGUI::COMPUTER);
cout << "My score: " << boggles.getScoreComputer()<<endl;
BoggleGUI::setScore(boggles.getScoreComputer(),BoggleGUI::COMPUTER);
if(boggles.getScoreComputer()>boggles.getScoreHuman()){
string statusMessage = "Ha ha ha, I destroyed you. Better luck next time, puny human!";
BoggleGUI::setStatusMessage(statusMessage);
cout << statusMessage << endl;
} else {
string statusMessage = "WOW, you defeated me! Congratulations!" ;
BoggleGUI::setStatusMessage(statusMessage);
cout << statusMessage << endl;
}
}
示例3: promptCreateGrid
/**
* @brief promptCreateGrid asks the player if it wants to create a random or
* manually inputted grid
*/
void promptCreateGrid(Boggle& boggle){
char answer;
bool answered = false;
string manualCharacters = "";
bool correctFormat;
cout << "\nDo you want to generate a random board? ";
while(!answered) {
cin >> answer;
if (answer == 'y' || answer == 'Y') {
boggle.createGrid(manualCharacters);
answered = true;
}
else if (answer == 'n' || answer == 'N') {
answered = true;
while (!correctFormat) {
cout << "Enter a string with 16 characters, must be a-z" << endl;
cin >> manualCharacters;
transform(manualCharacters.begin(), manualCharacters.end(),manualCharacters.begin(), ::toupper); //makes the str uppercase
int noCubes = boggle.getNUM_CUBES();
if (manualCharacters.size() == noCubes && (!manualCharacters.find_first_not_of(alphabet) != string::npos)) {
correctFormat = true;
} else {
cout << "Incorrect size of string or character, must be 16, a-z" << endl;
}
}
boggle.createGrid(manualCharacters);
}
}
示例4: presentComputersWords
//prints out all the computers word, depending on the userscore the output differs
void presentComputersWords(Boggle& boggle) {
vector<string> temp;
temp=boggle.getComputerWords();
cout<<"My words(all "<<temp.size()<<" of them):";
cout<<"{";
int score=0;
for (unsigned int i=0; i<temp.size(); i++) {
score=score+temp[i].size()-3;
cout<<'"'+temp[i]+'"'+",";
if (i%8==0) {
cout<<endl;
}
}
cout<<endl;
if (score>boggle.getUserScore()) {
cout<<"my score is "<<score<<" which is more than yours"<<endl;
}
else if (score==boggle.getUserScore()) {
cout<<"my score is "<<score<<" which is the same as yours, i guess you do have a gig of ram"<<endl;
}
else {
cout<<"my score is "<<score<<" which is the less than yours, that is impossible"<<endl;
}
}
示例5: main
int main()
{
Boggle game;
game.printBoard();
cout << "" << endl;
game.getUserInput();
cout << "" << endl;
game.printResults();
system("pause");
return 0;
}
示例6: compTurn
string compTurn(Boggle& boggleobj, string message) {
Set<string> compWords = boggleobj.computerWordSearch();
message = "It's my turn!";
for (auto i : compWords) {
BoggleGUI::recordWord(i, BoggleGUI::COMPUTER);
}
BoggleGUI::setScore(boggleobj.getScoreComputer(),BoggleGUI::COMPUTER);
printStatus(message, "My", boggleobj.getScoreComputer(), compWords, boggleobj);
if (boggleobj.getScoreHuman() >= boggleobj.getScoreComputer()) {
message = "WOW, you defeated me! Congratulations!";
} else {
message = "Ha ha ha, I destroyed you. Better luck next time, puny human!";
}
return message;
}
示例7: printBoard
//simply prints out the board
void printBoard(Boggle& boggle) {
for (int i=0; i<4; i++) {
for (int j=0; j<4; j++) {
cout<<boggle.getLetter(i,j);
}
cout<<endl;
}
cout<<endl;
}
示例8: printGUI
/*
* Function: printGUI
* --------------------
* sets up the GUI
*
* Preconditions:
*
* @param: boggles object of type Boggle
* @return: none
*/
void printGUI(Boggle& boggles){
string s;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
s += boggles.getLetter(i,j);
}
}
BoggleGUI::labelAllCubes(s);
}
示例9: printGrid
/**
* @brief printGrid prints the cubes that are in the grid
* @param boggle
*/
void printGrid(Boggle& boggle){
Grid<char> grid = boggle.getGrid();
for(int row = 0; row < grid.numRows(); row++){
for(int col = 0; col < grid.numCols(); col++){
cout << grid.get(row, col);
}
cout << endl;
}
}
示例10: printPlayerWords
/**
* @brief printPlayerWords outputs the words that the player has found
* @param boggle
*/
void printPlayerWords(Boggle& boggle) {
set<string> playerWords = boggle.getPlayerWords();
cout << "Your words (" << playerWords.size() << "):";
for(set<string>::iterator it = playerWords.begin(); it != playerWords.end(); it++){
cout << *it << " ";
}
cout << endl;
}
示例11: humanTurn
void humanTurn(string message, Boggle& boggleobj) {
while (true) {
printStatus(message, "Your", boggleobj.getScoreHuman(), boggleobj.getFoundWords(), boggleobj);
string word = getLine("Type a word (or Enter to stop):");
word = toLowerCase(word);
if (word == "") {
break;
} else {
clearConsole();
if (boggleobj.checkWord(word) && boggleobj.humanWordSearch(word)) {
message = "You have found a new word! \"" + word + "\"";
BoggleGUI::recordWord(word, BoggleGUI::HUMAN);
BoggleGUI::setScore(boggleobj.getScoreHuman(),BoggleGUI::HUMAN);
} else {
message = "You must enter an unfound 4+ letter word from the dictionary.";
}
}
}
}
示例12: playOneGame
void playOneGame(Lexicon& dictionary) {
// TODO: implement
Boggle boggle = Boggle(dictionary, "");
Set<string> humanWords;
while (true) {
string humanWord = getLine("Please enter a human word (Enter to exit human turn): ");
if(humanWord=="") break;
if(boggle.humanWordSearch(humanWord)){
humanWords.add(humanWord);
cout << "This is a valid word!" << endl;
} else
cout << "This is not a valid word!" << endl;
}
cout << humanWords.toString() << endl;
//Set<string> results = boggle.computerWordSearch();
}
示例13: printComputerWords
/**
* @brief printComputerWords prints the words that computer found and the score that it got
* @param boggle
*/
void printComputerWords(Boggle& boggle){
boggle.computerFind();
set<string> words = boggle.getComputerWords();
clearConsole();
cout << "It's my turn!" << endl;
cout << "My words (" << words.size() << "): " << "{";
for(set<string>::iterator it = words.begin(); it != words.end(); it++){
cout << "\""<< *it << "\",";
}
cout << "}";
cout << "\nMy score: " << boggle.getComputerScore() << endl;
//If the computer has won the game, taunt the player
if(boggle.getComputerScore() > boggle.getPlayerScore()){
cout << "Ha ha ha, I destroyed you. Better luck next time, puny human!" << endl;
}
}
示例14: presentUserWords
//prints out the users current words in a nice manner
void presentUserWords(Boggle& boggle) {
vector<string> temp;
temp=boggle.getUserWords();
cout<<"your words:"<<"("<<temp.size()<<"): {";
for (unsigned int i=0; i<temp.size(); i++) {
cout<<temp[i]<<" ";
if (i%4==3) {
cout<<endl;
}
}
cout<<"}"<<endl;
}
示例15: promptplayerInput
/**
* @brief promptplayerInput asks the player to type in a valid word
* @param boggle
*/
void promptplayerInput(Boggle& boggle){
Lexicon lex("EnglishWords.dat");
string tempWord;
cout << "It's your turn!" << endl;
printGrid(boggle);
printPlayerWords(boggle);
cout << "Your score: " << boggle.getPlayerScore() << endl;
cout << "Type a word (or press 1 to quit): ";
cin >> tempWord;
//makes the str uppercase
transform(tempWord.begin(), tempWord.end(),tempWord.begin(), ::toupper);
clearConsole();
while(tempWord != "1"){
printGrid(boggle);
if(!lex.contains(tempWord)){
cout << "Not a word in the dictionary" << endl;
}
else if (!(boggle.getPlayerWords().find(tempWord) != boggle.getPlayerWords().end())) {
cout << "Word already used" << endl;
}
else if ((tempWord.size() < 4)) {
cout << "Word is too small" << endl;
}
else if (!(boggle.findWordInGrid(tempWord))) {
cout << "That word can't be formed on this board." << endl;
}
else {
boggle.updateScore(tempWord);
boggle.insertplayerWord(tempWord);
}
printPlayerWords(boggle);
cout << endl;
cout << "Your score: " << boggle.getPlayerScore() << endl;
cout << "Type a word (or press 1 to quit): ";
cin >> tempWord;
clearConsole();
//makes the str uppercase
transform(tempWord.begin(), tempWord.end(),tempWord.begin(), ::toupper);
}
}