Deadline: Tuesday 03 October 2017 by 9:00pm
All of the work you submit must be done by you, and your work must not be submitted by someone else. Plagiarism is academic fraud and is taken very seriously. The department uses software that compares programs for evidence of similar code. Please read the Rules and Regulations from the U of T Governing Council (especially the Code of Behaviour on Academic Matters). Please also see the information for students from the Office of Student Academic Integrity.
Please don’t copy. We want you to succeed and are here to help. Here are a couple of general guidelines to help you avoid plagiarism:
In this assignment, you'll be writing a Phrase Puzzler game. To see how the game is played, please watch the demo below.
The video demonstrates playing the one-player version of the game, but your code will eventually also have a two-player human vs. human version and also a human vs. computer version.
This assignment is meant to give you practice working with strings, functions, and if statements.
For this assignment, we are giving you some files, including some Python starter code files. See the Downloads section below for instructions on how to get the files.
There are two starter code files:
puzzler.py, which contains the main program, and
You'll need to add the functions described below to the
puzzler_functions.py file. Do not
modify the file
puzzler.py main program depends on functions you will
write, so this program won't run properly until you've
implemented the functions.
We are also providing two files that contain puzzle phrases:
puzzles.txt. The puzzles
used in the Phrase Puzzler game will never involve uppercase characters.
Constants are special variables whose values do not change
once assigned. A different naming convention (uppercase
pothole) is used for constants, so that programmers
know to not change their values. For example, in the Phrase
Puzzler starter code, the constant
is assigned the value 1 at the beginning of the module and
the value of
VOWEL_PRICE should never change.
When writing your code, if you need to refer to the price of
a vowel, you should use
VOWEL_PRICE, rather than
1. The same goes for the other constant values.
Using constants simplifies code modifications and improves
readability. If we later decide to use a different vowel
price, we would only have to change the price in one place
VOWEL_PRICE assignment statement), rather
than throughout the program.
'^-m^^^ ^^^^^'and then if "i" is guessed, it becomes
puzzler_functionsmodule contains several constants:
DATA_FILE: the name of the file that contains the puzzles for the game
CONSONANT_POINTS: the number of points for each occurrence of a hidden consonant in the view when that consonant is revealed.
VOWEL_PRICE: the cost (in points) of guessing a vowel. This number of points is deducted once from that player's score regardless of whether there are 0, 1, or more occurrences of the vowel in the puzzle.
CONSONANT_BONUS: the bonus (in points) for each occurrence of a hidden consonant in the view when the puzzle is correctly solved. This number of bonus points, multiplied by the remaining number of hidden consonants, is added to the score of the player who solved the puzzle.
PLAYER_ONE, PLAYER_TWO: the players
CONSONANT, VOWEL, SOLVE, QUIT: the moves a player can make
When you run
puzzler.py, one of three game types (a one-player, a two-player human vs. human version,
or a two-player human vs. computer version) is played. Before you can play each of the three game types, you'll need to implement the following functions:
See the table below for a description of these functions.
Please download the Assignment 1 Files and extract the zip archive. The following paragraphs explain the files you have been given.
This file contains some constants, and a complete docstring (but not body!) for the first function you are to write. You will update this file to include the complete functions that you write. When you have written all of the functions, you may try playing the game with more challenging puzzles by changing the constant
This file contains the main program and when it is run, the functions that you wrote and put in the
puzzler_functions.py file will be called. Do not make any changes to the
These files contain Phrase Puzzler puzzles.
We have provided a checker program that you should use to test your code. See below for more information about
In the starter code file
complete the following function definitions. Use the function
design recipe that we have been learning in class, and write
complete docstrings for each function.
We have included the type contracts in the table; please read through the starter code to understand how they will be used.
(Parameter types) -> Return type
||The first parameter represent a puzzle and the second represents its view. Return True if and only if the puzzle is the same as the view. (Please note: we have provided the complete docstring for this function as an example.)|
The first parameter represents a puzzle, the second represents its view,
and the third represents the current selection (one of
||The parameters represent a puzzle, its view, and a letter to evaluate. Return True if and only if the letter appears in the puzzle but not in its view.|
||The first parameter represents a puzzle, the second represents its view, the third represents the index of the character to update, and the fourth represents the letter that has been guessed. Return a single character string representing the next view of the character at the given index. If the character at that index of the puzzle matches the guess, then return that character. Otherwise, return the character at that index of the view.|
The first parameter represents the current score, the second represents
the number of occurrences of a letter in the puzzle, and
the third represents whether that letter is a
The first parameter is the current player (one of
puzzler_functions.py file should contain the
starter code, plus the function definitions specified above.
puzzler_functions.py must not include any
calls to the
functions. Do not add any
Also, do not include any function calls outside of the
You should test each function individually by writing code to verify your
functions in the Python shell. For example, after defining function
is_win, you might call it from the shell (e.g.,
is_win('e-mail inbox', ^-m^il i^^^^')) to check whether it returns the right value (
False). One call usually isn't enough to thoroughly test the function — for example, we should also test
is_win in cases where it should return
Once you've checked each function individually, play the game using
puzzler.py starter code to see whether it works as expected. If not, go back to testing the functions individually.
We are providing a checker module (
checker.py) that tests two things:
To run the checker, open
checker.py and run it. Note: the checker file should be in the same directory as your
puzzler_functions.py, as provided in the starter code zip file.
You can find a demo of the checker being run in the Week 3 Prepare exercises on PCRS.
If the checker passes:
If the checker fails, carefully read the message provided:
Make sure the checker passes before submitting.
These are the aspects of your work that may be marked for A1:
The very last thing you do before submitting should be to run the checker program one last time. Otherwise, you could make a small error in your final changes before submitting that causes your code to receive zero for correctness.
puzzler_functions.py on MarkUs by following the
instructions on the course website. Remember that spelling of
filenames, including case, counts: your file must be named
exactly as above.