1. 程式人生 > >8,石頭,剪刀,布的邏輯程式碼

8,石頭,剪刀,布的邏輯程式碼

//石頭,剪刀,布

#include <stdio.h>

#include <stdlib.h>

int main(int argc,const char * argv[]) {

int cmp =arc4random_uniform(3);//會產生012代表 石頭,剪刀,布

printf("請您出拳:(0,1,2)\n");

    int person;

    scanf("%i",&person);

printf("cmp = %i,person = %i\n",cmp,person);

    if(person == cmp ){

        printf

("平局\n");

    }else if((0 == person && 2 == cmp)||(1 == person && 3 == cmp)||(3 == person || 1 == cmp)){

        printf("玩家贏了!\n");

    }else{

        printf("電腦贏了!\n");

    }

}