The License Plate Game (Assignment 2)
Overview
This is the first part in a multi-part programming assignment. The
overall purpose of this assignment is to give you experience applying
middleware patterns and frameworks by developing the license plate
game, which is an educational way to pass the time during long
car trips. This game works as follows:
- Players choose the current ``letter set,'' which is the
desired three letter string of letters from a license plate.
- Players then take turns suggesting words that contain the current
letter set in order in each word.
- Score 1 point for each correct word, lose 1 point for each
incorrect word, and score 0 points for each word that's already
been suggested.
- Continue until players can't think of any more words that contain
the letter set in order.
Program Description
The initial assignment involves writing a simple C++ program that
supports the following commands that help to automate the license
plate game:
- Initialize -- Allow players to designate a dictionary of
valid words. Feel free to use the dictionary available here.
- Configure -- Set the current letter set to the
desired three letter string of letters from a license plate and
also initializes the subset of words from the dictionary that
match the configured three letter string.
- Query -- Allow players to query whether a particular
word contains the current letter set in order in the word and
also exists in the dictionary. Queries should be case
insensitive, e.g., "vanderbilt" and "Vanderbilt" are the same word.
- List -- List all the words in the dictionary that match
the current letter set.
- Results -- Print the current results.
- Quit -- Stop playing the game and exit the program.
These commands can be invoked as follows:
- Initialize must be called before any other command is valid.
This command can be called at any time to reinitialize
the dictionary. If you don't have access to a dictionary on your
machine, there's one available online.
- Configure must be called before Query or
List. Configure can be called at any time to
reconfigure the letter set.
- Query always functions relative to whatever letter set
is currently configured.
- List always functions relative to whatever letter set and
dictionary are configured.
In the first part of the assignment, your license plate game program
will read commands from standard input and display the results on the
standard output. This first part is intended to be simple - it's
primary purpose is to get you started with C++, OO design, and regular
expressions. All of the software you write, however, will be reused
in subsequent parts of this assignment, so it's important to
understand them and get them right.
BTW, if you find it extremely hard to write this program, I recommend
you take my Software
Design course (CS 251) first since it focuses on the patterns and
tactics of effective OO/C++ design and programming.
Regular Expressions
An easy way to check whether a word matches the current letter set is
to use the POSIX regular expressions (regex) library. The function in
this library are defined below:
NAME
regcomp, regexec, regerror, regfree - regular expression matching
SYNOPSIS
#include <sys/types.h>
#include <regex.h>
// Compile the regular expression contained in the string pointed
// to by the pattern argument and place the results in the
// structure pointed to by preg.
int regcomp (regex_t *preg, // The compiled pattern
const char *pattern, // The regex pattern
int cflags); // Option flags (often 0)
// Compares the null-terminated string specified by string with
// the compiled regular expression. preg must be initialized by
// a previous call to regcomp().
int regexec (const regex_t *preg, // The compiled pattern
const char *string, // The subject string
size_t nmatch, // The number of the match (usually 0)
regmatch_t pmatch[], // Vector that holds the nmatch elements (usually 0)
int eflags); // Option flags (usually 0)
// Provides a mapping from error codes returned by regcomp() and
// regexec() to unspecified printable strings.
size_t regerror (int errcode,
const regex_t *preg,
char *errbuf,
size_t errbuf_size);
// Frees any memory allocated by regcomp() associated with preg.
void regfree (regex_t *preg);
The manual page and example usage for the POSIX regex functions are
available online. If
you need to download a copy of this library for non-Linux platforms
please see Perl-Compatible Regular Expression (PCRE) library, which is
available online.
Concluding Remarks
I strongly encourage you to use and develop reusable C++ components
based on the code you write. You will reuse these components
throughout the course. If you are a graduate student, please
implement this assignment using C++ Standard Template Library (STL)
algorithms and containers.
Please see the online help for information on
how to setup your development environment on Vanderbilt University's
EECS computing system.
Last modified 13:53:59 CDT 16 September 2007