Here's an implementation that pretty much does exactly that. If someone can beat this bot, lemme know: https://www.khanacademy.org/cs/in-tic-tac-toe-ception-perfec...
And here's James Irwin's original implementation, auto-set to a Monte-Carlo AI and with a rules variation that (to my knowledge) prevents Perfect Bot from winning. Play with the config variables at the top for some other AIs and 2-player games and whatnot. https://www.khanacademy.org/cs/in-tic-tac-toe-ception/167633...