Question
UP = 'up' DOWN = 'down' FORWARD = 'forward' BACKWARD = 'backward' FORWARD_FACTOR = 1 DOWN_FACTOR = 2 BACKWARD_FACTOR = 3 UP_FACTOR = 4 THRESHOLD
UP = 'up' DOWN = 'down' FORWARD = 'forward' BACKWARD = 'backward' FORWARD_FACTOR = 1 DOWN_FACTOR = 2 BACKWARD_FACTOR = 3 UP_FACTOR = 4 THRESHOLD = 5 BONUS = 12 P1 = 'player one' P2 = 'player two' P1_WINS = 'player one wins' P2_WINS = 'player two wins' TIE = 'tie game' PUZZLE_FILE = 'puzzle1.txt'
# CAN NOT MODIFY THESE FUNCTIONS. THESE ARE THE STARTER CODES
def get_column(puzzle: str, col_num: int) -> str: """Return column col_num of puzzle.
Precondition: 0 <= col_num < number of columns in puzzle
>>> get_column('abcd efgh ijkl ', 1) 'bfj' """ puzzle_list = puzzle.strip().split(' ') column = '' for row in puzzle_list: column += row[col_num]
return column
def get_row_length(puzzle: str) -> int: """Return the length of a row in puzzle.
>>> get_row_length('abcd efgh ijkl ') 4 """
return len(puzzle.split(' ')[0])
def contains(text1: str, text2: str) -> bool: return text2 in text1
1. Create a function called get_row(str, int) -> str that will do the following: The first parameter represents a puzzle and the second represents a row number. Return the letters in the row corresponding to the row number, excluding the newline character. The first row is row number 0. For example, if our puzzle is the string 'abcd efgh ijkl ', and we wanted to find row 1 (which contains 4 letters), we would expect the string 'efgh' to be returned. Hint: you need to call on one of the helper functions provided in the starter code.
2. Create a function called get_factor(str) -> int that will do the following:The parameter represents a direction (the value of one of the constants UP, DOWN, FORWARD and BACKWARD). Return the multiplicative factor associated with this direction.
3.Create a function called get_points(str, int) -> int that will do the following: The first parameter represents a direction (the value of one of the constants UP, DOWN, FORWARD and BACKWARD) and the second represents the number of words left to be found before this guess. Return the points that would be earned if we were to now find some word in this direction. Follow the approach given in the Scoring in the Game section of this handout. Hint: you will need to call on one of the functions above as a helper function.
Scoring in the Game
The number of points earned for finding a word depends on the word's direction and on the number of words left to be found. Each direction has a multiplicative factor shown in the table below. The table above shows the corresponding constants we provided in the starter code. These values are based on how difficult it is (for a human player!) to notice a word in each direction.
Direction | Forward | Down | Backward | Up |
---|---|---|---|---|
Factor | 1 | 2 | 3 | 4 |
If there are THRESHOLD or more words left to be found, the number of points for a correct guess is simply THRESHOLDtimes the factor for the appropriate direction. If the number of words left to be found is less than THRESHOLD, then the total points earned for a correct guess is two times THRESHOLD minus the number ofleft to be found before the guess, all multiplied by the factor for the appropriate direction. On top of that there is an extra bonus of BONUSpoints for finding the last word.
For example, suppose there are five words left to be found, and we correctly guess a backward word. Then the number of points for the correct guess is: THRESHOLD * BACKWARD_FACTOR = 15.
If there were only two words left to be found, and we correctly guess a backward word, then the number of points for the correct guess is: (2 * THRESHOLD - 2) * BACKWARD_FACTOR = 24 points.
If there was only one word left to be found, and we correctly guess a backward word, then the number of points for the correct guess is: (2 * THRESHOLD - 1) * BACKWARD_FACTOR + BONUS = 39 points.
When you are calculating the number of points for a correct guess, you should use the constants, since during grading we could change them to have different values (e.g., BACKWARD_FACTOR could be changed to 5 when we grade your code).
4. Create a function called check_guess(str, str, str, int, int) -> int that will do the following: The first parameter represents the puzzle, the second represents a direction (value of one of the constants UP, DOWN, FORWARD and BACKWARD), the third represents the guessed word, the fourth represents the row or column number, and the fifth represents the number of words left to be found before this guess. If this guessed word is found in this puzzle at this location (row or column) and in this direction, return the number of points earned for this guess. Otherwise, return 0. Hint: you need to call on several helper functions (from above and from the starter code).
Please note: we can not use while loops, we can not do lists. We can not use built-in python functions for ex) puzzle.split. The only thing that is ok is IF-ELSE STATEMENTS, BOOLEAN OPERATORS, AND. STRING OPERATIONS (SUCH AS puzzle[:])
The puzzle we are working with
0 1 2 3 4 5 6 7 8 9 0 r m h l z x c e u j 1 t x a y n a a a a a 2 o n n e j l u a p c 3 m a e l l e h c i q 4 x d y t o m a g b u 5 x i h e v a k p r e 6 v c t z e v b k i l 7 j g f a v q w j m i 8 q u o t j e n h o n 9 a n y a d d b x t e
It would be an honour if you can do all these. Please and thank you :)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started