Tic-tac-toe

 

As part of my final project for CS50, I created a tic-tac-toe game where the user can play against the computer. In addition to choosing whether to play as X or O, the user can choose which AI model the computer uses to play.

 

With all the computer AI models, the computer will first look for a winning move. If none is found, the computer will look for a move to block the user. If no winning and no blocking moves are found, the computer will use the selected AI model to choose the next move.

 

Computer AI Model Description
First Move Available With this AI, the computer plays in the first available cell, starting in the top left. Since it's easy to predict where the computer will play next, it's easy to beat this version.
Random Move With this AI, the computer plays in a random open cell. The computer's play is less predictable and a little more difficult to beat.
Minimax Optimized Move With this AI, the computer uses a minimax algorithm to find the optimal move. Since the computer is playing optimally, it should be impossible to beat the computer, with a tie being the best outcome for the user.
Trained on X Games With this AI, the computer has been "trained" by playing X simulated games. The computer uses the information it has "learned" to choose the next move. Depending on the value of X, this move may be more or less optimal. The user can also "train" the computer on X games to evaluate if the computer's gameplay changes. The user can then evaluate if the computer gets "smarter" with more simulated games.