What is Tic Tac Toe?
Tic Tac Toe, also popularly known as X and 0’s is a two-player game. Generally, there is a 3 X 3
grid, in which players take turns to mark the spaces with their respective symbol i.e. ‘X’ or ‘0’.
The player that succeeds in placing three of their makes either in horizontal, vertical or in a
diagonal row, wins.
Here are some rules for the game:
The player with symbol ‘X’ goes first
Players alternate placing Xs and Os on the board until either
one player has three in a row, horizontally, vertically or diagonally; or
all nine squares are filled.
The player who can draw three Xs or three Os in a row wins.
If all nine squares are filled and none of the players have three in a row, the game is a draw.
Java Tutorial for creating a Tic Tac Toe
Follow these steps to create a Tic Tac Toe program in java. Today, we will create a simple Tic
Tac Toe program, without any GUI and can be played by two players. Please note that both the
players must be human.
1. Create a new Project
The very first step of creating our Tic Tac Toe game is to make a new project. Open your IDE (I
am using NetBeans) and create a new Java Project by the name TicTacToe. Inside our project, we
will create three Model package Model, View and Controller. It contain classes
[Link], [Link], [Link], [Link], [Link]. The [Link] class
will contain the main() method and will be used to run the code in [Link]. The other class
which will contain an object that will have the state of the board and methods to manipulate the
game.
1. Adding GUI:
This game will be more interactive if GUI is added to it, the symbols can be added to the by
just clicking on the matrices, which would be buttons if GUI is used.
2. Introduction of Artificial Intelligence
An option of playing against the computer (bot) can be added too. An algorithm can be
implemented for the bot based on actual rules a player uses to fill the Tic-Tac-Toe board.
This can pose a challenge to the user when playing.
3. User scores
Both computer and humann’s score are displyed for multiple time .