Brief description of the game
In the game Otteretto Classic (which you can test directly in your browser; try it!) the player has to form palindromic sequences using adjacent cells on a square grid. Each cell has one of five possible colours, which we will denote by the letters \$\mathrm A, \ldots, \mathrm E\$.
The user creates a sequence by sliding the mouse or finger, joining cells one by one, and then releasing the mouse button or lifting the finger to end the sequence. Each time a cell is added, the game updates the score of the sequence that has been built so far. This is actually a partial score, because new cells may be added later. Also, those future cells must make the final sequence palindromic, but that condition cannot be evaluated at this point, so it is ignored when computing the current partial score of the sequence.
Interestingly, the tutorial of the game does not fully specify the scoring method. All it says (slightly rephrased here) is that
- longer sequences are worth more points than shorter ones;
- more complicated sequences are worth more points than simpler ones.
In addition, since future cells are unknown, we may add
- the (partial) score can only depend on the previous and current cells.
The tutorial gives the following examples. For each sequence, all partial scores are indicated:
ABA -> 1 4 9 AABAA -> 1 2 6 12 15 CABAC -> 1 4 9 16 25
The following images represent the sequence \$\mathrm A \mathrm B \mathrm A\$ being built in the actual game (with \$\mathrm A\$ corresponding to yellow and \$\mathrm B\$ to purple). The score is the number shown in the lower part of each image.
The scoring method
Based on the above examples and a few others, it appears that the game computes the score according to the rules described next. Note that these rules have only been inferred by me from observing the game, and therefore might not be correct; but in any case they are the applicable rules for the purpose of this challenge.
Let \$x\$ be a sequence of length \$n\$, formed by \$x, \ldots, x[n]\$, where each \$x[k]\$ takes one of the five possible values \$\mathrm A, \ldots, \mathrm E\$. For each \$k = 1,\ldots,n\$, let \$r[k]\$ be the number of times that a cell differs from the preceding one in the (prefix) subsequence \$x, \ldots, x[k]\$, considering the first cell as differing from the (non-existing) "preceding" one. For example, given the sequence \$\mathrm A \mathrm B \mathrm A \mathrm A \mathrm B \mathrm B \mathrm C \mathrm C\$,
x[k] = A B A A A B B C C k = 1 2 3 4 5 6 7 8 9 r[k] = 1 2 3 3 3 4 4 5 5
Equivalently, \$r[k]\$ can be seen as an integer label for each run of equal values.
With this definition, for any \$k = 1, \ldots, n\$ the \$k\$-th partial score \$S[k]\$ is obtained as:
\$S = 1\$.
For \$k \geq 2\$: \$S[k] = S[k-1] + u[k]\$, where:
a. \$u[k]\ = r[k]\$ if the current cell has the same value as the preceding one (\$x[k]=x[k-1]\$).
b. \$u[k]\ = r[k] + k - 1\$ if the current cell has a different value from the preceding one (\$x[k] \neq x[k-1]\$).
Equivalently, each cell's contribution to the score is the label of the run it belongs to (\$r[k]\$), plus the \$0\$-based cell index (\$k-1\$) if the cell starts a new run.
Observe that this computation satisfies the stated features that the score increases if the sequence is "longer" or "more complicated", where "complicated" is defined by comparing each cell with the preceding one.
Given a sequence \$x\$ of length \$n \geq 1\$, output its \$n\$ partial scores \$S, \ldots, S[k]\$.
The letters \$\mathrm A, \ldots, \mathrm E\$ can be replaced by other characters of your choice. The input can be a string, a list or array of characters or numbers, or any similar structure. There have to be \$5\$ distinct elements available to represent the original colours of the game.
Code golf. Shortest answer in bytes wins.
A -> 1 ABA -> 1 4 9 DDDD -> 1 2 3 4 AABAA -> 1 2 6 12 15 CABAC -> 1 4 9 16 25 EBBBE -> 1 4 6 8 15 DEBBBE -> 1 4 9 12 15 24 CCAABBA -> 1 2 6 8 15 18 28 AABCDEEA -> 1 2 6 12 20 30 35 48 CCAAAAABB -> 1 2 6 8 10 12 14 24 27 DCCAAAAABB -> 1 4 6 12 15 18 21 24 36 40 EDEADDCEEBB -> 1 4 9 16 25 30 42 56 63 80 88 BBCAADDAACBB -> 1 2 6 12 15 24 28 40 45 60 77 84 BBAACDDCAABB -> 1 2 6 8 15 24 28 40 54 60 77 84