Win conditions for a connect-4 like game

Posted by FrozenWasteland on Stack Overflow See other posts from Stack Overflow or by FrozenWasteland
Published on 2011-01-08T22:40:53Z Indexed on 2011/01/08 22:53 UTC
Read the original article Hit count: 122

Filed under:

I have an 5x10 array that is populated with random values 1-5. I want to be able to check when 3 numbers, either horizontally, or vertically, match. I can't figure out a way to do this without writing a ton of if statements.

Here is the code for the randomly populated array


int i;
int rowincrement = 10;
int row = 0;
int col = 5;
int board[10][5];
int randomnum = 5;


int main(int argc, char * argv[])
{
    srand(time(NULL));

    cout << "============\n";

    while(row < rowincrement)
    {

        for(i = 0; i < 5; i++)
        {
            board[row][col] = rand()%5 + 1; 
            cout << board[row][col] << " ";
        }
        cout << endl;
        cout << "============\n";
        row++;
    }
    cout << endl;
    return 0;
}

© Stack Overflow or respective owner

Related posts about c++