In Scrabble, players take turns placing tiles on a grid so that each contiguous set of (more than one) tiles in every row and column makes a word. In one play, tiles can be placed anywhere in a single row or column as long as there is a contiguous set of tiles that includes all of the ones placed.1 A word is scored (without considering premium score spaces) by adding up the point value of each of its letters. The point values of the letters are as follows:
1 point: E, A, I, O, N, R, T, L, S, U 2 points: D, G 3 points: B, C, M, P 4 points: F, H, V, W, Y 5 points: K 8 points: J, X 10 points: Q, Z
A play is scored by adding up the scores of each new word created in a play. For example, in the play below, N and W were played to form three new words, scoring 5 (PAN) + 6 (SEW) + 6 (NEW) = 17 points.
PAST PAST AXE -> AXE E NEW
Apart from the starting play, each play must involve at least one already existing tile, so that it is connected to the rest of the board.
Your challenge is to write a function which takes a play and returns the total points scored in that turn. You do not have to consider the legality of the words formed by the play, or any premium score squares. However, you should assume that the placement of the play will be valid (i.e. will connect to the board and be placed in a line) and that the board will be nonempty before the play. Unlike in Scrabble, a play can be more than 7 tiles, and the grid can be larger than 15x15.
Your function should take a mapping of the letters to their point values as a parameter. In addition to the letter point values, the function should take input in one of the following acceptable ways:
Two grids representing the board, with one showing the board before the play and one showing the board after the play.
A grid showing the board after the play and a list of the coordinates at which tiles were placed.
A grid showing the board either before or after the play, and a map containing each letter of the play with the coordinate at which it was placed.
The grid can be exactly big enough to contain the relevant squares, or can be padded to any larger size. This is Code Golf so the fewest bytes wins.
The examples use the first input method, with the board before and after the play separated with
| and the expected output in bold along with the words formed above each example.
17 (PAN, SEW, NEW)
PAST | PAST AXE | AXE E | NEW
18 (ST, OO, LO, IT, DE, TOOTED)
SOLID | SOLID | TOOTED
| H ROLL | ROLL | P | E
BAD | BAD A | A O NOT | NOT
PASTURE | PASTURE AXE Y | AXE Y NEW E | NEW NEW
GRAM | PROGRAMS
1 This set must be in a single row or column, but can include letters that were already on the board, i.e.