This section describes in detail all functional requirements of assignment #2. A rough indication of the number of marks for each requirement is provided. You should make a conscientious effort to write your program in a way that is capable of replicating the examples given in these requirements.
Word Link is a game where two players alternate entering words with the requirement that the first letter of a word must match the last letter of the previous word thus making a word chain such as the one below:
apple elephant taxi igloo oxygen ......
The game is over when one player cannot give another word or an incorrect word is given. The same word cannot be used twice. Your implementation will use a dictionary file to determine which words are considered valid/invalid. The game can be played between two human alternating players, or a human player playing against a computer selecting words automatically.
The user of your program must be able to execute it by passing in the names of one data file that the system is to use. You need to check that exactly 2 command-line arguments are entered and that the specified file is valid (that is, it exists). You need to abort the program and provide a suitable error message if this is not the case.
Your program will be run using these command line arguments:
%./wordlink < dictionary-file >
For this requirement you will be extracting all of the words from the dictionary file to be loaded into the linked-list data structure provided with the start up code. The dictionary file is any plain text file containing any number of words with one word per line.
Your data structure stores your words in 26 linked-lists with each linked list representing words beginning with one letter of the alphabet. The linked lists will remain unsorted by way of simply inserting each new word in a random position of the correct linked list. Duplicate words are not allowed. It is critical for your program to be able to load the smallest supplied data files as a minimum.
The data files were obtain from http://wordlist.aspell.net/scowl-readme/
Your program must display an interactive menu displaying seven options like the one below:
(1) 1 Player Game
(2) 2 Player Game
(3) Dictionary Summary
(4) Search Dictionary
(5) Add Dictionary Word
(6) Save Dictionary
Select your option (1-7):
Your program must allow the user to select these options by typing the number and hitting enter. Upon completion of all options except Exit, the user is returned to the main menu. The behavior of these options is described in requirements #4 #10.
This option runs the game between the user and a computer controlled opponent. Each word that is used is marked in the dictionary so that it cannot be used again in the current game. Hence you should not forget to reset the dictionary at the start of each game.
The player will lose if an incorrect word is entered or he/she chooses to give up by entering an empty line. The computer opponent will lose when it is exhausted of guesses. Example:
1 Player Game
Player: Enter a word (1-20 char, blank line to quit): apple
Computer selects word “elephant”.
Player: Enter a word (1-20 char, blank line to quit):
taxi Computer selects word “igloo”.
Player: Enter a word (1-20 char, blank line to quit): zzzzz
“zzzzz” is not in the dictionary.
Other terminating messages:
Computer could not make a guess.
You win! You entered a blank line to give up.
Better luck next time.
Note: In requirement 2, it was mentioned that the linked list is ordered randomly. This is to make sure that the 1 player game is always different when the computer player makes guesses by selecting words from the start of the relevant linked list.
This option runs the game between two alternating human controlled players. Other rules as per the one player game apply. Example:
2 Player Game -------------
Player 1: Enter a word (1-20 char, blank line to quit): apple
Player 2: Enter a word (1-20 char, blank line to quit): elephant
Player 1: Enter a word (1-20 char, blank line to quit): taxi
Player 2: Enter a word (1-20 char, blank line to quit): igloo
Player 1: Enter a word (1-20 char, blank line to quit): zzzzz
“zzzzz” is not in the dictionary.
Player 2 wins!
This option reports some statistics concerning the contents of the dictionary. This option reports the number of words beginning with each letter and the total number of words:
| a: 109 | n: 25 |
| b: 23 | o: 4 |
| c: 9 | p: 127 |
................... <- (Add other rows here)
| m: 10 | z: 1 |
Total Words: 567
This option prompts the user to enter a word and the program reports on whether or not the word is in the dictionary. Example:
Enter a word (1-20 char): abcde
“abcde” is NOT in the dictionary.
This option prompts the user to enter a new dictionary word to be stored in the dictionary data structure. The new word is added to the end of the relevant linked list. You must make sure that duplicate words are not inserted into the data structure.
Add Dictionary Word
Enter a word (1-20 char): hello
“hello” has been added to the dictionary.
This option writes all words in your dictionary back to the original data file. This file is overwritten. Each word is output on a separate line.
This option terminates your program. Memory deallocation is performed before the program terminates.
This option should terminate your program. All program data will be lost. You should be freeing memory at this point as well.
Your program should allow the user to return to the main menu at any point during data input from the user. The user can do this by simply hitting enter. i.e. an empty line was entered or pressing ctrl-d on an empty line.
We encourage the use of functional abstraction throughout your code. It is considered to be a good practice when developing software with many benefits. Abstracting code into separate functions reduces the possibility of bugs in your project, simplifies programming logic and eases the need for debugging. We are looking for some evidence of functional abstraction throughout your code. As a rule, if you notice that you have the same or similar block of code in two different locations of your source, you can abstract this into a separate function.
In this assignment, you are implementing an Abstract data type . For this requirement you will need to propose a list of interface functions for a list and implement these. All reference to these types should be via these interface functions.
Your project must be compiled using a Linux makefile. All compiler commands must include the -ansi -Wall -pedantic compile options and compile cleanly with these options.
Your makefile needs to compile your program incrementally. i.e.: use object files as an intermediate form of compilation.
Also include a directive called clean that deletes unnecessary files from your working directory such as object files, executable files, core dump files, etc. This directive should only be executed when the user types make clean at the command prompt.
Have a look at the courseware, Week 7 Laboratory for examples of makefiles.
The start up code requires the use of dynamic memory allocation. Therefore, you will need to check that your program does not contain memory leaks. Therefore, you will need to check that your program does not contain memory leaks. Use the:
valgrind --leak-check=full --show-reachable=yes < command> < arguments>
to check for memory leaks.
Marks will only be awarded for this requirement if the feedback valgrind provides reports zero memory leaks and no other memory related problems. Another common problem in is memory abuses. These are inappropriate accesses such as reading from uninitialized memory, writing to memory addresses you should not have access to and conditional statements that depend on uninitialized values. You can test for these again by using valgrind:
valgrind --track-origins=yes < command>< arguments>
You must implement Buffer Handling, Input Validation, and Coding Conventions as per the requirements listed on the Assignment General Information sheet (available on Blackboard. These requirements are going to be weighted as: