-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.c
executable file
·77 lines (66 loc) · 1.16 KB
/
card.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
#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>
//#include <locale.h>
#include "card.h"
CARD *
create_deck ()
{
CARD *p_deck, *p_p;
int i, j;
p_deck = (CARD *)calloc (52, sizeof (CARD));
p_p = p_deck;
for (i = HEARTS; i <= SPADES; i++)
{
for (j = ACE; j <= KING; j++)
{
p_p->suit = (enum suit)i;
p_p->face = (enum face)j;
p_p->isOpen = false;
p_p++;
}
}
return p_deck;
}
void
free_deck (CARD *p_deck)
{
free (p_deck);
return;
}
//Fisher–Yates shuffle
CARD *
shuffle (CARD *p_deck, int size)
{
int i, r;
CARD t;
for (i = size; i > 0; i--)
{
r = rand() % i;
t = p_deck[r];
p_deck[r] = p_deck[i - 1];
p_deck[i - 1] = t;
}
return p_deck;
}
void
print_card (CARD *p_c)
{
char face[] = "A23456789TJQK";
//char suit[] = "hcds";
wchar_t suit[] = L"\u2665\u2660\u2666\u2663";
if (!p_c) return;
if (p_c->isOpen)
{
attron (COLOR_PAIR(p_c->suit % 2 + 2));
printw ("%c%lc", face[p_c->face], suit[p_c->suit]);
attroff (COLOR_PAIR(p_c->suit % 2 + 2));
}
else
{
attron (COLOR_PAIR(1));
printw ("[]");
attroff (COLOR_PAIR(1));
}
return;
}