need help with this project
Introduction Word Game: This game is a lot like Scrabble or Words With Friends. Letters are dealt to players, who then construct one or more words using their letters. Each valid word earns the user points, based on the length of the word and the letters in that word. The rules of the game are as follows. Dealing • A player is dealt a hand of HAND_SIZE letters of the alphabet, chosen at random. This may include multiple instances of a particular letter. • The player arranges the hand into as many words as they want out of the letters, but using each letter at most once. • Some letters may remain unused, though the size of the hand when a word is played does affect its score. Scoring • The score for the hand is the sum of the score for each word formed. • The score for a word is the product of two components: o First component: the sum of the points for letters in the word. o Second component: either [7 * word_leng th - 3 * (n - word_length)] or 1, whichever value is greater, where: • word_length is the number of letters used in the word • n is the number of letters available in the current hand • Letters are scored as in Scrabble; A is worth 1, B is worth 3, C is worth 3, D is worth 2, E is worth 1, and so on. We have defined the dictionary SCRABBLE_LETTER_VALUES that maps each lowercase letter to its Scrabble letter value. • Examples: o For example, if n=6 and the hand includes 1 'w', 2 'e's, and 1 'd' (as well as two other letters), playing the word 'weed' would be worth 176 points:(4+1+1+2) * (7*4 - 3*(6-4)) = 176. The first term is the sum of the values of each letter used; the second term is the special computation that rewards a player for playing a longer word, and penalizes them for any left over letters. o As another example, if n=7, playing the word 'it' would be worth 2 points:(1+1) * (1) = 2. The second component is 1 because 7*2 - 3*(7 - 2) = -1, which is less than 1. Getting Started 1. Download and save ps3.zip . This includes the python file ps3.py, which should contain all of your code, as it provides a set of initial procedures and templates for new procedures. ps3.zip also includes a file for testing your code test_ps3.py , and a file of legitimate words words.txt . Do not change or delete anything in the file unless specified. 2. Run ps3.py , without making any modifications to it, in order to ensure that everything is set up correctly. The code we have given you loads a list of valid words from a file and then calls the play_game function. You will implement the functions it needs in order to work. If everything is okay, after a small delay, you should see the following printed out: Loading word list from file... 83667 words loaded. play_game not yet implemented. If you see an IOError instead (e.g., No such file or directory), make sure you have saved words.txt in the same directory as ps3.py ! 3. The file ps3.py has a number of already-implemented functions you can use while writing up your solution. You can ignore the code between the following comments, though you should read and understand everything else. # ----------------------------------- # Helper code# (you don’t need to understand this helper code) . . . # (end of helper code) # ----------------------------------- 4. This problem set is structured so that you will write a number of modular functions and then glue them together to form the complete game. Instead of waiting until the entire game is ready, you should test each function you write, individually, before moving on. This approach is known as unit testing, and it will help you debug your code. 5. We have included some hints about how you might want to implement some of there quired functions in the included files. You don't need to remove them in your final submission. We have provided several test functions to get you started. As you make progress on the problem set, run test_ps3.py to check your work so far. If your code passes the unit tests you will see a SUCCESS message; otherwise you will see a FAILURE message. These tests aren't exhaustive. You may want to test your code in other ways too (for example, with different test values) . If you run test_ps3.py using the initially provided ps3.py skeleton, you should see that allthe tests fail. If you run test_ps3.py using the initially provided ps3.py skeleton, you should see that all the tests fail. These are the provided test functions: test_get_word_score ---- Test the get_word_score implementation. test_update_hand ----Test the update_hand implementation. test_is_valid_word ----Test the is_valid_word implementation. test_wildcard ---- Test the modifications made to support wildcards. (more about those later on) Problem 1: Word scores The first step is to implement a function that calculates the score for a single word. Fill in the code for get_word_score in ps3.py according to the function specifications. As a reminder, here are the rules for scoring a word: • The score for a word is the product of two components: o First component: the sum of the points for letters in the word. o Second component: either [7 * word_length - 3 * ( n- word_length)] or 1, whichever value is greater, where: • word_length is the number of letters used in the word • n is the number of letters available in the current hand You should use the SCRABBLE_LETTER_VALUES dictionary defined at the top of ps3.py . Do not assume that there are always 7 letters in a hand! The parameter n is the total number of letters in the hand when the word was entered. Finally, you may find the str.lower function helpful: s = “My string” print(s.lower()) >>>> “my string” If you don’t know what this does you could try typing help (str.lower) in your Spyder shell to see the documentation for the functions. Testing: If this function is implemented correctly, and you run test_ps3.py , the test_get_word_score() tests will pass. You should also test your implementation of get_word_score yourself, using some reasonable English words. Note that the wildcard tests will crash due to a KeyError. This is fine for now - you will fix this in Problem 4. Problem 2: Dealing with hands **Please read problem 2 entirely before you begin coding your solution** Most of the functions described below have been implemented for you already. Representing hands A hand is the set of letters held by a player during the game. The player is initially dealt a set of random letters. For example, the player could start out with the following hand: a, q, l, m, u, i, l. In our program, a hand will be represented as a dictionary: the keys are (lowercase) letters and the values are the number of times the particular letter is repeated in that hand. For example, the above hand would be represented as: hand = {'a':1, 'q':1, 'l':2, 'm':1, 'u':1, 'i':1} Notice how the repeated letter 'l' is represented. With a dictionary representation, the usual way to access a value is hand['a'], where 'a' is the key we want to find. However, this only works if the key is in the dictionary; otherwise, we get a KeyError . To avoid this, we can instead use the function call hand.get('a',0) . This is the "safe" way to access a value if we are not sure the key is in the dictionary. d.get(key,default) returns the value for key if key is in the dictionary d , else it returns default . If default is not given, it returns None , so that this method never raises a KeyError. Converting words into dictionary representation One useful function we've defined for you is get_frequency_dict , defined near the top of ps3.py . When given a string of letters as an input, it returns a dictionary where the keys are letters and the values are the number of times that letter is represented in the input string. For example: >>get_frequency_dict("hello") {'h': 1, 'e': 1, 'l': 2, 'o': 1} As you can see, this is the same kind of dictionary we use to represent hands. Displaying a hand Given a hand represented as a dictionary, we want to display it in a user-friendly way. We have provided the implementation for this in the display_hand function. Take a few minutes right now to read through this function carefully and understand what it does and how it works. Generating a random hand The hand a player is dealt is a set of letters chosen at random. We provide you with a function that generates a random hand, deal_hand . The function takes as input a positive integer n, and returns a new dictionary representing a hand of n lowercase letters. Again, take a few minutes to read through this function carefully and understand what it does and how it works. Removing letters from a hand (you implement this!) The player starts with a full hand of n letters. As the player spells out words, letters from the set are used up. For example, the player could start with the following hand: a, q, l, m, u, i, l The player could choose to play the word quail. This would leave the following