1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
char suit[256];
char no[256];
int count;
}card;
drawcard(card *c){
int i,j,n=0,array[256];
srand(time(NULL));
i=rand()%52+1;
array[n++]=i;
for(j=0;j<n;j++){
if(j!=(--n)&&i==array[j]){
drawcard(c);
printf("Hi");
}
else{
if(i>0&&i<=13){
strcpy(c->suit,"Spades");
}
else if(i>13&&i<=25){
strcpy(c->suit,"Hearts");
}
else if(i>25&&i<=40){
strcpy(c->suit,"Diamonds");
}
else if(i>40&&i<=52){
strcpy(c->suit,"Clubs");
}
switch(i%13+1){
case 1:
strcpy(c->no,"[1]");
c->count=1;
break;
case 2:
strcpy(c->no,"[2]");
c->count=2;
break;
case 3:
strcpy(c->no,"[3]");
c->count=3;
break;
case 4:
strcpy(c->no,"[4]");
c->count=4;
break;
case 5:
strcpy(c->no,"[5]");
c->count=5;
break;
case 6:
strcpy(c->no,"[6]");
c->count=6;
break;
case 7:
strcpy(c->no,"[7]");
c->count=7;
break;
case 8:
strcpy(c->no,"[8]");
c->count=8;
break;
case 9:
strcpy(c->no,"[9]");
c->count=9;
break;
case 10:
strcpy(c->no,"[10]");
c->count=10;
break;
case 11:
strcpy(c->no,"[J]");
c->count=11;
break;
case 12:
strcpy(c->no,"[Q]");
c->count=12;
break;
case 13:
strcpy(c->no,"[K]");
c->count=13;
break;
}
}
}
}
int main(){
card card;
char fr,t,ht=5,bt=5,htt=5,btt=5;/*when the bot"s accumlated point larger than 12,the btt will become 0,when player don"t want to draw the card,the htt will become 1/when bot/player accumalted point exceed 21,the bt/pt will become4*/
int hc=0,bc=0;/*human count,bot count*/
int i;
printf("Welcome to play 21point poker\n");
printf("-------------------------------\n");
while(1){
printf("Would you like to start first?[Y/N]]");
scanf("%c",&fr);
getchar();
if(fr=='Y'){
t=1;
break;
}
else if(fr=='N'){
t=0;
break;
}
printf("\n");
}
while(1){
while(1){
if(t==1){
printf("It is your round\n");
drawcard(&card);
hc+=card.count;
printf("You have drawn %s %s\n",card.suit,card.no);
printf("Now your point is accumlated to %d\n",hc);
t=0;
break;
}
else if(t==2){
printf("Do you want to draw?[Y/N]");
scanf("%c",&t);
getchar();
if(t=='Y'){
drawcard(&card);
hc+=card.count;
printf("You have drawn %s %s\n",card.suit,card.no);
printf("Now your point is accumlated to %d\n",hc);
t=0;
if(hc>21){
ht=4;
htt=1;
}
if(btt==0){
t=2;
}
break;
}
else{
printf("You don't want to draw the card\n");
t=0;
htt=1;
break;
}
}
else if(t==0){
if(bc<=12){
printf("It is bot round\n");
drawcard(&card);
bc+=card.count;
printf("The bot have drawn %s %s\n",card.suit,card.no);
printf("Now the bot point is accumlated to %d\n",bc);
t=2;
if(htt==1){
t=0;
}
if(bc>21){
bt=4;
btt=0;
}
break;
}
else{
btt=0;
break;
}
}
}
if(btt==0&&htt==1){
if(hc==bc){
printf("Draw\n");
}
else if(hc>bc&&hc<=21||bt==4){
printf("Human win");
}
else if(bc>hc&&bc<=21||ht==4){
printf("Bot win");
}
break;
}
}
}
|