I really need help.

I need to write a connect 4 game against an AI using arrays and I really don't know what to do. I have spent hours on it and I can't figure it out

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
#include <iostream>
#include <cstdlib>
using namespace std;
const int ROWS = 6;

const int COLUMNS = 7;

char table[ROWS][COLUMNS];
int charplaced=0;
void initialize()
{

    for (int i=0; i<ROWS; i++)
    {

        for (int j=0; j<COLUMNS; j++)
            table[i][j] = ' ';
    }

}

void displayConfig()
{

    cout << endl;

    cout << "   1 2 3 4 5 6 7" ;

    for (int i=0; i<ROWS; i++)
    {

        cout << endl<<(ROWS-i) << ": " ;

        for (int j=0; j < COLUMNS; j++)
        {

            cout << table[i][j] << " ";

        }

    }
    cout << endl;
}
int userTurn(){
    int column1;
    cout<<"Where do you want to go?";
    cin>>column1;



	}
    int drop(int b, char player){
	if(b >=0 && b<= 6)
	{
		if(table[0][b] == ' '){
			int i;
			for(i = 0;table[i][b] == ' ';i++)
				if(i == 5){table[i][b] = player;
			return i;}
			i--;
			table[i][b] =player;
			return i;

		}
		else{
			return -1;
		}
}}
int computerTurn(){
 int column;{

        column = rand() % 6;

return column;

} }
int checkConfiguration(){
}
int checkRow1();
 int checkLeftDiagonal();
 int checkRightDiagonal();
        char checkRow(int i)
        {
                            string temp = "";
                for(int j=0; j<7 ; j++)
                    temp += table[i][j];

                //temp looks like "RR BBBB"
                if (temp.find("BBBB") != string::npos)
                    return 'B';
                if (temp.find("RRRR") != string::npos)
                    return 'R';

                return ' ';
        }
    int main(){

        initialize();

        displayConfig();
        do
        {
            userTurn();
            displayConfig();
            if (checkConfiguration() != 1)
                break;
            computerTurn();
            while (checkConfiguration() == 1);


            char table[6][7];



            initialize();

            displayConfig();



int i;
            checkRow(i);


int k;
           checkRow1(k)
            {
                //build a string
                string temp = "";
                for(int j=0; j<7 ; j++)
                    temp += table[k][j];

                //temp looks like "RR BBBB"
                if (temp.find("BBBB") != string::npos)
                    return USER_WINS;
                if (temp.find("RRRR") != string::npos)
                    return COMPUTER_WINS;

                return CONTINUE;
            }

            checkConfiguration():
                for(int row=0; row<6 ; row++)
            {
                int result = checkRow(row);
                if (result != CONTINUE)
                    return result;
            }
            for(int column=0; column<7 ; column++)
            {
                int result = checkColumn(column);
                if (result != CONTINUE)
                    return result;
            }


                    checkRightDiagonal(int i, int j)
                {
                    string temp = "";

                    while (i<6 && j<7)
                    {
                        temp += table[i][j];
                        i++;
                        j++;
                    }

                }
            checkLeftDiagonal(int i, int j)
            {
                string temp = "";

                while (i<6 && j>=0)
                {
                    temp += table[i][j];
                    i++;
                    j--;
                }

            }
        }
    }

closed account (G30GNwbp)
1.) This program does not compile; so you are not even at the step where you can see what logic problems you have.
2.) stop -- test each function individually to ensure they compile and return what you expect.
3.) When you have a problem with a specific function; either why it won't compile or why it is doing something other than what you expected--post that question.
4.) It is always best to break big problems into little ones first.
Last edited on
Topic archived. No new replies allowed.