Computers are great at repetitive tasks, and tic-tac-toe more often than not is very repetitive. Today’s problem is to make a Tic-Tac-Toe solver with or without an AI; to make things easy at first I’ll just make it play randomly.
- in the case of a draw, print an empty board and “Draw”
- in the case of a win, print out the completed board and who wins
- run until either player has 10 wins
Finding win conditions is the hardest part so far as the program has to watch each move and check for three matching pieces on each horizontal, vertical, and diagonal axis. Initially I’ll do the check manually after each move; it’d be much cooler for each piece to check for a win on its own by analyzing each adjacent piece. Mark that down for the second iteration and the AI for the third.
Today’s Problem of the Day is to implement an automated version of our favorite childhood game, tic-tac-toe. Your program can assign random moves for X and O or you can implement some AI to favor one over the other. When someone wins print out the board and who won. If the game is going to be a draw print out the board and print out that it will be a draw.
Based on these conditions your program should never print out a full board unless the final move is a game winning move. If a game is going to end in a draw just print out the board. The program should run until X or O has won 10 games.