Search code examples
mathematical-optimizationtic-tac-toe

optimal win/tie percentage against random player


I'm made my own version of Tic-Tac-Toe in R based on specific hardcoded custom rules. After some optimization I am now unable to improve the play. I benchmarked the bot against a random player in the following ways:

  1. The bot must not lose a single game
  2. The bot starts 50% of all simulated games
  3. The opponent plays by randomly choosing any open square on it's turn

When benchmarked in 100,000 games my bot wins 94.95% of the time (meaning there are 5053 tie games). Breaking it down in games where it starts the win rate is 99.49% and when it goes second it's 90.42%.

I believe that for starting the game I have reached the optimum achievable (winning 191 out of 192 games). However, I am unsure about the case when going second. The question is: What is the best any bot can achieve given the three conditions outlined above? A found a couple of papers that show that with a lot of training algorithms achieve win rates in the high eighties, so clearly this works well--just not clear if it could be improved.


Solution

  • For closure, I believe I got the answer in a different forum:

    With the restriction I have given in the OP, the optimal winrate for the bot going first is 191 out of 192 games or 99.479% and for the random player going first it is 866 out of 945 games or 91.640%. Overall that means the optimal winrate should be 115589/120960 or 95.5597%.