most basic and long tic tac toe game

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

#include<iostream> // my first EVER game 27/03/12
using namespace std;

int main() {


char a = '1';
char b = '2';
char c = '3';
char d = '4';
char e = '5';
char f = '6';
char g = '7';
char h = '8';
char i = '9';

bool gameover = false;
char move;
bool won = false;
int turn = 1;
int player;
char choice;

do { // loops until game is not over
    


char mark;
    
cout << a << " | " << b << " | " << c << endl; // the board
cout << "-----------" << endl;
cout << d << " | " << e << " | " << f << endl;
cout << "-----------" << endl;
cout << g << " | " << h << " | " << i << endl;



turn++; // turn = 2

if(turn % 2 == 0) { // if the turn is multiples of 2,then it'll be player 1.
mark = 'X';
player = 1;
}

else {
mark = 'O';
player = 2;
}

cin >> move;


if(move == '1' && a == '1') { // first check = if the player puts in 1.  Second check = if the space is available
a = mark;
}

else if(move == '2' && b == '2') {
b = mark;
}

else if(move == '3' && c == '3') {
c = mark;
}

else if(move == '4' && d == '4') {
d = mark;
}

else if(move == '5' && e == '5') {
e = mark;
}

else if(move == '6' && f == '6') {
f = mark;
}

else if(move == '7' && g == '7') {
g = mark;
}

else if(move == '8' && h == '8') {
h = mark;
}

else if(move == '9' && i == '9') {
i = mark;
}

else {

cout << "invalid move!" << endl; // if the spaces aren't available or player typed in invalid choice
}

if(a == mark && b == mark && c == mark) { // win conditions
won = true;
}

else if(a == mark && d == mark && g == mark) {
won = true;
}

else if(a == mark && e == mark && i == mark) {
won = true;
}

else if(d == mark && e == mark && f == mark) {
won = true;
}

else if (b == mark && e == mark && h == mark) {
won = true;
}

else if(c == mark && f == mark && i == mark) {
won = true;
}

else if(g == mark && e == mark && c == mark) {
won = true;
}

else if(g == mark && h == mark && i == mark) {
won = true;
}

else if (a != '1' && b != '2' && c != '3' && d != '4' && e != '5' && f != '6' && g != '7' && h != '8' && i != '9') {

won = false;  // if all the boxes are taken and there is no win condition,it's surely a draw.
gameover = true;
cout << "It's draw for both players!" << endl;

}



if (won == true) {
        
cout << "player " << player << " won!" << endl; // winner will surely have been the last player.
gameover = true; 


cout << a << " | " << b << " | " << c << endl;
cout << "-----------" << endl;
cout << d << " | " << e << " | " << f << endl;
cout << "-----------" << endl;
cout << g << " | " << h << " | " << i << endl; // the ending board.



}








}while(gameover == false); // the loop breaks if gameover is true :D





system("pause");
return 0;
}



the code is VERY long because I'm a beginner and there MIGHT be unecessary codes in there as well.three questions-

1.) How to make computer play against me.
2.) What can be improved.
3.) Basic feedbacks.

Thanks in advance.
Topic archived. No new replies allowed.