Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write functions to compute letter and word scores in the Scrabble board game. Introduction Scrabble is a board game in which players take turns spelling

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Write functions to compute letter and word scores in the Scrabble board game. Introduction Scrabble is a board game in which players take turns spelling words for points. Each letter has a point value, word scores are made up of the sum of letter scores, and multipliers can be applied if a letter or word lands on particular spaces on the board (as shown in the figure below). Different letters are worth different numbers of points in Scrabble. The distribution of these letters is given in this Wikipedia article; we will use the English letter distribution. You will need to write a Python function that, when given a letter, returns the number of points associated with that letter. For example, the letter A is worth 1 point, whereas the letter Z is worth 10. Points are scored in Scrabble by playing words. The score of a word, absent any multipliers (described below), is the sum of its letters' points. For example, the word APPLE would score 9 points. A standard Scrabble board - 3199 VS C B 4F H4 M * SCRABBLE -- Multipliers If a word crosses any of the coloured spaces on the game board, letter or word scores can be doubled or even tripled. For the purposes of this assignment, we will only consider word multipliers, which are: Triple word score Locations (0,0),(0,7), (0,14), (7,0), (7,7), (7,14), (14,0), (14,7), (14,14) Double word score Multipliers If a word crosses any of the coloured spaces on the game board, letter or word scores can be doubled or even tripled. For the purposes of this assignment, we will only consider word multipliers, which are: Triple word score Locations (0,0), (0,7), (0,14), (7,0), (7,7), (7,14), (14,0), (14,7), (1414) Double word score Locations (1,1),(1, 13), (2,2), (2, 12), (3,3), (3, 11),(4,4),(4, 10), (10,4), (10,10), (11,3), (11, 11), (12,2), (12, 12), (13,1), (13, 13) Thus, if the word APPLE is played from left to right at location (0,6), it will be worth 27 points (9* 3) because one of its tiles is on a triple word score tile at (0,7). As another example, if the word PYTHON is spelled from top to bottom at location (2,0), it should score 42 points (143) because one of its tiles is on a triple word score tile at (7,0). 0 1 2 3 4 5 5 6 7 0 1 2 P. 3 4 5 H 6 7 Requirements In this assignment, you must implement two Python functions, one to compute the score of a single letter and one to compute the score of a word. Single letters Triple word score Locations (0,0), (0,7), (0,14), (7,0), (7.7), (7,14), (14,0), (14,7), (14,14) Double word score Locations (1,1), (1, 13), (2,2), (2, 12), (3,3), (3, 11), (4,4),(4, 10), (10,4), (10, 10), (11,3), (11, 11), (12,2), (12, 12), (13,1), (13, 13) Thus, if the word APPLE is played from left to right at location (0,6), it will be worth 27 points ( 93) because one of its tiles is on a triple word score tile at (0,7). Requirements In this assignment, you must implement two Python functions, one to compute the score of a single letter and one to compute the score of a word. Single letters Use the points distribution referenced above to implement the following Python function: def letter_score(letter): This function should return the number of points scored by playing the letter 'letter. pass # replace this with your own work For example, letter_score('A') should return 1 andi letter_score('Z') should return 10. Words Use the description above to complete the following Python function that calculates a word's point value. def word_score(word, row=None, col=None, direction=None): Compute the points that will be scored if a player plays this word. Parameters: word row col direction the word to be played which row the word will be played at (or None) which column the word will be played at (or None) LR' for left-to-right, 'TB' for top-to-bottom, or None pass # replace this with your own work If any of row, col or direction are None, all of them should be; this means that you can ignore the word's placement. For example, the function call word_score("APPLE") should evaluation to 9. If any of row, col or direction are non-None, however, they should all be. In this case, you should take them all into account and apply any appropriate multipliers. For example, word_score("APPLE', 0, 6, 'LR') should evaluation to 27 (as described above). Completing the assignment Implement the two functions above and submit your work in a file called scrabble.py. You may start by copying the stub implementations above into your Python file appropriate multipliers. For example, word_score('APPLE', 8, 6, 'LR') should evaluation to 27 (as described above). Completing the assignment Implement the two functions above and submit your work in a file called scrabble.py. You may start by copying the stub implementations above into your Python file to help you get started. Then, follow our usual problem-solving approach (problem, pseudocode, Python) for each part of the assignment (letters, words, words with positions). I suggest that you work on one part at a time: 1. First, implement letter_score() 2. Next, implement word_score() while ignoring row, col and direction 3. Finally, take row, col and direction into account within word_score() Write functions to compute letter and word scores in the Scrabble board game. Introduction Scrabble is a board game in which players take turns spelling words for points. Each letter has a point value, word scores are made up of the sum of letter scores, and multipliers can be applied if a letter or word lands on particular spaces on the board (as shown in the figure below). Different letters are worth different numbers of points in Scrabble. The distribution of these letters is given in this Wikipedia article; we will use the English letter distribution. You will need to write a Python function that, when given a letter, returns the number of points associated with that letter. For example, the letter A is worth 1 point, whereas the letter Z is worth 10. Points are scored in Scrabble by playing words. The score of a word, absent any multipliers (described below), is the sum of its letters' points. For example, the word APPLE would score 9 points. A standard Scrabble board - 3199 VS C B 4F H4 M * SCRABBLE -- Multipliers If a word crosses any of the coloured spaces on the game board, letter or word scores can be doubled or even tripled. For the purposes of this assignment, we will only consider word multipliers, which are: Triple word score Locations (0,0),(0,7), (0,14), (7,0), (7,7), (7,14), (14,0), (14,7), (14,14) Double word score Multipliers If a word crosses any of the coloured spaces on the game board, letter or word scores can be doubled or even tripled. For the purposes of this assignment, we will only consider word multipliers, which are: Triple word score Locations (0,0), (0,7), (0,14), (7,0), (7,7), (7,14), (14,0), (14,7), (1414) Double word score Locations (1,1),(1, 13), (2,2), (2, 12), (3,3), (3, 11),(4,4),(4, 10), (10,4), (10,10), (11,3), (11, 11), (12,2), (12, 12), (13,1), (13, 13) Thus, if the word APPLE is played from left to right at location (0,6), it will be worth 27 points (9* 3) because one of its tiles is on a triple word score tile at (0,7). As another example, if the word PYTHON is spelled from top to bottom at location (2,0), it should score 42 points (143) because one of its tiles is on a triple word score tile at (7,0). 0 1 2 3 4 5 5 6 7 0 1 2 P. 3 4 5 H 6 7 Requirements In this assignment, you must implement two Python functions, one to compute the score of a single letter and one to compute the score of a word. Single letters Triple word score Locations (0,0), (0,7), (0,14), (7,0), (7.7), (7,14), (14,0), (14,7), (14,14) Double word score Locations (1,1), (1, 13), (2,2), (2, 12), (3,3), (3, 11), (4,4),(4, 10), (10,4), (10, 10), (11,3), (11, 11), (12,2), (12, 12), (13,1), (13, 13) Thus, if the word APPLE is played from left to right at location (0,6), it will be worth 27 points ( 93) because one of its tiles is on a triple word score tile at (0,7). Requirements In this assignment, you must implement two Python functions, one to compute the score of a single letter and one to compute the score of a word. Single letters Use the points distribution referenced above to implement the following Python function: def letter_score(letter): This function should return the number of points scored by playing the letter 'letter. pass # replace this with your own work For example, letter_score('A') should return 1 andi letter_score('Z') should return 10. Words Use the description above to complete the following Python function that calculates a word's point value. def word_score(word, row=None, col=None, direction=None): Compute the points that will be scored if a player plays this word. Parameters: word row col direction the word to be played which row the word will be played at (or None) which column the word will be played at (or None) LR' for left-to-right, 'TB' for top-to-bottom, or None pass # replace this with your own work If any of row, col or direction are None, all of them should be; this means that you can ignore the word's placement. For example, the function call word_score("APPLE") should evaluation to 9. If any of row, col or direction are non-None, however, they should all be. In this case, you should take them all into account and apply any appropriate multipliers. For example, word_score("APPLE', 0, 6, 'LR') should evaluation to 27 (as described above). Completing the assignment Implement the two functions above and submit your work in a file called scrabble.py. You may start by copying the stub implementations above into your Python file appropriate multipliers. For example, word_score('APPLE', 8, 6, 'LR') should evaluation to 27 (as described above). Completing the assignment Implement the two functions above and submit your work in a file called scrabble.py. You may start by copying the stub implementations above into your Python file to help you get started. Then, follow our usual problem-solving approach (problem, pseudocode, Python) for each part of the assignment (letters, words, words with positions). I suggest that you work on one part at a time: 1. First, implement letter_score() 2. Next, implement word_score() while ignoring row, col and direction 3. Finally, take row, col and direction into account within word_score()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions