If the number n
of coins is even, first player can guarantee himself the maximum of v1 + v3 + ... + v(n-1) and v2 + v4 + ... + vn. Figure out which is maximum, then take either v1 or vn. Thereafter, only take the coins that were originally in odd positions or even positions respectively. That is possible because no matter what second player does, a coin in both odd position and in even position are exposed when first player again moves.
Is that the best first player can do? First player can switch from "odds" to "evens" at any move, depending on whether the sum of the "new evens" is greater than or less than the sum of the "new odds". The strategy of the second player should then be to keep the incentive of switching as low as possible, which means picking the largest coin (first or last position). Might the resulting position still tempt first player to switch? Yes, as we see by the following game:
1 3 19 6 8 20
First player adds 1 + 19 + 8 = 28 and 3 + 6 + 20 = 29. He can guarantee a total score of at least 29 by picking evens, 20. The result is
1 3 19 6 8
To reduce the temptation of first player to switch from evens to odds and doing even better than a total score of 29, second player takes 8.
1 3 19 6
However, the temptation is still there. In fact, the sum of the odds position is 1 + 19 = 20, the sum of the evens only 3 + 6 = 9, so first player can do better now by switching to odds, and takes 1, even though 6 is greater.
3 19 6
The best second player can do is to pick 6, first player gets 19, second player gets 3. Total score: first player 20 + 1 + 19 = 40, second player 8 + 6 + 3 = 17.
It seems that first player can always get more than second player in this manner. However, we still don't know whether that is the optimal strategy for first player.
On the other hand, if the number of coins n is odd, the roles of first player and second player in the above analysis are essentially reversed.
Now the question becomes, are the greedy strategies outlined above truly optimal? We can check in specific cases by examining the binary decision tree where first player takes either the first or last coin, then second player takes first or last coin of remaining, etc. There will be 2^n
leaves in the tree; the score at each of those leaves can be calculated, then working back from leaves to root the value of each higher node can be calculated as either the max of the two children or min of the two children, depending on whose turn it is.
Instead of building the tree explicitly, it can be built implicitly by recursive function calls, which will save total memory required but will not save time.
If someone analyzes the game in this way and comes up with an optimal strategy different from mine, I would very much like to see it.