board.cpp
//return 1 if player win, return 2 if IA win
//x and y are the positions where the last pice was played
return 1 if player win, return 2 if IA win
x and y are the positions where the last pice was played
return 1 if player win return 2 if IA win x and y are the positions where the last pice was played
int Board::checkWin(int x, int y){
    int count=0;
   for(int j=1;j<4;j++){
		if(x >= 0 && x <= 5 && y-j >= 0 && y-j <=6){
			if(this->board[x][y - j] == this->turn){
				count++;
			}
        }
	}
    if(count == 3){
        if(this->turn == 'O')
            return 1; 
        else
            return 0; 
    }
    count=0;
    for(int j=1;j<4;j++){
		if(x >= 0 && x <= 5 && y+j >= 0 && y+j <=6){
			if(this->board[x][y + j] == this->turn){
				count++;
			}
        }
    }
    if(count == 3){
        if(this->turn == 'O')
            return 1; 
        else
            return 0; 
    }
    count=0;
    for(int i=1;i<4;i++){
		if(x-i >= 0 && x-i <= 5 && y >= 0 && y <=6){
			if(this->board[x-i][y] == this->turn){
				count++;
			}
        }
    }
    if(count == 3){
        if(this->turn == 'O')
            return 1; 
        else
            return 0; 
    }
    count=0;
    for(int i=1;i<4;i++){
		if(x+i >= 0 && x+i <= 5 && y >= 0 && y <=6){
			if(this->board[x+i][y] == this->turn){
				count++;
			}
        }
    }
    if(count == 3){
        if(this->turn == 'O')
            return 1; 
        else
            return 0; 
    }
    count=0;
    for(int i=1;i<4;i++){
        if(x+i < 6 && y-i >= 0){
            if(this->board[x+i][y-i]==this->turn)
                count++;
        }
    }
    if(count == 3){
        if(this->turn == 'O')
            return 1; 
        else
            return 0; 
    }
    count=0;
    for(int i=1;i<4;i++){
        if(x-i >= 0 && y+i < 7){
            if(this->board[x-i][y+i]==this->turn)
                count++;
        }
    }
    if(count == 3){
        if(this->turn == 'O')
            return 1; 
        else
            return 0; 
    }
    count=0;
    for(int i=1;i<4;i++){
        if(x+i < 6 && y+i < 7){
            if(this->board[x+i][y+i]==this->turn)
                count++;
        }
    }
    if(count == 3){
        if(this->turn == 'O')
            return 1; 
        else
            return 0; 
    }
    count=0;
    for(int i=1;i<4;i++){
        if(x-i >= 0 && y-i >= 0){
            if(this->board[x-i][y-i] == this->turn)
                count++;
        }
    }
    if(count == 3){
        if(this->turn == 'O')
            return 1; 
        else
            return 0; 
    }
    return -1; 
}
int Board :: checkWin ( int x , int y ) { int count = 0 ; for ( int j = 1 ; j < 4 ; j ++ ) { if ( x >= 0 && x <= 5 && y - j >= 0 && y - j <= 6 ) { if ( this -> board [ x ] [ y - j ] == this -> turn ) { count ++ ; } } } if ( count == 3 ) { if ( this -> turn == ' ' ) return 1 ; else return 0 ; } count = 0 ; for ( int j = 1 ; j < 4 ; j ++ ) { if ( x >= 0 && x <= 5 && y + j >= 0 && y + j <= 6 ) { if ( this -> board [ x ] [ y + j ] == this -> turn ) { count ++ ; } } } if ( count == 3 ) { if ( this -> turn == ' ' ) return 1 ; else return 0 ; } count = 0 ; for ( int i = 1 ; i < 4 ; i ++ ) { if ( x - i >= 0 && x - i <= 5 && y >= 0 && y <= 6 ) { if ( this -> board [ x - i ] [ y ] == this -> turn ) { count ++ ; } } } if ( count == 3 ) { if ( this -> turn == ' ' ) return 1 ; else return 0 ; } count = 0 ; for ( int i = 1 ; i < 4 ; i ++ ) { if ( x + i >= 0 && x + i <= 5 && y >= 0 && y <= 6 ) { if ( this -> board [ x + i ] [ y ] == this -> turn ) { count ++ ; } } } if ( count == 3 ) { if ( this -> turn == ' ' ) return 1 ; else return 0 ; } count = 0 ; for ( int i = 1 ; i < 4 ; i ++ ) { if ( x + i < 6 && y - i >= 0 ) { if ( this -> board [ x + i ] [ y - i ] == this -> turn ) count ++ ; } } if ( count == 3 ) { if ( this -> turn == ' ' ) return 1 ; else return 0 ; } count = 0 ; for ( int i = 1 ; i < 4 ; i ++ ) { if ( x - i >= 0 && y + i < 7 ) { if ( this -> board [ x - i ] [ y + i ] == this -> turn ) count ++ ; } } if ( count == 3 ) { if ( this -> turn == ' ' ) return 1 ; else return 0 ; } count = 0 ; for ( int i = 1 ; i < 4 ; i ++ ) { if ( x + i < 6 && y + i < 7 ) { if ( this -> board [ x + i ] [ y + i ] == this -> turn ) count ++ ; } } if ( count == 3 ) { if ( this -> turn == ' ' ) return 1 ; else return 0 ; } count = 0 ; for ( int i = 1 ; i < 4 ; i ++ ) { if ( x - i >= 0 && y - i >= 0 ) { if ( this -> board [ x - i ] [ y - i ] == this -> turn ) count ++ ; } } if ( count == 3 ) { if ( this -> turn == ' ' ) return 1 ; else return 0 ; } return -1 ; }
return 1 if player win, return 2 if IA win
x and y are the positions where the last pice was played
return 1 if player win return 2 if IA win x and y are the positions where the last pice was played
//check horizontal left //if(posj-j>=0){ //since board[x][y] is the same that was played we dont have to check it. //player won //IA WON //check horizontal right //if(posj+j<=6){ //since board[x][y] is the same that was played we dont have to check it. //player won //IA WON //checkVertUp //since board[x][y] is the same that was played we dont have to check it. //player won //IA WON //checkVertDown //since board[x][y] is the same that was played we dont have to check it. //player won //IA WON //diagLeft //since board[x][y] is the same that was played we dont have to check it. //player won //IA WON //DiagRight //since board[x][y] is the same that was played we dont have to check it. //player won //IA WON //reverseDiagLeft //since board[x][y] is the same that was played we dont have to check it. //player won //IA WON //reverseDiagRight //since board[x][y] is the same that was played we dont have to check it. //player won //IA WON //No one wins