Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

you will write a program in \"C+\" that will create the a set of 16 semi-random

ID: 665941 • Letter: Y

Question

you will write a program in "C+" that will create the a set of 16 semi-random letters in a 4-by-4 grid and have the user enter in as many words as possible that can be made from these letters in a 3 minute time frame.

This game has been marketed as Boggle. The wikipedia page for Boggle has a good discussion of the game as does the wikihow Boggle page. The official rules of Boggle can be found at the Hasbro Web Site:

http://www.hasbro.com/common/instruct/boggle.pdf

The letters used come from 16 6-sided cubes (or dice) with one letter per side. Each of the 16 locations in the 4-by-4 grid will use one letter from one of the dice. Since the letters on each of the dice are pre-determined, we can call this a "semi-random" distribution. We will use the following dice combinations:

AAEEGN

ABBJOO

ACHOPS

AFFKPS

AOOTTW

CIMOTU

DEILRX

DELRVY

DISTTY

EEGHNW

EEINSU

EHRTVW

EIOSST

ELRTTY

HIMNUQu

HLNNRZ

Storing the above information as an array of 16 strings may be a good way to keep track of the information.

Note that the 15th dice has a final letter as the combination Qu. Since the letter Q is almost always followed by the letter U in most English words, the game automatically allows this combination. Note, you may want to just use the letter Q

Your program is to display the Boggle grid of 4-by-4 letter based on randomly placing the 16 dice into the 16 grid positions and randomly selecting one of the 6 letters from each dice.

The scoring for each word is determined by its length (the number of characters in the word). The point values are shown in the following table.

The Letter Q has its own special rules. In the English language, the letter Q is almost always followed by the letter U. Consequently in the official Boggle Game, the side of one die is printed with the two-letter sequence Qu instead of Q (and this two-letter sequence must be used together when forming words). When scoring, Qu counts as two letters; for example, the word QuEUE scores as a 5-letter word even though it is formed by following a sequence of 4 dice. We will be following this rule for own game, but it is let to you as how to display the letter Q in the 4-by-4 grid as Q or as Qu.

The Word Dictionary

Each word entered by the user needs to be verified as an actual word. The program is to prompt the user for the name of a dictionary file and the game will use the words listed in that text file as the official dictionary. Below are three such files:

dictionary-algs4.txt

5desk.txt

dictionary-yawl.txt

The words in the dictionary are given in both upper and lower case. In Boggle, case does not matter. So you should covert all letters to either upper or lower case (it really doesn't matter which one you choose). When comparing the words entered by the user, again case does not matter. So those words should also be coverted to the same case as the words in the dictionary.

When storing the words in an array, we want to use a dynamic array of strings. A dynamic array will increase in size when the array fills up. You are NOT allowed to use the C++ Vector to implement this. Implementation of this will be covered in lecture.

When searching for the users word in the dynamic array, you are to use the binary search algorithm. Implementation of this will be covered in lecture.

Searching the Boggle Grid for a Word

The players compete to accumulate points by building valid words out of the dice according to the following rules:

A valid word must be composed by following a sequence of adjacent dice—two dice are adjacent if they are horizontal, vertical, or diagonal neighbors.

A valid word can use each die at most once.

A valid word must contain at least 3 letters.

A valid word must be in the dictionary (which typically does not contain proper nouns).

Here are some examples of valid and invalid words:

To determine if a word exists in the boggle grid, the following recursive algorithm is given to you. Note this is given in psuedo-code, so you will need to translate it to match how you have implemented the rest of your program. It uses two functions and only one is recursive. The first function looks for the first letter in the given word, then calls the second function to determine if the remaining letters actually exist in the boggle grid. Note: this does not solve for the Q/Qu case. A modification is needed that will be discussed during lecture. Also note: the algorithm is being given as an attachment as this wiki tends to remove indentation.

boggleFindAlg.txt

After the 3 minutes of time is finished, you should display a message showing the number of correct words found and the total points earned.

Word Length Points 0 - 2 0 3 - 4 1 5 2 6 3 7 5 8+ 11

Explanation / Answer

here is the c++ code for the boggle game :



#include <cctype>
#include <iostream>
using namespace std;

#include "simpio.h"
#include "gwindow.h"
#include "gboggle.h"
#include "random.h"
#include "vector.h"
#include "lexicon.h"
#include "grid.h"

static const string kEnglishLanguageDatafile = "EnglishWords.dat";
const int kBoggleWindowWidth = 650;
const int kBoggleWindowHeight = 350;

const string kStandardCubes[16] = {
   "AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS",
   "AOOTTW", "CIMOTU", "DEILRX", "DELRVY",
   "DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
   "EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"
};

const string kBigBoggleCubes[25] = {
   "AAAFRS", "AAEEEE", "AAFIRS", "ADENNN", "AEEEEM",
   "AEEGMU", "AEGMNN", "AFIRSY", "BJKQXZ", "CCNSTW",
   "CEIILT", "CEILPT", "CEIPST", "DDLNOR", "DDHNOT",
   "DHHLOR", "DHLNOR", "EIIITT", "EMOTTT", "ENSSSU",
   "FIPRSY", "GORRVW", "HIPRRY", "NOOTUW", "OOOTTU"
};

static void welcome() {
    cout << "Welcome! You're about to play an intense game ";
    cout << "of mind-numbing Boggle. The good news is that ";
    cout << "you might improve your vocabulary a bit. The ";
    cout << "bad news is that you're probably going to lose ";
    cout << "miserably to this little dictionary-toting hunk ";
    cout << "of silicon. If only YOU had a gig of RAM..." << endl << endl;
}

static void giveInstructions() {
    cout << endl;
    cout << "The boggle board is a grid onto which I ";
    cout << "I will randomly distribute cubes. These ";
    cout << "6-sided cubes have letters rather than ";
    cout << "numbers on the faces, creating a grid of ";
    cout << "letters on which you try to form words. ";
    cout << "You go first, entering all the words you can ";
    cout << "find that are formed by tracing adjoining ";
    cout << "letters. Two letters adjoin if they are next ";
    cout << "to each other horizontally, vertically, or ";
    cout << "diagonally. A letter can only be used once ";
    cout << "in each word. Words must be at least four ";
    cout << "letters long and can be counted only once. ";
    cout << "You score points based on word length: a ";
    cout << "4-letter word is worth 1 point, 5-letters ";
    cout << "earn 2 points, and so on. After your puny ";
    cout << "brain is exhausted, I, the supercomputer, ";
    cout << "will find all the remaining words and double ";
    cout << "or triple your paltry score." << endl << endl;
    cout << "Hit return when you're ready...";
    getLine();
}

static bool responseIsAffirmative(const string& prompt) {
    while (true) {
        string answer = getLine(prompt);
        if (!answer.empty()) {
            switch (toupper(answer[0])) {
                case 'Y': return true;
                case 'N': return false;
            }
        }
        cout << "Please answer yes or no(Y/N)." << endl;
    }
}

void swap(Vector<string>& cubes, int a, int b){
string temp = cubes.get(a);
cubes.set(a,cubes.get(b));
cubes.set(b,temp);
}
static Grid<char> randomShuffleCubes(const string c[]){
Vector<string> cubes;
for(int i =0; i<16; i++) //copies string from string array to a vector
  cubes.add(c[i]);
for(int j =0; j<16; j++){   
  int rand = randomInteger(j,15);  // Shuffles around dice
  swap(cubes,rand,j);
}
Grid<char> board(4,4);
for(int a = 0; a<4; a++)
  for(int b = 0; b<4; b++){
   int rand = randomInteger(0,5);
   board.set(a, b, c[a*4+b]);  // puts dice letters on Boggle board
   labelCube(a, b, cubes.get(4*a+b).at(rand));
  }
}

static Grid<char> readDatatoBoard(){ // puts dice letters on Boggle board from user
while(true){             // input string data
  string userLetters = getLine("Please enter at least 16 letters to be used in this game");
  Grid<char> board(4,4);
  if(userLetters.size()>=16){
   for(int a = 0; a<4; a++)    
    for(int b = 0; b<4; b++){
     board.set(a, b, userLetters[a*4+b]);
     labelCube(a, b, userLetters[a*4+b]);
    }
   return board;
  }
  cout << "Please enter a larger data set..." << endl;
}
}

static Grid<char> fillInBoard(const string& prompt) { // Gives user option to input data or use
    while (true) {        // randomly selected data and populates
        string answer = getLine(prompt);  // the board with appropriate letters
  bool input;
        if (!answer.empty()) {
            switch (toupper(answer[0])) {
                case 'I': input=true;
                case 'R': input=false;
            }
        }
  if(!input){
   
   return randomShuffleCubes(kStandardCubes);
  }
  else{

   return readDatatoBoard();
  }
        cout << "Please enter a vaild response..." << endl;
    }
}
bool contains(Vector<string> v, string s){
for(int i = 0; i<v.size(); i++)   
  if(v.get(i)==s)
   return true;
return false;
}
bool canBeFormed(){ //////////////Needs to be finished/////////////////////
}
bool isValidWord(Lexicon& english, Vector<string> wordList, Grid<char> board, string word){
if(word.size()<4)             
  return false;      
if(!english.contains(word))    
  return false;     
if(contains(wordList, word))
  return false;
if(!canBeFormed())//////////////argument needs to be finished/////////////////////
  return false;

return true;
}
static void playBoggle(string player){  // Starts the game of Boggle between the human
if(s=="Human"){       // and the computer
  cout << "Enter as many lines you can, puny-brained human." << endl;
  while(true){
   string word = getLine();
   if(isValidWord(word))
    

  }
}
}
/////////////////////////////////////////////////////////
int main() {
GWindow gw(kBoggleWindowWidth, kBoggleWindowHeight);
initGBoggle(gw);
welcome();
if (responseIsAffirmative("Do you need instructions? ")) {
  giveInstructions();
}
Lexicon english(kEnglishLanguageDatafile);
Grid<char> board(4,4) = fillInBoard("User input or random data for board?(I/R) ");
playBoggle("Human",gw,board,english);

// playBoggle("Computer);
return 0;
}

Hope it helps