-
Notifications
You must be signed in to change notification settings - Fork 0
/
gofish.h
202 lines (177 loc) · 5.69 KB
/
gofish.h
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* The below C macros are called header guards. It prevents the
* following content from being expanded more than once in a
* given source file. For example, if you include this header
* in a source file and you also include another header that
* includes this header, it will be included twice, therefore
* you will end up with more than one declaration of everything
* that is defined here. This header guard works as follows:
*
*
* 1) _GOFISH_H_ is undefined.
* 2) The c preprocessor starts processing your source file
* and encounters: #include "gofish.h"
* 3) The c preprocessor starts expanding gofish.h into your
* source file and encounters: #ifdef _GOFISH_H_
* 4) Is _GOFISH_H_ defined? NO
* 5) The c preprocessor encounters: define _GOFISH_H_ and
* now _GOFISH_H_ is defined (with no value).
* 6) The rest of the gofish.h header is expanded into the
* source file
*
* Now suppose in your source file, you include file.h, which
* also includes this header.
*
* 7) The c preprocessor encounters: "#include <file.h>"
* 8) The c preprocessor starts expanding file.h and
* encounters: #include "gofish.h"
* 9) Now, the c preprocessor starts expanding gofish.h for a second
* time and encounters: #ifndef _GOFISH_H_
* 10) Is _GOFISH_H_ defined? YES - we have already processes gofish.h
*
* Final notes:
*
* Macro expansion works on a per source file basis. This means that
* each source file starts with a clean slate of macros. When the
* c preprocessor works on each individual file, each file will
* get an expansion of the header gofish.h.
*
*/
#ifndef _GOFISH_H_
#define _GOFISH_H_
/** ^^ Header guard */
/* How slow should the dialog go? This is measured in seconds */
#define DIALOG_SPEED 1
/**
* The suit of a given card
*/
enum suit
{
CLUBS = 1, SPADES,
HEARTS, DIAMONDS
};
#define SUIT_MAX 4
typedef int suit_t;
/* The names of the ranks (defined in game.c) */
extern const char* rank_names[];
/**
* The values of any given card. Ace is high.
*/
enum rank
{
R2 = 2, R3, R4, R5, R6, R7,
R8, R9, R10, RJ, RQ, RK, RA
};
#define RANK_MAX 14
typedef int rank_t;
/**
* Represents a card in a given deck of standard
* playing cards.
*/
struct card
{
suit_t s; /* The suit of a card */
rank_t r; /* The rank/type of card */
};
/**
* Represents the deck of cards in the
* middle for drawing. Can also represent
* a player's hand.
*/
#define DECK_SIZE 52
struct deck
{
int top; /* The index of the top card (-1 means deck is empty) */
struct card cards[DECK_SIZE]; /* The cards in the deck (52 max) */
};
/**
* How many characters can a player's name have?
*/
#define NAME_MAX 64
/**
* A game player. This can either be a
* computer player or a human player.
*/
struct player
{
struct deck d; /* The player's hand */
char name[NAME_MAX]; /* The player's name */
int books; /* How many sets has the player acquired? */
/** Functions for player here */
/**
* When it is the player's turn, this function is called. A pointer
* to the player who's going is provided as p. The player will then
* place the rank that is guessed in guess_rank. The player will also
* place a pointer to the player who he is asing for.
*/
int (*my_turn)(struct player* p, /*The player that is currently going*/
rank_t* guess_rank, /* The rank we are guessing */
struct player** guess_player); /* The player we are asking */
};
/* How many player can play in a game? */
#define PLAYERS_MAX 12
/** The players in the game (defined in game.c) */
extern struct player game_players[PLAYERS_MAX];
/** The amount of players that are actually playing (defined in game.c)*/
extern int player_count;
/** The functions for manipulating decks.*/
/**
* Fill a deck with the 52 game cards. Takes the deck, d, as
* the parameter.
*/
void deck_populate(struct deck* d);
/**
* Shuffle the given deck, d.
*/
void deck_shuffle(struct deck* d);
/**
* Puts the given card, c, in the given deck, d. Returns 0 on
* success, nonzero otherwise.
*/
int deck_put(struct deck* d, struct card* c);
/**
* Draw a card from the given deck, d. Returns a pointer to
* a card on success (there were card(s) in the deck). Returns
* NULL on failure (the deck was empty).
*/
struct card* deck_draw(struct deck* d);
/**
* Check to see if a deck, d, contains any cards of rank, r.
* If there exists such a card in the deck, it is removed
* from the deck and returned. Returns NULL if there is no
* such card in the deck.
*/
struct card* deck_contains(struct deck* d, rank_t r);
/**
* Check to see if the deck contains a completed set of cards.
* Return the rank of the card that has a complete set, and
* removes all of those cards from the deck. Returns -1 if
* no set was found.
*/
rank_t deck_get_set(struct deck* d);
/** Functions for manipulating players */
/**
* Setup the given player with the given values. The name will
* be copied into the player struct. The player will be setup
* with the proper playing functions based on whether human
* is 1 (TRUE) or 0 (FALSE).
*/
void player_setup(struct player* p, const char* name, int human);
/**
* Logic function for doing a human player's turn. The human
* player will be prompted for a rank and a player's name.
* returns 0 on success.
*/
int human_player_turn(struct player* p,
rank_t* guess_rank,
struct player** guess_player);
/**
* Logic function for doing a computer player's turn. The computer
* players will basically do everything as random as possible. They
* will ask random players for cards that they have in their hand.
* Returns 0 on success, -1 if a move could not be generated.
*/
int computer_player_turn(struct player* p,
rank_t* guess_rank,
struct player** guess_player);
#endif