C Report Final
C Report Final
K. L. E. SOCIETY’S
K. L. E. INSTITUTE OF
TECHNOLOGY,
Opp. Airport, Gokul, Hubballi-580 027
Phone: 0836-2232681 Website: www.kleit.ac.in
Submitted By
Ms. Aparna N H
(2KE22CS024)
Ms. Bhagyashree A
(2KE22CS030)
Ms. Chandrika K
(2KE22CS036)
Ms. Deepa G T
(2KE22CS043)
TECHNOLOGY,
Opp. Airport, Gokul, Hubballi-580 027
Phone: 0836-2232681 Website: www.kleit.ac.in
CERTIFICATE
Certified that the mini project work entitled” Tic Tac Toe” is a bonafide work carried
out by Ms. Aparna N H, bearing USN 2KE22CS024, Ms. Bhagyashree A, bearing USN
2KE22CS030, Ms. Chandrika K, bearing USN 2KE22CS036, Ms. Deepa G T, bearing USN
2KE22CS043 in partial fulfillment for the award of degree of Bachelor of Engineering in
Semester, Computer Science and Engineering of Visvesvaraya Technological
University, Belagavi, during the year 2022-23. It is certified that all corrections/suggestions
indicated for internal assessment have been incorporated in the report deposited in the
department library.
2
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
ACKNOWLEDGEMENT
The mini project report on “Tic Tac Toe” is the outcome of guidance, moral support and
devotion bestowed on us throughout our work. For this we acknowledge and express our
profound sense of gratitude and thanks to everybody who have been a source of
inspiration during the project work.
First and foremost we offer our sincere phrases of thanks with innate humility to our
Principal Dr. Sharad G. Joshi who has been a constant source of support and
encouragement. We would like to thank our Dean Academics Dr. Manu T.M for his
constant support and guidance. We feel deeply indebted to our H.O.D. Dr. Yerriswamy
T. for the right help provided from the time of inception till date. We would take this
opportunity to acknowledge our Guide Prof. Mahantesh Sajjan, who not only stood by
us as a source of inspiration, but also dedicated his time for us to enable us to present the
project on time.
Last but not least, We would like to thank my parents, friends & well wishers who have
helped us in this work.
Aparna N H
Bhagyashree A
Chandrika K
Deepa G T
3
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
INTRODUCTION
1.1 Project overview:
Tic-Tac-Toe is a classic two-player game played on a 3x3 grid. The objective of the game
is to be the first player to form a horizontal, vertical, or diagonal line of their own symbol
(either "X" or "O") on the grid. Players take turns placing their symbols on the empty
cells of the grid until one player wins or the game ends in a draw.
2. *Displaying the Board*: You can create a function to display the current state of the
board by iterating through the array and printing the symbols in a grid format.
3. *Taking User Input*: Use the ` scanf ` function to take input from the players. They
will enter the row and column where they want to place their symbol.
4. *Validating Moves*: Check if the chosen cell is empty and falls within the valid range
(1-3) for both rows and columns.
5. *Checking for Win/Draw*: After each move, you'll need to check if the current player
has won the game or if the game has ended in a draw. Check for horizontal, vertical, and
diagonal lines of the same symbol.
6. *Switching Players*: After each move, switch the current player to the other player's
symbol ("X" to "O" or vice versa).
7. *Looping the Game*: Use a loop to keep the game running until there's a winner or
the game ends in a draw. Break the loop and display the result when the game is over.
8. *Additional buzzer*:With the help of the buzzer we can enhance the game tic tac toe,
When winner is declared the buzzer is activated.
9. *Final Touches*: You can add extra features like displaying the winner's name,
allowing players to restart the game, or improving the user interface.
4
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
One of the key features of C programming is its ability to provide low-level access to
memory and system resources. This makes it an excellent choice for writing systems
software, such as device drivers and operating systems. Additionally, C programming is
highly efficient and can be used to write high-performance applications.
Some of the important concepts in C programming include variables, data types, control
structures (such as if-else statements and loops), functions, and arrays. C also supports
pointers, which allow direct manipulation of memory addresses.
5
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
3. System Software: Many system software components, such as device drivers, network
protocols, and file systems, are implemented using C due to its low-level capabilities.
6. Web Development: C programming can also be used for server-side web development
using frameworks like CGI
6
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
7
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
1.4.B Algorithm:
8
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
2.project definition:
2.1 purpose and scope:
*Purpose: *
The purpose of creating a Tic Tac Toe game using a C programming language is
multifaceted. It serves as an excellent learning tool, an introduction to programming
concepts, and a practical application of logic and decision-making. The primary purposes
are:
1. *Educational Tool: * Tic Tac Toe provides a simple yet comprehensive environment
for beginners to understand and practice programming concepts such as arrays, loops,
conditionals, and functions. It offers an engaging way to introduce programming to
newcomers.
2. *Problem Solving: * Developing a Tic Tac Toe game involves tackling challenges like
user input validation, win-detection algorithms, and managing game states. These
challenges foster problem-solving skills and logical thinking.
*Scope: *
1. *Basic Gameplay: * The primary focus is on creating a functional Tic Tac Toe game
where two players can take turns and place their symbols ('X' and 'O') on the grid.
2. *Game Logic: * Implementing the core game logic, including checking for a win or a
draw, ensures a complete gaming experience.
9
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
3. *User Interaction: * The game provides a basic user interface for players to input their
moves and see the state of the game board.
4. *Limited Error Handling: * The scope includes basic input validation to ensure players
select valid moves. For example, preventing players from selecting an already occupied
cell.
5. *Single-Device Gameplay: * The game is designed for local multiplayer, where both
players interact with the same device.
7. *Learning and Expansion: * The project encourages learners to experiment and expand
on their own. They can enhance the project by adding features like improved user
interfaces, AI opponents, and error handling.
10
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
3.Program Tracing
1.Initialize Board(): This function initializes the game board by populating the board
array with empty spaces (' '). It also prints out the cell numbers and a visual representation
of the empty board.
2.Show Board(int x, int y): This function displays the current state of the game board. It
prints the symbols ('X' or 'O') stored in the board array and draws the grid lines between
cells.
3.Update Board(int cell, char player Sign): This function updates the game board based
on the player's move. It calculates the row and column indices corresponding to the
selected cell number. If the cell is already filled, it prints an error message. Otherwise, it
updates the cell with the player's symbol and calls showBoard() to display the updated
board. It returns isValid, which indicates whether the move was valid or not.
4.Check Winner(char sg): This function checks if a player has won the game. It checks
for three-in-a-row matches in rows, columns, and diagonals. If a match is found, it returns
1, indicating a winner. Otherwise, it returns 0.
Play Tic Tac Toe(): This is the main function that controls the game flow. It alternates
between players' turns, takes input for cell selection, and checks for a win or draw
condition. It also calls the other functions as needed.
main(): This is the entry point of the program. It displays instructions, initializes the
game, and manages the game loop. Players can restart the game or exit.
Overall, the program uses a 2D array called board to represent the Tic Tac Toe grid and
implements various functions to handle different aspects of the game, from initialization
to checking for a winner or draw. The main() function ties everything together, allowing
players to interact with the game and control its flow.
11
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
4.Requirements:
Hardware Requirements:
1. Computer: Any standard desktop or laptop computer can run a Tic Tac Toe program.
2. Processor: A basic processor like Intel Core i3 or equivalent should be sufficient.
3. Memory (RAM): Minimum 4GB RAM should be enough.
4. Display: Any standard monitor or display will work fine.
Software Requirements:
1. Operating System: The Tic Tac Toe program can run on various operating systems,
such as Windows, macOS, or Linux.
2. Development Environment: You will need a suitable programming language and
development environment installed on your computer. Some common choices for
implementing Tic Tac Toe programs are Python, Java, C++, or C#.
3. Compiler/Interpreter: If you choose a compiled language like C++ or Java, you will
need a compatible compiler installed to compile the source code. Alternatively,
interpreted languages like Python or C# would require an compiler.
12
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
5.Implementation:
13
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
printf("\n\n\n");
}
isValid = 0;
}
return isValid;
}
return 1;
}
// There is no winner
return 0;
}
{
updationResult = updateBoard(cell, playerSign);
// if updation is possible
if (updationResult)
{
gameResult = checkWinner(playerSign);
// print the winner of the game
if (gameResult)
{
printf("\t * Player %d Won!! *\n", playerSign == 'X' ? 1 : 2);
}
playCount++;
}
}
else if (cell == -1)
{
printf("\n\tGame Terminated\n");
return;
}
else
{
printf("\nPlease Enter a valid cell value\n");
}
}
int main()
17
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
{
printf("--------- Tic Tac Toe ----------\n\n");
scanf("%c", &start);
if (start)
{
int userChoice = 1;
// restart the game
while (userChoice)
{
playTicTacToe();
printf("\n* Menu\n");
printf("\nPress 1 to Restart");
printf("\nPress 0 for Exit");
printf("\n\nChoice: ");
scanf("%d", &userChoice);
if (userChoice)
{
initializeBoard();
}
printf("\n");
}
18
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
}
printf("\n :: Thanks for playing Tic Tac Toe game! :: \n");
return 0;
}
Output:
* Instructions
Player 1 sign = X
Player 2 sign = O
To exit from game, Enter -1
1 | 2 | 3
----------------
4 | 5 | 6
----------------
7 | 8 | 9
Player 1 [ X ] : 1
X | |
----------------
| |
----------------
19
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
| |
Player 2 [ O ] : 4
X | |
----------------
O | |
----------------
| |
Player 1 [ X ] : 5
X | |
----------------
O | X |
----------------
| |
Player 2 [ O ] : 6
X | |
----------------
O | X | O
----------------
| |
20
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
Player 1 [ X ] : 9
X | |
----------------
O | X | O
----------------
| | X
* Player 1 Won!! *
* Menu
Press 1 to Restart
Press 0 for Exit
Choice: 0
21
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
6.Snapshots:
Here are a few snapshots of a tic-tac-toe game progressing from an empty board
to a won game:
Snapshot 1:
|X|
-----------
| |
-----------
| |
Snapshot 2:
|X|
-----------
|O|
-----------
| |
Snapshot 3:
X|X|
-----------
|O|
-----------
| |
22
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
Snapshot 4:
X|X|O
-----------
|O|
-----------
| |
Snapshot 5:
X|X|O
-----------
|O|
-----------
X| |
Snapshot 6:
X|X|O
-----------
O|O|
-----------
X| |
This snapshot shows a player X winning the game by forming a line of X's
horizontally.
23
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
7.Conclusion:
The conclusion of a C program for a tic-tac-toe game would typically involve printing
the final game board, determining the winner (if any), and displaying the appropriate
message. Additionally, you might want to offer the option to play again or exit the game.
If you have specific code or questions, feel free to share, and I can assist you further!
24
Department of CSE K.L.E.I.T Hubballi
Mini report on “Tic Tac Toe”
REFERENCES:
Certainly, here are three C programming books that you can use to learn and implement
a Tic Tac Toe program:
1. "C Programming Absolute Beginner's Guide (3rd Edition)" by Perry and Miller
This book is designed for beginners and covers the fundamentals of C programming. It
provides clear explanations and practical examples that will help you build the skills
needed to create a Tic Tac Toe program.
Remember, while these books may not have a specific chapter dedicated to a Tic Tac
Toe program, they will provide the necessary knowledge to implement the game using
C programming. Additionally, you might want to explore online tutorials and resources
to supplement your learning and get hands-on with creating the game.
25
Department of CSE K.L.E.I.T Hubballi