Hello,
I'm designing a C++ Program for a connect 4 game. I have the matrix set up, the test to determine if there is a winner, and now I need to design the computer to go against the player. This seems to be quite a challenge. First, I need to make it block if there are 3 in a row. So far, I can't even accomplish that....
I made a function, and it looks like this:
int computertest(char matrix[6][7])
{
int row,column,b;
b=9;
for (row=5;row>2;row--)
{
for(column=0;column<7;column++)
{
if (matrix[row][column]==matrix[row-1][column] && matrix[row][column]== matrix[row-2][column] && matrix[row][column]!='-' && matrix[row-3][column]=='-')
{
b=column;
return b;
}
This is only the first part of the program...
the '-'
is what I use to display my matrix. I put it '-' for blank spaces, so the player knows what space is open.
Now..when I test it...the computer can't seem to place an 'X' when there is a vertical threat (when there are 3 "O's" in a row vertically up)..the computer just blanks out and takes a very long time to respond.
Can anyone tell me what is wrong?
Also, can someone teach me how I could program a computer to "think"?...I looked it up on the internet and you're supposed to put "weights" on certain columns...like if there is a potential threat, then the computer puts something to counter it early on.