Need to make a Four In A Row program, values in 2D array won't change...

So, I've gotten an assignment in class to make a Four In A Row game, but it won't work properly; The values of the board won't change, and as far as I can see it should be working.

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
#include <iostream>
using namespace std;
int p1=0,p2=0,turn=1,xturn=2,temp,go=0,col,total=0,width=7,height=6,x1=0,x2,x3,x4,y1=0,y2,y3,y4;
int FIAR[][7]={{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0}};
int check();
void board();
int main(){
 do{board();
 cin>>col;
 col--;
 if(col<0||col>6){		//Checks if the input is within the amount of columns
  cout<<"Your input is invalid, try again...\nSelect a column:\t";
  cin.ignore();
  cin.get();}
 else if(FIAR[col][5]==0){FIAR[col][5]==turn;}
 else if(FIAR[col][4]==0){FIAR[col][4]==turn;}
 else if(FIAR[col][3]==0){FIAR[col][3]==turn;}
 else if(FIAR[col][2]==0){FIAR[col][2]==turn;}
 else if(FIAR[col][1]==0){FIAR[col][1]==turn;}
 else if(FIAR[col][0]==0){FIAR[col][0]==turn;}
 else{cout<<"The column you've chosen is full, try again...\nSelect a column:\t";cin.ignore();cin.get();}
 temp=turn;
 turn=xturn;	//Switches variable 'turn' between 1 and 2
 xturn=temp;
 check();
 total++;
 if (go==0){
  if(p1==1||p2==1||total==42){
  go++;}}}while(go==0);
 if(go==1&&p1==1){
  cout<<"Game Over, Player 1 wins!";}
 if(go==1&&p2==1){
  cout<<"Game Over, Player 2 wins!";}
 if(go==1&&p1==0&&p2==0){
  cout<<"Game Over, It's a draw!";}
 return 0;
}
 
int check(){
 while(y1<5){while(x1<3){x2=x1+1;x2=x2+1;x3=x2+1;y2=y1+1;y3=y2+1;y4=y3+1;if(FIAR[x1][y1]==1&&FIAR[x2][y1]==1&&FIAR[x3][y1]==1&&FIAR[x4][y1]==1)p1++;x1++;}y1++;x1=0;}y1=0; //Row P1
 while(y1<2){while(x1<6){x2=x1+1;x2=x2+1;x3=x2+1;y2=y1+1;y3=y2+1;y4=y3+1;if(FIAR[x1][y1]==1&&FIAR[x1][y2]==1&&FIAR[x1][y3]==1&&FIAR[x1][y4]==1)p1++;x1++;}y1++;x1=0;}y1=0; //Column P1
 while(y1<2){while(x1<6){x2=x1+1;x2=x2+1;x3=x2+1;y2=y1+1;y3=y2+1;y4=y3+1;if(FIAR[x4][y1]==1&&FIAR[x3][y2]==1&&FIAR[x2][y3]==1&&FIAR[x1][y4]==1)p1++;x1++;}y1++;x1=0;}y1=0; //Diagonal 1 P1
 while(y1<2){while(x1<3){x2=x1+1;x2=x2+1;x3=x2+1;y2=y1+1;y3=y2+1;y4=y3+1;if(FIAR[x1][y1]==1&&FIAR[x2][y2]==1&&FIAR[x3][y3]==1&&FIAR[x4][y4]==1)p1++;x1++;}y1++;x1=0;}y1=0; //Diagonal 2 P1
 while(y1<5){while(x1<3){x2=x1+1;x2=x2+1;x3=x2+1;y2=y1+1;y3=y2+1;y4=y3+1;if(FIAR[x1][y1]==2&&FIAR[x2][y1]==2&&FIAR[x3][y1]==2&&FIAR[x4][y1]==2)p2++;x1++;}y1++;x1=0;}y1=0; //Row P2
 while(y1<2){while(x1<6){x2=x1+1;x2=x2+1;x3=x2+1;y2=y1+1;y3=y2+1;y4=y3+1;if(FIAR[x1][y1]==2&&FIAR[x1][y2]==2&&FIAR[x1][y3]==2&&FIAR[x1][y4]==2)p2++;x1++;}y1++;x1=0;}y1=0; //Column P2
 while(y1<2){while(x1<6){x2=x1+1;x2=x2+1;x3=x2+1;y2=y1+1;y3=y2+1;y4=y3+1;if(FIAR[x4][y1]==2&&FIAR[x3][y2]==2&&FIAR[x2][y3]==2&&FIAR[x1][y4]==2)p2++;x1++;}y1++;x1=0;}y1=0; //Diagonal 1 P2
 while(y1<2){while(x1<3){x2=x1+1;x2=x2+1;x3=x2+1;y2=y1+1;y3=y2+1;y4=y3+1;if(FIAR[x1][y1]==2&&FIAR[x2][y2]==2&&FIAR[x3][y3]==2&&FIAR[x4][y4]==2)p2++;x1++;}y1++;x1=0;}y1=0; //Diagonal 2 P2
}
 
void board(){
 system("cls");
 cout<<"\nFour In A Row\n\n";
 for(int y=0;y<height;++y){
  cout<<"\t";
  for(int x=0;x<width;++x){
   cout<<FIAR[x][y];
  }
  cout<<"\n";
 }
 cout<<"\nPlayer "<<turn<<"'s turn.\nSelect a column:\t";
}
It's very important to format your code nicely so that it can be read by others.

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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include <iostream>
using namespace std;
int p1 = 0, p2 = 0, turn = 1, xturn = 2, temp, go = 0, col, total = 0, width = 7, height = 6, x1 = 0, x2, x3, x4, y1 = 0, y2, y3, y4;
int FIAR[][7] = { 
	{ 0,0,0,0,0,0,0 },
	{ 0,0,0,0,0,0,0 },
	{ 0,0,0,0,0,0,0 },
	{ 0,0,0,0,0,0,0 },
	{ 0,0,0,0,0,0,0 },
	{ 0,0,0,0,0,0,0 } };
int check();
void board();
int main() {
	do {
		board();
		cin >> col;
		col--;
		if (col<0 || col>6) {		//Checks if the input is within the amount of columns
			cout << "Your input is invalid, try again...\nSelect a column:\t";
			cin.ignore();
			cin.get();
		}
		else if (FIAR[col][5] == 0) { 
			FIAR[col][5] == turn;
		}
		else if (FIAR[col][4] == 0) {
			FIAR[col][4] == turn;
		}
		else if (FIAR[col][3] == 0) { 
			FIAR[col][3] == turn; 
		}
		else if (FIAR[col][2] == 0) { 
			FIAR[col][2] == turn; 
		}
		else if (FIAR[col][1] == 0) { 
			FIAR[col][1] == turn; 
		}
		else if (FIAR[col][0] == 0) { 
			FIAR[col][0] == turn; 
		}
		else { 
			cout << "The column you've chosen is full, try again...\nSelect a column:\t";
			cin.ignore(); 
			cin.get(); 
		}
		temp = turn;
		turn = xturn;	//Switches variable 'turn' between 1 and 2
		xturn = temp;
		check();
		total++;
		if (go == 0) {
			if (p1 == 1 || p2 == 1 || total == 42) {
				go++;
			}
		}
	} while (go == 0);

	if (go == 1 && p1 == 1) {
		cout << "Game Over, Player 1 wins!";
	}
	if (go == 1 && p2 == 1) {
		cout << "Game Over, Player 2 wins!";
	}
	if (go == 1 && p1 == 0 && p2 == 0) {
		cout << "Game Over, It's a draw!";
	}
	return 0;
}

int check() {
	while (y1<5) {
		while (x1<3) {
			x2 = x1 + 1; 
			x2 = x2 + 1; 
			x3 = x2 + 1; 
			y2 = y1 + 1; 
			y3 = y2 + 1; 
			y4 = y3 + 1; 
			if (FIAR[x1][y1] == 1 && FIAR[x2][y1] == 1 && FIAR[x3][y1] == 1 && FIAR[x4][y1] == 1)
				p1++; 
			x1++; 
		}
		y1++; 
		x1 = 0; 
	}y1 = 0; //Row P1

	while (y1<2) {
		while (x1<6) { 
			x2 = x1 + 1;
			x2 = x2 + 1; 
			x3 = x2 + 1; 
			y2 = y1 + 1; 
			y3 = y2 + 1; 
			y4 = y3 + 1; 
			if (FIAR[x1][y1] == 1 && FIAR[x1][y2] == 1 && FIAR[x1][y3] == 1 && FIAR[x1][y4] == 1)
				p1++; 
			x1++; 
		}
		y1++; 
		x1 = 0; 
	}y1 = 0; //Column P1

	while (y1<2) { 
		while (x1<6) { 
			x2 = x1 + 1; 
			x2 = x2 + 1; 
			x3 = x2 + 1; 
			y2 = y1 + 1; 
			y3 = y2 + 1; 
			y4 = y3 + 1; 
			if (FIAR[x4][y1] == 1 && FIAR[x3][y2] == 1 && FIAR[x2][y3] == 1 && FIAR[x1][y4] == 1)
				p1++; 
			x1++; 
		}
		y1++;
		x1 = 0; 
	}
	y1 = 0; //Diagonal 1 P1

	while (y1<2) { 
		while (x1<3) { 
			x2 = x1 + 1; 
			x2 = x2 + 1; 
			x3 = x2 + 1; 
			y2 = y1 + 1; 
			y3 = y2 + 1; 
			y4 = y3 + 1; 
			if (FIAR[x1][y1] == 1 && FIAR[x2][y2] == 1 && FIAR[x3][y3] == 1 && FIAR[x4][y4] == 1)
				p1++; 
			x1++; 
		}
		y1++; 
		x1 = 0; 
	}
	y1 = 0; //Diagonal 2 P1

	while (y1<5) { 
		while (x1<3) { 
			x2 = x1 + 1; 
			x2 = x2 + 1; 
			x3 = x2 + 1; 
			y2 = y1 + 1; 
			y3 = y2 + 1; 
			y4 = y3 + 1; 
			if (FIAR[x1][y1] == 2 && FIAR[x2][y1] == 2 && FIAR[x3][y1] == 2 && FIAR[x4][y1] == 2)
				p2++; 
			x1++; 
		}
		y1++; 
		x1 = 0; 
	}
	y1 = 0; //Row P2

	while (y1<2) { 
		while (x1<6) { 
			x2 = x1 + 1; 
			x2 = x2 + 1; 
			x3 = x2 + 1; 
			y2 = y1 + 1; 
			y3 = y2 + 1; 
			y4 = y3 + 1; 
			if (FIAR[x1][y1] == 2 && FIAR[x1][y2] == 2 && FIAR[x1][y3] == 2 && FIAR[x1][y4] == 2)
				p2++; 
			x1++; 
		}
		y1++; 
		x1 = 0; 
	}
	y1 = 0; //Column P2

	while (y1<2) { 
		while (x1<6) { 
			x2 = x1 + 1; 
			x2 = x2 + 1; 
			x3 = x2 + 1; 
			y2 = y1 + 1; 
			y3 = y2 + 1; 
			y4 = y3 + 1; 
			if (FIAR[x4][y1] == 2 && FIAR[x3][y2] == 2 && FIAR[x2][y3] == 2 && FIAR[x1][y4] == 2)
				p2++; 
			x1++; 
		}
		y1++; 
		x1 = 0; 
	}
	y1 = 0; //Diagonal 1 P2

	while (y1<2) { 
		while (x1<3) { 
			x2 = x1 + 1; 
			x2 = x2 + 1; 
			x3 = x2 + 1; 
			y2 = y1 + 1; 
			y3 = y2 + 1; 
			y4 = y3 + 1; 
			if (FIAR[x1][y1] == 2 && FIAR[x2][y2] == 2 && FIAR[x3][y3] == 2 && FIAR[x4][y4] == 2)
				p2++; 
			x1++; 
		}
		y1++; 
		x1 = 0; 
	}
	y1 = 0; //Diagonal 2 P2
}

void board() {
	system("cls");
	cout << "\nFour In A Row\n\n";
	for (int y = 0; y<height; ++y) {
		cout << "\t";
		for (int x = 0; x<width; ++x) {
			cout << FIAR[x][y];
		}
		cout << "\n";
	}
	cout << "\nPlayer " << turn << "'s turn.\nSelect a column:\t";
}
Topic archived. No new replies allowed.