CS 107 - Summer 2015

Programming Project 3 - Boggle - Phase 1

Due: Tuesday, July 21, 2015 at 11:59pm

For this project, 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:

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:
  1. AAEEGN
  2. ABBJOO
  3. ACHOPS
  4. AFFKPS
  5. AOOTTW
  6. CIMOTU
  7. DEILRX
  8. DELRVY
  9. DISTTY
  10. EEGHNW
  11. EEINSU
  12. EHRTVW
  13. EIOSST
  14. ELRTTY
  15. HIMNUQu
  16. 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.

After the grid has been displayed your program is to allow the user to enter in as many words as possible until 3 minutes has elapsed. Since we are not making a truly interactive User Interface, we will only check for the time after the user enters in a work. When a user enters a word, check to see how long it have been since the letter grid was displayed. If it have been less than 3 minutes (or 180 seconds), loop and allow the user to enter another word. If it has been more than 3 minutes, display the number of words entered by the user and the end the program. This manner will allow the user to enter in one word after the 3 minutes has expired, but that will be OK for this program.

Note: This program is not validating the words entered by the user nor keeping track of the points scored. That will be done in Phase 2 (Project 4).

Your program must determine and store the letters in the grid first. Then it can display the grid after all 16 locations have been determined. The 4-by-4 grid of letters may best be stored in a 2 dimensional array. This is not a requirement for Phase 1, but will be a requirement for Phase 2.

You should use functions as much as possible when writing this program. You are REQUIRED to have

  • a function to determine and store the letters in the grid
  • a function to print out the letters to user
  • a function to monitor the users input of words and keep track of the 3 minutes of time
The array used to store the letters in the grid will be passed out of the first function and into the second function. For Phase 2, this array will also need to be passed into the third function.

User Input

At the start of your program, you should give the user some instructions on how the play the game. The exact verbiage is left up to you, but some points will be given for the appropriateness of this message.

After the grid has been displayed, allow the user to enter in input. Reading this information as string is probably the easiest. We are not doing anything with this data except counting the number of words entered by the user and checking how long it has been since the grid was displayed.

At the end of the program, you should thank the user for playing and give some information on the "development team" (i.e. your name, that this program was developed for CS 107, etc).

Random Numbers and More on Time

While there really is no such thing as a real random number, the sequences of numbers generated are complicated enough that to just about everyone, they seem random. A nice discussion of random numbers is given on the cplusplus.com web page.

The primary library function for random numbers in C/C++ is rand() in the C library stdlib.h or in the C++ library cstdlib.

The rand() library function returns an integer value from 0 to the largest integer usable on the machine. To get this value into a desired range the modulus operator % is normally used. The modulus operator will get the random value to be in the range from 0 to some number. Since we want to have our random number to be in the range from 1 to 6, we will want to add 1 to the random number after the modulus operation is performed.

Note that rand() when used by itself will generate the same random numbers everytime a program runs. While this is useful for testing, if makes playing a game like codebreaker a bit boring. Thus we will also want to use the library function of srand() to make things become truly random. The most common way to use srand() is to use the library function of time(). All of the cplusplus.com web pages that discuss rand() show how to use srand() and time() to create truly random numbers.

The time library also has a function called difftime(). This function will take two instances of the type time_t and return the number of seconds between the two times. Consider the following example.

// Example program
#include <iostream>
#include <string>
#include <ctime>

using namespace std;

int main()
{
time_t now, then;
double seconds;
// get the starting time
time(&now);

std::string name;
std::cout << "What is your name? ";
getline (std::cin, name);
std::cout << "Hello, " << name << "!\n";

// get the ending time
time(&then);

seconds = difftime(then, now);

cout << "You took " << seconds << " seconds to type in your name." << endl;
}

Submittal of your Program

Use the submission link in Blackboard to electronically submit your .cpp file for grading.

Please name your program file using both your NET-ID and the Project Number. Thus for Project 3, if you NET-ID was ptroy4, your program should be named: ptroy4Proj3.cpp

-- Main.troy - 2015-07-15

Topic revision: r1 - 2015-07-15 - 16:43:27 - Main.troy
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF