con4lib.c
int check_status(const struct connect4 *game) {

    int dir,i,j;

    int DX[] = {0,1,1,1}; // cols
    int DY[] = {-1,-1,0,1}; // rows

    // Look in each possible direction.
    for (dir=0; dir<NUM_DIR; dir++) {

        // Try each starting spot.
        for (i=0; i<NUM_COLS; i++) {
            for (j=0; j<NUM_ROWS; j++) {

                // Calculate the corresponding ending point.
                int lastx = i + DX[dir]*(WIN_STREAK-1);
                int lasty = j + DY[dir]*(WIN_STREAK-1);

                // Not a possible streak.
                if (!inbounds(lastx, lasty)) continue;

                if (count_char(game, j, i, DY[dir], DX[dir], WIN_STREAK, PLAYERONE) == WIN_STREAK)
                    return X_WINS;
                if (count_char(game, j, i, DY[dir], DX[dir], WIN_STREAK, PLAYERTWO) == WIN_STREAK)
                    return O_WINS;
            }
        }
    }

    // See if there's an empty slot on the board.
    for (i=0; i<NUM_COLS; i++)
        if (game->board[NUM_ROWS-1][i] == EMPTY)
            return NOT_OVER;

    // If we get here, we have a CATS game.
    return CATS;

}
// Returns the current status of game.
Returns the current status of game.
Returns the current status of game .
int check_status(const struct connect4 *game) {
    int dir,i,j;
    int DX[] = {0,1,1,1}; 
    int DY[] = {-1,-1,0,1}; 
    for (dir=0; dir<NUM_DIR; dir++) {
        for (i=0; i<NUM_COLS; i++) {
            for (j=0; j<NUM_ROWS; j++) {
                int lastx = i + DX[dir]*(WIN_STREAK-1);
                int lasty = j + DY[dir]*(WIN_STREAK-1);
                if (!inbounds(lastx, lasty)) continue;
                if (count_char(game, j, i, DY[dir], DX[dir], WIN_STREAK, PLAYERONE) == WIN_STREAK)
                    return X_WINS;
                if (count_char(game, j, i, DY[dir], DX[dir], WIN_STREAK, PLAYERTWO) == WIN_STREAK)
                    return O_WINS;
            }
        }
    }
    for (i=0; i<NUM_COLS; i++)
        if (game->board[NUM_ROWS-1][i] == EMPTY)
            return NOT_OVER;
    return CATS;
}
int check_status ( const struct connect4 * game ) { int dir , i , j ; int DX [ ] = { 0 , 1 , 1 , 1 } ; int DY [ ] = { -1 , -1 , 0 , 1 } ; for ( dir = 0 ; dir < NUM_DIR ; dir ++ ) { for ( i = 0 ; i < NUM_COLS ; i ++ ) { for ( j = 0 ; j < NUM_ROWS ; j ++ ) { int lastx = i + DX [ dir ] * ( WIN_STREAK - 1 ) ; int lasty = j + DY [ dir ] * ( WIN_STREAK - 1 ) ; if ( ! inbounds ( lastx , lasty ) ) continue ; if ( count_char ( game , j , i , DY [ dir ] , DX [ dir ] , WIN_STREAK , PLAYERONE ) == WIN_STREAK ) return X_WINS ; if ( count_char ( game , j , i , DY [ dir ] , DX [ dir ] , WIN_STREAK , PLAYERTWO ) == WIN_STREAK ) return O_WINS ; } } } for ( i = 0 ; i < NUM_COLS ; i ++ ) if ( game -> board [ NUM_ROWS - 1 ] [ i ] == EMPTY ) return NOT_OVER ; return CATS ; }
Returns the current status of game.
Returns the current status of game .
// cols // rows // Look in each possible direction. // Try each starting spot. // Calculate the corresponding ending point. // Not a possible streak. // See if there's an empty slot on the board. // If we get here, we have a CATS game.