Programming Assignment 3/Final

SevenLittleWords.png 

1 Learning Objectives

This assignment is designed to help you learn several things, including:
  • Writing utility and class modules
  • Using basic UML diagrams showing class relationships
  • Writing a main function using both utility functions and objects
  • Writing unit tests for created modules.

It will also help you get better at using objects and testing.

2 Introduction

7 Little Words is a popular game that is available as both a "Web App" and a "Phone App". For this assignment, you are going to create a JMU-themed (i.e., purple and gold) knockoff called 00000111 Little Words that can run on a desktop/laptop computer.

When running, it will look something like the following.

screenshot.png

3 Game Play

00000111 Little Words is a single-player game. The player's objective is to guess the seven words that correspond to the seven provided clues. There is no time limit and there is no penalty for incorrect guesses.

3.1 Information Provided to the Player

The player is provided with seven clues and the length of the corresponding word/answer. In addition, the player is provided with a group of tiles, each of which contains a slice of one of the words to be guessed.

3.2 Guessing

To make a guess, the player selects tiles (in order) and then presses the Guess button. When a tile is selected it is temporarily removed from the board.

After a correct guess, the tiles that constituted the guess are permanently removed from the board. After an incorrect guess, the tiles that constituted the guess are returned to the board (i.e., made available for another guess).

3.3 Hints

At any point, the player can request (with no penalty) a hint for a particular clue. Specifically, the player can ask for the first letter in the word associated with the clue, the first tile in the word associated with the clue, or the answer.

3.4 Shuffling

At any point, the player can shuffle the available tiles (which may help the player see patterns that weren't visible before).

4 Game Creation

Games are created by an author, not the player. To create a game, the author creates a single text file that contains seven dash-delimited records/lines. The first field in each record/line contains the answer, and the second contains the clue.

Note that the author does not create the tiles, the program creates them from the words using a slicing algorithm.

An outside author created three game files that you can use for testing.

Of course, you can easily create more.

5 System Design

The system that you must implement is summarized in the following UML class diagram.
Seven Little Words UML

You are responsible for implementing the classes in black. The graphical user interface files to play the game are available here:

Python 3.8.x(linux labs/Thonny): 
Python3.10.x(most Windows/Mac at home):
  • game_board.pyc
  • file_utilities.pyc

    The purpose of the methods in the other classes should be apparent from their names.  Download these files and put them in the same directory as your other py files you write.

6 The WordSlice Class

A WordSlice is a two-letter or three-letter portion of a word.

A WordSlice can either be in the used state or the unused state. When a WordSlice is in the unused state its __str__() must return its text. However, when it is in the used state it must return the empty str (i.e., "").

It must be possible to put a WordSlice in the used state by calling its use() method. On the other hand, it must be possible to put it into the unused state by calling its reset() method. Its is_used() method must return True when it is in the used state and False otherwise.

7 The WordUtilities Class

The only public method in the WordUtilities class is slicer(). It must create the word slices for the word it is passed in a manner that is consistent with the following specifications.
  1. All the letters in a word slice must be uppercase characters.
  2. When the length of the word (in characters) is evenly divisible by three, each word slice must contain exactly three characters.
  3. When the length of the word (in characters) is instead evenly divisible by two, each word slice must contain exactly two characters.
  4. When the length of the word (in characters) is neither evenly divisible by three nor evenly divisible by two, slice 0 must contain exactly three characters and all other slices must contain exactly two characters.

For example, the word "Madison" has the slices "MAD", "IS", and "ON".

The list that is returned by this method must contain the appropriate number of word slices, no more and no fewer.

Note that, though the game has the modifier "little" in its name, this method must work correctly for any parameter that has two or more characters.

8 The WordClue Class

A WordClue is an class that contains a word along with its associated clue and slices.

The constructor must initialize all of the attributes in the obvious way, with two exceptions. When the word passed to the constructor is None or has fewer than MIN_WORD_LENGTH characters, the corresponding attribute must be set to "DEFAULT". Similarly, when the clue passed to the constructor is None, or has no characters, or has more than MAX_CLUE_LENGTH characters, the corresponding attribute must be set to "DEFAULT CLUE".

All of the methods that return a hint must return a str that contains nothing but uppercase characters. (Hint: Look in the String class for a method or methods that might be helpful.) On the other hand, the get_clue() and get_word() methods must return the corresponding attribute "as is".

The __str__ method must return a str representation of the WordClue. The first line must consist of a single "line" (terminated by a '\n' character) that contains the word, followed by a dash (i.e., a '-'character), followed by the clue. For example, __str__() for the WordClue constructed from "madison" and "the university's namesake" must return madison-the university's namesake\n. The second "line" must contain the slices, with a space between each word slice. For example, for the WordClue constructed from "madison" and "the university's namesake" must return madison-the university's namesake\nMAD IS ON\n.

The __eq__() method must return True when the word attribute of the two WordClueobjects contain the same characters, ignoring their case. (Hint: Look in the str class for a method or methods that might be helpful.)

9 The GameInfo Class

The GameInfo class is an encapsulation of all of the information needed to play a game, including the information provided by the author of the game (stored in a WordClue[]) and the calculated information (stored in a WordSlice[]).

The constructor must read the information (provided by the author of the game) from the given file (using the FileUtilities class), construct a WordClue object from each line, and compile a list all of the Slice objects for all of the words.

The is_complete() method must return True if the appropriate number of words/clues were read and must return False otherwise.

The __str__() method must return a String that consists of multiple "lines" (each terminated with a '\n' character) satisfying the following specifications.

  • The first line must contain the str literal "Cluelist".
  • The next NUMBER_OF_WORDS "lines" must contain just the first line of the the str representation of the WordClue objects.
  • The next "line" must be blank.
  • The next "line" must contain the str literal "Slices".
  • The next "lines" must contain the str representation of all of the slices.

For example, the __str__() method must return the following str for the game in net.txt (where each "line" is on its own line).

Cluelist
browser-it helps you surf the net
bullock-The Net actress Sandra
fault-result of serve into the net
brooklyn-Nets home, in the NBA
acrobat-performer with a safety net
gross-net pay before withholdings
imprecise-like one casting a wide net

Slices
BRO
WS
ER
BUL
LO
CK
FAU
LT
BR
OO
KL
YN
ACR
OB
AT
GRO
SS
IMP
REC
ISE

10 The Main Module

The main module for this assignment is seven_little_words. It must:
  1. Construct a GameInfo object using the file name passed to it as command-line argument 1. If no such argument is provided, it must print an error message beginning with "Usage: python seven_little_words.py <game_file>" on the console and terminate.
  2. Construct a GameBoard using the GameInfo object. If the GameInfo object isn't read properly/completely, it must instead print an error message of "Game file is incomplete" on the console and terminate.
  3. Show the GameBoard object by calling its set_visible() method and passing it the value True.

11 Submission

See submission file requirements for each part below

12 Grading

Your submissions will be graded according to the following criteria.

12.1 Part A Readiness Quiz(see Canvas section for due date) no files to submit

Part A accounts for 10 points of the total grade. You may attempt Part A multiple times but you may not complete it after the due date.

Though Canvas will assess each question individually, Part A will be graded on an "all or nothing" basis. In other words, you must receive a grade of 10 from Canvas to get any credit for Part A.

12.2 Part B 30 points - WordSlice and WordUtilities classes and test for WordUtilities(see Canvas section for due date).  Submit your word_slice.py, word_utilities.py, and test_word_utilities.py files to Gradescope

Part B accounts for 30 points of the total grade, divided as follows:
  • Style: 2 points
  • Test Coverage for test_word_utilities.py: 5
  • WordSlice/WordUtilities: 16 points
  • slicer method tests: 7 points

12.3 Part C 60 points - Submit your game_info.py, seven_little_words.py, word_clue.py, word_slice.py, word_utilities.py files to Gradescope(see Canvas Section for due date)

Part C accounts for 60 points of the total grade, divided as follows:

  • Instructor points: 10 points
  • Style: 5 points 
  • WordClue: 15 points
  • GameInfo: 15 points
  • seven_little_words.py: 15 points

Note also that the correctness of some classes depends on the correctness of the others (e.g., WordClue uses WordUtilities and WordSlice, GameInfo uses WordClue and WordSlice). So, it is important that you get the "foundational" classes working correctly.

13 Some Advice

You should write and test one class at a time, and, within each class, you should write and test only a few methods at a time.

Probably the best way to proceed is as follows.

  1. Write the WordSlice class.
  2. Test the use(), reset() and is_used() methods.
  3. Test the __str__() method.
  4. Write the WordUtilities class.
  5. Test the slicer() method in the WordUtilities class on str objects of length 3, 4, 6, 8, and 11.
  6. Write the constructor, get_clue(), and get_word() methods of the WordClue class.
  7. Test those methods.
  8. Write the equals() method.
  9. Test the equals() method.
  10. Write the other "getters" in the WordClue class.
  11. Test the other "getters" in the WordClue class.
  12. Write the __str__() method in the WordClue class.
  13. Test the  __str__() method in the WordClue class.
  14. Write the constructor and is_complete() method of the GameInfo class.
  15. Test the constructor and is_complete() method of the GameInfo class.
  16. Write the "getters" in the GameInfo class.
  17. Test the "getters" in the GameInfo class.
  18. Write the __str__() method in the GameInfo class.
  19. Test the __str__() method in the GameInfo class.
  20. Write SevenLittleWords main module(does not need a class).
  21. Test the complete product.

Copyright 2022

Back to Top