Scrabble is a word game in which two to four players score points by placing tiles — each bearing a single letter — onto a game board. The tiles must form words which, in crossword fashion, flow left to right in rows or downwards in columns. The words must be defined in a standard dictionary, or be present in specified reference works that provide a list of officially permissible words.
The game is played on a square board with a $$15 \times 15 = 225$$ grid of squares, each of which accommodates a single letter tile. The board is marked with "premium" squares, which multiply the number of points awarded: eight dark red "triple-word" squares, 17 pink "double-word" squares, of which one, the center square, is marked with a star or other symbol; 12 dark blue "triple-letter" squares, and 24 light blue "double-letter" squares.
In an English-language set, the game contains of 100 tiles, 98 of which are marked with a letter and a point value ranging from 1 to 10. The number of points of each lettered tile is based on the letter's frequency in standard English writing. Commonly used letters such as vowels are worth one point, while less common letters score higher, with Q and Z each worth 10 points. The game also has two blank tiles that are unmarked and carry no point value. The blank tiles can be used as substitutes for any letter. Once laid on the board, however, the choice is fixed. Other language sets use different letter set distributions with different point values.
Before the game starts, a resource (either a word list or a dictionary) is selected for the purpose of adjudicating any challenges during the game. The letter tiles are put in an opaque bag. Next, players decide the order in which they play. The normal approach is for players to each draw one tile: the player who picks the letter closest to the beginning of the alphabet goes first, with the blank tiles taking precedence over A's. At the beginning of the game, each player draws a fixed number of tiles from the bag and places them on his or her rack, concealed from the other player(s). On each turn, the player has three options:
pass, forfeiting the turn and scoring nothing
exchange one or more tiles for an equal number from the bag, scoring nothing
play at least one tile on the board, adding the value of all words formed to the player's cumulative score
A proper play uses one or more of the player's tiles to form a continuous string of letters that make a word (the play's "main word") on the board, reading either left-to-right or top-to-bottom. The main word must either use the letters of one or more previously played words or else have at least one of its tiles horizontally or vertically adjacent to an already played word. If any words other than the main word are formed by the play, they are scored as well, and are subject to the same criteria of acceptability.
A blank tile may represent any letter, and scores zero points, regardless of its placement or what letter it represents. But its placement on a double-word or triple-word square does cause the corresponding premium to be applied to the word(s) in which it is used. Once a blank tile is placed, it remains that letter for the rest of the game. The player then draws tiles from the bag to replenish his or her rack. If there are not enough tiles in the bag to do so, the player takes all the remaining tiles. The game ends when either one player plays every tile on his or her rack and there are no tiles remaining in the bag (regardless of the tiles on his or her opponent's rack) or at least six successive scoreless turns have occurred and either player decides to end the game.
Each letter of the alphabet is assigned a fixed score between 1 and 10, with scores differing between countries and between languages. The score of a word that is placed on the Scrabble board is simply the sum of the scores of the individual letters of the word. For example, the word shrubbery has score 19 with the following scores assigned to the letters of the alphabet.
When placing a word on the Scrabble board it may happen that the score of an individual letter must be multiplied by a factor $$n \in \{2, 3\}$$. For longer words it is even possible that the score of more than one letter has to be multiplied, whereby the multiplication factors do not necessarily have to be same.
This is indicated in Scrabble notation by putting letters that must be doubled ($$n = 2$$) between square brackets, and letters that must be tripled ($$n = 3$$) between round brackets. As such, the Scrabble notation e[q]u(i)n[o]x indicates that the score of the letters q and o must be doubled and that the score of the letter i must be tripled. This way, the word equinox yields a total score of 36 points with the above score distribution.
In Scrabble notation it is also allowed to group successive letters that need to be doubled or tripled in between the same pair of square or round brackets. As such, the Scrabble notation e[xt]ra(vag)an[z]a indicates that the score of the letters x, t and z must be doubled and that the score of the letters v, a and g must be tripled. This way, the word extravaganza yields a total score of 65 points with the above score distribution.
A letter score is a score for an individual letter (between 1 and 10) that is represented by one of the following characters (str):
one of the digits from 1 to 9 that represent the corresponding score
the uppercase letter X that represents the score 10
A score distribution describes a fixed score for all letters of the alphabet for a given country and a given language. The distribution is represented as a string (str) with the letter score of all 26 letters of the alphabet, in order of appearance in the alphabet.
Your task:
Write a function letter_score that takes a letter $$l$$ (str) and a score distribution (str). The function must return the letter score (str) of letter $$l$$ according to the given score distribution.
Write a function letter_scores that takes the Scrabble notation of a word $$w$$ (str) and a score distribution (str). The function must return a string (str) containing the letter score of each successive letter in $$w$$ according to the given score distribution.
Write a function multipliers that takes the Scrabble notation of a word $$w$$ (str). The function must return a string (str) containing a digit 1, 2 or 3 for each successive letter in $$w$$, indicating the factor by which the score of the letter must be multiplied according to the given Scrabble notation.
Write a function word_score that takes the Scrabble notation of a word $$w$$ (str) and a score distribution (str). The function must return the score (int) of $$w$$ according to the given Scrabble notation and score distribution.
Make sure none of these functions makes a distinction between uppercase and lowercase letters.
>>> letter_score('s', '1332142418513113X11114484X')
'1'
>>> letter_score('Z', '1332142418513113X11114484X')
'X'
>>> letter_score('x', '1332142418513113X11114484X')
'8'
>>> letter_scores('shrubbery', '1332142418513113X11114484X')
'141133114'
>>> letter_scores('E[Q]U(I)N[O]X', '1332142418513113X11114484X')
'1X11118'
>>> letter_scores('e[XT]ra(VAG)an[Z]a', '1332142418513113X11114484X')
'1811141211X1'
>>> multipliers('shrubbery')
'111111111'
>>> multipliers('E[Q]U(I)N[O]X')
'1213121'
>>> multipliers('e[XT]ra(VAG)an[Z]a')
'122113331121'
>>> word_score('shrubbery', '1332142418513113X11114484X')
19
>>> word_score('E[Q]U(I)N[O]X', '1332142418513113X11114484X')
36
>>> word_score('e[XT]ra(VAG)an[Z]a', '1332142418513113X11114484X')
65
The 12th edition of The Chambers Dictionary1 — published in 2011 — highlighted about 500 words that the editors considered especially entertaining. For the 13th edition — published in 2014 — they chose to remove the highlighting but inadvertently removed the entries entirely.
The missing entries have since been reinstated, but in the interval the publishers supplied a list of the missing words2.