3

In the minimax algorithm, the first player plays optimally, which means it wants to maximise its score, and the second player tries to minimise the first player's chances of winning. Does this mean that the second player also plays optimally to win the game? Trying to choose some path in order to minimise the first player's chances of winning also means trying to win?

I am actually trying to solve this task from TopCoder: EllysCandyGame. I wonder whether we can apply the minimax algorithm here. That statement "both to play optimally" really confuses me and I would like some advice how to deal with this type of problems, if there is some general idea.

nbro
  • 15,395
  • 32
  • 113
  • 196
LearningMath
  • 851
  • 4
  • 15
  • 38

2 Answers2

2

Yes, you can use the minimax algorithm here.

The problem statement says that the winner of the game is "the girl who has more candies at the end of the game." So one reasonable scoring function you could use is the difference in the number of candies held by the first and second player.

Does this mean that the second player also plays optimally to win the game?

Yes. When you are evaluating a MIN level, the MIN player will always choose the path with the lowest score for the MAX player.

Note: both the MIN and MAX levels can be implemented with the same code, if you evaluate every node from the perspective of the player making the move in that round, and convert scores between levels. If the score is a difference in number of candies, you could simply negate it between levels.

Trying to choose some path in order to minimize the first player's chances of winning also means trying to win?

Yes. The second player is trying to minimize the first player's score. A reasonable scoring function will give the first player a lower score for a loss than a tie.

I wonder whether we can apply the minimax algorithm here.

Yes. If I've read the problem correctly, the number of levels will be equal to the number of boxes. If there's no limit on the number of boxes, you'll need to use an n-move lookahead, evaluating nodes in the minimax tree to a maximum depth.

Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
  • The number of boxes is between 1 and 10. Is there a mathematical proof that if MIN player tries to minimize MAX's score he is choosing his best strategy to win? – LearningMath Sep 29 '14 at 21:40
  • 1
    From the problem statement, both players play optimally, and the winner is the player with most candies. If there are only 10 boxes, we can evaluate the tree all the way to the leaf nodes representing the end of the game. If the scoring function is the final difference between player 1's candies and player 2's candies, then player 2 wins if the difference is negative. At any given game state, there are a finite number of choices, and there must be a minimum score among them. Either that minimum is negative or not. If <0, second player will win. If =0, tie. If >0, first player will win. – Andy Thomas Sep 29 '14 at 21:53
0

Properties of the game:

  • At each point, there are a limited, well defined number of moves (picking one of the non-empty boxes)
  • The game ends after a finite number of moves (when all boxes are empty)

As a result, the search tree consists of a finite number of leafs. You are right that by applying Minimax, you can find the best move.

Note that you only have to evaluate the game at the final positions (when there are no more moves left). At that point, there are only three results: The first player won, the second player won, or it is a draw.

Note that the standard Minimax algorithm has nothing to do with probabilities. The result of the Minimax algorithm determines the perfect play for both side (assuming that both sides make no mistakes).

By the way, if you need to improve the search algorithm, a safe and simple optimization is to apply Alpha Beta pruning.

Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
  • I know about alpha beta pruning, but my first problem was whether I could use the minimax algorithm. I got one more question: Is there a problem if the second player makes the last move in the game? Because we need the first player to make the last move(i think so) to start building the solution from the leaf nodes. – LearningMath Sep 29 '14 at 22:03
  • 1
    @J.M It does not make a difference, who moves last. The only assumptions is that each player has to choose the best move. So, if the game starts with the first player and the last move is made by the second player, your implementation has to guarantee that the last move will be the move that is worst for the first player (in other words, the score has to be minimized). – Philipp Claßen Sep 29 '14 at 22:16