-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.c
1101 lines (920 loc) · 29.9 KB
/
Game.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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Made by Alex, Ruby, Louis and Steph
//Game.c
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include "Game.h"
//Possible movements via path:
#define LEFT 'L'
#define RIGHT 'R'
#define BACK 'B'
#define NUM_DIRECTIONS 6
//Number of coordinates in x, y, z plane, -3to3
#define COORD 7
//Maximum values of items
#define MAX_KPIPTS 150
#define MAX_G08S 8
#define MAX_STU_TYPES 6
#define NO_PLAYERS 4
//Initial number of students the player starts with
#define INITIAL_THD 0
#define INITIAL_BPS 3
#define INITIAL_BQN 3
#define INITIAL_MTV 1
#define INITIAL_MJ 1
#define INITIAL_MMONEY 1
//KPI Value of each move:
#define CAMPUSPTS 10
#define G08PTS 20
#define ARCPTS 2
#define SPINOFFPTS 0 //Will have effect only if pub/ip.
#define PUBPTS 0 //Only prestige, no actual points
#define IPPTS 10
#define RETRAINPTS 0 //No KPI points will be earned
#define MOSTARCPTS 10
#define MOSTPUBPTS 10
//Paths to different retraining centres from top Campus A
#define TV1 "R" //MTV 1 retraining centre
#define TV2 "RR" //MTV 2 retraining centre
#define MONEY1 "LR" //MMONEY2 retraining centre
#define MONEY2 "LRL" //MMONEY2 retraining centre
#define ENGINEER1 "RLRRLLRLR" //BPS1 retraining centre
#define ENGINEER2 "RLRRLLRLRL" //BPS2 retraining centre
#define SCIENCE1 "RLLRLRLR" //BQN1 retraining centre
#define SCIENCE2 "RLLRLRLRR" //BQN2 retraining centre
#define JOB1 "RLLRLRRLRL" //MJOBS1 retraining centre
#define JOB2 "RLLRLRRLRLR" //MJOBS2 retraining centre
typedef struct _boardCoord {
//Coordinates of the board
int direction; // Range 0-5, initially determined by campus
//Coordinate ranges are from -3 to 3.
//Anything else is within the sea.
//Observation also all coordinates of vertexes add to +/-2
//All region coordinates add up to 0
//Two adjacent coordinates add up to 0 too
int x;
int y;
int z;
} coord;
typedef struct _boardEdge {
//Edge defined as line between two coordinates
coord pointA;
coord pointB;
} edge;
typedef struct _board {
//Stores campus player code
//Regular campuses are 1, 2, 3 but G08s are 4, 5, 6
int campus[COORD][COORD][COORD];
int region[COORD][COORD][COORD];
//Stores arc player code
//Each arc will have two copies, since an arc is between two
//points, hence points A - B and B - A
int arc[COORD][COORD][COORD][COORD][COORD][COORD];
//not needed anymore
//int retraining [COORD][COORD][COORD][COORD][COORD][COORD];
} board;
typedef struct _player {
int numArcs;
int numCmps;
int numG08s;
int numPubs;
int numIPs;
int numStudents[MAX_STU_TYPES];
} player;
typedef struct _game {
int currentTurn; //should start at -1
int mostArcs;
int mostPubs;
int numRegions;
int regionDiscipline[NUM_REGIONS];
int regionDice[NUM_REGIONS];
board gameBoard;
player uni[NO_PLAYERS];
} game;
void initializeBoard (Game g);
void makeRegion (Game g, int discipline[]);
void makeArc (Game g, char * path, int player);
void makeCampus (Game g, char * path, int player);
void makeG08 (Game g, char * path, int player);
void addStudents (Game g, int regionID);
int cmpsConditions (Game g, action a, int player);
int G08Conditions (Game g, action a, int player);
int arcConditions (Game g, action a, int player);
int spinoffConditions (Game g, action a, int player);
int retrainConditions (Game g, action a, int player);
int rollDice (void);
int *getRegion (Game g, int x, int y, int z);
coord pathMovement (char * path);
coord movement (coord point, char move); //single movements only
// Creates a new game and intialises the game board
// and player resources
Game newGame (int discipline[], int dice[]) {
// sets memory aside for the game
Game g = malloc (sizeof(game));
//Makes region
makeRegion(g, discipline);
// initialise turn to -1
g->currentTurn = -1;
// initialise game board
int regionID;
regionID = 0;
while (regionID < NUM_REGIONS) {
g->regionDiscipline[regionID] = discipline[regionID];
g->regionDice[regionID] = dice[regionID];
regionID++;
}
// initialise prestige awards
g->mostArcs = NO_ONE;
g->mostPubs = NO_ONE;
// initialise players
// 1<=player<=3 but array is from 0 to 2 so minus 1 to rectify
int curPlayer = UNI_A;
while (curPlayer < NO_PLAYERS) {
// initialises a player's students resources
g->uni[curPlayer].numStudents[STUDENT_THD] = INITIAL_THD;
g->uni[curPlayer].numStudents[STUDENT_BPS] = INITIAL_BPS;
g->uni[curPlayer].numStudents[STUDENT_BQN] = INITIAL_BQN;
g->uni[curPlayer].numStudents[STUDENT_MJ] = INITIAL_MJ;
g->uni[curPlayer].numStudents[STUDENT_MTV] = INITIAL_MTV;
g->uni[curPlayer].numStudents[STUDENT_MMONEY] = INITIAL_MMONEY;
// initialises a player's resources and points
g->uni[curPlayer].numArcs = 0;
g->uni[curPlayer].numCmps = 2;
g->uni[curPlayer].numG08s = 0;
g->uni[curPlayer].numPubs = 0;
g->uni[curPlayer].numIPs = 0;
curPlayer++;
}
//Initialize the gameboard:
initializeBoard(g);
return g;
}
//Initializes the board for newGame()
void initializeBoard (Game g) {
//For player 1 UNI_A
g->gameBoard.campus[2][5][0] = UNI_A;
g->gameBoard.campus[4][1][6] = UNI_A;
g->gameBoard.campus[1][6][4] = UNI_B;
g->gameBoard.campus[5][0][2] = UNI_B;
g->gameBoard.campus[0][2][5] = UNI_C;
char *path = malloc (10);
path = "LRLRL";
makeCampus (g, path, UNI_C);
/*
char * path;
path = "L";
makeArc (g, path, UNI_A);
path = "R";
makeArc (g, path, UNI_A);
g->gameBoard.arc[4][1][6][3][0][4] = UNI_A;
g->gameBoard.arc[3][0][4][4][1][6] = UNI_A;
g->gameBoard.arc[4][1][6][2][0][5] = UNI_A;
g->gameBoard.arc[2][0][5][4][1][6] = UNI_A;
//For player 2 UNI_B
g->gameBoard.arc[1][6][4][0][4][3] = UNI_B;
g->gameBoard.arc[0][4][3][1][6][4] = UNI_B;
g->gameBoard.arc[1][6][4][0][5][2] = UNI_B;
g->gameBoard.arc[0][5][2][1][6][4] = UNI_B;
g->gameBoard.arc[5][0][2][6][2][3] = UNI_B;
g->gameBoard.arc[6][2][3][5][0][2] = UNI_B;
g->gameBoard.arc[5][0][2][6][1][4] = UNI_B;
g->gameBoard.arc[6][1][4][5][0][2] = UNI_B;
g->gameBoard.arc[6][4][1][4][3][0] = UNI_C;
g->gameBoard.arc[4][3][0][6][4][1] = UNI_C;
g->gameBoard.arc[6][4][1][5][2][0] = UNI_C;
g->gameBoard.arc[5][2][0][6][4][1] = UNI_C;
g->gameBoard.arc[0][2][5][2][3][6] = UNI_C;
g->gameBoard.arc[2][3][6][0][2][5] = UNI_C;
g->gameBoard.arc[0][2][5][1][4][6] = UNI_C;
g->gameBoard.arc[1][4][6][0][2][5] = UNI_C;
*/
}
// release all the memory malloced for the game
void disposeGame (Game g) {
free (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
void makeAction (Game g, action a) {
// determine the current player
int curPlayer;
curPlayer = getWhoseTurn (g);
int rate = 0;
// peforms a particular action given the action code
if (a.actionCode == PASS) {
throwDice (g, rollDice());
} else if (a.actionCode == BUILD_CAMPUS) {
// deduct the resources from the player
g->uni[curPlayer].numStudents[STUDENT_BPS] -= 1;
g->uni[curPlayer].numStudents[STUDENT_BQN] -= 1;
g->uni[curPlayer].numStudents[STUDENT_MJ] -= 1;
g->uni[curPlayer].numStudents[STUDENT_MTV] -= 1;
makeCampus (g, a.destination, curPlayer);
g->uni[curPlayer].numCmps++;
} else if (a.actionCode == BUILD_GO8) {
// deduct the resources from the player
g->uni[curPlayer].numStudents[STUDENT_MJ] -= 2;
g->uni[curPlayer].numStudents[STUDENT_MMONEY] -= 3;
makeG08 (g, a.destination, curPlayer);
g->uni[curPlayer].numCmps--;
g->uni[curPlayer].numG08s++;
} else if (a.actionCode == OBTAIN_ARC) {
// deduct the resources from the player
g->uni[curPlayer].numStudents[STUDENT_BQN] -= 1;
g->uni[curPlayer].numStudents[STUDENT_BPS] -= 1;
makeArc (g, a.destination, curPlayer);
g->uni[curPlayer].numArcs++;
//change mostArcs
if (g->mostArcs == NO_ONE) {
g->mostArcs = curPlayer;
}
else if(g->uni[curPlayer].numArcs > g->uni[g->mostArcs].numArcs){
g->mostArcs = curPlayer;
}
} else if (a.actionCode == OBTAIN_PUBLICATION) {
g->uni[curPlayer].numPubs++;
//change mostPubs
if (g->mostPubs == NO_ONE) {
g->mostPubs = curPlayer;
}
else if(g->uni[curPlayer].numPubs > g->uni[g->mostPubs].numPubs){
g->mostPubs = curPlayer;
}
} else if (a.actionCode == OBTAIN_IP_PATENT) {
g->uni[curPlayer].numIPs++;
} else if (a.actionCode == RETRAIN_STUDENTS) {
rate = getExchangeRate (g, curPlayer, a.disciplineFrom, a.disciplineTo);
g->uni[curPlayer].numStudents[a.disciplineFrom] -= rate;
g->uni[curPlayer].numStudents[a.disciplineTo]++;
}
}
// 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.
// determines which region contains the diceValue of the diceScore
// determines who gets what
void throwDice (Game g, int diceScore) {
// advances the game to next turn
g->currentTurn++;
// to obtain the regionID/location of the diceScore/diceValue
int i = 0;
int regionID = 0;
while (i < NUM_REGIONS) {
if (diceScore == getDiceValue(g, i)) {
regionID = i;
addStudents (g, regionID);
}
i++;
}
// whenever a 7 is thrown, immediately after any new students are produced,
// all MTV and MMONEY students of all universities decide to switch to ThD's.
int curPlayer = 0;
if (diceScore == 7) {
curPlayer = UNI_A;
while (curPlayer < NO_PLAYERS) {
g->uni[curPlayer].numStudents[STUDENT_THD] += g->uni[curPlayer].numStudents[STUDENT_MTV] +
g->uni[curPlayer].numStudents[STUDENT_MMONEY];
g->uni[curPlayer].numStudents[STUDENT_MTV] = 0;
g->uni[curPlayer].numStudents[STUDENT_MMONEY] = 0;
curPlayer++;
}
}
}
//Stores region data in gameboard
void makeRegion (Game g, int discipline[]) {
g->gameBoard.region[1][5][3] = 0;
g->gameBoard.region[1][4][4] = 1;
g->gameBoard.region[1][3][5] = 2;
g->gameBoard.region[2][5][2] = 3;
g->gameBoard.region[2][4][3] = 4;
g->gameBoard.region[2][3][4] = 5;
g->gameBoard.region[2][2][5] = 6;
g->gameBoard.region[3][5][1] = 7;
g->gameBoard.region[3][4][2] = 8;
g->gameBoard.region[3][3][3] = 9;
g->gameBoard.region[3][2][4] = 10;
g->gameBoard.region[3][1][5] = 11;
g->gameBoard.region[4][4][1] = 12;
g->gameBoard.region[4][3][2] = 13;
g->gameBoard.region[4][2][3] = 14;
g->gameBoard.region[4][1][4] = 15;
g->gameBoard.region[5][3][1] = 16;
g->gameBoard.region[5][2][2] = 17;
g->gameBoard.region[5][1][3] = 18;
}
//Creates an ARC in given board
void makeArc (Game g, char * path, int player) {
int xPtA = 0;
int yPtA = 0;
int zPtA = 0;
int xPtB = 0;
int yPtB = 0;
int zPtB = 0;
edge arc;
arc.pointA = pathMovement (path);
arc.pointB = movement (arc.pointA, BACK);
xPtA = arc.pointA.x + 3;
yPtA = arc.pointA.y + 3;
zPtA = arc.pointA.z + 3;
xPtB = arc.pointB.x + 3;
yPtB = arc.pointB.y + 3;
zPtB = arc.pointB.z + 3;
g->gameBoard.arc[xPtA][yPtA][zPtA][xPtB][yPtB][zPtB] = player;
g->gameBoard.arc[xPtB][yPtB][zPtB][xPtA][yPtA][zPtA] = player;
}
//Stores campus data in gameboard
void makeCampus (Game g, char * path, int player) {
int xArray = 0;
int yArray = 0;
int zArray = 0;
coord movedPoint;
movedPoint = pathMovement (path);
//Save the player code into the array
xArray = movedPoint.x + 3;
yArray = movedPoint.y + 3;
zArray = movedPoint.z + 3;
g->gameBoard.campus[xArray][yArray][zArray] = player;
}
//Stores G08 data in gameboard
void makeG08 (Game g, char * path, int player) {
int xArray = 0;
int yArray = 0;
int zArray = 0;
coord movedPoint;
movedPoint = pathMovement (path);
//Save the player code into the array
xArray = movedPoint.x + 3;
yArray = movedPoint.y + 3;
zArray = movedPoint.z + 3;
//Since it's 4, 5, 6 for a GO8
g->gameBoard.campus[xArray][yArray][zArray] = player+3;
}
void addStudents (Game g, int regionID) {
int i = 0;
int x = 0;
int y = 0;
int z = 0;
int curPlayer = UNI_A;
int curVertex = g->gameBoard.campus[x][y][z];
int *regionSurround = getRegion (g, x, y, z);
while (x < COORD) {
while (y < COORD) {
while (z < COORD) {
curVertex = g->gameBoard.campus[x][y][z];
if (curVertex > 0) {
regionSurround = getRegion (g, x, y, z);
i = 0;
while (i < 3) {
if (regionSurround[i] == regionID) {
if (curVertex >= 1 && curVertex <= 3) {
curPlayer = curVertex;
g->uni[curPlayer].numStudents[getDiscipline(g, regionID)]++;
} else {
curPlayer = curVertex - 3;
g->uni[curPlayer].numStudents[getDiscipline(g, regionID)]+=2;
}
}
i++;
}
}
z++;
}
z = 0;
y++;
}
y = 0;
x++;
}
free (regionSurround);
}
// what type of students are produced by the specified region?
// regionID is the index of the region in the newGame arrays (above)
// see discipline codes above
int getDiscipline (Game g, int regionID) {
int discipline;
discipline = g->regionDiscipline[regionID];
return discipline;
}
// what dice value produces students in the specified region?
// 2..12
int getDiceValue (Game g, int regionID) {
int diceValue;
diceValue = g->regionDice[regionID];
return diceValue;
}
//Returns TRUE/FALSE on whether action is legal or not
int isLegalAction (Game g, action a) {
int output = TRUE;
int player = getWhoseTurn (g);
//Ensures game has already started
if (getTurnNumber (g) == -1) {
output = FALSE;
}
//Ensure action codes are legal
if ((a.actionCode < 0) || (a.actionCode >= 8)) {
output = FALSE;
}
//Tests the conditions for building things if it's not already false
if (output != FALSE) {
if (a.actionCode == PASS) {
output = TRUE;
} else if (a.actionCode == BUILD_CAMPUS) {
output = cmpsConditions (g, a, player);
} else if (a.actionCode == BUILD_GO8) {
output = G08Conditions (g, a, player);
} else if (a.actionCode == OBTAIN_ARC) {
output = arcConditions (g, a, player);
} else if (a.actionCode == START_SPINOFF) {
output = spinoffConditions (g, a, player);
} else if (a.actionCode == OBTAIN_PUBLICATION) {
//no player should be able to obtain publication freely
output = FALSE;
} else if (a.actionCode == OBTAIN_IP_PATENT) {
//no player should be able to obtain IP patent freely
output = FALSE;
} else if (a.actionCode == RETRAIN_STUDENTS) {
output = retrainConditions (g, a, player);
}
}
return output;
}
//Returns true/false, tests conditions for campus,
// which needs 1 of each but THD or M$,
// and no two campuses can be on adjacent vertexes
int cmpsConditions (Game g, action a, int player) {
int answer = TRUE;
char *path = a.destination;
coord vertex = pathMovement (path);
coord adj = movement (vertex, BACK);
if ((getStudents (g, player, STUDENT_BPS) >= 1)
&& (getStudents (g, player, STUDENT_BQN) >= 1)
&& (getStudents (g, player, STUDENT_MJ) >= 1)
&& (getStudents (g, player, STUDENT_MTV) >= 1)
&& (getCampus (g, a.destination) == VACANT_VERTEX)
&& (getARC (g, a.destination) != VACANT_ARC)) {
answer = TRUE;
} else {
answer = FALSE;
}
//check if they're inside the boundaries
if (answer == TRUE
&& abs (vertex.x) >= 3
&& abs (vertex.y) >= 3
&& abs (vertex.z) >= 3) {
answer = FALSE;
}
//Checks for adjacent campuses which would be illegal
if (answer == TRUE
&& g->gameBoard.campus[adj.x][adj.y][adj.z] != NO_ONE) {
answer = FALSE;
}
//Check that it's an actual vertex
if (answer == TRUE
&& abs (vertex.x+vertex.y+vertex.z) != 2) {
answer = FALSE;
}
return answer;
}
//Tests conditions for G08, which needs a campus + 2MJs + 3M$
int G08Conditions (Game g, action a, int player) {
int answer = FALSE;
char *path = a.destination;
coord vertex = pathMovement (path);
coord adj = movement (vertex, BACK);
if ((getStudents (g, player, STUDENT_MJ) >= 2)
&& (getStudents (g, player, STUDENT_MMONEY) >= 3)
&& (getCampuses (g, player) > 0)
&& (getGO8s (g, player) < MAX_G08S)
&& (getCampus (g, a.destination) > 3)) {
answer = TRUE;
} else {
answer = FALSE;
}
//check if they're inside the boundaries
if (answer == TRUE
&& abs (vertex.x) >= 3
&& abs (vertex.y) >= 3
&& abs (vertex.z) >= 3) {
answer = FALSE;
}
//Checks for adjacent campuses which would be illegal
if (answer == TRUE
&& g->gameBoard.campus[adj.x][adj.y][adj.z] != NO_ONE) {
answer = FALSE;
}
//Checks that it's a vertex
if (answer == TRUE
&& abs (vertex.x+vertex.y+vertex.z) != 2) {
answer = FALSE;
}
return answer;
}
//Tests conditions for a spinoff, which is MJ+MTV+MMNY
int spinoffConditions (Game g, action a, int player) {
int answer = FALSE;
if ((g->uni[player].numStudents[STUDENT_MJ] >= 1)
&& (g->uni[player].numStudents[STUDENT_MTV] >= 1)
&& (g->uni[player].numStudents[STUDENT_MMONEY] >= 1)){
answer = TRUE;
} else {
answer = FALSE;
}
return answer;
}
//Tests conditions for path, which needs 1 BPS and 1 BQN
//Ensure paths are connected to other paths & are legal paths
//Does not leave into the sea, and path is vacant
int arcConditions (Game g, action a, int player) {
int answer = TRUE;
char *path = a.destination;
edge arc;
arc.pointA = pathMovement (path);
arc.pointB = movement (arc.pointA, BACK);
if ((getStudents (g, player, STUDENT_BPS) >= 1)
&& (getStudents (g, player, STUDENT_BQN) >= 1)
&& (a.destination[0] != BACK)) { //doesn't move back into the sea
answer = TRUE;
} else {
answer = FALSE;
}
//check if they're inside the boundaries
if (answer == TRUE
&& abs (arc.pointA.x) >= 3
&& abs (arc.pointA.y) >= 3
&& abs (arc.pointA.z) >= 3) {
answer = FALSE;
}
//Checks to see that they are actual adjacent vertexes
if (answer == TRUE
&& abs(arc.pointA.x+arc.pointA.y+arc.pointA.z) != 2
&& (arc.pointA.x+arc.pointA.y+arc.pointA.z+arc.pointB.x+arc.pointB.y+arc.pointB.z != 0)
&& (getARC (g, a.destination) != VACANT_ARC)) {
answer = FALSE;
}
return answer;
}
//Returns true/false based on whether it suits retraining conditions
//Ensures valid discipline numbers used
//Ensures enough students for retraining
//THDs cannot be retrained, (code 0)
int retrainConditions (Game g, action a, int player) {
int answer = FALSE;
int rate = 0;
int numStudents = 0;
rate = getExchangeRate (g, player, a.disciplineFrom, a.disciplineTo);
numStudents = getStudents (g, player, a.disciplineFrom);
if (numStudents < rate) {
return FALSE;
}
if ((answer == TRUE) && (a.disciplineTo >= 0)
&& (a.disciplineFrom > 0)
&& (a.disciplineTo < MAX_STU_TYPES)
&& (a.disciplineFrom < MAX_STU_TYPES)
&& (numStudents >= rate)) {
answer = TRUE;
} else {
answer = FALSE;
}
return answer;
printf ("answer is %d\n", answer);
}
//Function returns the KPI points of specified player
int getKPIpoints (Game g, int player) {
int kpiPoints = 0;
//Add KPI points from every object player owns
kpiPoints += getARCs(g, player) * ARCPTS;
kpiPoints += getCampuses (g, player) * CAMPUSPTS;
kpiPoints += getGO8s (g, player) * G08PTS;
kpiPoints += getIPs (g, player) * IPPTS;
//Conditions for prestige KPI points
if (player == getMostARCs (g)) {
kpiPoints += MOSTARCPTS;
}
if (player == getMostPublications (g)) {
kpiPoints += MOSTPUBPTS;
}
return kpiPoints;
}
//Returns the number of arcs of the player
int getARCs (Game g, int player) {
return g->uni[player].numArcs;
}
//Returns number of G08s of specified player
int getGO8s (Game g, int player) {
//Ensures that there is less than 8G08s the player owns, else error
assert (g->uni[player].numG08s <= MAX_G08S);
return g->uni[player].numG08s;
}
//Checks to see if there is an arc in the edge
int getARC (Game g, path pathToEdge) {
int arcCode = 0;
char *path = pathToEdge;
int xPtA = 0;
int yPtA = 0;
int zPtA = 0;
int xPtB = 0;
int yPtB = 0;
int zPtB = 0;
edge arc; //Edge to be checked
arc.pointA = pathMovement (path);
arc.pointB = movement (arc.pointA, BACK);
xPtA = arc.pointA.x + 3;
yPtA = arc.pointA.y + 3;
zPtA = arc.pointA.z + 3;
xPtB = arc.pointB.x + 3;
yPtB = arc.pointB.y + 3;
zPtB = arc.pointB.z + 3;
arcCode = g->gameBoard.arc[xPtA][yPtA][zPtA][xPtB][yPtB][zPtB];
return arcCode;
}
//Checks to see if there is a campus
int getCampus (Game g, path pathToVertex) {
char *path = pathToVertex;
int campusCode = 0;
int xArray = 0;
int yArray = 0;
int zArray = 0;
coord vertex = pathMovement (path); //Vertex to be checked
//Ensure that it is a vertex, that it adds to +-2
assert (abs(vertex.x+vertex.y+vertex.z) == 2);
xArray = vertex.x + 3;
yArray = vertex.y + 3;
zArray = vertex.z + 3;
//Returns whatever code inside (player or 0)
campusCode = g->gameBoard.campus[xArray][yArray][zArray];
return campusCode;
}
// 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){
return g->mostArcs;
}
// which university currently has the prestige award for the most pubs?
// this is NO_ONE until the first publication is made.
int getMostPublications (Game g){
return g->mostPubs;
}
// return the current turn number of the game -1,0,1, ..
int getTurnNumber (Game g){
return g->currentTurn;
}
// 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){
int whoseTurn = NO_ONE;
//special case for terra nullis
if (g->currentTurn == -1) {
whoseTurn = NO_ONE;
}
//mod turn number by 3 as the turn rotates between 3 unis
else if (g->currentTurn % 3 == 0) {
whoseTurn = UNI_A;
}
else if (g->currentTurn % 3 == 1) {
whoseTurn = UNI_B;
}
else if (g->currentTurn % 3 == 2) {
whoseTurn = UNI_C;
}
return whoseTurn;
}
//gets the number of normal campuses a player has
int getCampuses (Game g, int player) {
//player 1 is position 0 and player 3 is position 2
return g->uni[player].numCmps;
}
//get the number of IPS a player has
int getIPs (Game g, int player) {
//g is a pointer to a struct
return g->uni[player].numIPs;
}
//gets the number of Publications that a player has
int getPublications (Game g, int player) {
//g is a pointer to a struct
//NB player 1 is position 0 and player 3 is position 2 in the array
return g->uni[player].numPubs;
}
//gets the number of students a player has of a specific discipline
int getStudents (Game g, int player, int discipline) {
//g is a pointer to a struct hence using "->" not "."
// 1<=player<=3 but array is from 0 to 2 so minus 1 to rectify
return g->uni[player].numStudents[discipline];
}
//get the exchange rate for retraining a student
int getExchangeRate (Game g, int player,
int disciplineFrom, int disciplineTo) {
//double check that isLegal is working
//assert (disciplineFrom != STUDENT_THD);
//paths to different retraining centres
path training1, training2;
int rate;
if (disciplineFrom == STUDENT_MTV) {
strcpy (training1, TV1);
strcpy (training2, TV2);
} else if (disciplineFrom == STUDENT_MMONEY) {
strcpy (training1, MONEY1);
strcpy (training2, MONEY2);
} else if (disciplineFrom == STUDENT_BPS) {
strcpy (training1, ENGINEER1);
strcpy (training2, ENGINEER2);
} else if (disciplineFrom == STUDENT_BQN) {
strcpy (training1, SCIENCE1);
strcpy (training2, SCIENCE2);
} else {
strcpy (training1, JOB1);
strcpy (training2, JOB2);
}
//NB player = ARC code e.g. player 1/(UNI_A) = ARC_A
if ((getCampus (g, training1) == player) || \
(getCampus (g, training2) == player)) {
rate = 2;
} else {
rate = 3;
}
return rate;
}
int rollDice (void) {
int diceValue = 0;
diceValue = (rand()%6 + 1) + (rand()%6 + 1);
return diceValue;
}
//Returns a pointer to an array of three regions,
//Each with a student value supposedly.
//Assuming input x, y, z are in array form (coordinate +3)
int *getRegion (Game g, int x, int y, int z) {
//These variables are used to test the conditions:
int xCon = x-3;
int yCon = y-3;
int zCon = z-3;
int sign = 0;
//When coordinate > 0, the others are -+1.
int *region = malloc (3);
//Since there are max 3 regions covering vertex
//Since it's 4, 5, 6 for a GO8
//As logically sum of region coordinates = 0,
//Thus to make it 0 you have to add the opposite to the
//other coordinates. (opposite sign)
if (xCon+yCon+zCon == -2) {
sign = 1;
} else {
sign = -1;
}
//Now to determine if the board is at the edge
//Since then it will only have two regions instead.
//Returns the regionIDs, if regionID = 19, there is no region there
if (abs (xCon) == 3 && (abs (yCon) == 1 || abs (yCon) == 0)
&& (abs (zCon) == 1 || abs (zCon) == 0)) {
region[0] = g->gameBoard.region[x+sign][y][z+sign];
region[1] = g->gameBoard.region[x+sign][y+sign][z];
region[2] = 19;
} else if (abs (yCon) == 3 && (abs (xCon) == 1 || abs (xCon) == 0)
&& (abs (zCon) == 1 || abs (zCon) == 0)) {
region[0] = g->gameBoard.region[x+sign][y+sign][z];
region[1] = g->gameBoard.region[x][y+sign][z+sign];
region[2] = 19;
} else if (abs (zCon) == 3 && (abs (xCon) == 1 || abs (xCon) == 0)
&& (abs (yCon) == 1 || abs (yCon) == 0)) {
region[0] = g->gameBoard.region[x][y+sign][z+sign];
region[1] = g->gameBoard.region[x+sign][y][z+sign];
region[2] = 19;
} else if ((abs (xCon*yCon*zCon) == 8) || (abs (xCon*yCon*zCon) == 6)) {
if ((xCon == yCon) || (abs (zCon) == 2 &&
(abs (xCon) == 1 || abs (xCon) == 3))) {
//Only one region in this few ones:
region[0] = g->gameBoard.region[x+sign][y+sign][z];
region[1] = 19;
region[2] = 19;
} else if ((xCon == zCon) || (abs (yCon) == 2 &&
(abs (xCon) == 1 || abs (xCon) == 3))) {
region[0] = g->gameBoard.region[x+sign][y][z+sign];
region[1] = 19;
region[2] = 19;
} else if ((yCon == zCon) || (abs (xCon) == 2 &&
(abs (yCon) == 1 || abs (yCon) == 3))) {
region[0] = g->gameBoard.region[x][y+sign][z+sign];
region[1] = 19;
region[2] = 19;
}
} else {
region[0] = g->gameBoard.region[x][y+sign][z+sign];
region[1] = g->gameBoard.region[x+sign][y][z+sign];
region[2] = g->gameBoard.region[x+sign][y+sign][z];
}
return region;
}
coord pathMovement (char * path) {
int move = 0;
int i = 0;
coord movedPoint;
coord start;
//Always start from upper Campus A
start.direction = 3;
start.x = -1;
start.y = 2;
start.z = -3;
movedPoint = start;
//Continuously searches string for movements and make moves to get to point
while (path[i] != 0) {
move = path[i];
movedPoint = movement (movedPoint, move);
i ++;