"Create Tik Tac Toe Game Using C" 1.Aims/Benefits of The Micro-Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

PART-A

“Create tik tac toe game using C”

1.Aims/Benefits of The Micro-Project:

 To know how to make tic tac toe game using c language.


 To get Information about C programming.
 Gain Knowledge about The structure of the C language.

2. Course Outcomes Addressed:


 Develop 'C' programs using a control structure.
 Develop 'C' programs using arrays and structuresc. Develop 'C' programs
using a control structure.

3. Proposed Methodology:

 First of all, we are going to collect all the information about the topic “
Create tik tac toe game Using C” WE are going to collect the
information through our workbooks, internet, reference book & also
taking guidance of our subject teacher. After collecting, a lot of raw data,
we are going to separate some main points with the help of subject
teacher.
 We will make a primary report of that collected information then check it
out by subject teacher. After correction, advice, reading. We will fare our
work and make final report with chart.
4. Action Plan: -

Sr.N Details Of Activity Planned Planne Name Of Responsible


o Start Date d Finish Team Members
Date

1 Discussion and
finalization of topic

2 Collect information
about topic

3 Discussion on topic

4 Implementation of
micro-project.

5 Create a pseudocode of
the micro project.

6 Report writing and


completion of project

7 Final submission of

micro-project

8 Seminar

5. Resources Required:

SR.No Name Of Specifications Qty. Remarks


Resource/Material

1 Tech 01 Used
knowledge
Books

2 Operating system. Windows. 01 Used

3 Software. MS office 01 Used

4 Browser . Chrome. 01 Used


6.Names of Team Members with Roll No: -

Roll No Name Of Member Signature of Teacher

45 Jadhav Sumil Sunil


46 Shinde Rohan Anil

47 Kore Anushka Prakash

48 Navale Shantanu Anil Mrs.H.G.Wani

Name and sign of teacher

PART-B
“Create tik tac toe game using C”
1.Rationale:
The goal of the game is for players to position their marks so that they make a
continuous line of three cells vertically, horizontally, or diagonally. An opponent can
prevent a win by blocking the completion of the.

2.Aims/ Benefits of The Micro-Project:


 To know how to make tic tac toe game using c language.
 To get Information about C programming.
 Gain Knowledge about The structure of the C language.

3.Course Outcome Achieved:


 Develop 'C' programs using a control structure.
 Develop 'C' programs using arrays and structures.
4.Literature Review:
Here is source code of the C program to play the Tic Tac Toe game. The C program
is successfully compiled and run.

/*
* C Program to Play the Tic Tac Toe Game
*/

#include <stdio.h>

// Globally declared 2D-array


char board[3][3];

// Function to initialize the game board


void initializeBoard()
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
board[i][j] = ' ';
}
}
int count = 1;
printf("\n\n\t ");
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
printf("%d", count++);
if (j < 2)
{
printf(" | ");
}
}
if (i < 2)
printf("\n\t----------------\n\t ");
}
printf("\n\n\n");
}

// Function shows the game board


void showBoard(int x, int y)
{
printf("\n\n\t ");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
printf("%c", board[i][j]);
if (j < 2)
{
printf(" | ");
}
}
if (i < 2)
printf("\n\t----------------\n\t ");
}
printf("\n\n\n");
}

// Function to update the game board


int updateBoard(int cell, char playerSign)
{
int row = (cell - 1) / 3;
int col = (cell - 1) % 3;
int isValid = 1;

// accessing already played cell number


if (board[row][col] != ' ')
{
printf("\nInvalid: Cell is already Filled!\n");
isValid = 0;
}

// valid cell position


else
{
board[row][col] = playerSign;
}
showBoard(row, col);

return isValid;
}

// Function to check the winner of the game


int checkWinner(char sg)
{
// check all rows
if (board[0][0] == sg && board[0][1] == sg && board[0][2] == sg ||
board[1][0] == sg && board[1][1] == sg && board[1][2] == sg ||
board[2][0] == sg && board[2][1] == sg && board[2][2] == sg)
{
return 1;
}
// check all columns
else if (board[0][0] == sg && board[1][0] == sg && board[2][0] == sg ||
board[0][1] == sg && board[1][1] == sg && board[2][1] == sg ||
board[0][2] == sg && board[1][2] == sg && board[2][2] == sg)
{
return 1;
}
// check both diagonals
else if (board[0][0] == sg && board[1][1] == sg && board[2][2] == sg ||
board[0][2] == sg && board[1][1] == sg && board[2][0] == sg)
{
return 1;
}

// There is no winner
return 0;
}

// Start your game from here


void playTicTacToe()
{
int gameResult = 0;
int cell = 0;
int playCount = 0;
int updationResult = 1;

char playerSign = ' ';

// start playing the game


while (!gameResult && playCount < 9)
{
if (playCount % 2 == 0)
{
// player 1
printf("\nPlayer 1 [ X ] : ");
playerSign = 'X';
}
else
{
// player 2
printf("\nPlayer 2 [ O ] : ");
playerSign = 'O';
}
scanf("%d", &cell);
if (cell > 0 && cell < 10)
{
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");
}
}

// no one won the game


if (!gameResult && playCount == 9)
{
printf("\n\t *** Draw... ***\n");
}
printf("\n\t --- Game Over --- \n");
}

int main()
{
printf("--------- Tic Tac Toe ----------\n\n");

printf("\n* Instructions \n\n");


printf("\tPlayer 1 sign = X\n");
printf("\tPlayer 2 sign = O");
printf("\n\tTo exit from game, Enter -1\n");

printf("\n\n* Cell Numbers on Board\n");


initializeBoard();

char start = ' ';


printf("\n> Press Enter to start...");

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");
}
}
printf("\n :: Thanks for playing Tic Tac Toe game! :: \n");
return 0;
}

Out put of the program.

--------- Tic Tac Toe ----------


 
 
* Instructions
 
Player 1 sign = X
Player 2 sign = O
To exit from the game, Enter -1
 
 
* Cell Numbers on Board
 
 
1 | 2 | 3
----------------
4 | 5 | 6
----------------
7 | 8 | 9
 
 
 
> Press Enter to start...
 
Player 1 [ X ] : 1
 
 
X | |
----------------
| |
----------------
| |
 
 
 
Player 2 [ O ] : 2
 
 
X | O |
----------------
| |
----------------
| |
 
 
 
Player 1 [ X ] : 5
 
 
X | O |
----------------
| X |
----------------
| |
 
 
 
Player 2 [ O ] : 6
 
 
X | O |
----------------
| X | O
----------------
| |
 
 
 
Player 1 [ X ] : 9
 
 
X | O |
----------------
| X | O
----------------
| | X
 
 
*** Player 1 Won!! ***
 
--- Game Over ---
 
* Menu
 
Press 1 to Restart
Press 0 for Exit
 
Choice: 0
 
 
:: Thanks for playing Tic Tac Toe game! ::
6.Actual Resources Used

Sr.No Name Of Specifications Qty. Remarks


Resource/Material

1 Books Reference book 01 Used

2 Operating system. Windows 01 Used

3 Software. MS office 01 Used

4 Browser . Chrome. 01 Used

7. Outputs of The Micro-Project:


Structure in C is a user-defined data type that allows us to keep a collection of
various data types. The struct keyword is utilized to define the structure. No memory
or storage space is assigned when a struct type is defined. We require to define
variables in order to assign the memory of a specific structure type and operate with
it.

8. Skill Developed / Learning Outcomes of This Micro Project:

These are the skill that develop by doing this micro-project:

 Ability of team work.


 Critical thinking and problem solve.
 Effective oral and written communication.

9. Applications of Micro-Project:

 Because of the simplicity of tic-tac-toe, it is often used as a


pedagogical tool for teaching the concepts of good sportsmanship
and the branch of artificial intelligence that deals with the
searching of game trees.c

You might also like