summaryrefslogtreecommitdiff
path: root/c3prj2_eval/deck.c~
diff options
context:
space:
mode:
authorHaidong Ji2022-04-15 15:51:30 -0500
committerHaidong Ji2022-04-15 15:51:30 -0500
commit442a49ad5a48d417345959b903ae6a6d32d55759 (patch)
treec7127bb497e5e439018b1915e0136eec2c9cb124 /c3prj2_eval/deck.c~
Great C programming funHEADmaster
Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git
Diffstat (limited to 'c3prj2_eval/deck.c~')
-rw-r--r--c3prj2_eval/deck.c~40
1 files changed, 40 insertions, 0 deletions
diff --git a/c3prj2_eval/deck.c~ b/c3prj2_eval/deck.c~
new file mode 100644
index 0000000..c4a3d78
--- /dev/null
+++ b/c3prj2_eval/deck.c~
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "deck.h"
+
+void print_hand(deck_t * hand){
+ for (size_t i = 0; i < hand->n_cards; i++) {
+ print_card(*hand->cards[i]);
+ printf(" ");
+ }
+}
+
+int deck_contains(deck_t * d, card_t c) {
+ for (size_t i = 0; i < d->n_cards; i++) {
+ if (d->cards[i]->value == c.value && d->cards[i]->suit == c.suit ) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void shuffle(deck_t * d){
+ card_t c;
+ for (size_t i = d->n_cards; i > 0; i--) {
+ int r = rand() % i;
+ c = *d->cards[i-1];
+ *d->cards[i-1] = *d->cards[r];
+ //d[i-1] = d[r];
+ *d->cards[r] = c;
+ }
+}
+
+void assert_full_deck(deck_t * d) {
+ card_t temp;
+ for (int i = 0; i <= 51; i++) {
+ temp = card_from_num(i);
+ assert(deck_contains(d, temp) == 1);
+ }
+
+}