Exemple #1
0
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;
}
Exemple #2
0
/*
 * 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;
    }
}
/**
 * @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);
        }
    }
Exemple #4
0
//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;
    }
}
int main()
{
	Boggle game; 
	game.printBoard(); 
	cout << "" << endl; 
	game.getUserInput(); 
	cout << "" << endl;
	game.printResults(); 
	system("pause"); 
	return 0;
}
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;
}
Exemple #7
0
//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;
}
Exemple #8
0
/*
 * 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);
}
/**
 * @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;
    }
}
Exemple #10
0
/**
 * @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;
}
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.";
            }

        }
    }
}
Exemple #12
0
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();
}
Exemple #13
0
/**
 * @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;
    }
}
Exemple #14
0
//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;
}
Exemple #15
0
/**
 * @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);
    }
}
Exemple #16
0
void getUserBoard(Boggle& boggle){
    string dummy;
    for (int i = 0; i < 4; ++i) {
        while(true) {
            getline(cin,dummy);
            std::transform(dummy.begin(), dummy.end(), dummy.begin(), ::toupper);
            if(dummy.size() != 4) {
                cout << "You didn't enter a valid string, please try to enter a correct row again." << endl;
            } else {

                boggle.setBoard(i, dummy);
                break;

            }
        }
    }
}
Exemple #17
0
/*
 * Function: userTurn
 * --------------------
 * This is the user's turn. Prompt them for random/set board, get their word selections
 * use the boggles obj to check words
 *
 * Preconditions:
 *
 *  @param: word: the word to check
 *  @return: boolean true if valid word
 */
void userTurn(Boggle& boggles) {
    Set<string> humanWords;
    string userInputW;
    //int humanScore = 0;

    while(true) {
        clearConsole();
        // First time through this is skipped, goes to else
        if(userInputW!=""){
            if(boggles.checkWord(userInputW)){
                if(boggles.humanWordSearch(toLowerCase(userInputW))){
                    string statusMessage = "You found a new word! \""+toUpperCase(userInputW)+"\"";
                    BoggleGUI::setStatusMessage(statusMessage);
                    cout << statusMessage<<endl;
                    BoggleGUI::recordWord(userInputW,BoggleGUI::HUMAN);
                } else{
                    string statusMessage = "That word cant be formed on this board!";
                    BoggleGUI::setStatusMessage(statusMessage);
                    cout << statusMessage<<endl;
                }
            } else {
                cout << "You must enter an unfound 4+ letter word from the dictionary." << endl;
            }
        }else {
            string sM =  "It's your turn!";
            BoggleGUI::setStatusMessage(sM);
            cout << sM << endl;
        }
        cout << boggles;

        cout << "Your words (" << boggles.getUserValidStrings().size() << "): " << boggles.getUserValidStrings().toString() << endl;
        cout << "Your score: " << boggles.getScoreHuman() << endl;
        BoggleGUI::setScore(boggles.getScoreHuman(),BoggleGUI::HUMAN);

        userInputW = getLine("Type a word (or enter to stop): ");

        // Enter to stop
        if(userInputW==""){
            break;
        }
    }
}
Exemple #18
0
//prints out the users current score
void presentUserScore(Boggle& boggle) {
    cout<<"Your score:"<<boggle.getUserScore()<<endl;

}
Exemple #19
0
void playOneGame(Boggle& boggle) {
    while(true){
        if(yesOrNo("Manually enter a board configuration? (Y/N) ")){
            getUserBoard(boggle);
            break;
        }else{
            boggle.makeBoard();
            break;
        }
    }
    boggle.clearUsedWords();
    Lexicon dic;
    dic.addWordsFromFile("EnglishWords.dat");
    vector<string> foundWords;
    string input;
    while(true){

        clearConsole();
        boggle.printUserWords(cout);
        cout << "Your score: " << boggle.userScore() << endl;
        boggle.clearAllVisited();
        boggle.printBoard(cout);
        cout << "Type a word (or press Enter to end your turn): " << endl;
        getline(cin, input);
        std::transform(input.begin(), input.end(), input.begin(), ::toupper);
        if (input.size() <= 16 && input.size() > 3 && dic.contains(input)){
            if(boggle.possibleWord(input, dic)){
                cout << "You found a new word! " << input << endl;
                foundWords.push_back(input);
            }
        }
        if(input.empty()){
            break;
        }
    }
    cout << "It's my turn!" << endl;
    boggle.computerPlayer(dic);
    boggle.printComputerWords(cout);
    cout << "My score: " << boggle.computerScore() << endl;
    if(boggle.computerScore() > boggle.userScore()){
        cout << "Ha ha ha, I destroyed you. Better luck next time, puny human!" << endl;
    }
}
/*
 * Plays one game of Boggle using the given boggle game state object.
 */
void playOneGame(Boggle& boggle) {
    boggle.resetBoard();
    cout << "Would you like to randomize the board? (y/n)" << endl;
    string userChoice;
    getline(cin,userChoice);

    if(toLowerCase(trim(userChoice)) == "y"){
        boggle.randomizeBoard();
    }else{

        string boardSeq;
        do {
            cout << "Please enter a valid sequence of letters to fill the board with" << endl;
            getline(cin,boardSeq);
        } while (!boggle.checkValidBoardSeq(boardSeq));
        boggle.setBoard(boardSeq);

    }
    string guessedWord;
    do {
        clearConsole();
        cout << "It's your turn!" << endl;
        boggle.printBoard();
        boggle.printGuessedWords();
        cout << "Your score: " + to_string(boggle.getPlayerScore()) << endl;
        cout << "Type a word (or press Enter to end your turn): ";

        getline(cin,guessedWord);
        if (boggle.checkGuessedWord(guessedWord)) {
            cout << "You found a new word! \"" + toUpperCase(guessedWord) + "\"" << endl;
        }
    } while (!guessedWord.empty());

    cout << "It's my turn!" << endl;
    boggle.printComputerWords();
    cout << "My score: " + to_string(boggle.getComputerScore()) << endl;
    if (boggle.getComputerScore() > boggle.getPlayerScore()) {
        cout << "Ha ha ha, I destroyed you. Better luck next time, puny human!" << endl;
    } else {
        cout << "Screw you... Puny human!" << endl;
    }

}
Exemple #21
0
/**
 * @brief clearWordsScore calls boggle.resetScore() to reset the score
 */
void clearWordsScore(Boggle& boggle){
    boggle.resetWordsScore();
}
Exemple #22
0
//mainfunctions of the game
void playOneGame(Boggle& boggle) {
    string input="";
    //runs until a board is generated
    while (1) {
        cout<<endl;
        cout<<"Do you want to generate a random board?: ";
        cin>>input;
        //the user wants to enter an own board
        if (input=="n") {
            //runs until the user has entered a correct board,
            while(1) {
                cout<<"Type the 16 letters to appear on the board:";
                cin>>input;
                vector<string> temp;
                temp=checkInput(input);
                if (temp.size()==16) {
                    for (int i=0; i<16; i++) {
                        boggle.addLetter(temp[i]);
                    }
                    break;
                }
                else {
                    cout<<"That is not a valid 16-letter board String. Try again."<<endl;
                }

            }
            boggle.calculateWords();
            break;
        }
        //if the user wants to autogenerate a board this i used
        if(input=="y") {
            boggle.setupBoardAuto();
            break;
        }
    }
    bool usersTurn=true;
    clearConsole();
    //runs until the user enters "n"
    while (usersTurn) {
        cout<<"it's your turn!"<<endl;
        printBoard(boggle);
        presentUserWords(boggle);
        presentUserScore(boggle);
        input="";
        cout<<"enter a word or  enter n to end your turn:";
        cin>>input;
        //end while loop
        if (input=="n") {
            usersTurn=false;
        }
        else {
            //checks if the word is correct
            if (boggle.addUserWord(input)) {
                //if it is then the score is added to the userscore
                boggle.addUserScore(input.size()-3);
                //says that you have found a new word
                presentNewWord(input);
            }
            else {
                //if it not a correct word then the error is printed out for the user
                cout<<boggle.getUserError()<<endl;
            }
        }
    }
    //prints out with how much the computer has won
    cout<<"It is my turn! now you are going down"<<endl;
    presentComputersWords(boggle);
    boggle.resetBoard();

}