Addition 11/14 shown in blue
On 11/17 I changed the output to show total dictionary words as well as the number of words of the correct length. To reflect ongoing discussion on Piazza I also showed output for the 's' option to solve the board, and the 'r' option to reset the board, and included those in the steps of items to be done, giving them point values. These clarifications are shown in red.
Write a program in C / C++ to create a 4x4 Boggle board. To play a similar game online see wordtwist.org.
Running your program should look like the following:
Author: Dale Reed Program: #5, Boggle TA: Claude Shannon, Th 4-5 Nov 5, 2016 Welcome to the game of Boggle, where you play against the clock to see how many words you can find using adjacent letters on the board. Each letter can be used only once for a given word. When prompted to provide input you may also: Enter 'r' to reset the board to user-defined values. Enter 's' to solve the board and display all possible words. Enter 't' to toggle the timer on/off. Enter 'x' to exit the program. The dictionary total number of words is: 263533 Number of words of the right length is: 259709 60 seconds remaining a c r l n e a p p u i m s a a n Score: 0 1. Enter a word: plain Worth 4 points. Words so far are: plain 53 seconds remaining a c r l n e a p p u i m s a a n Score: 4 2. Enter a word: can Worth 1 points. Words so far are: can plain 49 seconds remaining a c r l n e a p p u i m s a a n Score: 5 3. Enter a word: map Worth 1 points. Words so far are: can map plain 39 seconds remaining a c r l n e a p p u i m s a a n Score: 6 4. Enter a word: can Sorry, that word was already previously found. Words so far are: can map plain 39 seconds remaining a c r l n e a p p u i m s a a n Score: 6 4. Enter a word: acrl was not found in the dictionary. 34 seconds remaining a c r l n e a p p u i m s a a n Score: 6 4. Enter a word: rail cannot be formed on this board. 30 seconds remaining a c r l n e a p p u i m s a a n Score: 6 4. Enter a word: r Enter 16 characters to be used to set the board: abcdefghijklmnop 30 seconds remaining a b c d e f g h i j k l m n o p Score: 6 4. Enter a word: s Enter min and max word lengths to display: 4 7 Words between 4 and 7 are: bein fink fino glop jink knop koji mink mino nief nife polk ponk knife plonk Exiting the program.
Words must be of length 3 or greater. Scoring is based on word length as follows:
Use the dictionary file included as an attachment at the bottom of this page. It has 263,533 words in it.
Use the following frequency counts for random character selection used in generating a board:
0.07680, // a 0.09485, // b 0.13527, // c 0.16824, // d 0.28129, // e 0.29299, // f 0.32033, // g 0.34499, // h 0.43625, // i 0.43783, // j 0.44627, // k 0.49865, // l 0.52743, // m 0.59567, // n 0.66222, // o 0.69246, // p 0.69246, // q 0.76380, // r 0.86042, // s 0.92666, // t 0.95963, // u 0.96892, // v 0.97616, // w 0.97892, // x 0.99510, // y 1.00000}; // z
I suggest you write the program one stage at a time as follows:
(0 points) Declare an array to represent the board and then display the board.
(0 points) Now successively generate a random number between 0..1. Loop through the alphabetic table of values shown above while your random number is greater than the current row value. Once the loop stops, the index corresponds to the letter you want.
(0 points) Read in the dictionary file into an array of the appropriate size. Note that you do not need to keep words of length <3 or words of length >16. Ensure everything is in lower case as you read it in. See this program for an example of reading words from a file into an array. Similarly see this program that reads words from a file into a really large array. You may want to dynamically allocate memory to store the words, as illustrated in this program.
(0 points) Retrieve the dictionary binary search function from a previous program.
(5 points) Allow playing the game, where all you do is the dictionary lookup for now, and don't validate that the word is on the board.
(3 points) When 'r' is entered it should reset the board. You don't have to reset anything else. This would only really make sense to do at the beginning, such as when we are testing your program.
(20 points) Now figure out how to check each word to make sure it is on the board. This is the most challenging part!
(5 points) Add error checking messages for when word is not in the dictionary, or when it is not found on the board.
(10 points) Add a boolean array to keep track of words found. Use this to display all the words found on each move, and to verify that a word cannot be guessed twice. Note that words found must be displayed in alphabetical order, shortest first. E.g. first display all words found of length 3 in alphabetical order, then display all words found of length 4 in alphabetical order, and so on.
(10 points) Display all the possible words when the user chooses 's'. Your program should prompt for the min and max lengths of the words to be displayed. Exit the program after displaying the words. You will need to choose an approach, which will likely be one of the following:
Starting with the characters on the board, generate strings of adjacent letters and see if they are valid dictionary words
Alternatively start with the words in the dictionary and see if they can be found on the board
(2 points) When 't' is entered it should toggle the timer. This doesn't reset the timer, but it simply stops checking it each move, so you can take as long as you would like. Once the timer is toggled back on, play resumes with whatever value the timer is at that point in time.