#ifndef FUNCTIONS_MAINS_H_INCLUDED
#define FUNCTIONS_MAINS_H_INCLUDED

mains allouerBlock(mains *p) {
    *p = (mains) malloc(sizeof(carte));
}

//-----------------------------------------------

mains recherchePosition(mains tete, int symbb, int x) {
    mains p = tete, last = tete;

    while(p != NULL && symb(p) <= symbb) {
        if(symb(p) == symbb && num(p) >= x) break;
        last = p;
        p = adress(p);
    }
    return last;
}

//-----------------------------------------------

int insererCarte(mains *tete, int symb, int num) {
    mains p, rslt;
    int sortie = 0;

    allouerBlock(&p);

    if(p != NULL) {
        sortie = 1;
        affectSymb(p,symb);
        affectNum(p,num);

        if(*tete == NULL) {
            affectAdress(p,NULL);
            *tete = p;
        }
        else {
            rslt = recherchePosition(*tete,symb,num);

            if(rslt == *tete) {
                affectAdress(p,*tete);
                *tete = p;
            }
            else {
                affectAdress(p,adress(rslt));
                affectAdress(rslt,p);
            }

        }
    }

    return sortie;
}

//-----------------------------------------------

int totalAnnonces(mains tete) {
    mains p = tete, lastSymb = tete;
    int cpt = 0, total;

    while(p != NULL) {
        if(symb(p) == symb(lastSymb) && symb(p) == num(p)-1) {
            cpt++;
        }
        else cpt = 0;

        p = adress(p);
    }

    switch(cpt) {
        case 3:total = 20;break;
        case 4:total = 50;break;
        case 5:total = 100;break;
        default:total = 0;
    }

    return total;
}

//-----------------------------------------------

int Total(mains tete, int atout) {
    mains p = tete;
    int points = 0;

    while(p != NULL) {
        switch(num(p)) {
            case 1:points += 11;break;
            case 10:points += 10;break;
            case 13:points += 4;break;
            case 12:points += 3;break;
            case 11:
                if(atout == 1) points += 20;
                else points += 2;
                break;
            case 9:
                if(atout == 1) points += 14;
                break;
            default:points += 0;
        }

        p = adress(p);
    }
}

#endif // FUNCTIONS_MAINS_H_INCLUDED

Last edited Jan 28, 2012 at 11:02 AM by JooS, version 3

Comments

No comments yet.