0% found this document useful (0 votes)
19 views12 pages

Tictactoe (Main)

The document is a project report for a Tic Tac Toe game implemented in C language, submitted for a Bachelor of Technology degree at UCER. It outlines the game's objectives, tools used, testing methods, and provides a detailed code implementation along with explanations of various functions. Future enhancements suggested include adding a graphical user interface, AI for single-player mode, and support for larger grids.

Uploaded by

addieya837
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views12 pages

Tictactoe (Main)

The document is a project report for a Tic Tac Toe game implemented in C language, submitted for a Bachelor of Technology degree at UCER. It outlines the game's objectives, tools used, testing methods, and provides a detailed code implementation along with explanations of various functions. Future enhancements suggested include adding a graphical user interface, AI for single-player mode, and support for larger grids.

Uploaded by

addieya837
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Project Report

Tic Tac Toe Game in C Language


A Mini Project Report Submitted To UCER
For the degree of
Bachelor Of Technology

Guided By: Mr. Bhanu Pratap Rai


Designation: Professor at UCER

Submitted By: Adarsh Kumar Yadav


Anurag Gupta
Anurag Kumar Chaurasia
Saumitra Singh
Table of Contents:
1.Abstract
Tic-tac-toe, noughts and crosses, or Xs and
Os is a paper-and-pencil game for two
players who take turns marking the spaces
in a three-by-three grid with X or O. The
player who succeeds in placing three of
their marks in a horizontal, vertical, or
diagonal row is the winner. It is a solved
game, with a forced draw assuming best
play from both players.
2.Introduction

 Tic Tac Toe is a classic two-player


game played on a 3x3 grid, where
players take turns marking a square
with their respective symbols (X or
O). The objective is to be the first to
get three of your symbols in a row,
either horizontally, vertically, or
diagonally. This project aims to
implement the game in the C
programming language, providing
both a console-based interface and
basic game logic.
3.Objectives:
· Design a simple console-based Tic Tac
Toe game.
· Implement game logic to determine
valid moves and winning conditions.
· Provide a user-friendly interface for
input and output.
· Enable replay functionality for
multiple games.

4. Tools and Technologies

 Programming Language: C
 Compiler: GCC or any C compiler
 IDE: Code::Blocks, Dev-C++, or any text
editor
5. Testing
The game was tested for various scenarios,
including:
 Valid moves.
 Invalid moves (out of bounds and
occupied spaces).
 Winning conditions for both players.
 Draw conditions.

6. Hardware & Software Requirements:

 Used: Visual Studio Code


on Windows 11 64-Bit
 Programming IDE
Language Used: C

6. Implementation
Program Structure
The program is structured into several
functions to handle various tasks:

 printBoard(): Displays the current


state of the board.
 checkWin(): Checks for a winning
condition.
 main(): The main function to drive
the game.

7. Code Implementation
Below is a simplified version of the Tic Tac Toe game code in C

Header Files

#include<stdio.h>

#include<conio.h>

* #include<stdio.h>:This includes the standard input-output library,which allows the program to use
function like printf and scanf.

* #include<conio.h>:This includes the console input-output library, which provides function like getch and
clrscr.

Function Declaration

void printBoard();

int checkWin();

void system();

* void printBoard();: Declares a function to print the Tic Tac Toe board.

* int checkWin();: Declares a function to check the game status(win, draw, or ongoing).
* void system();: Declares a function to excutes system commands (like clearing the screen).

Global Variables

char board[]={‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’};

* char board[]: An array representing the Tic Tac Toe board with initial from ‘0’ to ‘9’.

Main Function

void main(){

int player=1,input,status=-1;

printBoard();

* void main(): The main function where the program execution starts.

* int player=1: Initializes the player variable to 1 (Player 1 starts).

* int input,status=-1: Initializes input for player moves and status to -1(game ongoing).

* printBoard(); Call the function to print the initial board.

Game Loop

while (status==-1)

player=(player%2==0) ? 2 : 1,

char mark=(player==1) ? ‘X’ : ‘O’;

printf(“Please Enter Number For Players %d\n”,player);

scanf(“%d”,&input);

* while (status==-1): Continues the loop while the game is ongoing.

* player(player%2==0)?21;: Alternates between Player 1 and Player 2.

* char mark=(player==1)? 'X': '0';: Sets the mark to 'X' for Player 1 and 'O' for Player 2.

* printf("Please Enter Number For Player %d\n",player);: Prompts the player to enter number.

* scanf("%d",&input);: Reads the player's input.


Input Validation and Board Update

if(input<1 || input>9){

printf("invalid input");

board[input]=mark;

printBoard();

* if(input<1 || input>9): Checks if the input is valid (between 1 and 9).

* printf("invalid input");: Prints an error message for invalid input.

* board[input]=mark;:Updates the board with the player's mark.

* printBoard();: Prints the updated board.

Check Game Status

int result-checkWin();

if(result==1){

printf("Player %d is the Winner", player);

return;

}else if(result==0){

printf("draw");

return;}

player++;

* int result-checkwin();: Calls the function to check the game status.

* if(result==1): If the result is 1, the current player wins.

* printf("Player %d is the Winner", player);: Prints the winner message.

* return;: Ends the game.


* else if (result==0): If the result is 0, the game is a draw.

* printf("draw");: Prints the draw message.

* return;: Ends the game.

* player++;: Increments the player number for the next turn.

Print Board Function

void printBoard()

{system("cls");

printf("\n\n");

printf("=== TIC TAC TOE ===\n\n");

printf(" | | \n”);

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

printf(“____|_____|_____\n");

printf(" %c | %c | %c \n", board[4], board[5], board[6]);

printf(“____|_____|_____\n");

printf(" %c | %c | %c \n", board[7], board[8], board[9]);

printf(“____|_____|_____\n");

printf(“\n\n”);

* system("cls");: Clears the screen.

* printf("\n\n");: Prints new lines for spacing.

* printf("== TIC TAC TOE ===\n\n");: Prints the game title..

* The following printf statements print the Tic Tac Toe board with the current marks.

Check Win Function

int checkwin(){

if(board[1]==board[2] && board[2]==board[3]){

return 1;
}

if(board[1]==board[4] && board[4]==board[7]) {

return 1;

if(board[7]==board[8] && board[8]==board[9]{

return 1;

if(board[3]==board[6] && board[6]==board[9]){

return 1;

if(board[1]==board [5] && board [5]==board[9]){

return 1;

if(board[3 ]--board[5] && board[5]--board[7]){

return 1;

if(board[2]==board[5] && board[5]=board[8]){

return 1;

if(board[4]=-board[5] && board[5]=-board[6]){

return 1;

int count=0;

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

if(board[i]=='X' || board[1]-'0'){

count++;
}

if(count==9){

return 0;

return -1;

* This function checks all possible winning combinations.

* If any combination is met, it returns 1 (win).

* If all cells are filled and no winner, it returns 0 (draw).

* Otherwise, it returns-1 (game ongoing).

I hope this helps! Let me know if you have any questions or need further clarification.

8. Conclusion
FutureThe Tic Tac Toe game
implemented in C demonstrates
fundamental programming
concepts such as arrays, loops,
conditionals, and functions. It
serves as an excellent project for
beginners to understand game
development and basic C
programming.

9. Bibliography:
Google – For learning about the various functions used in the
project and researching about calculators
https://www.geeksforgeeks.org – For learning about the structure and
working of the code.

10. Future Enhancements


 Implement a graphical user interface
(GUI).
 Add AI for single-player mode.
 Enhance input validation.
 Support for larger grids (e.g., 4x4 or
5x5).

You might also like