![]() |
VOOZH | about |
Tic Tac Toe is a game that was popularly played on paper or pen using the board. This is a fun game played by people of all ages. But now the digital version is becoming popular to have fun on the same game with friends. In this article, we will learn to write a program that allows a person to play tic tac toe against the computer.
The working of tic tac toe game is same as traditional tic tac toe having following components:
Note: The program uses the algorithm discussed here to find the best possible move for the computer to make the game competitive.
Tic-Tac-Toe Choose a cell numbered from 1 to 9 as below and play 1 | 2 | 3 -------------- 4 | 5 | 6 -------------- 7 | 8 | 9 - - - - - - - - - - COMPUTER has put a O in cell 0 0 O | | -------------- | | -------------- | | Enter your move (1-9): 9 O | | -------------- | | -------------- | | X COMPUTER has put a O in cell 0 2 O | | O -------------- | | -------------- | | X Enter your move (1-9): 2 O | X | O -------------- | | -------------- | | X COMPUTER has put a O in cell 2 1 O | X | O -------------- | | -------------- | O | X Enter your move (1-9): 5 O | X | O -------------- | X | -------------- | O | X COMPUTER has put a O in cell 1 0 O | X | O -------------- O | X | -------------- | O | X Enter your move (1-9): 6 O | X | O -------------- O | X | X -------------- | O | X COMPUTER has put a O in cell 2 0 O | X | O -------------- O | X | X -------------- O | O | X COMPUTER has won
Overall, this program implements a simple single-player Tic tac Toe game with input validation, user interface, winning logic and the game continues until there is a winner or draw.
If you want to implement Tic-Tac-Toe using Java, and Javascript, refer to the articles: