top of page

Tic Tac Toe Using Verilog

Tic-tac-toe is a classic game with a grid layout of nine cells. Two players, represented by X and O, fill one square with their symbol until one player wins or a draw is reached. A win is achieved when the player fills three adjacent cells in a particular combination with his/her symbol.

One of the project’s objectives was implementing a working tic tac toe game using Verlog language and simulating the code.

The Xlinix PlanAhead 14.6 program was used with the following configuration:

 

the design of Tic Tac Toe game

Top Level Design:

The block diagram shows the inputs and outputs of the data path and the control signals and status signals of the control unit.


The data path inputs are two 2-bit variables, row and column, to indicate the position of the chosen square, and a 1-bit player to indicate whose turn it is. Its outputs are four 1-bit variables. The ‘gameover’ signal indicates the end of the game, an error is caused by different cases and makes the game terminate, winner shows who won the game, and draw shows that neither player has won.

 

Data path Design:

The control unit has two status signals: the 1-bit player and the 9-bit mark that tells the control unit, which square might change its state. Four control signals are outputted from the control unit that goes into the data path. The enable signal is used for a decoder to locate the selected square. The 9-bit signals marked, owner, and error are used in the data path to determine the status of the game and if a player has won. A decoder is used in the design to mark the square that the player selects. The output of the decoder is a 9-bit array where the bits equal to one correspond to marked positions.


The playersError module was done to raise an error signal if the same player played twice sequentially, by comparing the previously stored player and current player values. The winner module is designed to determine the final state of the game. If any of the eight-win cases are found, the output signal winner will indicate who won the game, and IsGameOver will equal one. If all positions are marked and none of the win cases occur, the draw will be equal to one. Otherwise, IsGameOver is zero, and the game continues.


An OR gate is used to find if any error has occurred in the nine squares, and its output will enter an AND gate with the inverted IsGameOver. This AND is used to prevent ERR from rising when the game is over. Finally, ERR and IsGameOver enter an OR gate to indicate the end of the game after a win, draw, or an error occurs.

 

Control Unit Design:

The control unit represents each square in the game. In addition to a reset signal, the design has:


four states: S0, S1, S2, and S3

two inputs: mark, player; and

Three outputs: marked, owner, and error.


The first state, S0, indicates that the square is empty and has not been used yet. If reset was turned on, the control unit will go back to this state. If player ‘O’ marks the square (i.e. player equals zero and mark equals one), the system moves to state S1, which will output that the square has been marked and indicate which player marked it. On the other hand, if player ‘X’ marks the square (i.e. player and mark equal one), the system goes to S2 where the outputs indicate that the square is marked by this player. Finally, the control unit will go to S3 if either player attempted to mark an occupied square. This state will output error as well as indicate the marked status of the square.

 

Testing

The timing diagram shows the case where the player “X” wins the game after its third turn. The winner signal rises, indicating the player “X” has won the game as well as the gameover signal for indicating there is a winner and the game is over.


second output represents the output signals of the Tic Tac Toe module for the “draw” case. It shows that the draw signal rises to one after filling all the squares without one of the players won.

 

Finally I would like to THANK Eng, Haya Al-Sharif for pushing us outside the box and letting us learn through a unique learning method by giving us projects that run our minds to think critically.

The program is uploaded in GitHub page:

Done by: Nada Abughazalah, Sara Alabbasi, Ruba Bin Jabal, Ruaa A. Obeid.





Recent Posts
Archive
Search By Tags
bottom of page