TIC TAC TOE
TIC TAC TOE
TIC TAC TOE
Achowledgment
Certificate
Abstract
Abstract
The calculator operates through a console-based interface where users can select from a menu
of operations. The application continuously prompts the user to input their choice of
operation and the required operands until the user decides to exit. Error handling is
incorporated to manage division by zero and invalid menu selections, ensuring the program's
robustness and reliability.
Interactive Menu: A clear and concise menu allows users to choose between
addition, subtraction, multiplication, and division.
Input Handling: Users can input two floating-point numbers and receive the result of
the selected arithmetic operation.
Error Management: Includes checks for invalid menu choices and division by zero,
providing appropriate feedback to users.
Continuous Operation: The calculator remains active, allowing multiple calculations
until the user opts to exit.
1. Introduction
Tic Tac Toe is a classic two-player game where players take turns marking a 3x3 grid with
either X or O. The objective is to align three of one's own marks in a row, column, or
diagonal. This document provides a detailed explanation of each module in the
implementation of Tic Tac Toe using the C programming language.
2. Project Structure
1. Main Module
2. Board Display Module
3. Player Input Module
4. Game Logic Module
5. Error Handling Module
Each module is essential for creating a functional Tic Tac Toe game. The following sections
provide a detailed explanation of each module.
3. Main Module
3.1 Overview
The Main Module is responsible for initializing the game, managing turns, and controlling
the game flow. It ties together all other modules and handles the overall game logic.
int main() {
char board[3][3];
initializeBoard(board);
if (gameStatus == 1) {
printf("Player %c wins!\n", currentPlayer);
} else if (gameStatus == 0) {
printf("It's a draw!\n");
}
displayBoard(board);
return 0;
}
3.3 Explanation
4.1 Overview
This module is responsible for displaying the game board to the players. It provides a visual
representation of the game state.
Board Layout: The board is printed row by row, with | separating columns and ---
separating rows.
Visual Structure: printf statements manage the layout to ensure the board is clearly
presented to the player.
5.1 Overview
This module handles input from the players. It ensures that the moves are valid and updates
the board accordingly.
while (1) {
scanf("%d %d", &row, &col);
if (row >= 0 && row < 3 && col >= 0 && col < 3 && board[row][col]
== ' ') {
board[row][col] = currentPlayer;
break;
} else {
printf("Invalid move. Try again: ");
}
}
}
5.3 Explanation
Input Handling: scanf is used to take input for row and column.
Validation: The while loop ensures the move is within bounds and the chosen cell is empty
before updating the board.
6.1 Overview
This module contains the core logic for determining the game state, including win conditions
and draw scenarios.
// Check diagonals
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;
}
6.3 Explanation
Win Conditions: Checks all rows, columns, and diagonals for three identical marks.
Draw Condition: Checks if all cells are filled and no winner is found.
7.1 Overview
This module handles any errors or invalid states that arise during gameplay, ensuring a
smooth user experience.
void handleInvalidMove() {
printf("Error: Invalid move. Try again.\n");
}
7.3 Explanation
Error Messages: Provides feedback to the user when an invalid move is made. This is a
placeholder function for more advanced error handling that could be implemented.
8.1 Integration
All modules are integrated into the main program. The main() function coordinates the game
flow, calling functions from each module as needed.
8.2 Testing
Input Validation: Ensuring the input is within bounds and the cell is empty.
Game Status Checking: Accurately determining win, loss, or draw conditions.
9.2 Solutions
Enhanced Input Handling: Added checks to validate and prompt for correct input.
Robust Game Logic: Thorough testing and validation of the game status checking logic.
10. Conclusion
10.1 Summary
The Tic Tac Toe project in C language is successfully implemented with key modules
handling different aspects of the game. Each module has been tested and integrated to create
a functional and interactive game.
11.1 Appendix
Full Code Listings: Include complete code files for all modules.
Technical Notes: Any additional notes or explanations relevant to the project.