1. National University of Sciences and Technology (NUST)
School of Electrical Engineering and Computer Science
_____________________________________________________________________________________
CS250: Data Structures and Algorithms
Project Final Report
Evil Hangman
Class: BEE5 - B
Members:
HassanSaeed (5718)
Taimoor Tahir (4628)
Submitted to: Sir.Asad Waqar
2. National University of Sciences and Technology (NUST)
School of Electrical Engineering and Computer Science
_____________________________________________________________________________________
Evil Hangman
Abstract:
Evil Hangman is a game that cheats at the classic game Hangman. Normally, when writing a
computer to play Hangman, the computer picks a single word and accurately represents it as
the human player tries to guess all of the letters in the word. In Evil Hangman, the computer
instead maintains a list of every word in the English language, then continuously cuts down the
word list to try to dodge the player's guesses as much as possible.
Introduction:
The basic purpose of the program was to renew the conventional game of Hangman so that it
become almost impossible for the player to win. That game was played in a way that a word
was given to the player of specific length. Then the player guesses the word by hit and trial and
by his/her own knowledge. As the player guesses the word by guessing its alphabets he/she
wins. Now, the game has changed in such a way that the difficulty of the game is enhanced by
90%. In this game instead of a single word there is a whole list of possible words of the length
as per selected by the player. So, depending upon the guesses the program changes the word in
such a way that it became least probable for the player to win unless there is one and only one
word is possible in the list.
Now, it is not easy to synthesize a program like this because the words have to be checked
again and again. So, a really efficient program is not easy to write for this using simple arrays.
For this purpose in this program linked list is used with various helping functions. The details of
these functions and the working along with the way of programing is given under the heading
of implementation.
3. National University of Sciences and Technology (NUST)
School of Electrical Engineering and Computer Science
_____________________________________________________________________________________
Implementation:
This program is implemented in such a way that its efficiency would not be ignored. So. The
program is implemented using linked list and various different helping functions in its linked list
class.
Firstly the player chooses the difficulty level. This is done by inserting the length of the word
and the number of guesses he/she wants. Then the program checks whether any word of the
given word length is present in the program or not. If there is, then it continues or if not, then it
asks again.
After selecting the difficulty level the program inserts all the words of the length given by the
player into a linked list by reading from the dictionary. Now all the possible word of a specific
length are present in a linked list.
In the next step the player is then asked for the word he/she wants to insert to play the game.
As the user inserts the alphabet in the program a check (bool) function checks the list if that
specific alphabet is present in all the words or not. If that alphabet is not present in every word
of the list then it removes all the words in the list that include this alphabet. This is done with
help of search and remove (void) function, which checks for a specific letter in all the words
present in the list to remove the words from the list in case of presence of that letter entered
by the player. If the alphabet is present in every word of the list then it places the word on the
same position as it is placed in the first word of the list and remove all the other words from the
list where that alphabet is not present at the specific position as in the first alphabet of the list.
This done with the help of remove other (void) and insert (void) function. First function checks
all the words in the list letter by letter for the alphabet entered by the player and its position, if
that specific letter is present at the same position as in the first word then it is not removed
else the word is removed from the list. While the second function helps to place the letter in
the word at its specific position in a string to display the word on the screen.
Same procedure continues till the player ran out of guesses or succeed in guessing the word.
When only one word remains in the list the game executes same as the old conventional
Hangman game. If the player was unable to guess the word then a list of all the words together
with a loss message and amount of words possible is displayed on the screen. If the player
succeed to win then a congratulatory message appears at the screen. At the end the game asks
the player that if he/she want to play again or not.
This is the table of the functions used in the linked list class.
4. National University of Sciences and Technology (NUST)
School of Electrical Engineering and Computer Science
_____________________________________________________________________________________
Functions Name Purpose
void insert(string str) //For inserting a word into linked list
void remove(string str) //For removing a word from the linked list
void SearchAndRemove(char c) //For removing all the words from the
linked list having a specific alphabet
int length() //For measuring the number of words in the
linked list
void display() //For displaying all the words in the
linked list
bool check(char c) //For checking if a spcific alphabet is
present in all the words of the linked
list
void RemoveOther(char c) //For removing all the words which do not
have a specific letter at specific
positions
string place(char c) //For placing an alphabet at it's position
in the word
5. National University of Sciences and Technology (NUST)
School of Electrical Engineering and Computer Science
_____________________________________________________________________________________
Results:
Below are a fewsamplesof the workingof the program
Sample run: Result Lost
6. National University of Sciences and Technology (NUST)
School of Electrical Engineering and Computer Science
_____________________________________________________________________________________
Sample run: Result Win
7. National University of Sciences and Technology (NUST)
School of Electrical Engineering and Computer Science
_____________________________________________________________________________________
If a letter, already used, is entered again, an error is generated saying “You have already used
this word”. Although number of guesses remains the same.
Discussionand Conclusion:
Overall the game wasnot easyto program.There were a lotof problemsinitiallyandduringthe later
phasesof the program. Once,we understoodthe logicandmade a comprehensive flow chartof our
program inour mindsitbecame a biteasy.At laterstageswe have to come up withdifferentideasto
solve ourproblemsfordifferentstepsof our programwithdeepthinking.We applieddifferentlogicsto
performspecifictasksinthis waywe proceedtoour code by editing,changing andvarying.We alsotook
helpfromvariouswebsitesforsyntax issuesandvariousotherissuesespeciallyregardingstringsto
performdifferentfunctionsonwords,whichwere inthe formof strings.Atlastafterall the effortand
hard workwe succeededinmakingagreat program, whichwe enjoyedalot.