You are on page 1of 20

Koneru Lakshmaiah Education Foundation

(Deemed to be University)

FRESHMAN ENGINEERING DEPARTMENT


A Project Based Lab Report

On

TIC TAC TOE GAME

SUBMITTED BY:

I.D NUMBER NAME

2200032093 P POOJITHA

2200032177 M MOURYA

2200033076 SAMI

UNDER THE GUIDANCE OF

DR . ARUMLLA NAGARAJU

Associate Professor

KL UNIVERSITY
Green fields, Vaddeswaram – 522 302
Guntur Dt., AP, India.

DEPARTMENT OF BASIC ENGINEERING SCIENCES-1

1
CERTIFICATE

This is to certify that the project based laboratory report entitled


“ TIC TAC TOE GAME” submitted by Ms.P POOJITHA bearing redg no.
2200032093, Mr. M MOURYA bearing Regd. No. 2200032177, Mr. SAMI ,the
Department of Basic Engineering Sciences-1, KL University in partial
fulfillment of the requirements for the completion of a project based Laboratory
in “DATA STRUCTURES ”course in I year B Tech 2 Semester, is a bonafide record
of the work carried out by him/her under my supervision during the academic
year 2022 – 2023.

PROJECT SUPERVISOR HEAD OF THE DEPARTMENT

DR. ARUMLLA NAGARAJU Dr.D.Haritha

2
ACKNOWLEDGEMENTS

It is great pleasure for me to express my gratitude to our honorable President


Sri. Koneru Satyanarayana, for giving the opportunity and platform with
facilities in accomplishing the project based laboratory report.

I express the sincere gratitude to our principal Dr. A. Jagadeesh for his
administration towards our academic growth.

I express sincere gratitude to HOD-BES-1Dr. D. Harithafor her leadership and


constant motivation provided in successful completion of our academic semester.
I record it as my privilege to deeply thank for providing us the efficient faculty
and facilities to make our ideas into reality.

I express my sincere thanks to our project supervisor Dr.S.Dora Babu sir for his
novel association of ideas, encouragement, appreciation and intellectual zeal
which motivated us to venture this project successfully.

Finally, it is pleased to acknowledge the indebtedness to all those who devoted


themselves directly or indirectly to make this project report success.

Reg.ID NAME

2200032093 P POOJITHA

2200032177 M MOURYA

2200033076 SAMI

3
ABSTRACT

There are lots of research methodologies which are arising to give the

fastest and correct result set. This paper mainly focuses on survey of the

ranking models and learning to rank technique for giving the effective and

efficient information retrieval. Learning to rank is flattering progressively

more trendy research area in machine learning. The problem of ranking

aims to encourage an ordering or inclination of relation among a set of

instances in the input space. Learning to rank for information retrieval has

gained a lot of interest in the recent years as ranking is the central problem

in many information retrieval applications, like document retrieval,

multimedia retrieval, text summarization, collaborative filtering, question

answering and online advertising machine translation etc. The

tremendously large size of the web documents makes it usually

impracticable for the common users for finding their desired information

by surfing the net. As a result, effective and efficient information retrieval is

being more important and also search engine (information retrieval

system) has turned out to be a vital tool for people to locate their needed

information.

4
INDEX

S.NO TITLE PAGE NO

1 Introduction 6-7

2 Aim of the Project 8

2.1 Advantages & Disadvantages 9

2.2 Future Implementation 10

3 Software & Hardware Details 11

4 Algorithm 12-13

5 Flowchart 14

6 Implementation 15-19

7 Results and Screenshots 21-22

8 Conclusion 22

9 Reference 23

5
1. INTRODUCTION
People began to show interest in using their computers as a source of

entertainment in the 1970s, resulting in th emergence of a multibillion-

dollar game business. The origin is uncertain, though ancient Egyptians

claim to have discovered the Tic-Tac-Toe pattern etched on rocks around

3500 years ago. Later, they discovered how much fun it was to play a

game using this pattern. The game became popular after that, and it

could be played on a wooden board, a table, or even a piece of paper. Tic-

Tac Toe is a popular board game in which two players alternately place

X’s and O’s on a 3x3 grid. The players must first pick who would go first

and who will record his actions with an X. The game continues with the

opponents placing their marks on any unoccupied cell. The goal of the

game is for the first player to collect three marks ina row, which might be

vertical, horizontal, or diagonal. If all of the cells are filled, the game ends

in a tie. Using the C programming language, we created a two-person tic

tac toe game in which the player who forms a horizontal vertical, or

diagonal sequence of three marks wins. When a player is successful in

forming a vertical, diagonal or horizontal sequence of either X or 0, the

game declares the winner. The system has been designed in such

6
waythat the 3X3 grid will be displayed first along with the positions on

each square.

7
2 . AIM OF THE PROJECT
1. Teaches strategy skills.

Playing Tic-Tac-Toe may seem like a game of chance at first, but after

playing a few rounds, players usually notice that there’s a certain strategy

and pattern of movements that can end up in a win. Because of this, it

teaches players (both young and old) to start thinking strategically, which

can be highly beneficial in other areas of life too .

2. Develops logical thinking.

There’s a great deal of logic that can be applied to a game of Tic-Tac-Toe.

Simple moves that are quite logical are the ones that result in a win. This

can help people to start thinking about things differently; from a more

logical point of view.

8
2.1 ADVANTAGES :

1. The game usually takes less than a minute to play.If you are looking for a
game to while away a few hours of the afternoon or evening, Tic-Tac-Toe
might not be it. The game is quick and easy, which means that it usually
takes less than a minute for one of the players to win.

2. It can get boring knowing that you are going to win every single time If
you are an experienced Tic-Tac-Toe player, you probably (in fact, you do)
know precisely how to win. If you are playing against newbies to the game
or kids who haven’t had much experience with it, it can become a little
boring if you are winning round after round

2.1 DISADVANTAGES :

1.Predictable outcomes: With optimal play, Tic Tac Toe will always result in
a tie game. This means that once players have mastered the game, it may
become less interesting or exciting.

2.Lack of variety: Since there are only three possible moves (placing an "X",
placing an "O", or not making a move), Tic Tac Toe may become repetitive
for some players, especially if they are playing the game frequently. Lack of
social interaction: Tic Tac Toe is a two-player game, and playing it may not
provide the same level of social interaction or engagement as playing
games that involve larger groups of people.

9
2.2 FUTURE IMPLEMENTATION
Virtual Reality: One possible future implementation of Tic Tac Toe could be
in virtual reality. This would allow players to feel as though they are
actually playing the game in a three-dimensional environment, with the
game board and pieces appearing to be right in front of them. Artificial
Intelligence: Another potential future implementation of Tic Tac Toe could
involve the use of artificial intelligence. This would allow the game to
become much more challenging, as players could face off against a
computer opponent that is capable of adapting to their moves and learning
from its mistakes. Multiplayer Options: Tic Tac Toe could also benefit from
more multiplayer options, such as online play or local network play. This
would allow players to compete against others from all over the world,
which would be especially appealing to those who enjoy competitive
gaming.Customizable Game Boards: Another possible future
implementation of Tic Tac Toe could be customizable game boards. Players
could create their own game boards with unique designs, colors, and
shapes, making the game more personalized and enjoyable. Additional
Game Modes: Finally, additional game modes could be added to Tic Tac Toe
to make it more engaging and challenging. For example, a timed mode
could be added, where players have a limited amount of time to make their
moves, or a survival mode, where players have to win a certain number of
games in a row to progress to the next level

10
SOFTWARE REQUIRMENTS

The software requirements of the project are as follows:


Language : C
IDE : dev c+
Operating system: Windows Xp or later.

HARDWARE REQUIRMENTS
The hardware requirements of the project are as follows:

RAM : 8 Gb or More.

Processor :Intel i5 8th gen and higher (or)Ryzen 5 or higher.

11
4.ALGORITHM

STEP 1:

Initialize the Tic Tac Toe board: Create a 3x3 grid to represent the game
board. Each cell in the grid can be represented by a variable or array
element. Initialize each cell to be empty (e.g. " ").

STEP 2:

Display the board: Print the current state of the board to the console, so
that the players can see it. The board can be displayed as a grid with row
and column numbers.

STEP 3:

Assign symbols to each player: Decide which symbol (X or O) each player


will use. Typically, player 1 will use X and player 2 will use O. Display this
information to the players.

STEP 4:

Start the game: Set the starting player (usually player 1) and start the game
loop.

STEP 5:

Get the player's move: Prompt the current player to choose a cell to place
their symbol in. The player can select a cell by specifying the row and
column numbers.

12
STEP 6:

Validate the move: Check if the selected cell is empty and within the
boundaries of the game board. If the selected cell is invalid, prompt the
player to select a different cell.

STEP 7:

Update the board: If the player's move is valid, update the game board by
placing their symbol in the selected cell.

STEP 8:

Check for a win: After each move, check if the current player has won the
game. A player wins the game if they have three of their symbols in a row
(horizontally, vertically, or diagonally).

STEP 9:

Check for a tie: If there are no empty cells left on the board and no player
has won, the game is a tie.

STEP 10:

Switch players: After each move, switch to the next player's turn.

STEP 11:

Repeat steps 5-10 until the game ends: Continue the game loop until one
player wins or the game is a tie.

STEP 12: Display the result: Print the final state of the board and the
outcome of the game (win or tie).

13
5.FLOWCHART

14
6.CODE IMPLEMENATATION :

#include<stdio.h>

#include<stdlib.h>

char board[3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}}; //the board is a 3x3 grid with


numbers 1-9 to represent each cell

int movesLeft = 9; //keep track of how many moves are left, starting with 9

void displayBoard() {

printf("\n");

printf(" %c | %c | %c \n", board[0][0], board[0][1], board[0][2]);

printf("-----------\n");

printf(" %c | %c | %c \n", board[1][0], board[1][1], board[1][2]);

printf("-----------\n");

printf(" %c | %c | %c \n", board[2][0], board[2][1], board[2][2]);

int checkWin(char c) {

//check rows

for(int i=0; i<3; i++) {

if(board[i][0] == c && board[i][1] == c && board[i][2] == c) {

return 1;

//check columns

for(int i=0; i<3; i++) {

if(board[0][i] == c && board[1][i] == c && board[2][i] == c) {

15
return 1;

//check diagonals

if(board[0][0] == c && board[1][1] == c && board[2][2] == c) {

return 1;

if(board[0][2] == c && board[1][1] == c && board[2][0] == c) {

return 1;

return 0;

int makeMove(char c, int position) {

int row = (position-1) / 3;

int col = (position-1) % 3;

if(board[row][col] != 'X' && board[row][col] != 'O') {

board[row][col] = c;

movesLeft--;

return 1;

else {

printf("Invalid move. Please try again.\n");

return 0;

16
int computerMove() {

//check if the computer can win in the next move

for(int i=1; i<=9; i++) {

int row = (i-1) / 3;

int col = (i-1) % 3;

if(board[row][col] != 'X' && board[row][col] != 'O') {

board[row][col] = 'O';

if(checkWin('O')) {

movesLeft--;

return 1;

board[row][col] = i + '0';

//check if the player can win in the next move and block them

for(int i=1; i<=9; i++) {

int row = (i-1) / 3;

int col = (i-1) % 3;

if(board[row][col] != 'X' && board[row][col] != 'O') {

board[row][col] = 'X';

if(checkWin('X')) {

board[row][col] = 'O';

movesLeft--;

return 1;

board[row][col] = i + '0';

17
}

//make a random move

int position;

do {

position = rand() % 9 + 1;

int row = (position-1) / 3;

int col = (position-1) % 3;

if(board[row][col] != 'X' && board[row][col] != 'O') {

board[row][col] = 'O';

movesLeft--;

return 1;

} while(1);

int main() {

printf("Welcome to Tic-Tac-Toe!\n");

printf("You will be playing against the computer.\n");

printf("You are X, and the computer is O.\n");

printf("Here is the board. Each cell is numbered 1-9.\n");

displayBoard();

while(movesLeft > 0) {

//player move

int playerPosition;

do {

printf("Enter the number of the cell where you want to place your X: ");

scanf("%d", &playerPosition);

18
} while(!makeMove('X', playerPosition));

displayBoard();

if(checkWin('X')) {

printf("Congratulations, you won!\n");

return 0;

if(movesLeft == 0) {

printf("It's a draw.\n");

return 0;

//computer move

printf("The computer is making its move...\n");

if(computerMove()) {

displayBoard();

if(checkWin('O')) {

printf("Sorry, you lost.\n");

return 0;

if(movesLeft == 0) {

printf("It's a draw.\n");

return 0;

return 0;

19
20

You might also like