Tic Tac Toe Nabeegh Ahmed (19L-1098), Muhammad Hassan (19L-1011) Section 2B

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Tic Tac Toe

Nabeegh Ahmed (19L-1098), Muhammad Hassan(19L-1011)

Section 2B
Menu:
A menu has been implemented which lets the players select the option of either 3x3, 4x4 or 5x5
tic-tac-toe. A 2x4 DeMultiplexer is used for this purpose. The output (which would be either
3x3, 4x4 or 5x5) would help in determining which game-board is to be used among the 3. They
all are inverted by a NOT gate as the selection output is 0 in logic works.

The working of the menu is explained by the following table:

EN S0 S1 Game Mode

1 x x x

0 0 0 3x3

0 0 1 4x4

0 1 0 5x5
Binary Switches:
According to the game selected, the input will be taken from the binary switches. The switches
will be arranged so that there is no confusion in playing the game. For 3x3 tic-tac-toe, 9 switches
are used; similarly 16 and 25 switches are used for 4x4 and 5x5 respectively.

The arrangement for 3x3, 4x4 and 5x5 is shown as follows:

3x3

4x4
5x5

The naming of switches is as follows.

● The leftmost digit shows us the game number. For example, 3 for 3x3 etc.
● The digit(s) followed signify the input number. For example, 43 would mean as 3​rd​ input
of 4x4. 512 would mean 12​th​ input of 5x5.
● The inputs 17-25 of 5x5 are named directly after their corresponding decimal as they are
not common with other games. This will be explained further below.

Common Output:
To reduce the cost, the common inputs have been made a single one by the use of OR-gates so
that we do not need more than 50 flip flops. To further elaborate, 3x3, 4x4 and 5x5 have
common input that is of decimal 1. It has been named:

● 31 for 3x3
● 41 for 4x4
● 51 for 5x5

They all go in one 3 way OR gate and the output is named 1. As only one game is played at a
time, this reduces the cost of the circuit.

Further elaborating, 4x4 has input decimal 13 common with 5x5. There is no input 13 for 3x3 as
it ends at decimal 9. So in this case, the OR-gate is a two way gate and the inputs that go in are
413 and 513 and the output will be named 13.

As 17-25 are not common, they do not go to any OR-gate. An image is inserted below for
clarification.
Player Selection:
As it is important for the game to differentiate between the 2 players, we would use an
arrangement of XOR gates to select either player 1 or player 2.

The XOR combination will either output 1 or 0, and that would be the selection for player 1. A
NOT gate would be used to invert the output and that would be the selection for player 2. The
truth table of XOR gate is:

Input 1 Input 2 Output


0 0 0
0 1 1
1 0 1
1 1 0

XOR gates operate when either of the inputs is 1. When any input is turned to 1, the output
becomes 1. Similarly, on the next turn, the last XOR gate gets the same inputs and hence, the
output becomes 0(see table). In this way, the players can have alternate turns. On even turns,
player 1 would be active and on odd turns, player 2 would be active. A small section is inserted
from the circuit to further clarify things.

The circuit is further extended to input 25 on the same pattern in the implementation.

Storing Mechanism:
We need to permanently store the input from the user. D Flip-Flops are used for this purpose. For
a single input, a set of 2 D Flip-Flops are used with a common clock pulse which corresponds to
the decimal input e.g. 1, 2 etc.

The D input is player 1 for one D Flip-Flop and player 2 for the other Flip-Flop. Set is connected
to a switch that is always on. The reset is connected to the Reset switch. This reset switch resets
the games when pushed.
The following circuit would be needed 25 times for each input.

Working:
When input 1 is pressed, the flip flops get a trigger and whatever is the value of player1 or
player2 gets stored in the Flip-Flops.

As player1 is inverted to get player2, the Flip-Flops will always have opposite value stored in
them. This ensures that only one L.E.D is turned on at the game board. Both of them will not
turn on as one would always be 0.

L.E.D Logic:
As there are 3 different games, if we directly connect the output from the Flip-Flops to the LEDs
all corresponding L.E.D’s of 3x3, 4x4 and 5x5 will turn on. For solving this problem, the
selection from the menu will be used.

The output of Flip Flops will go to an AND gate along with the selection that is 3 x 3, 4x4 or
5x5. Hence, there would be different inputs to the LED's and all of them will not turn on. Only
the L.E.D of the selected game would turn on. Figures are attached to elaborate:
A1, B1 and C1 will go to the L.E.D 1 of 3x3, 4x4 and 5x5 game-boards. This idea is expanded to
each L.E.D of each game-board.

● 3x3 will have L.E.D’s corresponding to inputs A1-A9 for player 1 and A1’-A9’ for
player 2, expanding the logic explained above.
● 4x4 will have L.E.D’s corresponding to inputs B1-B16 for player 1 and B16’-B16’ for
player 2, expanding the logic explained above.
● 5x5 will have L.E.D’s corresponding to inputs C1-C25 for player 1 and C1’-C25’ for
player 2, expanding the logic explained above.

L.E.D Layout:
The outputs A (1-9), B (1-16) and C (1-25) along with the outputs A (1-9)’, B (1-16)’ and C
(1-25)’ will go to the inputs of their corresponding L.E.D’s on their corresponding game-boards
as inputs while a ground will be provided to each L.E.D.

The LEDs will be arranged in the same pattern in which the input switches were arranged. They
will help in tracking the process of the game. Two LEDs will be arranged side by side so that
player1 and player2 can be differentiated. The colors used are:

● Red for player 1


● Blue for player 2

In addition to this, three additional LEDs will be used which will turn on if any of the players has
won, or if the game ends in a draw. The colors used for these LEDs are:

● Green for the win of player 1


● Yellow for the win of player 2
● Black for a draw
The same logic is extended to 4x4 and 5x5 game-boards.

Winning Logic:
A game is won if a row/column is occupied by a single player. Similarly, if a complete diagonal
is also occupied by a player, the player wins. To implement the logic on N x N board, the input
to the rows are given as an input to a N-Way AND gate, Similarly, the input to each individual
column is given to a N- Way AND gate. In the same way, diagonals are also given as input to an
N-Way AND gate. The output of each AND gate is given to an OR gate. Hence even if one
condition is true, the output is 1. The output goes to the winning LED.

It is important to note that we would need 2 copies of the same circuit to check for both players 1
and player 2.

The example shown is of a 3x3 board and it can be extended to 4x4 and 5x5 boards.
Draw Logic:
The logic for a drawn game requires a NOR gate, OR gates and some AND gates. The NOR gate
checks if a player has already won or not. If both players have not won, it will output 1 otherwise
it would give 0. All LED inputs will be given as inputs to OR gates with corresponding inputs
from player 1 and player 2 going to the same OR gate. Hence, if either is 1, the output would be
1, indicating that the button has been pressed. This output will go to AND gates. All of the inputs
will be AND-ED and the output will go to the draw LED.

An example of draw logic of 3x3 boards is shown. This can be expanded to 4x4 and 5x5 boards
as well.
Reset:
A reset button is given to reset the game board. The game resets when the button is pushed. It is
advisable to turn off all input switches when Reset is 1. Push the reset back to 0 to play again.

*An important note would be that you need to turn off all the switches regardless of the
game you are playing. You need to make sure that all the input switches of all boards are at
0 before playing a game.

You might also like