Even coins game - rFronteddu/general_wiki GitHub Wiki

  • Consider a two-player coin game where each A and B gets the turn one by one.
  • There is a row of even number of coins
  • a player on his/her turn can pick a coin from any of the two corners of the row.
  • The player that collects coins with more value wins the game.

Develop a strategy for the player making the first turn i.e, Player A, such that he/she never loses the game. Note that the strategy to pick a maximum of two corners may not work. In the following example, the first player, Player A loses the game when he/she uses a strategy to pick a maximum of two corners.

Solution

  • The idea is to count the sum of values of all even-placed coins and odd-placed coins, compare the two values.
  • The player that makes the first move can always make sure that the other player is never able to choose an even-placed coin if the sum of even-placed coins is higher.
  • Similarly, he can make sure that the other player is never able to choose an odd-placed coin if the sum of odd-placed coins is higher.

When EVEN = ODD, Player A should dynamically evaluate the potential outcomes of the first few moves and choose the highest immediate benefit while considering the opponent’s optimal responses.