Tic-Tac-Toe Game
Transcript: TIC-Tac-Toe Game Group Members: * Sadia Shakeel 15B-015-SE * Muhammad Haroon 15B-011-BS *Ameer Baig 15B-012-BS Tic-Tac-Toe Game in C Program Wait what? Tic-Tac-Toe game in C program ? Is it Possible? Yup It's Possible now! Because it's 21st Century generation But how? Come on let's know! ✳✱* Come on let's Play! do { printf("\nPlayer %d, please enter the number of the square " "where you want to place your %c: ", player,(player==1)?'X':'O'); scanf("%d", &choice); row = --choice/3; column = choice%3; }while(choice<0 || choice>9 || board [row][column]>'9'); board[row][column] = (player == 1) ? 'X' : 'O'; if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) || (board[0][2]==board[1][1] && board[0][2]==board[2][0])) winner = player; else for(line = 0; line <=2; line++) if((board[line][0]==board[line][1] && board[line][0]==board[line][2]) || (board[0][line]==board[1][line] && board[0][line]==board[2][line])) winner = player; } printf("\n\n"); printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]); printf("---|---|---\n"); printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]); printf("---|---|---\n"); printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]); if(winner==0){ printf("The game is a draw\n"); }else printf("Player %d has won\n", winner); getch(); } History OF Tic-Tac-Toe: Simplicity of tic-tac-toe, it is often used as a pedagogical tool for teaching the concepts of good sportsmanship The branch of artificial intelligence that deals with the searching of game trees. It is straightforward to write a computer program to play tic-tac-toe. There are 26,830 possible games up to rotations and reflections (the game tree complexity) on this space. USES: An early variation of tic-tac-toe was played in the Roman Empire Around the first century. It was called Terni Lapilli and instead of having any number of pieces, each player only had three. Feeling bored ? main() { int player = 0; int winner = 0; int choice = 0; int row = 0; int column = 0; int line = 0; char board [3][3] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'} }; int i=0; for ( i = 0; i<9 && winner==0; i++) { printf("\n\n"); printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]); printf("---|---|---\n"); printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]); printf("---|---|---\n"); printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]); player = i%2 + 1; OUTPUT BE LIKE THIS It's Easy to make Tic Tac Toe game in C program Initializing of 2D Array because Tic-Tac-Toe game contains Rows and Column and 2D array defines Rows and Columnns For loop Conditional If Else Statement Do While OPERATORS: Arithmetic (+,-,*,/,%) Relational (<,>,<=,>=,==,!=) Logical (&&,||,!) Bitwise (&,|) Assignment (=) Let's Implement the code :