Perfect play with minimax (Tic-Tac-Toe)
Make the computer unbeatable. Minimax looks at every possible continuation: a win for X scores +10, for O −10, a draw 0, and each move closer to the end makes a win worth 1 less (so faster wins are preferred and losses are delayed). X maximises, O minimises; among equally good moves take the first in reading order. Print <player plays <row <col - <X wins|O wins|draw with best play, or the status if the game is over.
Input: Three lines.
Output: One line.
Difficulty: Hard. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.
Hint
- Recursion: try each empty cell, recurse with the other player, undo.