blob: 548f23c2dbf4995246b83db4f9f760a0f191d865 (
plain)
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
|
#include "card_stack.h"
#include <stdlib.h>
#include <string.h>
void init_stack(player_cards *deck)
{
*deck = NULL;
}
void push_stack(player_cards *deck, const char *str)
{
struct card_stack_item *new_card = malloc(sizeof(struct card_stack_item));
new_card->str = str;
new_card->next = *deck;
if(new_card->next)
new_card->next->prev = new_card;
new_card->prev = NULL;
*deck = new_card;
}
int is_empty_stack(const player_cards deck)
{
return !deck;
}
int find_out_card_quantity_in_deck(player_cards deck)
{
int counter = 0;
while(deck) {
++counter;
deck = deck->next;
}
return counter;
}
const char* remove_card_from_stack(player_cards *deck, const char *str)
{
struct card_stack_item *tmp = NULL;
struct card_stack_item *first_tmp = *deck;
const char *card = NULL;
while(first_tmp) {
if(!strcmp(first_tmp->str, str)) {
tmp = first_tmp;
if(first_tmp->prev)
first_tmp->prev->next = first_tmp->next;
else
*deck = first_tmp->next;
if(first_tmp->next)
first_tmp->next->prev = first_tmp->prev;
card = tmp->str;
free(tmp);
return card;
}
first_tmp = first_tmp->next;
}
return 0;
}
void pop_stack(player_cards *deck)
{
struct card_stack_item *tmp;
tmp = *deck;
*deck = (*deck)->next;
free(tmp);
}
struct card_stack_item* get_next_card_from_stack(player_cards deck,
player_cards prev)
{
if(prev == NULL)
return deck;
else
return prev->next;
}
int find_card_in_stack(player_cards involved_cards, const char *str)
{
while(involved_cards) {
if(!strcmp(involved_cards->str, str))
return 1;
involved_cards = involved_cards->next;
}
return 0;
}
void clear_stack(player_cards *deck)
{
struct card_stack_item *tmp;
player_cards tmp_deck = *deck;
while(tmp_deck) {
tmp = tmp_deck;
tmp_deck = tmp_deck->next;
free(tmp);
}
*deck = NULL;
}
|