-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame (V1).h
255 lines (208 loc) · 8.23 KB
/
Game (V1).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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
* Game.h
* 1917 v1.03
* Do not alter this file except to modify the Game struct
*
* Created by Richard Buckland on 20/04/11.
* Copyright 2011 Licensed under Creative Commons SA-BY-NC 3.0.
*
*/
#define NUM_UNIS 3
// player ID of each university
#define NO_ONE 0
#define UNI_A 1
#define UNI_B 2
#define UNI_C 3
// contents of an ARC
#define VACANT_ARC 0
#define ARC_A 1
#define ARC_B 2
#define ARC_C 3
// contents of a VERTEX
#define VACANT_VERTEX 0
#define CAMPUS_A 1
#define CAMPUS_B 2
#define CAMPUS_C 3
#define GO8_A 4
#define GO8_B 5
#define GO8_C 6
// action codes
#define PASS 0
#define BUILD_CAMPUS 1
#define BUILD_GO8 2
#define OBTAIN_ARC 3
#define START_SPINOFF 4
#define OBTAIN_PUBLICATION 5
#define OBTAIN_IP_PATENT 6
#define RETRAIN_STUDENTS 7
// disciplines
#define STUDENT_THD 0
#define STUDENT_BPS 1
#define STUDENT_BQN 2
#define STUDENT_MJ 3
#define STUDENT_MTV 4
#define STUDENT_MMONEY 5
#define NUM_REGIONS 19
#define PATH_LIMIT 150
#define TRUE 1
#define FALSE 0
// New defines
#define NUM_DISCIPLINES 6
#define NUM_VERTICES_HEXAGON 6
#define NUM_EDGES_HEXAGON 6
#define NUM_EDGES_AT_VERTEX 3
typedef struct _boardEdge boardEdge;
typedef struct _boardVertex boardVertex;
struct _boardVertex {
int campus;
boardEdge *edges[NUM_EDGES_AT_VERTEX];
};
struct _boardEdge {
int ARCGrant;
boardVertex *vertex1;
boardVertex *vertex2;
};
// ^
// Starting from say the left side of the board we index the vertices going
// down a row then to the top of the next row. i.e. hexagon.vertices[0] points
// to boardVertex[0]. And boardVertex[0].edges[0] points to boardEdge[0].
// boardEdge[0].vertex1 points to boardVertex[0] ect.
// I think that's a correct understanding of how all the pointers go. But
// we'll have to come up with the best place to start the indexing from.
typedef struct _hexagon {
boardVertex *vertices[NUM_VERTICES_HEXAGON];
boardEdge *edges[NUM_EDGES_HEXAGON];
int diceValue;
int discipline;
} hexagon;
typedef struct _player {
// Generating KPI on the fly makes sense, go with that.
int campuses;
int GO8s;
int patents;
int papers;
int students[NUM_DISCIPLINES];
} player;
// your team designs this type not us
// store in this struct all the things you might want to know about
// the game so you can write the interface functions in this header
// eg you might want to store the current turn number (so i've put
// it in for you as an example but take it out if you don't want it)
typedef struct _game {
hexagon boardHexagons[NUM_REGIONS];
player univeristies[NUM_UNIS];
int mostPapersUni;
int mostArcsUni;
int currentTurn;
} Game;
// a path is a sequence of L=left R=right B=back steps
// starting from the starting node of player 0, represented
// as a string of length PATH_LIMIT or less (including the
// terminating 0)
// a path can specify a vertex (the vertex at the end of the path)
// and a path can specify an ARC (the last ARC in the path)
// it is fine and legal for a path to not be the shortest path
// to the destination, it can even contain loops if you like.
// The length of a path (including the terminating 0) must never
// exceed PATH_LIMIT. Every edge in the path must lie on the
// island, paths cannot include edges which are in the sea.
typedef char path[PATH_LIMIT];
// actions are what the player AI returns. They say the one thing
// the AI wants to do next. In the playGame logic you'll ask
// a player for their next action, then you'll check it is a legal
// action (using isLegalAction()), then you'll perform that action
// for them (using makeAction()), then you'll ask the same player
// for another action and repeat this over and over again until they
// return PASS at which time you'll throw the dice (using
// throwDice()) and advance the game to the next player. And repeat.
typedef struct _action {
int actionCode; // see #defines above
path destination; // if the action operates on a vertex or ARC this
// specifies *which* vertex or path. unused
// otherwise
int disciplineFrom; // used for the retrain students action
int disciplineTo; // used for the retrain students action
} action;
/* **** Functions which change the game aka SETTERS **** */
// make a new game, given the disciplines produced by each
// region, and the value on the dice discs in each region.
// note: each array must be NUM_REGIONS long
// eg if you are using my sample game struct above this function
// would need to set the field currentTurn to -1. (because the turn
// number is -1 at the start of the game)
Game newGame (int discipline[], int dice[]);
// after week 7 we will talk about implementing this. for now
// you can have it doing nothing
void disposeGame (Game g);
// make the specified action for the current player and update the
// game state accordingly.
// The function may assume that the action requested is legal.
// START_SPINOFF is not a legal action here
Game makeAction (Game g, action a);
// advance the game to the next turn,
// assuming that the dice has just been rolled and produced diceScore
// the game starts in turn -1 (we call this state "Terra Nullis") and
// moves to turn 0 as soon as the first dice is thrown.
Game throwDice (Game g, int diceScore);
/* **** Functions which GET data about the game aka GETTERS **** */
// what type of students are produced by the specified region?
// see discipline codes above
int getDiscipline (Game g, int regionID);
// what dice value produces students in the specified region?
// 2..12
int getDiceValue (Game g, int regionID);
// which university currently has the prestige award for the most ARCs?
// this is NO_ONE until the first arc is purchased after the game
// has started.
int getMostARCs (Game g);
// which university currently has the prestige award for the most pubs?
// this is NO_ONE until the first IP is patented after the game
// has started.
int getMostPublications (Game g);
// return the current turn number of the game -1,0,1, ..
int getTurnNumber (Game g);
// return the player id of the player whose turn it is
// the result of this function is NO_ONE during Terra Nullis
int getWhoseTurn (Game g);
// return the contents of the given vertex (ie campus code or
// VACANT_VERTEX)
int getCampus(Game g, path pathToVertex);
// the contents of the given edge (ie ARC code or vacent ARC)
int getARC(Game g, path pathToEdge);
// returns TRUE if it is legal for the current
// player to make the specified move, FALSE otherwise.
// legal means everything is legal eg when placing a campus consider
// such things as:
// * is the specified path a valid path?
// * does it lead to a vacent vertex?
// * under the rules of the game are they allowed to place a
// campus at that vertex? (eg is it adjacent to one of their ARCs?)
// * does the player have the 4 specific students required to pay for
// that campus?
// It is not legal to make any action during Terra Nullis ie
// before the game has started.
// It is not legal for a player to make the moves OBTAIN_PUBLICATION
// or OBTAIN_IP_PATENT (they can make the move START_SPINOFF)
int isLegalAction (Game g, action a);
// --- get data about a specified player ---
// return the number of KPI points the specified player currently has
int getKPIpoints (Game g, int player);
// return the number of ARC grants the specified player currently has
int getARCs (Game g, int player);
// return the number of GO8 campuses the specified player currently has
int getGO8s (Game g, int player);
// return the number of normal Campuses the specified player currently has
int getCampuses (Game g, int player);
// return the number of IP Patents the specified player currently has
int getIPs (Game g, int player);
// return the number of Publications the specified player currently has
int getPublications (Game g, int player);
// return the number of students of the specified discipline type
// the specified player currently has
int getStudents (Game g, int player, int discipline);
// return how many students of discipline type disciplineFrom
// the specified player would need to retrain in order to get one
// student of discipline type disciplineTo. This will depend
// on what retraining centers, if any, they have a campus at.
int getExchangeRate (Game g, int player,
int disciplineFrom, int disciplineTo);