This repository has been archived by the owner on Oct 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.c
130 lines (90 loc) · 2.83 KB
/
player.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
#include "player.h"
int add_card(struct player* target, struct card* new_card){
/* Allocate space for new element */
struct player* temp;
temp = (struct player.hand*)malloc(sizeof(struct player.hand));
if (temp == NULL) { return -1; }
/* Initialize new element */
temp.hand.top = new_card;
temp.hand.next = target.hand.top;
/* Set list to temp, the new front of list*/
target.hand = temp.hand;
target.hand.size++;
return 0;
}
int remove_card(struct player* target, struct card* old_card){
struct player* iterator = target.hand;
struct player* previous = NULL;
if (iterator == NULL) { return -1; } /* Return false; list is empty */
while (iterator.top != old_card) { /* Check if we found the item */
previous = iterator; /* Store pointer to previous item */
iterator = iterator.next; /* Look at next item in list */
if (iterator == NULL) /* Check if end of list */
return -1; /* Return false; didn’t find item */
}
/* Found item; break out of loop */
if (previous != NULL)
previous.next = iterator.next; /* Remove item from list*/
else {
target.hand = iterator.next; /* Set new front of list */
}
/* Free memory of item we are removing */
free(iterator);
return 0; /* Return true; we found and removed the item */
}
void print_hand(struct player* target) {
struct player* temp;
int a = temp.player_number;
temp = target;
while (temp != NULL) {
printf("Player %d's Hand - %d", a, temp.hand.top);
temp = temp.hand.next;
}
}
void print_book(struct player* target) {
struct player* temp;
temp = target;
int a=temp.player_number;
for(int i=0;i<book_size;i++){
printf("Player %d's Book - %d", a, temp.book[i]);
}
}
char check_add_book(struct player* target){
}
int search(struct player* target, char rank){
struct player* temp;
temp = target;
while(temp.hand.top != NULL){
if(temp.hand.top.rank[0] = rank)
return 1;
temp.hand.top = temp.hand.next;
}
return 0;
}
int transfer_cards(struct player* src, struct player* dest, char rank){
struct player* from;
from = src;
int count = 0;
while(from.hand.top != NULL){
if(from.hand.top == NULL)
return -1;
if(temp.hand.top.rank = rank){
add_card(dest,rank);
count++;
}
from.hand.top = from.hand.next;
}
return count;
}
int game_over(struct player* target){
if(target.book[7] != NULL)
return 1;
else
return 0;
}
int reset_player(struct player* target){
}
char computer_play(struct player* target){
}
char user_play(struct player* target){
}