Assignment 7 - Scrambled Strings
Due: Thursday, November 6, 2025, at 10pm
You may work alone or with a partner, but you must type up the code yourself. You may also discuss the assignment at a high level with other students. You should list any student with whom you discussed each part, and the manner of discussion (high-level, partner, etc.) in a comment at the top of each file. You should only have one partner for an entire assignment.
You should submit your assignment as a scrabble.py file on Gradescope.
Getting started:
You will do most of your work in a single file, scrabble.py. You should download this “skeleton” version, and save it as scrabble.py in a folder into which you also download this file to be called words.txt. (You will only submit scrabble.py to Gradescope.)
Goals
The primary goal for this assignment is to give you practice working with classes. You will additionally get practice working with dictionaries and list methods.
Parts of this assignment:
Comments and collaboration
As with all assignments in this course, for each file in this assignment, you are expected to provide top-level comments (lines that start with # at the top of the file) with your name and a collaboration statement.
You need a collaboration statement, even if just to say that you worked alone.
Note on style:
The following style guidelines are expected moving forward, and will typically constitute 5-10 points of each assignment (out of 100 points).
- Variable names should be clear and easy to understand, should not start with a capital letter, and should only be a single letter when appropriate (usually for
i,j, andkas indices, potentially forxandyas coordinates, and maybepas a point,cfor a circle,rfor a rectangle, etc.). - It’s good to use empty lines to break code into logical chunks.
- Comments should be used for anything complex, and typically for chunks of 3-5 lines of code, but not every line.
- Don’t leave extra print statements in the code, even if you left them commented out.
- Make sure not to have code that computes the right answer by doing extra work (e.g., leaving a computation in a for loop when it could have occurred after the for loop, only once).
- Avoid having tons of lines of code immediately after another that could have been in a loop.
Note: The example triangle-drawing program on page 108 of the textbook demonstrates a great use of empty lines and comments, and has very clear variable names. It is a good model to follow for style.
Part 1: The ScoreJudge class
# You should be fully equipped to complete this part after Lesson 20 (Friday Oct. 31).
Before you get started, read through the code. There is a lot here that is provided for you already, including the entire TileBag class and much of the other two classes. Anything with a # TODO is something you’ll need to complete. For Part 1, you will focus on the ScoreJudge class. Objects of this class know all the words in the dictionary and are able to give the corresponding Scrabble scores of each one.
Spefically, you should:
- Implement
loadScoreDict. This method should fill theself.scoreDictinstance variable (a dictionary) with key-value entries for each letter, mapping them to their associated Scrabble score (described further in the comments of the skeleton code). Note: think about how you can avoid code reuse here--this doesn't need to be 26+ lines long! - Implement
scoreWord. This method should return the total score that the given word is worth in Scrabble, and must make use ofself.scoreDict.
Before moving on, be sure to test your methods to make sure they work. The easiest way of doing this at this stage is likely to create an instance of your ScoreJudge class in the main function and call its scoreWord method on some words you know the scores of.
Part 2: The PlayerHand class
# You should be fully equipped to complete this part after Lesson 20 (Friday Oct. 31).
- Implement
isPlayablemethod. Should return True if given word is playable using the tiles contained in this instance of thePlayerHandclass, and False otherwise - Implement
getPlayablesmethod. Should return a list of all words contained in the word list that are playable with this hand. - Implement
getBestmethod. Should return a tuple, the first element of which is the highest scoring word playable by this hand, the second element of which is the score of that word.
Before moving on, be sure to test your methods to make sure they work. Again, this likely means adding code to the main method instantiating one or more instances of the PlayerHand class and trying its methods. Note that the constructor for this class has a parameter called tiles with a default value of None. While leaving that parameter out when instantiating a new hand lets us try out a random hand, giving a known set of tiles to the constructor may be valuable for testing.
Part 3: Implementing an AI v. AI game
# You should be fully equipped to complete this part after Lesson 20 (Friday Oct. 31).
Finally, once you are confident that your two classes are working properly, you can move on to using them to simulate a (very rudimentary) game of Scrabble between two AI players! Specifically, we are going to create a dumbed-down version of Scrabble with the following setup and rules:
- Both players draw random hands of 7 tiles.
- Players alternate taking turns:
- If the player can form a valid word with the tiles in their hand, they can play that word, removing the corresponding tiles from their hand and scoring the corresponding number of points.
- If the player cannot form a valid word (or prefers not to), they can draw a single tile from the
TileBag. - After a predetermined number of turns (say, 5), the player with the higher score wins.
(Note that this is dramatically different from actual Scrabble, in that players are not having to play their words on a board upon which other tiles have already been played, etc.)
In the main function of scrabble.py, write code that instantiates a ScoreJudge, a TileBag, and two PlayerHand objects and has them play this game against each other. You should report the players' moves at each turn and give score updates, and should declare the winner at the end.
So, for instance, running your scrabble.py file (and thus, your main function) might give the following output:
P1 [SEEAEQN] plays SANE.
P1 has 4 points.
P2 [EKJHIPL] plays HIKE.
P2 has 11 points.
P1 [EEQ] draws [L].
P2 [JPL] draws [T].
P1 [EEQL] plays EEL.
P1 has 7 points.
P2 [JPLT] draws [U].
P1 [Q] draws [O].
P2 [JPLTU] plays JUT.
P2 has 21 points.
P1 [QO] draws [H].
P2 [PL] draws [T].
Final score:
P1: 7 ['SANE', 'EEL']
P2: 21 ['HIKE', 'JUT']
P2 wins!
For full credit, be sure to make proper use of the functionality provided in the classes given to you (rather than, say, writing redundant functionality to things already in the given methods).
NOT REQUIRED: Human players!
This part is not something you should submit, nor will it be graded, but these are the natural next steps to make this program a better version of itself.
If you'd like to extend yourself, create a new function called main2 in which you write the functionality required to have a human player play against an AI player.
Reflection
# You should be equipped to complete this part after finishing your assignment.
Were there any particular issues or challenges you dealt with in completing this assignment? How long did you spend on this assignment? Write a brief discussion (a sentence or two is fine) in comments at the bottom of your scrabble.py file.
Grading
This assignment will be graded out of 100 points, as follows:
-
5 points - submit a valid
scrabble.pyfile with the right name -
5 points -
scrabble.pyfile contain top-level comments with file name, purpose, author names, and collaboration statement -
10 points - code style enables readable programs
-
20 points - Part 1 (10 pts for
loadScoreDictand 10 pts forscoreWord) -
35 points - Part 2 (15 pts for
isPlayable, 10 pts forgetPlayables, and 10 pts forgetBest) -
20 points - Part 3 (20 pts for
mainfunction executing AI vs AI game) -
5 points - reflection in the comments at the bottom of the
imageProcessing.pyfile
What you should submit
You should submit a single scrabble.py file on Gradescope. Do not submit the words.txt file, as that should be unchanged from the one we provided you.