forked from achintyapataskar/card-games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blackjack.c
executable file
·141 lines (139 loc) · 2.11 KB
/
blackjack.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "blackjack.h"
void inithand(hand *a) {
a->ncards = 0;
a->sum = 0;
return;
}
void deck(card *a, int state) {
char s[8];
int i, k;
switch(state) {
case 1:
strcpy(s, "Club");
state++;
i = 0;
break;
case 2:
strcpy(s, "Diamond");
state++;
i = 13;
break;
case 3:
strcpy(s, "Spade");
state++;
i = 26;
break;
case 4:
strcpy(s, "Heart");
state++;
i = 39;
break;
default:
printf("Initialization Finished");
break;
}
k = i + 13;
while(i < k) {
strcpy(a[i].suite, s);
a[i].rank = (i % 13) + 1;
i++;
}
if(state <= 4)
deck(a, state);
return;
}
void printdeck(card *a) {
int i = 0;
while(i < 52) {
printf("%s %d\n", a[i].suite, a[i].rank);
i++;
}
return;
}
void printhand(hand *a) {
int i = 0;
printf("\n");
while(i < a->ncards) {
printf("%s%d\n",(a->h)[i].suite, (a->h)[i].rank);
i++;
}
return;
}
int additup(hand *a) {
int i = 0;
int s = 0;
int acecount = 0;
checkace k[5];
/* while(i < a->ncards) {
if((a->h)[i].rank == 1) {
k[i]->n = 10;
k[i]->ace = 1;
acecount++;
} else if((a->h).rank > 10) {
k[i]->n = 10;
k[i]->ace = 0;
} else {
k[i]->n = (a->h)[i].rank;
k[i]->ace = 0;
}
i++;
}
i = 0;
*/
return 0;
}
/*void shuffle(card *a) {
time_t t;
int i = 0, n, k;
srandom(&t);
while(i < 10000) {
n = random();
n %= 52;
k = 0;
while()
i++;
}
return 0;
}*/
void deal(card *a, hand *player, hand *dealer) {
int i = 0;
player->sum = dealer->sum = 0;
(dealer->h)[0] = a[i];
i++;
(dealer->h)[1] = a[i];
dealer->ncards += 2;
i++;
(player->h)[0] = a[i];
i++;
(player->h)[1] = a[i];
player->ncards += 2;
i++;
printf("\n");
printf("\n");
return;
}
int main() {
int s = 1;
char c;
deck(shoe, s);
//printdeck(shoe);
/*while(1) {
shuffle(shoe);
printdeck(shoe);
c = getchar();
if(c == EOF)
break;
}*/
deal(shoe, &player, &dealer);
printf("Dealer:\n");
printhand(&dealer);
printf("%d\n", (additup(&dealer)));
printf("Player\n");
printhand(&player);
printf("%d\n", (additup(&player)));
return 0;
}