DOC PREVIEW
MIT 6 00 - Problem Set 10 - 6.00

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

MIT OpenCourseWare http://ocw.mit.edu 6.00 Introduction to Computer Science and Programming Fall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.6.00: Introduction to Computer Science and Programming Problem Set 10: OOP I did it again Handed out: Thursday, November 6, 2008 Due: Thursday, November 13, 2008 Introduction We hope you enjoyed the word game from problem sets 5 & 6… because it’s back! In this problem set, you will fill in code for a graphical version of the 6.00 word game, with support for single player, two player, and vs. computer game modes. Along the way, you will implement classes to encapsulate and manage the data and functions for the word game. You will also practice manipulating instances of these classes through methods. Finally, you will see your classes in action as they interact with a graphical user interface (GUI) module for the 6.00 word game. Workload Please let us know how long you spend on each problem. We want to be careful not to overload you by giving out problems that take longer than we anticipated. Collaboration You may work with other students. However, each student should write up and hand in his or her assignment separately. Be sure to indicate with whom you have worked. For further details, please review the collaboration policy as stated in the syllabus. Getting Started Download and save these files into the same folder. ps10.py: The code template for the word game ps10_test.py: A skeleton test harness for the classes in ps10.py. You should add tests to this file. ps10_gui.py: The code for the word game graphical user interface. You should not need to modify this file. words.txt: The list of words from Problem sets 5 and 6 Problem 1: Install wxPython Before you begin the problem set, you will need a toolkit for making a graphical user interface (GUI) in python. We will use the wxPython toolkit for this purpose. First make sure you have Python 2.5.2. You can check what version of Python you have by going to the “Help” menu and clicking “About IDLE” from the Python Shell window in IDLE. With Python 2.5.2 installed, you can download and install wxPython. Download information for wxPython can be found here. Follow the instructions given in the installer. After the installation, start up IDLE and enter “import wx” at the prompt. If no error message appears, you have successfully installed the wxPython toolkit. Install the wxPython toolkit. You do not have to submit anything for this problem.Problem 2: Representing a Hand In problem set 5, you managed a number of data structures and functions pertaining to a player’s hand. The data for the hand was stored as a dictionary that mapped characters to their corresponding frequencies in the hand. A number of functions were used to manage the hand—deal_hand() was used to initialize a new hand, display_hand(), was used to print the hand to the screen in a readable format, update_hand() was used to remove the letters in a word from the hand, and is_valid_word() used the hand to check if the letters necessary for making up a word were present. We are now going to encapsulate the functions and data associated with a hand in a class called Hand. We have already provided the constructor method, __init__(), which takes as an argument the initial size of the hand (the initialSize parameter). The constructor also takes an optional second argument (the initialHandDict parameter), which is a dictionary representation (mapping characters to frequencies) that is used to initialize the hand to a particular set of characters. This argument is used for testing purposes. If no second argument is given, the constructor initializes the hand with random characters. The class stores the initial size of the hand as the attribute self.initialSize and the dictionary representation for the hand as the attribute self.handDict. You will need to fill in the remaining functions according to the specifications to have a class representation of a hand. Fill in the update(), containsLetters(), isEmpty(), and __eq__() methods in the Hand class according to the specifications. Your implementation for each of these methods should be relatively short (probably around 10–20 lines or fewer per method). Feel free to make use of the solutions to problem set 5 and problem set 6 in your code. We have provided a skeleton test harness in ps10_test.py. Use testHand() to test your Hand class. You should add additional tests to testHand() to adequately test your Hand class. class Hand(object):""" A class representation of a hand. """ . . . def update(self, word): """ Remove letters in word from this hand. word: The word (a string) to remove from the hand postcondition: Letters in word are removed from this hand """ # TODO def containsLetters(self, letters):""" Test if this hand contains the characters required to make the input string (letters) returns: True if the hand contains the characters to make up letters, False otherwise """ # TODO def isEmpty(self):""" Test if there are any more letters left in this hand.returns: True if there are no letters remaining, False otherwise. """ # TODO def __eq__(self, other):""" Equality test, for testing purposes returns: True if this Hand contains the same number of each letter as the other Hand, False otherwise """ # TODO . . . Problem 3: Representing a Player In problem sets 5 and 6, you initialized and managed the state of a player. You kept track of the player’s score, their remaining time, and their current hand. In this problem set, you will encapsulate this information in a Player class, except you are no longer keeping track of time. You will write a set of methods to access and modify this data. We have provided the constructor method, __init__(), for the Player class. The constructor takes as arguments an ID number (idNum) (either 1 for player 1 or 2 for player 2) and a Hand object (hand) for the player’s hand and stores them as class attributes self.idNum and self.hand, respectively. In this problem, you will fill in the remaining methods of the Player class according to the specifications to have a class representation of a Player. Fill in the getHand(), addPoints(), getPoints(), getIdNum() and __cmp__() methods in the Player class. Again, your implementation for these methods should be very short. We have provided a skeleton test harness in ps10_test.py. Use testPlayer() to test your Player class.


View Full Document

MIT 6 00 - Problem Set 10 - 6.00

Download Problem Set 10 - 6.00
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Problem Set 10 - 6.00 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Problem Set 10 - 6.00 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?