group3.c
int g3_handleSpecialCase(const struct connect4 *game) {
    // Play the center if there are no other moves
    if (!not_valid(game, g3_CENTER)) {
        //isCrazy checks if there are moves in other columns;
        if (!g3_isCrazy(game)) return g3_CENTER;
    }

    //Continue to checking for 3wins and 2wins if you shouldn't play the center

    int col;
    int didTheyWin = -1;

    //determines who is who for each of the pieces based on whose turn it is
    char us = game->whoseTurn;

    //they have to be the opposite of our piece, so set them to the opposite of us
    char them = other(us);

    //Check all of the columns for if we win by playing in the column or if we block their win
    for (col = 0; col < NUM_COLS; col++) {
        //finds the row you will be playing in if you select that column
        int validRow = get_row(game, col);
        //If you can win there, play there!
        if (g3_is3Win(game, validRow, col, us)) {
            return col;
        }
        //Otherwise, keep track of where to block the opponent if they have a 3win
        if (g3_is3Win(game, validRow, col, them)) didTheyWin = col;
    }

    //If you found a column you have to block, block it.
    if (didTheyWin != -1) return didTheyWin;

    //If there are no 3wins, check for 2wins

    int enemy2Wins[NUM_COLS];
    memset(enemy2Wins, 0, sizeof(enemy2Wins));

    //Check in each col if there is a 2win
    for (col = 0; col < NUM_COLS; col++) {
        int validRow = get_row(game, col);

        //if you have a 2win and you don't cause a 3win for the opponent, you should play there
        if (g3_is2Win(game, validRow, col, us)) {
            if (g3_isSafe(game, validRow, col, us)) {
                return col;
            }
        }
/*
		//If your opponent has a 2win and its safe to block them, do it
		if (g3_is2Win(game, validRow, col, them) && g3_isSafe(game, validRow, col, us)) {
			enemy2Wins[col] = 1;
		}
*/
    }

/*
    for (col = 0; col < NUM_COLS; col++) {
        if (enemy2Wins[col] ==  1)
            return g3_fastMove(game, enemy2Wins);
    }
*/
    return -1;
}
/*
 * Handles the cases where pieces have only been played in the middle,
 * There is a 3 in a row on the board to be blocked, or if there is
 * A two in a row that will result in 2 different places to win on the board,
 * and it is safe to block that 2 in a row from happening, or it is safe to start it
 */
Handles the cases where pieces have only been played in the middle,
There is a 3 in a row on the board to be blocked, or if there is
A two in a row that will result in 2 different places to win on the board,
and it is safe to block that 2 in a row from happening, or it is safe to start it
Handles the cases where pieces have only been played in the middle There is a 3 in a row on the board to be blocked or if there is A two in a row that will result in 2 different places to win on the board and it is safe to block that 2 in a row from happening or it is safe to start it
int g3_handleSpecialCase(const struct connect4 *game) {
    if (!not_valid(game, g3_CENTER)) {
        if (!g3_isCrazy(game)) return g3_CENTER;
    }
    int col;
    int didTheyWin = -1;
    char us = game->whoseTurn;
    char them = other(us);
    for (col = 0; col < NUM_COLS; col++) {
        int validRow = get_row(game, col);
        if (g3_is3Win(game, validRow, col, us)) {
            return col;
        }
        if (g3_is3Win(game, validRow, col, them)) didTheyWin = col;
    }
    if (didTheyWin != -1) return didTheyWin;
    int enemy2Wins[NUM_COLS];
    memset(enemy2Wins, 0, sizeof(enemy2Wins));
    for (col = 0; col < NUM_COLS; col++) {
        int validRow = get_row(game, col);
        if (g3_is2Win(game, validRow, col, us)) {
            if (g3_isSafe(game, validRow, col, us)) {
                return col;
            }
        }
    }
    return -1;
}
int g3_handleSpecialCase ( const struct connect4 * game ) { if ( ! not_valid ( game , g3_CENTER ) ) { if ( ! g3_isCrazy ( game ) ) return g3_CENTER ; } int col ; int didTheyWin = -1 ; char us = game -> whoseTurn ; char them = other ( us ) ; for ( col = 0 ; col < NUM_COLS ; col ++ ) { int validRow = get_row ( game , col ) ; if ( g3_is3Win ( game , validRow , col , us ) ) { return col ; } if ( g3_is3Win ( game , validRow , col , them ) ) didTheyWin = col ; } if ( didTheyWin != -1 ) return didTheyWin ; int enemy2Wins [ NUM_COLS ] ; memset ( enemy2Wins , 0 , sizeof ( enemy2Wins ) ) ; for ( col = 0 ; col < NUM_COLS ; col ++ ) { int validRow = get_row ( game , col ) ; if ( g3_is2Win ( game , validRow , col , us ) ) { if ( g3_isSafe ( game , validRow , col , us ) ) { return col ; } } } return -1 ; }
Handles the cases where pieces have only been played in the middle,
 There is a 3 in a row on the board to be blocked, or if there is
 A two in a row that will result in 2 different places to win on the board,
 and it is safe to block that 2 in a row from happening, or it is safe to start it
Handles the cases where pieces have only been played in the middle There is a 3 in a row on the board to be blocked or if there is A two in a row that will result in 2 different places to win on the board and it is safe to block that 2 in a row from happening or it is safe to start it
// Play the center if there are no other moves //isCrazy checks if there are moves in other columns; //Continue to checking for 3wins and 2wins if you shouldn't play the center //determines who is who for each of the pieces based on whose turn it is //they have to be the opposite of our piece, so set them to the opposite of us //Check all of the columns for if we win by playing in the column or if we block their win //finds the row you will be playing in if you select that column //If you can win there, play there! //Otherwise, keep track of where to block the opponent if they have a 3win //If you found a column you have to block, block it. //If there are no 3wins, check for 2wins //Check in each col if there is a 2win //if you have a 2win and you don't cause a 3win for the opponent, you should play there /*
		//If your opponent has a 2win and its safe to block them, do it
		if (g3_is2Win(game, validRow, col, them) && g3_isSafe(game, validRow, col, us)) {
			enemy2Wins[col] = 1;
		}
*/ /*
    for (col = 0; col < NUM_COLS; col++) {
        if (enemy2Wins[col] ==  1)
            return g3_fastMove(game, enemy2Wins);
    }
*/