I've always wanted to write a tic tac toe AI for years and finally I decided to get off my ass and do it: https://github.com/1f604/tictactoe-ai
The actual core algorithm took me only a few minutes to code up but the scoring function was the hard part. The given perfect play every first move leads to a draw so there's no reason to prefer any particular move. But if the opponent is imperfect then some moves are better than others, since some moves will get you into a state where you can still win if the enemy makes a mistake, while other moves will get you into a state where you cannot win no matter what. So my scoring function (win_probability) calculates this by assuming the opponent picks moves randomly (with a heuristic).
No comments:
Post a Comment