#include #include #include #define CARD_MAX 52 #define BLACKJACK 21 void shuffle(int card[],const int num) { int r,temp; for(int i=0;iBLACKJACK && ichi--){ sum-=10; } return sum; } int think(const int card[],int *ca,int cpu[],int *cn) { int sum,r; sum=sumCheck(cpu,*cn); if(sum>=BLACKJACK) return 0; if(sum>11){ r=rand()%10; if(r*r>=(BLACKJACK-sum)*(BLACKJACK-sum)) return 0; } cpu[(*cn)++]=card[(*ca)++]; return 1; } int main(void) { int card[CARD_MAX]; //カード int cpu[11],you[11]; //手札 int cn,yn,ca; //次にアクセスする配列の添字 int c_play,y_play; //終了条件 int h,i; //汎用変数 int count; //残り試合数 int c_win,y_win; //勝ち数 for(h=0;h<4;h++) for(i=0;i<13;i++) card[i+h*13]=(i+1)+(h+1)*100; srand((unsigned int)time(NULL)); do{ count=5; c_win=y_win=0; do{ cn=yn=ca=0; c_play=y_play=1; puts("○○ NEW GAME START ○○"); printf("残り%d試合:CPU(%d勝) / YOU(%d勝)\n",count,c_win,y_win); shuffle(card,CARD_MAX); cpu[cn++]=card[ca++]; cpu[cn++]=card[ca++]; you[yn++]=card[ca++]; you[yn++]=card[ca++]; do{ if(c_play){ printf("CPU:"); for(i=0;i=BLACKJACK) y_play=0; } if(c_play){ if(c_play=think(card,&ca,cpu,&cn)) printf("CPUは引きました\n"); else printf("CPUは終了しました\n"); } if(y_play){ printf("あなたはもう一枚引きますか? Yes(1) No(0):"); scanf("%d",&y_play); fflush(stdin); if(y_play){ you[yn++]=card[ca++]; if(sumCheck(you,yn)>=BLACKJACK) y_play=0; } } }while(c_play || y_play); puts("□□ JUDGE □□"); printf("CPU:"); for(i=0;i ",h,i); if(h>BLACKJACK && i>BLACKJACK) puts("DRAW"); else if(h>BLACKJACK){puts("YOU WIN !"); y_win++;} else if(i>BLACKJACK){puts("CPU WIN !"); c_win++;} else if(BLACKJACK-h < BLACKJACK-i){puts("CPU WIN !"); c_win++;} else if(BLACKJACK-h > BLACKJACK-i){puts("YOU WIN !"); y_win++;} else puts("DRAW !"); printf("Enterキーを押して下さい"); getchar(); fflush(stdin); puts(""); }while(--count); puts("○○ RESULT ○○"); printf("CPU(%d勝) / YOU(%d勝)\n",c_win,y_win); printf("TOTAL WINNER IS "); if(c_win>y_win) puts("CPU !"); else if(c_win