Oppure

Loading
07/12/11 20:56
Driverfury
Sono riuscito ad ottimizzare la funzione utilizzando 2 cicli for e un operatore ternario:
int controlTris2(int table[3][3)
{
    int r, d; // contatori
    
    // Ciclo
    for(r=0; r<3; r++)
    {
        if(table[r][0]==table[r][1] && table[r][0]==table[r][2] && table[r][0]>0 && table[r][1]>0 && table[r][2]>0)
            return 1;
        else if(table[0][r]==table[1][r] && table[0][r]==table[2][r] && table[0][r]>0 && table[1][r]>0 && table[2][r]>0)
            return 1;
        for(d=0; d<=2; d+=2)
            if(table[0][d]==table[1][1] && table[0][d]==table[2][(d==0) ? 2 : 0] && table[0][d]>0 && table[1][1]>0 && table[2][(d==0) ? 2 : 0]>0)
                return 1;
    }
    
    return 0; // Se non è stato trovato nessun tris ritorna 0
}


Si può ottimizzare ulteriormente questa funzione?
aaa