Hey guys I wrote a connect four program in C++ but Im having trouble figuring out the issue with my algorithm for finding out the winning move diagonally. Here is the code that I wrote: My horizontal and vertical functions work though
//checks for a horizontal win
//returns 1 if there's a win
for(int i=0;i<numrows;i++)
for(int j=0;j<rowsize-3;j++)
if(board[i][j]!=" " && board[i][j]==board[i][j+1] && board[i][j]==board[i][j+2] && board[i][j]==board[i][j+3])
return 1;
//checks for a vertical win
//returns one if theres a win
for(int i=0;i<numrows-3;i++)
for(int j=0;j<rowsize;j++)
if(board[i][j] !=" " && board[i][j]==board[i+1][j] && board[i][j]==board[i+2][j] && board[i][j]==board[i+3][j])
return 1;
int numrows=6;
int rowsize=7;
//checks the right side of a diagonal for a win
for(int i=0;i<numrows;i++)
for(int j=0;j<rowsize;j++)
if(board[i][j] !=" " && board[i][j]==board[i+1][j+1] && board[i][j]==board[i+2][j+2] && board[i][j]==board[i+3][j+3])
return 1;
//checks left diagonal win for a win
for(int i=0;i<numrows;i++)
for(int j=0;j<rowsize;j++)
if(board[i][j] !=" " && board[i][j]==board[i+1][j-1] && board[i][j]==board[i+2][j-2] && board[i][j]==board[i+3][j-3])
return 1;
//creates a typical 7 by 6 connect four board
for (int i=0;i<numrows; i++){
vector<string> row;
for (int j=0;j<rowsize; j++)
row.push_back(" ");
board.push_back(row);
}