column dropping

Jan 20, 2019 at 11:21pm
Write a function called drop(char c, int col) that will "drop" char c into column #col
The board is 6 by 7.
Connect 4
This is what I have so far:

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
#include <iostream>
using namespace std;

// global variables
char board[6][7] ={};


//placeinto() places char x into col of b[][] array
void placeinto(char b[6][7], char x, int col){
   bool placed = false;
   for(int j = 5; j>=0 && !placed; j--){
       if(b[j][col] == '_') {
           b[j][col] = x;
           placed = true;
       }
   }
   return;
}
/*
//Checks horizontal wins 
bool hwin(){
	for(int r=0; r<6; r++){
		for (int c=0; c<7;c++){	
			if ((board [r][c] == 'X'||board [r][c] == 'O')&& 
			board[r][c] == board[r+1][c]&&
			board[r][c+1] == board[r+2][c]&&
			board[r][c+2] == board[r+3][c]&&
			board[r][c+3] == board[r+4][c]&&
			board[r][c+4] == board[r+5][c]&&
			board[r][c+5] == board[r+6][c]&&
			board[r][c+6] == board[r+7][c]&&
			)
				return true;
		}		
	}
	return false;
}

bool dwin(){
	for (int r=0; r<6; r++){
		for (int c=0; c<7;c++){	
			if((board [r][c] == 'X'||board [r][c] == 'O')&& 
			board 
}
*/

int drop(char c, int col){
	
}
int main() {
	
	cout<<"C O N N E C T 4"<<endl;
   // assigning '_'s
   for (int r=0; r<6; r++){
       for(int c=0; c<7;c++){
           board[r][c] = '_';
       }
   }
   
   //printing
   for(int i=0; i<6; i++){
       for(int j=0; j<7; j++)
           cout << board[i][j] <<" ";
       cout << endl;
   }
   for(int j=1; j<=7; j++)
       cout << j << " ";
}
Jan 21, 2019 at 2:44am
Interesting. If you have a question about it, just ask.
Jan 21, 2019 at 2:52am
Same topic as your previous three threads. Please don't start new threads unless they're about something completely different from your old ones.
Last edited on Jan 21, 2019 at 3:00am
Topic archived. No new replies allowed.