Win conditions for a connect-4 like game

后端 未结 3 1649
时光说笑
时光说笑 2021-01-06 16:48

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 wa

3条回答
  •  悲哀的现实
    2021-01-06 17:01

    I think this should work ; If any one point out the mistake, I would be happy to correct.

    for( int row = 0; row<8 ; ++row )
    {
        bool outerLoopBreakFlag = false ;
        for( int col=0 ; col<3; ++col )
        {
             // check for the winning conditions
             // i.e., board[row][col] == board[row][col+1] == board[row][col+2]
             //       board[row][col] == board[row+1][col] == board[row+2][col]
             //       if any one is satisfied, set the outerLoopBreakFlag to true
             else
                 break ;
        }
        if( outerLoopBreakFlag == true )
            break ;
    }              
    

提交回复
热议问题