tic tac toe c 2b 2b

Solutions on MaxInterview for tic tac toe c 2b 2b by the best coders in the world

showing results for - "tic tac toe c 2b 2b"
Isabelle
18 Jan 2021
1#include<bits/stdc++.h>
2using namespace std;
3
4static char board[3][3] = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}}, ch1;
5string p1, p2;
6int r, c;
7int alt = 0;
8
9void boardReset(){
10    for(int i = 0; i < 3; i++)
11        for(int j = 0; j < 3; j++)
12            board[i][j] = ' ';
13}
14
15void printBoard(){
16    system("cls");
17    for(int i = 0; i < 3; i++){
18        for(int j = 0; j < 3; j++){
19            if(j == 0)
20                cout << "\t\t\t";
21            cout << " " << board[i][j] << " ";
22            if(j != 2)
23                cout << "|";
24        }
25        cout << "\n";
26        if(i != 2)
27            cout << "\t\t\t-----------\n";
28    }
29}
30
31bool isWinner(char ch4){
32    return ((board[0][0] == ch4 && board[0][1] == ch4 && board[0][2] == ch4) ||
33     (board[1][0] == ch4 && board[1][1] == ch4 && board[1][2] == ch4) ||
34     (board[2][0] == ch4 && board[2][1] == ch4 && board[2][2] == ch4) ||
35     (board[0][0] == ch4 && board[1][0] == ch4 && board[2][0] == ch4) ||
36     (board[0][1] == ch4 && board[1][1] == ch4 && board[2][1] == ch4) ||
37     (board[0][2] == ch4 && board[1][2] == ch4 && board[2][2] == ch4) ||
38     (board[0][0] == ch4 && board[1][1] == ch4 && board[2][2] == ch4) ||
39     (board[0][2] == ch4 && board[1][1] == ch4 && board[2][0] == ch4));
40}
41
42bool Boardfull(){
43    for(int i = 0; i < 3; i++)
44        for(int j = 0; j < 3; j++)
45            if(board[i][j] == ' ')
46                return false;
47    return true;
48}
49
50void makeMove(char c1){
51    if(board[r-1][c-1] == ' ')
52        board[r-1][c-1] = c1;
53    else{
54        cout << "\nThis Position is Already Occupied!\n\n";
55        alt--;
56    }
57}
58
59void playGame(){
60    do{
61        if(alt % 2 == 0){
62            cout << endl << "\n" << p1 << "'s Turn\n";
63            ch1 = 'X';
64        }
65        else{
66            cout << endl << "\n" << p2 << "'s Turn\n";
67            ch1 = 'O';
68        }
69        while(1){
70            cout << "Enter Column No. you want to make move: ";
71            cin >> c;
72            if(c < 1 || c > 3)
73                cout << "Enter Coulmn in Range 1 to 3\n";
74            else
75                break;
76        }
77        while(1){
78            cout << "Enter Row No. you want to make move: ";
79            cin >> r;
80            if(r < 1 || r > 3)
81                cout << "Enter Row in Range 1 to 3\n";
82            else
83                break;
84        }
85        makeMove(ch1);
86        alt++;
87        printBoard();
88    }while(!isWinner(ch1) && !Boardfull());
89}
90
91int main(){
92    char ch;
93    system("cls");
94    do{
95        cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
96        cout << "\t\t\tWELCOME TO THE TIC-TAC-TOE GAME\n";
97        cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
98        cout << "\nEnter First Player's first Name: ";
99        cin >> p1;
100        cout << "Symbol Assigned to " << p1 << " is 'X'\n";
101        cout << "\nEnter Second Player's first Name: ";
102        cin >> p2;
103        cout << "Symbol Assigned to " << p2 << " is 'O'\n\n";
104        printBoard();
105        playGame();
106        cout << "\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
107        cout << "\t\t\t\tRESULT: ";
108        if(Boardfull() && !(isWinner('X') || isWinner('O')))
109            cout << "Game Tie!\n";
110        else if(alt % 2 == 0)
111            cout << p2 << " Wins!\n";
112        else
113            cout << p1 << " Wins!\n";
114        cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";
115        cout << "\nDo You Want to Play Again? (Y / N): ";
116        boardReset();
117        alt = 0;
118        cin >> ch;
119    }while(ch != 'n' && ch != 'N');
120}
121
queries leading to this page
making a tic tac toe game in c 2b 2btic tac toe game using c 2b 2btic tac toe codetica tac toe cpptic tac toe vs computer c 2b 2btic tac toe game c plus pluscan we build a tic tac toe in c 2b 2btic tac toe c 2b 2b gaddishow to make tic tac toe in c 2b 2b online idetic tack game codecreate a tic tac toe game in c 2b 2btic tac toe c 2b 2b programhow to build tic tac toe in c 2b 2bhow to create a tic tac toe board in c 2b 2btic tac toe algorithm c 2b 2btic tac toe c 2b 2b ooptic tac toe uml c 2b 2bmake tic tac toe in c 2b 2btic tac toe using c 2b 2b mini maxc 2b 2b tic tac toe aitic tac toe project cppc 2b 2b tic tac toe assignmentdesign tic tac toe gfgtic tac toe c 2b 2btic tac toe dynamic programmingc 2b 2b tic tac toe game controllercpp tic tac toe graphicstic tac toe cpptic tac toe game code in c 2b 2btic tac toe c 2b 2b using asteriskstic tac toe source code in cpptic tac toe pseudocodeprogramming logic for tic tac toetic tac toe in c 2b 2bhow to create tic tac toe in c 2b 2balgorithm for tic tac toe in c 2b 2btic tac toe c 2b 2b vs computertic tac toe code c 2b 2btic tac toe against computer c 2b 2bmetode game tic tac toe c 2b 2bc 2b 2b code for tic tac toetic tac toe gui c 2b 2btic tac toe game in c 2b 2b against computertic tac toe c 2b 2b full codetic tac toe pattern c 2b 2btic tac toe c 2b 2b using asterisktic tac toe in c 2b 2b codetic tac toe c 2b 2b code using classesc 2b 2b skills needed for tic tac toeis it easy to program a tic tac toecode for tic tac toe game in c 2b 2bc 2b 2b tic tac toe graphics hmake a tic tac toe game in c 2b 2btic tac toe using c 2b 2btic tac toe game c 2b 2bc 2b 2b tic tac toe codehow to make an tic tac toe with c 2b 2bhow to make tic tac toe in c 2b 2b tic tac toe win condition c 2b 2bc 2b 2b simple tic tac toe ainxn tic tac toe c 2b 2btic tac toe c 2b 2b source code3d tic tac toe c 2b 2bwriting a easy tic tac toe in c 2b 2btic tac toe algorithm in c 2b 2btic tac toe using cppcode of tic tac toe game in c 2b 2btic tac toe c 2b 2b code cheftic tac toe program in c 2b 2bc 2b 2b tic tac toec 2b 2b how to make tic tac toetic tac toe c 2b 2b program against computerc 2b 2b tic tac toe gametic tac toe using oop c 2b 2btic tac toe c 2b 2b tabletic tac toe game source code in c 2b 2btic tac toe c 2b 2b descriptiontic tac toe using c 2b 2b graphicstic tac toe c 2b 2b program with explanationbeginner c 2b 2b tic tac toetic tac toe game in c 2b 2btic tac toe game cpp tic tac toe in c 2b 2btoc tac toe c 2b 2btic tac toe game c 7b 2btic tac toe using c 2b 2btic tac toe c 2b 2b exampletic tac toe thptik tok game in c 2b 2b codetic tac toe in c 2b 2b using classesc 2b 2b tic tac toe vs computerhow to make a tic tac toe in c 2b 2btic tac toe c 2b 2b computer playerhow to make a tic tac toe game in c 2b 2b graphicstic tac toe c 2b 2b by jmnkitictactoe c c 2b 2btic tac toe c 2b 2b program 2 playertic tac toe in java using ctic tac toe ai c 2b 2btic toc cpp programtic tac toe game c 2b 2b programtic tac toe game using c 2b 2b with classestic tac toe game in c 2b 2b projectmaking tic tac toe in c 2b 2btic tac toe in c 2b 2b using loopstic tac toe 2b 2btic tac toe efficiency using stl c 2b 2b codetic tac toe c 2b 2b codec 2b 2b code for tic tac toe graphicstic tac toe game in cpptic tac toe c 2b 2bhow hard is it to create a tic tac toe game c 2b 2bhow to code tic tac toe in c 2b 2btic tac toe c 2b 2b