Dsa Re-1
Dsa Re-1
A PBL REPORT
on
TIC-TAC-TOE USING ARRAYS
Submitted in partial fulfillment of academic year requirement of 3th semester
Data Structure and Application (BCS304)
SUBMITTED BY
KAVANASHRI M USN:1SJ23CS067
MADHUSHREE P USN: ISJ23CS080
MALLIKA M USN:1SJ23CS084
PALLAVI CJ USN:1SJ23CS113
PALLAVI RS USN:1SJ23CS115
Carried out at
DSA Lab,
Dept of CSE,
SJCIT
CERTIFICATE
This is to certify that the project work entitled “DSA PBL title TIC-TAC-TOE” is a
bonafide work carried out by Ms. KAVANASHRI M (USN: 1SJ23CS067), Ms.
MADHUSHREE P(USN:1SJ23CS080), Ms. MALLIKA M(USN:1SJ23CS084), Ms.
PALLAVI CJ (USN:1SJ23CS113), Ms. PALLAVI RS (USN:1SJ23CS115) in partial
fulfilment for the award of Bachelor of Engineering in Computer Science and
Engineering of Visvesvaraya Technological University, Belagavi during the year
2024-2025. It is certified that all corrections/suggestions indicated for internal
assessment have been incorporated in the report. The project report has been approved
as it satisfies the academic requirements with respect to Third semester Data Structure
and Application (BCS304) project based learning report.
................................
......................................
Signature of Guide
Signature of HOD
Dr. Shrihari M R Dr. Manjunatha Kumar B H
Associative Professor
Dept. of CSE, SJCIT. Dean Academics, Professor & HOD
Dept. of CSE, SJCIT.
CONTENTS OF REPORT
1. Introduction 1
2. Objectives 2
3. Outcomes 3
4. Source Code 4-5
5. MCQ-Questions 6
6. Feedback 7-9
7. Photos 10
1
INTRODUCTION
The Tic Tac Toe game is a classic example of a simple yet engaging game that can be
implemented using arrays. The game's simplicity makes it an ideal candidate for
demonstrating the basics of array programming. In this project, we aim to implement a Tic
Tac Toe game using arrays, with the objective of understanding the concept of arrays and
their application in game development.
* Explain the basic rules of the game: two players take turns placing their marks (X or O)
on a 3x3 grid, aiming to get three of their marks in a row (horizontally, vertically, or
diagonally).
* Clearly state why arrays are an ideal data structure for representing the game board
* Explain: Arrays provide a structured and efficient way to store and access the state of
each cell on the grid.
* Example: You can use a 2D array (e.g., board [3][3]) where each element represents a
cell on the board.
*Examples:
2
OBJECTIVES
• To understand the concept of arrays in programming: Arrays are a fundamental data
structure in programming, and understanding how they work is essential for any
aspirin programmer.
• To implement a Tic Tac Toe game using arrays: By implementing a Tic Tac Toe
game using arrays, we can demonstrate our understanding of array concepts and
their application in game development.
• To test and debug the game: Testing and debugging are essential steps in the
software development process, and we aim to ensure that our game is free from
errors and functions as expected.
• List specific, measurable, achievable, relevant, and time-bound (SMART)
objectives.
• To be the first to make a straight line with either 'X' or 'O'. Game Board: The board
consists of a 3x3 matrix-like structure, having 9 small boxes. The computer: Since
it is a two-player game each player gets one chance alternatively. i.e; first player1
than
• Tic Tac Toe game is to be the first player to place three of their symbols in a row,
either horizontally, vertically, or diagonally. This is commonly referred to as getting
“three in a row” or creating a “winning line”. Once a player achieves this, they are
declared the winner of the game
3
OUTCOMES
1. A working Tic Tac Toe game implemented using arrays: We expect to develop a fully
functional Tic Tac Toe game that uses arrays to store game data.
* Google Form:
* Briefly explain the purpose of the Google Form (e.g., to assess understanding of game
concepts).
* Describe the types of questions included (MCQs) and their relevance to the project.
https://doccom/forms/d/17tZ2D2RQOE8F5j3RknhYUPfL_igSD2us16yL3exXMjU/edit -
responses
4
SOURCE CODE OF TIC-TAC-TOE USING ARRAYS
#include <stdio.h>
void initializeBoard() {
// Fill the board with empty spaces
{
for (int j = 0; j < 3; j++) {
board[i][j] = ' ';
}
}
}
void printBoard() {
// Print the Tic-Tac-Toe board
printf("\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf(" %c ", board[i][j]);
if (j < 2) printf("|");
}
printf("\n");
if (i < 2) printf("---|---|---\n");
}
printf("\n");
}
int isWinner() {
// Check for a winner in rows, columns, and diagonals
for (int i = 0; i < 3; i++) {
if (board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][0] != ' ')
return 1;
if (board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[0][i] != ' ')
return 1;
}
if (board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] != '
') return 1;
if (board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[0][2] != '
') return 1;
return 0;
}
int isBoardFull() {
// Check if the board is full
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (board[i][j] == ' ') return 0; // Empty space found
}
5
}
// No empty spaces, board is full
}
void switchPlayer() {
// Switch players
if (currentPlayer == 'X') currentPlayer = 'O';
void else currentPlayer = 'X';
}
playerMove() {
int row, col;
printf("Player %c, enter your move (row and column [0-2]): ", currentPlayer);
scanf("%d %d", &row, &col);
if (row < 0 || row > 2 || col < 0 || col > 2 || board[row][col] != ' ') {
printf("Invalid move, try again.\n");
playerMove();
} else {
board[row][col] = currentPlayer;
}
}
int main() {
currentPlayer = 'X'; // X starts the game
initializeBoard();
while (1) {
printBoard();
if (isWinner()) {
printBoard();
printf("Player %c wins!\n", currentPlayer);
break;
}
if (isBoardFull()) {
printBoard();
printf("It's a draw!\n");
break;
switchPlayer();
}
return 0;
}
6
MCQ-QUESTIONS
1.what are the two symbols commonly used in Tic-Tac-Toe.
A) A and B
B) X and O
C) 1 and 2
D) P and Q
ANSWER: B) X and O
2.In Tic-Tac-Toe, what is it called when neither player wins, and the board is full?
A) A draw
B) A win
C) A loss
D) A Retry
ANSWER: A) A draw
3.If a player marks the centre and two opposite corners, what type oof line do they form?
A) Vertical
B) Horizontal
C) Diagonal
D) Zigzag
ANSWER: C) Diagonal
A) `printf("Invalid move!\n");`
B) `printf("Player %c wins!\n", player);`
C) `player = (player == 'X')? 'O': 'X'; `
D) `printf("Game over!\n");
7
FEEDBACK
8
9
10
PHOTOS
11