Sie sind auf Seite 1von 2

Bard High School Early College Queens Data Structures & Algorithms SK2U Spring 2012 Instructor: Matthew

Carlberg Review Project #1: Text Twist Due Date: Wednesday, February 15 at 11:59PM Description: In this project, you will implement a basic form of the game Text Twist, which can be played online at: http://games.yahoo.com/game/text-twist. Our version of the game will work as follows: The user is dealt eight random letters, 2 vowels and 6 consonants. The user has 60 seconds to identify as many words as possible that can be created using all or a subset of the eight random letters in their hand. If the user plays a 3 letter word, they get 3 points; if the user plays a 4 letter word, they get 4 points; and so on. Starter Code: Starter code is located in Python Resources > Data Structures > TextTwist. This folder also contains words.txt, which is a list of the valid words that a user is allowed to play. This file needs to be in the same folder as your Python file for your code to run correctly. Working Example of Program: Loading word list from file... 83667 words loaded. You have 60 seconds left. Your current score is 0. Your hand is: i a c f b m b l Enter a word contained in your hand: film Good job! You have 42 seconds left. Your current score is 4. Your hand is: i a c f b m b l Enter a word contained in your hand: fail Good job! You have 18 seconds left. Your current score is 8. Your hand is: i a c f b m b l Enter a word contained in your hand: bmb That word is not in the dictionary. You have 9 seconds left. Your current score is 8. Your hand is: i a c f b m b l Enter a word contained in your hand: fable You do not have the proper letters in your hand to play that word. Your time is up.

Turning in the Code: TBA Problems: Note: You do not have to define any classes for this project, so all of the functions below are stand-alone functions. 1. (10 points) Define a function called stringToDict. Input: A string Output: A dictionary containing the number of times each letter appears. Example: If hello is the input to this function, it should return the following dictionary: {h:1, e:1, l:2, o:1} 2. (5 points) Define a function called isValidWord Input: 1. A string corresponding to a single word played in the game. 2. A list of strings containing every valid word that could be played. Output: True if the input string is in the word list, False otherwise. 3. (10 points) Define a function called isSubset Input: Two strings, the first corresponding to a word that the user has attempted to play and the second one corresponding to the users hand. That is, the second string contains the eight letters that the user is allowed to play in the game. Output: True if the word that the user has attempted to play is a subset of what the user has in his hand. Examples: 1. If the user attempts to play hello and the letters in their hand are oecdlrhl, then this function returns True. 2. If the user attempts to play hill and the letters in their hand are iahlbcdf, then this function returns False. 3. If the user attempts to play helix and the letters in their hand are iehlptvh, then this function returns False. 4. If the user attempts to play brb and the letters in their hand are oubrzxst, then this function returns False. 4. (10 points) Define a function called makeRandomHand. Input: None Output: A string containing two random vowels and six random consonants. Note that you should take advantage of the following two strings that are defined for you in the starter code: VOWELS = 'aeiou' CONSONANTS = 'bcdfghjklmnpqrstvwxyz' 5. (20 points) Define a function called playGame, which implements the Text Twist game using the above defined functions, as well as the readWordList function which has already been defined for you. 6. (5 points) In the playGame function, prevent the user from playing the same word more than once.

7. (+5 bonus) Implement the twist part of Text Twist. That is, if the user enters the space bar key, the order of their hand is re-displayed with the letters shuffled randomly. This helps the user to see words in their hand better.

Das könnte Ihnen auch gefallen