old_db.c
int old_fast_check_status(const struct connect4 *game) {

    int i, j;

    // We go through each row, to look for a horizontal win.
    for (j = 0; j < NUM_ROWS; j++) {

        // We iterate through the possible column starting positions of four
        // consecutive winning pieces.
        for (i = 0; i < NUM_COLS - 3; i++) {

            if ((game->board[j][i] == PLAYERONE) && (game->board[j][i + 1] == PLAYERONE) &&
                (game->board[j][i + 2] == PLAYERONE) && (game->board[j][i + 3] == PLAYERONE))

                return X_WINS;

            else if ((game->board[j][i] == PLAYERTWO) && (game->board[j][i + 1] == PLAYERTWO) &&
                     (game->board[j][i + 2] == PLAYERTWO) && (game->board[j][i + 3] == PLAYERTWO))

                return O_WINS;
        }
    }

    // We go through each column, to look for a vertical win.
    for (j = 0; j < NUM_COLS; j++) {

        // We iterate through possible row starting positions of four
        // consecutive winning pieces.
        for (i = 0; i < NUM_ROWS - 3; i++) {

            if ((game->board[i][j] == PLAYERONE) && (game->board[i + 1][j] == PLAYERONE) &&
                (game->board[i + 2][j] == PLAYERONE) && (game->board[i + 3][j] == PLAYERONE))

                return X_WINS;

            else if ((game->board[i][j] == PLAYERTWO) && (game->board[i + 1][j] == PLAYERTWO) &&
                     (game->board[i + 2][j] == PLAYERTWO) && (game->board[i + 3][j] == PLAYERTWO))

                return O_WINS;
        }
    }

    // We start at the possible row positions for a "forward" diagonal.
    for (i = 0; i < NUM_ROWS - 3; i++) {

        // We start at the possible column positions.
        for (j = 0; j < NUM_COLS - 3; j++) {

            if ((game->board[i][j] == PLAYERONE) && (game->board[i + 1][j + 1] == PLAYERONE) &&
                (game->board[i + 2][j + 2] == PLAYERONE) && (game->board[i + 3][j + 3] == PLAYERONE))

                return X_WINS;

            else if ((game->board[i][j] == PLAYERTWO) && (game->board[i + 1][j + 1] == PLAYERTWO) &&
                     (game->board[i + 2][j + 2] == PLAYERTWO) && (game->board[i + 3][j + 3] == PLAYERTWO))

                return O_WINS;
        }
    }

    // We start at the possible row positions for a "backward" diagonal.
    for (i = 0; i < NUM_ROWS - 3; i++) {

        // Here are the possible column positions for a backwards diagonal.
        for (j = NUM_COLS - 1; j > 2; j--) {

            if ((game->board[i][j] == PLAYERONE) && (game->board[i + 1][j - 1] == PLAYERONE) &&
                (game->board[i + 2][j - 2] == PLAYERONE) && (game->board[i + 3][j - 3] == PLAYERONE))

                return X_WINS;

            else if ((game->board[i][j] == PLAYERTWO) && (game->board[i + 1][j - 1] == PLAYERTWO) &&
                     (game->board[i + 2][j - 2] == PLAYERTWO) && (game->board[i + 3][j - 3] == PLAYERTWO))

                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;
}
// The older and faster version of check_status from con4lib.h
// Credit to Arup Guha for this function
The older and faster version of check_status from con4lib.h
Credit to Arup Guha for this function
The older and faster version of check_status from con4lib . h Credit to Arup Guha for this function
int old_fast_check_status(const struct connect4 *game) {
    int i, j;
    for (j = 0; j < NUM_ROWS; j++) {
        for (i = 0; i < NUM_COLS - 3; i++) {
            if ((game->board[j][i] == PLAYERONE) && (game->board[j][i + 1] == PLAYERONE) &&
                (game->board[j][i + 2] == PLAYERONE) && (game->board[j][i + 3] == PLAYERONE))
                return X_WINS;
            else if ((game->board[j][i] == PLAYERTWO) && (game->board[j][i + 1] == PLAYERTWO) &&
                     (game->board[j][i + 2] == PLAYERTWO) && (game->board[j][i + 3] == PLAYERTWO))
                return O_WINS;
        }
    }
    for (j = 0; j < NUM_COLS; j++) {
        for (i = 0; i < NUM_ROWS - 3; i++) {
            if ((game->board[i][j] == PLAYERONE) && (game->board[i + 1][j] == PLAYERONE) &&
                (game->board[i + 2][j] == PLAYERONE) && (game->board[i + 3][j] == PLAYERONE))
                return X_WINS;
            else if ((game->board[i][j] == PLAYERTWO) && (game->board[i + 1][j] == PLAYERTWO) &&
                     (game->board[i + 2][j] == PLAYERTWO) && (game->board[i + 3][j] == PLAYERTWO))
                return O_WINS;
        }
    }
    for (i = 0; i < NUM_ROWS - 3; i++) {
        for (j = 0; j < NUM_COLS - 3; j++) {
            if ((game->board[i][j] == PLAYERONE) && (game->board[i + 1][j + 1] == PLAYERONE) &&
                (game->board[i + 2][j + 2] == PLAYERONE) && (game->board[i + 3][j + 3] == PLAYERONE))
                return X_WINS;
            else if ((game->board[i][j] == PLAYERTWO) && (game->board[i + 1][j + 1] == PLAYERTWO) &&
                     (game->board[i + 2][j + 2] == PLAYERTWO) && (game->board[i + 3][j + 3] == PLAYERTWO))
                return O_WINS;
        }
    }
    for (i = 0; i < NUM_ROWS - 3; i++) {
        for (j = NUM_COLS - 1; j > 2; j--) {
            if ((game->board[i][j] == PLAYERONE) && (game->board[i + 1][j - 1] == PLAYERONE) &&
                (game->board[i + 2][j - 2] == PLAYERONE) && (game->board[i + 3][j - 3] == PLAYERONE))
                return X_WINS;
            else if ((game->board[i][j] == PLAYERTWO) && (game->board[i + 1][j - 1] == PLAYERTWO) &&
                     (game->board[i + 2][j - 2] == PLAYERTWO) && (game->board[i + 3][j - 3] == PLAYERTWO))
                return O_WINS;
        }
    }
    for (i = 0; i < NUM_COLS; i++)
        if (game->board[NUM_ROWS - 1][i] == EMPTY)
            return NOT_OVER;
    return CATS;
}
int old_fast_check_status ( const struct connect4 * game ) { int i , j ; for ( j = 0 ; j < NUM_ROWS ; j ++ ) { for ( i = 0 ; i < NUM_COLS - 3 ; i ++ ) { if ( ( game -> board [ j ] [ i ] == PLAYERONE ) && ( game -> board [ j ] [ i + 1 ] == PLAYERONE ) && ( game -> board [ j ] [ i + 2 ] == PLAYERONE ) && ( game -> board [ j ] [ i + 3 ] == PLAYERONE ) ) return X_WINS ; else if ( ( game -> board [ j ] [ i ] == PLAYERTWO ) && ( game -> board [ j ] [ i + 1 ] == PLAYERTWO ) && ( game -> board [ j ] [ i + 2 ] == PLAYERTWO ) && ( game -> board [ j ] [ i + 3 ] == PLAYERTWO ) ) return O_WINS ; } } for ( j = 0 ; j < NUM_COLS ; j ++ ) { for ( i = 0 ; i < NUM_ROWS - 3 ; i ++ ) { if ( ( game -> board [ i ] [ j ] == PLAYERONE ) && ( game -> board [ i + 1 ] [ j ] == PLAYERONE ) && ( game -> board [ i + 2 ] [ j ] == PLAYERONE ) && ( game -> board [ i + 3 ] [ j ] == PLAYERONE ) ) return X_WINS ; else if ( ( game -> board [ i ] [ j ] == PLAYERTWO ) && ( game -> board [ i + 1 ] [ j ] == PLAYERTWO ) && ( game -> board [ i + 2 ] [ j ] == PLAYERTWO ) && ( game -> board [ i + 3 ] [ j ] == PLAYERTWO ) ) return O_WINS ; } } for ( i = 0 ; i < NUM_ROWS - 3 ; i ++ ) { for ( j = 0 ; j < NUM_COLS - 3 ; j ++ ) { if ( ( game -> board [ i ] [ j ] == PLAYERONE ) && ( game -> board [ i + 1 ] [ j + 1 ] == PLAYERONE ) && ( game -> board [ i + 2 ] [ j + 2 ] == PLAYERONE ) && ( game -> board [ i + 3 ] [ j + 3 ] == PLAYERONE ) ) return X_WINS ; else if ( ( game -> board [ i ] [ j ] == PLAYERTWO ) && ( game -> board [ i + 1 ] [ j + 1 ] == PLAYERTWO ) && ( game -> board [ i + 2 ] [ j + 2 ] == PLAYERTWO ) && ( game -> board [ i + 3 ] [ j + 3 ] == PLAYERTWO ) ) return O_WINS ; } } for ( i = 0 ; i < NUM_ROWS - 3 ; i ++ ) { for ( j = NUM_COLS - 1 ; j > 2 ; j -- ) { if ( ( game -> board [ i ] [ j ] == PLAYERONE ) && ( game -> board [ i + 1 ] [ j - 1 ] == PLAYERONE ) && ( game -> board [ i + 2 ] [ j - 2 ] == PLAYERONE ) && ( game -> board [ i + 3 ] [ j - 3 ] == PLAYERONE ) ) return X_WINS ; else if ( ( game -> board [ i ] [ j ] == PLAYERTWO ) && ( game -> board [ i + 1 ] [ j - 1 ] == PLAYERTWO ) && ( game -> board [ i + 2 ] [ j - 2 ] == PLAYERTWO ) && ( game -> board [ i + 3 ] [ j - 3 ] == PLAYERTWO ) ) return O_WINS ; } } for ( i = 0 ; i < NUM_COLS ; i ++ ) if ( game -> board [ NUM_ROWS - 1 ] [ i ] == EMPTY ) return NOT_OVER ; return CATS ; }
The older and faster version of check_status from con4lib.h
Credit to Arup Guha for this function
The older and faster version of check_status from con4lib . h Credit to Arup Guha for this function
// We go through each row, to look for a horizontal win. // We iterate through the possible column starting positions of four // consecutive winning pieces. // We go through each column, to look for a vertical win. // We iterate through possible row starting positions of four // consecutive winning pieces. // We start at the possible row positions for a "forward" diagonal. // We start at the possible column positions. // We start at the possible row positions for a "backward" diagonal. // Here are the possible column positions for a backwards diagonal. // See if there's an empty slot on the board. // If we get here, we have a CATS game.