Download - Data Structures Project Text Twist
5/13/2018 Data Structures Project Text Twist - slidepdf.com
http://slidepdf.com/reader/full/data-structures-project-text-twist 1/3
Bard High School Early College QueensData Structures & Algorithms SK2U
Spring 2012Instructor: 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 willwork 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. Thisfolder 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 lEnter a word contained in your hand:
bmbThat 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 lEnter a word contained in your hand:
fableYou do not have the proper letters in your hand to play that word.
Your time is up.
5/13/2018 Data Structures Project Text Twist - slidepdf.com
http://slidepdf.com/reader/full/data-structures-project-text-twist 2/3
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 stringOutput: A dictionary containing the number of times each letter appears.
Example: If ³hello´ is the input to this function, it should return the followingdictionary: {µ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 user¶s hand. That is, the secondstring 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.
Not e that you should t ake advant age o f the f oll owing two str ings that ar e defined f or you in the st art er 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 hasalready been defined for you.
6. (5 points) In the ³playGame´ function, prevent the user from playing the same wordmore 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.