This assignment tests your understanding of and ability to apply the programming concepts we have covered in the unit so far, including the usage of variables, input/output, data types, selection, iteration, functions and data structures. Above all else, it tests your ability to design and then implement a solution to a problem using these concepts.
You are required to design and implement a Word Game program in which the user must identify a randomly selected password from a list of 8 words. The 8 words are selected at random from the list of 100 words in the starter file (word_game.py) provided to you with this assignment brief. Please use the starter file as the basis of your assignment code.
The user has 4 attempts in which to guess the password. Whenever they guess incorrectly, they are told how many of the letters are the same between the word they guessed and the password. For example, if the password is COMEDY and they guessed MOULDY, they would be told that 3/6 letters were correct due to the O, D and Y being the same. Note that a letter must be in the correct position to be correct. e.g. in the example above, both words contain the letter M but it is in a different position in the word so it is not counted as a correct letter.
Using this information, the user can make increasingly knowledgeable guesses and win the game by selecting the password within four guesses. If the user fails to select the correct word within 4 guesses, they lose the game.
This game is similar in some ways to the game of mastermind, and is based upon the terminal hacking minigame from the Fallout video game franchise. You do not need to be familiar with either of these games in order to complete this assignment contact your tutor if you do not understand the game.
To help illustrate the program, here is an annotated screenshot of the game being played: See image.
As emphasised by the case study of Module 5, it is important to take the time to properly design a solution before starting to write code. Hence, this assignment requires you to write and submit pseudocode of your program design as well as the code for the program. Furthermore, while your tutors are happy to provide help and feedback on your assignment work throughout the semester, they will expect you to be able to show your pseudocode and explain the design of your code.
You will gain a lot more benefit from pseudocode if you actually attempt it before trying to code your program even if you just start with a rough draft to establish the overall program structure, and then revise and refine it as you work on the code. This back and forth cycle of designing and coding is completely normal and expected, particularly when you are new to programming. The requirements detailed on the following pages should give you a good idea of the structure of the program, allowing you to make a start on designing your solution in pseudocode.
See Reading 3.3 for further information and tips regarding writing good pseudocode.
Write a separate section of pseudocode for each function you define in your program so that the pseudocode for the main part of your program is not cluttered with function definitions. Ensure that the pseudocode for each of your functions clearly describes the parameters that the function receives and what the function returns back to the program.
It may help to think of the pseudocode of your program as the content of a book, and the pseudocode of functions as its appendices: It should be possible to read and understand a book without necessarily reading the appendices, however they are there for further reference if needed.
Only one function is required in this assignment (detailed later in the assignment brief).
The requirements begin where the starter file ends after defining the candidateWords list. In the following information, numbered points describe a requirement of the program, and bullet points (in italics) are additional details, notes and hints regarding the requirement. Ask your tutor if you do not understand the requirements or would like further information.
1. Set up the game by creating a list of 8 randomly selected words from candidateWords and then randomly select one of those words to be the password. Also create a boolean variable to keep track of whether or not the game has been won (set it to False) and an integer variable to keep track of the number of guesses remaining (set it to 4).
2. Print a message to welcome the user, and then enter a loop that will repeat while guessesRemaining is greater than 0 and won is False. The body of this loop must
2.1. Print all of the words in wordList along with their corresponding index number, and then print the number of guesses remaining.
2.2. Prompt the user to choose one of the words by entering its index number (0-7), and reduce guessesRemaining by 1.
2.3. Print the selected word, and then check if it is the same as password. If the words are the same, the user has guessed correctly: The program should print a password correct message and set the won variable to True.
If the words are not the same, the user has guessed incorrectly: Print a password incorrect message, then call the compareWords function to determine the number of matching letters before printing a message to tell the user how many letters are correct.
3. The last thing the program should do (after the body of the loop described in Requirement 2) is print a you win message if the won variable is True, or a you lose message if it is False.
When the user selects a word that is not the password, the program needs to determine how many matching letters there are between the password and the selected word (see Requirement 2.3).
Your program must define a function named compareWords that receives two words (the password and the selected word) as parameters. It must determine the number of matching letters between the words, and return this number back to the program as an integer. To do this, set a counter variable to 0 and then then loop through each letter of the words, adding one to the counter if they match.
The definition of the function should be at the start of the program (as it is in the starter file provided), and it should be called where needed in the program. Revise Module 4 if you are uncertain about defining and using functions.
If you are in CSP5110, the following additional requirements apply. If you are in CSP1150, you do not need to do implement these requirements (but you are encouraged to do so if you want). Ask your tutor if you do not understand any of the requirements or would like further information.
1. Add 1 to the index number of words whenever you show the list of words (Requirement 2.1), so that the games are numbered from 1-8 instead of 0-7. Remember to subtract 1 from the users input when they guess a word, so that you reference the appropriate index in the wordList.
2. To make it easier for the user to keep track of previous guesses, show the number of matching letters next to the words that have been guessed whenever you show the list of words.
Below are some suggestions for minor additions and enhancements that you can make to the program to further test and demonstrate your programming ability. They are not required and you can earn full marks in the assignment without implementing them.