広島大学じゃんけん
サークル

第2回関数じゃんけん大会で使用されたコード(一部)

K.W.

データじゃんけん


int p(unsigned long int n, unsigned long int w){
    int x;
    static int ncount;
    static int ccount;
    static int wcount;

    if((n != ncount) && (n%100 == 0) && (n != 0) ){
        if(((float)w - wcount)/100 < 1/3.0){
            ccount++;
        }
        wcount=w;
    }
    if(n%2==0){
        x = 0 + 2*ccount;
    }
    else{
        x=1 + 2*ccount;
    }
    ncount=n;
    return x % 3;
}
            

ふるた

static int型の変数3つでグーチョキパーがでた回数をカウントし、3回ごとに出が少ないものを出してなるべくバランスよく手を出すことを心がけた


int p (unsigned long int n, unsigned long int w){
    static unsigned long int count_g=0, count_p=0, count_c=0;
    if (n == 0)
        return 0;

    int a[15] = {0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2}; /* 0が5回 1が5回 2が5回 */
    int b[15] = {0, 1, 1, 2, 2, 0, 1, 1, 2, 2, 0, 1, 1, 2, 2}; /* 0が3回 1が6回 2が6回 */
    int c[15] = {0, 0, 1, 2, 2, 0, 0, 1, 2, 2, 0, 0, 1, 2, 2}; /* 0が6回 1が3回 2が6回 */
    int d[15] = {0, 0, 1, 1, 2, 0, 0, 1, 1, 2, 0, 0, 1, 1, 2}; /* 0が6回 1が6回 2が3回 */
    int e[15] = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}; /* 0が7回 1が8回 2が0回 */
    int f[15] = {1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2}; /* 0が0回 1が7回 2が8回 */
    int g[15] = {2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0}; /* 0が8回 1が0回 2が7回 */

    unsigned long int parameter=(n*2)%15;
    int num, furuta = n % 2;
    double rate = w / n; //勝率 
    if (n <= 1000)
        num = a[parameter];

    if (n > 1000){
        num = b[parameter];
        if ( n > 4000 && rate < 0.6 ){                                                                                                                                                                   
            switch (furuta){
                case 0:
                    num = c[parameter];
                    break;
            
                default:
                    num = d[parameter];
                    break;
            }
        }
    }


    if(n % 3 == 0){
        if(count_g<count_c && count_g<count_p)
        num = 0;
        else if(count_c<count_g && count_c<count_p)
        num = 1;
        else if(count_p<count_c && count_p<count_g)
        num = 2;
    }


    if(num == 0)
        count_g++;
    else if(num == 1)
        count_c++;
    else if(num == 2)
        count_p++;

    return num;
}
            

たそがれ


int p(unsigned long int n, unsigned long int w){
    return ((int)fabs(n * sin(n) ))%3; //|sin n| × n を3で割った余り
}
            

タカ


int p(unsigned long int n, unsigned long int w){
    int i = 0, k = 0;

    if (w <= 5000){
        while ((n = (n >> i)) != 0){
            if (n & 1 == 1){
                k++;
            }
            i++;
        }
    }
    else{
        while ((n = ((~n) >> i)) != 0){
            if (n & 1 == 1){
                k++;
            }
            i++;
        }
    }
    return k % 3;
}
            

とくめい

思ってたのと違う


int p(unsigned long int n, unsigned long int w){
    static int o_hand[3] = {};
    static int w_pre = 0;
    static int h_pre;
    static int wcount = 0;
    static int nwcount = 0;
    int i, max, max_i, tmp;

    if (n == 0){
        h_pre = 0;
        return 0;
    }

    if(w == w_pre){
        o_hand[(h_pre + 2) % 3]++;
        nwcount++;
    }
    else{
        o_hand[(h_pre + 1) % 3]++;
        if(n >= 3000){
            wcount++;
        }
    }
    

    if (n < 1000){
        h_pre = 0;
        return 0;
    }
    else if(n < 2000){
        h_pre = 1;
        return 1;
    }
    else if(n < 3000){
        h_pre = 2;
        return 2;
    }
    else{
        if (nwcount == 1000){
            if(wcount > 1000){
                for (i = 0; i <= 1; i++){
                    tmp = o_hand[i];
                    o_hand[i] = o_hand[i + 1];
                    o_hand[i + 1] = tmp;
                }
            }
            nwcount = 0;
            wcount = 0;
        }

        max = 0;
        for(i = 0; i <= 2; i++){
            if (o_hand[i] > max){
                max = o_hand[i];
                max_i = i;
            }
        }

        h_pre = (max_i + 2) % 3;
        return h_pre;
    }
}