group3.c
int g3_is2WinDirection(const struct connect4 *game, int row, int col, int dir, char piece) {
    const int DX[] = {-1, -1, -1, 0, 0, 1, 1, 1};
    const int DY[] = {-1, 1, 0, -1, 1, 0, -1, 1};

    //We are looking at the 5 pieces around us to see if we find our pattern for a 2win
    // (The pattern is _XX__, where index 3 is where you are moving, and you are able to play on all blanks present)
    char pieces[5];
    int i;

    //Look in each of the 5 slots in the direction around our piece and put that into our pieces
    //array which we are using to see if the pattern we want is present
    for (i = 0; i < 5; i++) {
        //Find the slot on the board
        int newRow = row + (i - 3) * DY[dir];
        int newCol = col + (i - 3) * DX[dir];

        //Checks to see if the location is on the board, and if it is it puts it into pieces
        if (g3_isOnBoard(newRow, newCol)) {
            pieces[i] = game->board[newRow][newCol];
            //For blanks, you have to make sure you can move in each blank location
            //Here, i check if each blank is a valid location to move
            //If it is, then I switch the char to 'Y', otherwise its 'N'
            if (pieces[i] == '_') {
                if (g3_canMove(game, newRow, newCol)) pieces[i] = 'Y';
                else pieces[i] = 'N';
            }
        }
        else {
            //set it to something that lets you know its off the board
            //'R' FOR RIP
            pieces[i] = 'R';
        }
    }

    //Now you have to check if your pattern holds
    return pieces[0] == 'Y' && pieces[1] == piece && pieces[2] == piece && pieces[3] == 'Y' && pieces[4] == 'Y';
}
/* Checks to see if at the current location and direction you have a 2win */
Checks to see if at the current location and direction you have a 2win
Checks to see if at the current location and direction you have a 2win
int g3_is2WinDirection(const struct connect4 *game, int row, int col, int dir, char piece) {
    const int DX[] = {-1, -1, -1, 0, 0, 1, 1, 1};
    const int DY[] = {-1, 1, 0, -1, 1, 0, -1, 1};
    char pieces[5];
    int i;
    for (i = 0; i < 5; i++) {
        int newRow = row + (i - 3) * DY[dir];
        int newCol = col + (i - 3) * DX[dir];
        if (g3_isOnBoard(newRow, newCol)) {
            pieces[i] = game->board[newRow][newCol];
            if (pieces[i] == '_') {
                if (g3_canMove(game, newRow, newCol)) pieces[i] = 'Y';
                else pieces[i] = 'N';
            }
        }
        else {
            pieces[i] = 'R';
        }
    }
    return pieces[0] == 'Y' && pieces[1] == piece && pieces[2] == piece && pieces[3] == 'Y' && pieces[4] == 'Y';
}
int g3_is2WinDirection ( const struct connect4 * game , int row , int col , int dir , char piece ) { const int DX [ ] = { -1 , -1 , -1 , 0 , 0 , 1 , 1 , 1 } ; const int DY [ ] = { -1 , 1 , 0 , -1 , 1 , 0 , -1 , 1 } ; char pieces [ 5 ] ; int i ; for ( i = 0 ; i < 5 ; i ++ ) { int newRow = row + ( i - 3 ) * DY [ dir ] ; int newCol = col + ( i - 3 ) * DX [ dir ] ; if ( g3_isOnBoard ( newRow , newCol ) ) { pieces [ i ] = game -> board [ newRow ] [ newCol ] ; if ( pieces [ i ] == ' ' ) { if ( g3_canMove ( game , newRow , newCol ) ) pieces [ i ] = ' ' ; else pieces [ i ] = ' ' ; } } else { pieces [ i ] = ' ' ; } } return pieces [ 0 ] == ' ' && pieces [ 1 ] == piece && pieces [ 2 ] == piece && pieces [ 3 ] == ' ' && pieces [ 4 ] == ' ' ; }
Checks to see if at the current location and direction you have a 2win
Checks to see if at the current location and direction you have a 2win
//We are looking at the 5 pieces around us to see if we find our pattern for a 2win // (The pattern is _XX__, where index 3 is where you are moving, and you are able to play on all blanks present) //Look in each of the 5 slots in the direction around our piece and put that into our pieces //array which we are using to see if the pattern we want is present //Find the slot on the board //Checks to see if the location is on the board, and if it is it puts it into pieces //For blanks, you have to make sure you can move in each blank location //Here, i check if each blank is a valid location to move //If it is, then I switch the char to 'Y', otherwise its 'N' //set it to something that lets you know its off the board //'R' FOR RIP //Now you have to check if your pattern holds