/testGame.c
C | 1046 lines | 950 code | 48 blank | 48 comment | 202 complexity | 614b54f444b2bc9df29e7dee8f4d2546 MD5 | raw file
- // alexis.shaw, edward.ong, roseline.tayeh, yun.xu (Peter)
- // Mon09Spoons, Aleksander Budzynowski
- // 6/5/2011
- // testGame.c - tests a Game struct implementation.
- #include <stdlib.h>
- #include <stdio.h>
- #include <assert.h>
- #include <string.h>
- #include <math.h>
- #include "Game.h"
- //Edward's #defines
- #define NUM_STUDENT_TYPES 6
- #define NO_OF_INITIAL_ARCS 2
- #define NO_OF_INITIAL_GO8s 0
- #define NO_OF_INITIAL_CAMPUSES 2
- #define NO_OF_INITIAL_IPs 0
- #define NO_OF_INITIAL_PUBs 0
- //Peter's #defines
- #define NUM_STUDENT_TYPES 6
- #define NUM_OF_EACH_TYPE_STUDENT 5
- #define NUM_VERTICIES 54
- #define NUM_EDGES 72
- //Edward's #defines
- #define NUM_STUDENT_TYPES 6
- #define NO_OF_INITIAL_ARCS 2
- #define NO_OF_INITIAL_GO8s 0
- #define NO_OF_INITIAL_CAMPUSES 2
- #define NO_OF_INITIAL_IPs 0
- #define NO_OF_INITIAL_PUBs 0
- //Peter's #defines
- #define NUM_STUDENT_TYPES 6
- #define NUM_OF_EACH_TYPE_STUDENT 5
- #define NUM_EDGES 72
- //alexis shaw's typedefs
- typedef struct _point{
- int x;
- int y;
- }point;
- typedef struct _edge{
- point p1;
- point p2;
- }edge;
- static void testNewGame (void);
- static void testDisposeGame(void);
- static void testGettersReturnDefaults(Game g);
- static void testGetCampusIsDefault(Game g);
- static void testGetArcIsDefault(Game g);
- //alexis Shaw's declarations for helper functions.
- static void getPathThroughEdge(point start,point back,edge end,path destination);
- static int getVertexIndex(int specialPoint);
- static void getPathToVertex(int index, int type, path path);
- static int isOnBoard(int row,int col);
- static int isVertex(int row,int col);
- static int getArrayOfVertecies(point points[]);
- static double getDistance(point p1, point point2);
- static void getPath(point start,point back,point end,path path);
- static point getRight(point input,point back);
- static point getLeft(point input,point back);
- static void getSurroundingVerticies(point p1, point surroundingVertecies[]);
- static int getArrayOfEdges(edge edges[]);
- static void getPathToEdge(int index, int type, path path);
- static int getEdgeIndex(int specialPoint);
- static Game getGameWithStudents(int p1[], int p2[], int p3[],int activePlayer,int nullRoll);
- static Game getGameWithStudentsSmall(int studentType, int Player, int amount,
- int null_roll);
- //Edward's function declarations
- static void givePlayersStudents(int p1[], int p2[], int p3[], int num);
- static void testMakeAction(void);
- // under here are the sub-tests that testMakeAction calls.
- static void testActionBuildGO8(Game g, int activePlayer);
- static void testActionObtainARC(Game g, int activePlayer);
- static void testActionBuildCampus(Game g, int activePlayer);
- static void testActionObtainPublication(Game g, int activePlayer);
- static void testActionObtainIPPatent(Game g, int activePlayer);
- static void testActionRetrainStudents(Game g, int activePlayer, int disciplineFrom, int disciplineTo);
- static void testGetKPIPoints(void);
- static void testThrowDice (void);
- static void testGetStudents(void);
- int main(int argc, char* argv[]){
- printf("\nNow testing newGame()\n");
- testNewGame ();
- printf("\nNow testing disposeGame()\n");
- testDisposeGame();
- testMakeAction();
- printf("\nNow testing getKPIpoints()\n");
- testGetKPIPoints();
- printf("tests passed");
- printf("\nNow testing throwDice()\n");
- testThrowDice ();
- printf("tests passed");
- printf("\nNow testing getStudents()\n");
- testGetStudents();
- printf("tests passed");
- printf("\nAll tests passed! You are Awsome!\n");
- return EXIT_SUCCESS;
- }
- static void testGetStudents(void){
- Game g;
- int p1[NUM_STUDENT_TYPES];
- int p2[NUM_STUDENT_TYPES];
- int p3[NUM_STUDENT_TYPES];
- int null_roll = 0;
- int activePlayer = UNI_A;
- int noOfStudents = 0;
- int disc = 0;
- // test for all possible permutations of activePlayer and disc
- // (student discipline) upto a number of students defined
- // as 20.
- // at noOfStudents = 0, test is equivalent to initialisation test.
- while (noOfStudents < 30){
- activePlayer = 1;
- while (activePlayer < 4){
- givePlayersStudents(p1, p2, p3, noOfStudents);
- g = getGameWithStudents(p1, p2, p3, activePlayer, null_roll); //g with students
- disc = 1;
- while (disc < NUM_STUDENT_TYPES){
- assert(getStudents(g,activePlayer,disc) ==noOfStudents);
- disc++;
- }
- activePlayer++;
- }
- disposeGame(g);
- noOfStudents++;
- }
-
- //TODO: test against rollDice()
- }
- static void testThrowDice (void){
- int g1;
- int g2;
- int g3;
- Game g;
- int dicipline[19] = {0};
- int dice[19] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};
- g = newGame(dicipline, dice);
- throwDice(g, 1);
- g1=getTurnNumber(g);
- throwDice(g, 2);
- g2=getTurnNumber(g);
- assert (g2-g1==1);
- throwDice(g, 2);
- g3=getTurnNumber(g);
- assert (g3-g2==1);
- disposeGame(g);
- }
- //Roseline's test code
- static void testNewGame (void){
- Game g;
- int dicipline[19] = {0};
- int dice[19] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
- printf("Create a new Game g\n");
- g = newGame(dicipline, dice);
- printf("Is g NULL?\n");
- assert(g != NULL);
- printf("test that Getters return default calues on a new Game?\n");
- testGettersReturnDefaults(g);
- printf("test that The board is in a default state for a new Game\n");
- testGetCampusIsDefault(g);
- testGetArcIsDefault(g);
- disposeGame(g);
- printf("tests passed! You are Awsome!\n");
- }
- static void testDisposeGame(void){
- Game g;
- int dicipline[19] = {0};
- int dice[19] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
- printf("Create a new Game g\n");
- g = newGame(dicipline, dice);
- printf("Is g NULL?\n");
- assert(g != NULL);
- printf("does the game crash when disposeGame() is Run?\n");
- disposeGame(g);
- printf("tests passed! You are Awsome!\n");
- }
- static void testGettersReturnDefaults(Game g){
- int player;
- int discipline;
- int disciplineFrom;
- int disciplineTo;
- player = 1;
- while (player < 4){
- printf("\nTesting getters for player %d return Defaults\n", player);
- //am i meant to make the counter 'i' rather than 'player'?
- //if so, what do i do to the player in, say, getKPIpoints(g, player)
- //so that the value of player++? would i change that 'player'
- //to 'i' as well?
- printf("testing that player %d has 24 KPI points\n", player);
- assert (getKPIpoints(g, player)==24);
- printf("testing that player %d has 2 ARCs\n", player);
- assert (getARCs(g, player)==2);
- printf("testing that player %d has 0 GO8s\n", player);
- assert (getGO8s(g, player)==0);
- printf("testing that player %d has 2 Campuses\n", player);
- assert (getCampuses(g, player)==2);
- printf("testing that player %d has 0 IPs\n", player);
- assert (getIPs(g, player)==0);
- printf("testing that player %d has 0 publications\n", player);
- assert (getPublications(g, player)==0);
- printf("testing that player %d has No students of any type\n", player);
- for (discipline=0; discipline<=5; discipline++){
- assert (getStudents(g, player, discipline)==0);
- }
- printf("testing that the default exchange rate for player %d\n", player);
- printf("is 3 for all combinations\n");
- for (disciplineFrom=1; disciplineFrom<6; disciplineFrom++){
- for (disciplineTo=0; disciplineTo<6; disciplineTo++){
- if (disciplineFrom != disciplineTo){
- assert(getExchangeRate(g, player, disciplineFrom, disciplineTo)==3);
- }
- }
- }
- player++;
- }
- }
- static void testGetCampusIsDefault(Game g){
- int index;
- path pathToVertex;
- for (index=0; index<=53; index++){
- getPathToVertex(index, 0, pathToVertex);
- printf("we are testing vertex with path %s\n", pathToVertex);
- if (index==getVertexIndex(0) || index==getVertexIndex(3)){
- printf("campus is of type %d\n", getCampus(g, pathToVertex));
- printf("this is one of UNI_A's campuses, should be %d\n", CAMPUS_A);
- assert (getCampus(g, pathToVertex)==CAMPUS_A);
- } else if (index==getVertexIndex(1) || index==getVertexIndex(4)){
- printf("campus is of type %d\n", getCampus(g, pathToVertex));
- printf("this is one of UNI_B's campuses, should be %d\n", CAMPUS_B);
- assert (getCampus(g, pathToVertex)==CAMPUS_B);
- } else if (index==getVertexIndex(2) || index==getVertexIndex(5)){
- printf("campus is of type %d\n", getCampus(g, pathToVertex));
- printf("this is one of UNI_C's campuses, should be %d\n", CAMPUS_C);
- assert (getCampus(g, pathToVertex)==CAMPUS_C);
- } else{
- printf("campus is of type %d\n", getCampus(g, pathToVertex));
- printf("this is an empty Vertex, should be %d\n",VACANT_VERTEX);
- assert (getCampus(g, pathToVertex)==VACANT_VERTEX);
- }
- }
- }
- static void testGetArcIsDefault(Game g){
- int index;
- path pathToEdge;
- for (index=0; index<=71; index++){
- printf("we are testing vertex with path %s, index is %d\n", pathToEdge, index);
- getPathToEdge(index, 0, pathToEdge);
- if (index==getEdgeIndex(0) || index==getEdgeIndex(3)){
- printf("ARC is of type %d\n", getARC(g, pathToEdge));
- printf("this is one of UNI_A's ARCs, should be %d\n",ARC_A);
- assert (getARC(g, pathToEdge)==ARC_A);
- } else if (index==getEdgeIndex(1) || index==getEdgeIndex(4)){
- printf("ARC is of type %d\n", getARC(g, pathToEdge));
- printf("this is one of UNI_B's ARCs, should be %d\n",ARC_B);
- assert (getARC(g, pathToEdge)==ARC_B);
- } else if (index==getEdgeIndex(2) || index==getEdgeIndex(5)){
- printf("ARC is of type %d\n", getARC(g, pathToEdge));
- printf("this is one of UNI_C's ARCs, should be %d\n",ARC_C);
- assert (getARC(g, pathToEdge)==ARC_C);
- } else{
- assert (getARC(g, pathToEdge)==VACANT_ARC);
- }
- }
- }
- static void givePlayersStudents(int *p1, int *p2, int *p3, int num){
- int typeStudent = 0;
- while (typeStudent < NUM_STUDENT_TYPES){
- p1[typeStudent] = num;
- p2[typeStudent] = num;
- p3[typeStudent] = num;
-
- typeStudent++;
- }
- }
- static void testMakeAction(void){
- Game g;
- int p1[NUM_STUDENT_TYPES];
- int p2[NUM_STUDENT_TYPES];
- int p3[NUM_STUDENT_TYPES];
- int activePlayer = 1;
- int null_roll = 3; // ???
- int i, j;
-
- while (activePlayer < NUM_UNIS+1){
- printf("\nNow testing makeAction, for OBTAIN_ARC for player %d\n", activePlayer);
- givePlayersStudents(p1, p2, p3, 5);
- g = getGameWithStudents(p1, p2, p3, activePlayer, null_roll);
- testActionObtainARC(g, activePlayer);
- disposeGame(g);
- printf("Tests passed, you are Awsome!\n");
- printf("\nNow testing makeAction, for BUILD_CAMPUS for player %d\n", activePlayer);
- givePlayersStudents(p1, p2, p3, 5);
- g = getGameWithStudents(p1, p2, p3, activePlayer, null_roll);
- testActionBuildCampus(g, activePlayer);
- disposeGame(g);
- printf("Tests passed, you are Awsome!\n");
- printf("\nNow testing makeAction, for BUILD_GO8 for player %d\n", activePlayer);
- givePlayersStudents(p1, p2, p3, 5);
- g = getGameWithStudents(p1, p2, p3, activePlayer, null_roll);
- testActionBuildGO8(g, activePlayer);
- disposeGame(g);
- printf("Tests passed, you are Awsome!\n");
- printf("\nNow testing makeAction, for OBTAIN_PUBLICATION for player %d\n", activePlayer);
- givePlayersStudents(p1, p2, p3, 5);
- g = getGameWithStudents(p1, p2, p3, activePlayer, null_roll);
- testActionObtainPublication(g, activePlayer);
- disposeGame(g);
- printf("Tests passed, you are Awsome!\n");
- printf("\nNow testing makeAction, for OBTAIN_IP_PATENT for player %d\n", activePlayer);
- givePlayersStudents(p1, p2, p3, 5);
- g = getGameWithStudents(p1, p2, p3, activePlayer, null_roll);
- testActionObtainIPPatent(g, activePlayer);
- disposeGame(g);
- printf("Tests passed, you are Awsome!\n");
- printf("\nNow testing makeAction, for RETRAIN_STUDENTS for player %d\n", activePlayer);
- i=1;
- while (i<NUM_STUDENT_TYPES){
- j = 1;
- while (j<NUM_STUDENT_TYPES){;
- if(i != j){
- printf("between Student type %d and Student type %d\n", i,j);
- givePlayersStudents(p1, p2, p3, 5);
- g = getGameWithStudents(p1, p2, p3, activePlayer, null_roll);
- testActionRetrainStudents(g, activePlayer, i, j);
- disposeGame(g);
- }
- j++;
- }
- i++;
- }
- printf("Tests passed, you are Awsome!\n");
- activePlayer++;
- }
- }
- static void testActionRetrainStudents(Game g, int activePlayer, int disciplineFrom, int disciplineTo){
- action theAction;
- int exchangeRateBefore[NUM_STUDENT_TYPES][NUM_STUDENT_TYPES];
- int exchangeRateAfter[NUM_STUDENT_TYPES][NUM_STUDENT_TYPES];
- int studentsBefore[NUM_STUDENT_TYPES];
- int studentsAfter[NUM_STUDENT_TYPES];
- int i,j;
- int cost;
- theAction.disciplineFrom = disciplineFrom;
- theAction.disciplineTo = disciplineTo;
- theAction.actionCode = RETRAIN_STUDENTS;
- getPathToVertex(getVertexIndex(0), 0, theAction.destination);
- cost = getExchangeRate (g, activePlayer, disciplineFrom, disciplineTo);
- i=0;
- while (i < NUM_STUDENT_TYPES){
- j = 0; // can't retrain type 0 (THDs).. lol. (:
- while (j < NUM_STUDENT_TYPES){
- exchangeRateBefore[i][j] = getExchangeRate (g, activePlayer, i, j);
- j++;
- }
- i++;
- }
- i=0;
- while (i < NUM_STUDENT_TYPES){
- studentsBefore[i] = getStudents(g, activePlayer, i);
- i++;
- }
- makeAction(g, theAction);
- i=0;
- while (i < NUM_STUDENT_TYPES){
- j = 0;
- while (j < NUM_STUDENT_TYPES){
- exchangeRateAfter[i][j] = getExchangeRate (g, activePlayer, i, j);
- j++;
- }
- i++;
- }
- i=0;
- while (i < NUM_STUDENT_TYPES){
- studentsAfter[i] = getStudents(g, activePlayer, i);
- i++;
- }
- // retraining checks..
- // tests every valid permutation of
- // disciplineTo's and disciplineFrom's
- printf("checking that the exchange rates have not changed\n");
- i = 1;
- while (i < NUM_STUDENT_TYPES){
- j = 0;
- while (j < NUM_STUDENT_TYPES){
- assert(exchangeRateAfter[i][j] == exchangeRateBefore[i][j]);
- j++;
- }
- i++;
- }
- printf("checking that the number of students has changed in the\n");
- printf("right way\n");
- i=0;
- while (i < NUM_STUDENT_TYPES){
- if (i == disciplineFrom){
- assert(studentsAfter[i] == (studentsBefore[i] - cost));
- } else if (i == disciplineTo){
- assert(studentsAfter[i] == (studentsBefore[i] + 1));
- } else {
- assert(studentsBefore[i] == studentsAfter[i]);
- }
- i++;
- }
- //TODO: more tests.
- }
- static void testActionObtainIPPatent(Game g, int activePlayer){
- action theAction;
- theAction.actionCode = OBTAIN_IP_PATENT;
- getPathToVertex(getVertexIndex(0), 0, theAction.destination);
- int IPsBefore = getIPs(g, activePlayer);
- int KPIsBefore = getKPIpoints(g, activePlayer);
- int studentMJBefore = getStudents(g, activePlayer, STUDENT_MJ);
- int studentMMBefore = getStudents(g, activePlayer, STUDENT_MMONEY);
- int studentMTVBefore = getStudents(g, activePlayer, STUDENT_MTV);
- printf("doing makeAction with OBTAIN_IP_PATENT\n");
- makeAction(g, theAction);
- int IPsAfter = getIPs(g, activePlayer);
- int KPIsAfter = getKPIpoints(g, activePlayer);
- int studentMJAfter = getStudents(g, activePlayer, STUDENT_MJ);
- int studentMMAfter = getStudents(g, activePlayer, STUDENT_MMONEY);
- int studentMTVAfter = getStudents(g, activePlayer, STUDENT_MTV);
- printf("Checking that OBTAIN_PUBLICATION has the right cost\n");
- assert(studentMJAfter == studentMJBefore- 1);
- assert(studentMMAfter == studentMMBefore - 1);
- assert(studentMTVAfter == studentMTVBefore - 1);
- // give 10 more KPI points
- printf("checking that the number of KPIs has been incremented by 10\n");
- assert(KPIsAfter == KPIsBefore + 10);
- // increment getIPs()
- printf("checking that the number of IPs has been incremented by 1\n");
- assert(IPsAfter == IPsBefore + 1);
- // should not change anything else (just checking no. campuses atm)
- }
- static void testActionObtainPublication(Game g, int activePlayer){
- action theAction;
- theAction.actionCode = OBTAIN_PUBLICATION;
- getPathToVertex(getVertexIndex(0), 0, theAction.destination);
-
- int studentMJBefore = getStudents(g, activePlayer, STUDENT_MJ);
- int studentMMBefore = getStudents(g, activePlayer, STUDENT_MMONEY);
- int studentMTVBefore = getStudents(g, activePlayer, STUDENT_MTV);
- printf("Now running makeAction with OBTAIN_PUBLICATION\n");
- makeAction(g, theAction);
- int studentMJAfter = getStudents(g, activePlayer, STUDENT_MJ);
- int studentMMAfter = getStudents(g, activePlayer, STUDENT_MMONEY);
- int studentMTVAfter = getStudents(g, activePlayer, STUDENT_MTV);
- // cost of publication
- printf("Checking that OBTAIN_PUBLICATION has the right cost\n");
- assert(studentMJAfter == studentMJBefore- 1);
- assert(studentMMAfter == studentMMBefore - 1);
- assert(studentMTVAfter == studentMTVBefore - 1);
- // todo: max no of publication bonus KPI points check
-
- }
- static void testActionObtainARC(Game g, int activePlayer){
- action theAction;
- int edgeIndex[4] = {0, 5, 26, 54};
- getPathToEdge(edgeIndex[activePlayer], 0, theAction.destination);
- theAction.actionCode = OBTAIN_ARC;
- int edgeCode[NUM_EDGES];
- path tempPath;
- int i = 0;
- while (i < NUM_EDGES){
- getPathToEdge(i, 0, tempPath);
- edgeCode[i] = getARC(g, tempPath);
- i++;
- }
- int KPIsBefore = getKPIpoints(g, activePlayer);
- int ARCsBefore = getARCs(g, activePlayer);
- int studentBPSBefore = getStudents(g, activePlayer, STUDENT_BPS);
- int studentBQNBefore = getStudents(g, activePlayer, STUDENT_BQN);
- makeAction(g, theAction);
- int KPIsAfter = getKPIpoints(g, activePlayer);
- int ARCsAfter = getARCs(g, activePlayer);
- int studentBPSAfter = getStudents(g, activePlayer, STUDENT_BPS);
- int studentBQNAfter = getStudents(g, activePlayer, STUDENT_BQN);
- // cost of obtaining ARC
- assert(studentBPSAfter == studentBPSBefore - 1);
- assert(studentBQNAfter == studentBQNBefore - 1);
- // increment number of ARCs for player
- printf("Checking that the number of ARCs is incremented by 1\n");
- assert(ARCsAfter == ARCsBefore + 1);
- // increase value of KPI by 12
- printf("Checking that the number of GO8s is incremented by 12\n");
- assert(KPIsAfter == KPIsBefore + 12);
-
- printf("checking that the only edge that has changed is the\n");
- printf("arc that we changed\n");
- i = 0;
- while (i < NUM_EDGES){
- getPathToEdge(i, 0, tempPath);
- if(i == edgeIndex[activePlayer]){
- assert((activePlayer) == getARC(g, tempPath));
- } else {
- assert(edgeCode[i] == getARC(g, tempPath));
- }
- i++;
- }
-
- // TODO - stuff happening with leader of ARCs and such.
- }
- static void testActionBuildCampus(Game g, int activePlayer){
- action theAction;
- int arcIndex[4] = {0, 5, 26, 54};
- int vertexIndex[4] = {0,8,19,37};
- theAction.actionCode = OBTAIN_ARC;
- getPathToEdge(arcIndex[activePlayer], 0, theAction.destination);
- printf("doing OBTAIN_ARC on path %s\n", theAction.destination);
- makeAction(g, theAction);
- theAction.actionCode = BUILD_CAMPUS;
- getPathToVertex(vertexIndex[activePlayer], 0, theAction.destination);
- int campusCode[NUM_VERTICIES];
- path tempPath;
- int i = 0;
- while (i < NUM_VERTICIES){
- getPathToVertex(i, 0, tempPath);
- campusCode[i] = getCampus(g, tempPath);
- i++;
- }
- int campusesBefore = getCampuses(g, activePlayer);
- int KPIPointsBefore = getKPIpoints(g, activePlayer);
- int studentBPSBefore = getStudents(g, activePlayer, STUDENT_BPS);
- int studentBQNBefore = getStudents(g, activePlayer, STUDENT_BQN);
- int studentMJBefore = getStudents(g, activePlayer, STUDENT_MJ);
- int studentMTVBefore = getStudents(g, activePlayer, STUDENT_MTV);
- printf("doing action BUILD_CAMPUS on path %s\n", theAction.destination);
- makeAction(g, theAction);
- int campusesAfter = getCampuses(g, activePlayer);
- int KPIPointsAfter = getKPIpoints(g, activePlayer);
- int studentBPSAfter = getStudents(g, activePlayer, STUDENT_BPS);
- int studentBQNAfter = getStudents(g, activePlayer, STUDENT_BQN);
- int studentMJAfter = getStudents(g, activePlayer, STUDENT_MJ);
- int studentMTVAfter = getStudents(g, activePlayer, STUDENT_MTV);
- printf("Checking that the number of Campuses is incremented by 1\n");
- //Number of campuses incremenet
- assert(campusesAfter == campusesBefore + 1);
- printf("Checking that the number of KPIs is incremented by 10\n");
- // KPI points increment
- assert(KPIPointsAfter == KPIPointsBefore + 10);
- printf("Checking that the number of students has been decremented\n");
- printf("by the right amount\n");
- //cost of building campus
- assert(studentBPSAfter == studentBPSBefore - 1);
- assert(studentBQNAfter == studentBQNBefore - 1);
- assert(studentMJAfter == studentMJBefore - 1);
- assert(studentMTVAfter == studentMTVBefore - 1);
-
- //change in tile state - checks every single tile!
- i = 0;
- while (i < NUM_VERTICIES){
- getPathToVertex(i, 0, tempPath);
- if(i == vertexIndex[activePlayer]){
- assert((activePlayer) == getCampus(g, tempPath));
- } else {
- assert(campusCode[i] == getCampus(g, tempPath));
- }
- i++;
- }
- }
- static void testActionBuildGO8(Game g, int activePlayer){
- action theAction;
- theAction.actionCode = BUILD_GO8;
- int index[NUM_UNIS+1] = {0, 0, 1, 2};
- getPathToVertex(getVertexIndex(index[activePlayer]), 0, theAction.destination);
- int campusCode[NUM_VERTICIES];
- path tempPath;
- int i = 0;
- while (i < NUM_VERTICIES){
- getPathToVertex(i, 0, tempPath);
- campusCode[i] = getCampus(g, tempPath);
- i++;
- }
- int campusesBefore = getCampuses(g, activePlayer);
- int GO8sBefore = getGO8s(g, activePlayer);
- int KPIsBefore = getKPIpoints(g, activePlayer);
- int studentMJBefore= getStudents(g, activePlayer, STUDENT_MJ);
- int studentMMBefore= getStudents(g, activePlayer, STUDENT_MMONEY);
- printf("doing BUILD_GO8 on path %s\n", theAction.destination);
- makeAction(g, theAction);
- int campusesAfter = getCampuses(g, activePlayer);
- int GO8sAfter = getGO8s(g, activePlayer);
- int KPIsAfter = getKPIpoints(g, activePlayer);
- int studentMJAfter = getStudents(g, activePlayer, STUDENT_MJ);
- int studentMMAfter = getStudents(g, activePlayer, STUDENT_MMONEY);
- // decrement in number of campuses
- printf("Checking that the number of campuses is decremented by 1\n");
- assert(campusesAfter == campusesBefore - 1);
- // increment in number of GO8s
- printf("Checking that the number of GO8s is incremented by 1\n");
- assert(GO8sAfter == GO8sBefore + 1);
- // KPI + 10
- printf("Checking that a player has 10 more KPIs than before\n");
- assert(KPIsAfter == KPIsBefore + 10);
- // cost of building
- printf("Checking that the number of students you have is\n");
- printf("decreased by the right ammount\n");
- assert(studentMJAfter == studentMJBefore - 2);
- assert(studentMMAfter == studentMMBefore - 3);
-
- //change in tile state - checking in EVERY tile.
- printf("checking that the board has only changed by converting a\n");
- printf("camapus to a GO8 of the right type and in the right spot\n");
- i = 0;
- while (i < NUM_VERTICIES){
- getPathToVertex(i, 0, tempPath);
- if(i == getVertexIndex(index[activePlayer])){
- assert((activePlayer + 3) == getCampus(g, tempPath));
- } else {
- assert(campusCode[i] == getCampus(g, tempPath));
- }
- i++;
- }
- }
- static void testGetKPIPoints(void){
- Game g;
- int p1[NUM_STUDENT_TYPES];
- int p2[NUM_STUDENT_TYPES];
- int p3[NUM_STUDENT_TYPES];
- int activePlayer = 1;
- int null_roll = 4;
- int noOfCampuses;
- int noOfGO8;
- int noOfARC;
- int noOfIP;
- int hasLargestARC;
- int hasLargestPubs;
- int expectedKPI;
- givePlayersStudents(p1, p2, p3, 1);
-
- while (activePlayer < NUM_UNIS + 1){
- g = getGameWithStudents(p1, p2, p3, activePlayer, null_roll);
- noOfCampuses = getCampuses(g,activePlayer);
- noOfGO8 = getGO8s(g,activePlayer);
- noOfARC = getARCs(g,activePlayer);
- noOfIP = getIPs(g,activePlayer);
-
- // this is a cheap hack.
- hasLargestARC = (getMostARCs (g) == activePlayer);
- hasLargestPubs = (getMostPublications (g) == activePlayer);
-
- expectedKPI = 10*noOfCampuses + 20*noOfGO8 + 2*noOfARC
- + 10*noOfIP + 10*hasLargestARC + 10*hasLargestPubs;
-
- // testing correct calculation of KPI
- assert(getKPIpoints(g, activePlayer) == expectedKPI);
-
- /* TODO (WT#1#): test for change of game state */
- activePlayer++;
- disposeGame (g);
- }
- }
- //Alexis Shaw's test code
- static Game getGameWithStudentsSmall(int studentType, int Player, int amount,
- int nullRoll){
- int regions[19] = {studentType,0,studentType,0,0,0,0,studentType,
- 0,0,0,0,0,0,0,0,0,0,0};
- int dice[2][19] = {{1,0,2,0,0,0,0,3,0,0,0,4,0,0,0,0,5,0,6},
- {8,0,9,0,0,0,0,10,0,0,0,11,0,0,0,0,12,0,13}};
- int diceToRoll[2][3][2] = {{{3,4},{1,6},{2,5}},
- {{10,11},{8,13},{9,13}}};
- int diceSet;
- if(nullRoll<7){
- diceSet = 0;
- } else {
- diceSet = 1;
- }
- Game g = newGame (regions, dice[diceSet]);
- int k;
- k = 0;
- while(k<amount){
- throwDice(g, diceToRoll[diceSet][Player][0]);
- k++;
- }
- while(getWhoseTurn (g) != Player){
- throwDice(g, nullRoll);
- }
- return g;
- }
- static Game getGameWithStudents(int p1[], int p2[], int p3[],int activePlayer,int nullRoll){
- int regions[19] = {STUDENT_BPS,0,STUDENT_BPS,0,0,0,0,STUDENT_BPS,
- 0,0,0,STUDENT_THD,0,0,0,0,STUDENT_THD,0,STUDENT_THD};
- int dice[2][19] = {{1,0,2,0,0,0,0,3,0,0,0,4,0,0,0,0,5,0,6},
- {8,0,9,0,0,0,0,10,0,0,0,11,0,0,0,0,12,0,13}};
- int diceToRoll[2][3][2] = {{{3,4},{1,6},{2,5}},
- {{10,11},{8,13},{9,13}}};
- int diceSet;
- int students[3][6];
- int i,j,k;
- i=0;
- while (i<6) {
- students[0][i] = p1[i];
- i++;
- }
- i=0;
- while (i<6) {
- students[1][i] = p2[i];
- i++;
- }
- i=0;
- while (i<6) {
- students[2][i] = p3[i];
- i++;
- }
- if(nullRoll<7){
- diceSet = 0;
- } else {
- diceSet = 1;
- }
- Game g = newGame (regions, dice[diceSet]);
- throwDice(g, nullRoll);
- i=0;
- action myAction;
- myAction.disciplineFrom = STUDENT_BPS;
- myAction.actionCode = RETRAIN_STUDENTS;
-
- while (i < 3){
- j = 0;
- while (j<6){
- k = 0;
- while(k<students[i][j]){
- if(j == STUDENT_THD){
- throwDice(g, diceToRoll[diceSet][i][1]);
- throwDice(g, nullRoll);
- throwDice(g, nullRoll);
- } else if(j == STUDENT_BPS){
- throwDice(g, diceToRoll[diceSet][i][0]);
- throwDice(g, nullRoll);
- throwDice(g, nullRoll);
- } else {
- myAction.disciplineTo = j;
- throwDice(g, diceToRoll[diceSet][i][0]);
- throwDice(g, nullRoll);
- throwDice(g, nullRoll);
- throwDice(g, diceToRoll[diceSet][i][0]);
- throwDice(g, nullRoll);
- throwDice(g, nullRoll);
- throwDice(g, diceToRoll[diceSet][i][0]);
- throwDice(g, nullRoll);
- throwDice(g, nullRoll);
- makeAction(g, myAction);
- }
- k++;
- }
- j++;
- }
- throwDice(g, nullRoll);
- i++;
- }
- while((getWhoseTurn (g) != activePlayer)){
- throwDice(g, nullRoll);
- }
- return g;
- }
- static int getEdgeIndex(int specialPoint){
- int specialPointArray[6] = {1, 18, 60, 70, 51, 15};
- return specialPointArray[specialPoint];
- }
- static void getPathToEdge(int index, int type, path destination){
- edge edges[150];
- getArrayOfEdges(edges);
- point start = {2, 10};
- point back = {-100, -100};
- getPathThroughEdge(start,back,edges[index],destination);
- }
- static int getArrayOfEdges(edge edges[]){
- int i = 0;
- int row = 10;
- while(row>=0){
- int col=0;
- while( col<=10){
- if(isVertex(row, col) && isOnBoard(row, col)){
- if(isVertex(row, col+1) && isOnBoard(row, col+1)){
- edges[i].p1.x = col;
- edges[i].p1.y = row;
- edges[i].p2.x = col+1;
- edges[i].p2.y = row;
- i++;
- }
- if(isVertex(row-1, col) && isOnBoard(row-1,col)){
- edges[i].p1.x = col;
- edges[i].p1.y = row;
- edges[i].p2.x = col;
- edges[i].p2.y = row-1;
- i++;
- }
- if(isVertex(row-1,col+1)&& isOnBoard(row-1, col+1)){
- edges[i].p1.x = col;
- edges[i].p1.y = row;
- edges[i].p2.x = col+1;
- edges[i].p2.y = row-1;
- i++;
- }
- }
- col++;
- }
- row --;
- }
- return i;
- }
- static int getVertexIndex(int specialPoint){
- int specialPointArray[6] = {0, 6, 42, 53, 41, 11};
- return specialPointArray[specialPoint];
- }
- static void getPathToVertex(int index, int type, path destination){
- point points[100];
- getArrayOfVertecies(points);
- point start = {2, 10};
- point back = {-100, -100};
- getPath(start,back,points[index],destination);
- }
- static int isOnBoard(int row,int col){
- return (((row+2*col)>= 7)&& ((2*row+col)>= 7) && ((row-col) <= 8) &&
- ((2*row + col) <= 23) && ((row+2*col) <= 23) && ((col- row) <= 8));
- }
- static int isVertex(int row,int col){
- return ((row - col)%3 != 0);
- }
- static int getArrayOfVertecies(point points[]){
- int i = 0;
- int row = 10;
- while(row>=0){
- int col=0;
- while( col<=10){
- if(isVertex(row, col) && isOnBoard(row, col)){
- points[i].x = col;
- points[i].y = row;
- i++;
- }
- col++;
- }
- row --;
- }
- return i;
- }
- static double getDistance(point p1, point point2){
- double ix1;
- double iy1;
- double iy2;
- double ix2;
- double xBasisx = 1;
- double xBasisy = 0;
- double yBasisx = cos(M_PI/3);
- double yBasisy = sin(M_PI/3);
- ix1 = p1.x*xBasisx + p1.y*yBasisx;
- iy1 = p1.x*xBasisy + p1.y*yBasisy;
- ix2 = point2.x*xBasisx + point2.y*yBasisx;
- iy2 = point2.x*xBasisy + point2.y*yBasisy;
- return (ix1-ix2)*(ix1-ix2) + (iy1-iy2)*(iy1-iy2);
- }
- static void getPathThroughEdge(point start,point back,edge end,path destination){
- point currentNode = start;
- point currentBackDirection = back;
- double Ldist;
- double Rdist;
- double Bdist;
- char next[3] = {0};
- destination[0] = '\0';
- point temp;
- while((currentNode.x != end.p1.x) || (currentNode.y != end.p1.y)){
- Bdist = getDistance(end.p1, currentBackDirection);
- Rdist = getDistance(end.p1, getRight(currentNode, currentBackDirection));
- Ldist = getDistance(end.p1, getLeft(currentNode, currentBackDirection));
- if(Rdist < Ldist){
- if (Rdist < Bdist){
- next[0] = 'R';
- } else {
- next[0] = 'B';
- }
- } else if (Rdist > Ldist){
- if (Ldist < Bdist){
- next[0] = 'L';
- } else {
- next[0] = 'B';
- }
- } else {
- if (Bdist < Rdist){
- next[0] = 'B';
- } else {
- next[0] = 'R';
- }
- }
- strcat (destination, next);
- temp = currentNode;
- if(next[0] == 'L'){
- currentNode = getLeft(currentNode, currentBackDirection);
- currentBackDirection = temp;
- } else if (next [0]== 'R'){
- currentNode = getRight(currentNode, currentBackDirection);
- currentBackDirection = temp;
- } else if (next[0] == 'B'){
- currentNode = currentBackDirection;
- currentBackDirection = temp;
- }
- }
- if(end.p2.x == currentBackDirection.x && end.p2.y == currentBackDirection.y){
- next[0] = 'B';
- } else if (end.p2.x == getLeft(currentNode, currentBackDirection).x
- && end.p2.y == getLeft(currentNode, currentBackDirection).y){
- next[0] = 'L';
- } else if (end.p2.x == getRight(currentNode, currentBackDirection).x
- && end.p2.y == getRight(currentNode, currentBackDirection).y){
- next[0] = 'R';
- }
- strcat (destination, next);
- }
- static void getPath(point start,point back,point end,path destination){
- point currentNode = start;
- point currentBackDirection = back;
- double Ldist;
- double Rdist;
- double Bdist;
- char next[3] = {0};
- destination[0] = '\0';
- point temp;
- while((currentNode.x != end.x) || (currentNode.y != end.y)){
- Bdist = getDistance(end, currentBackDirection);
- Rdist = getDistance(end, getRight(currentNode, currentBackDirection));
- Ldist = getDistance(end, getLeft(currentNode, currentBackDirection));
- if(Rdist < Ldist){
- if (Rdist < Bdist){
- next[0] = 'R';
- } else {
- next[0] = 'B';
- }
- } else if (Rdist > Ldist){
- if (Ldist < Bdist){
- next[0] = 'L';
- } else {
- next[0] = 'B';
- }
- } else {
- if (Bdist < Rdist){
- next[0] = 'B';
- } else {
- next[0] = 'R';
- }
- }
- strcat (destination, next);
- temp = currentNode;
- if(next[0] == 'L'){
- currentNode = getLeft(currentNode, currentBackDirection);
- currentBackDirection = temp;
- } else if (next [0]== 'R'){
- currentNode = getRight(currentNode, currentBackDirection);
- currentBackDirection = temp;
- } else if (next[0] == 'B'){
- currentNode = currentBackDirection;
- currentBackDirection = temp;
- }
- }
- }
- static point getRight(point input,point back){
- int backcount;
- int i=0;
- point surroundingVertecies[3];
- getSurroundingVerticies(input, surroundingVertecies);
- while(i<3){
- if((surroundingVertecies[i].x == back.x) && (surroundingVertecies[i].y == back.y)){
- backcount = i;
- }
- i++;
- }
- return surroundingVertecies[(backcount+2)%3];
- }
- static point getLeft(point input,point back){
- int backcount;
- int i=0;
- point surroundingVertecies[3];
- getSurroundingVerticies(input, surroundingVertecies);
- while(i<3){
- if((surroundingVertecies[i].x == back.x) && (surroundingVertecies[i].y == back.y)){
- backcount = i;
- }
- i++;
- }
- return surroundingVertecies[(backcount+1)%3];
- }
- static void getSurroundingVerticies(point p1, point surroundingVertecies[]){
- int i = 0;
- if(isVertex(p1.x,p1.y+1)){
- point temp = {p1.x, p1.y +1};
- surroundingVertecies[i] = temp;
- i++;
- }
- if(isVertex(p1.x+1,p1.y)){
- point temp = {p1.x+1, p1.y};
- surroundingVertecies[i] = temp;
- i++;
- }
- if(isVertex(p1.x+1,p1.y-1)){
- point temp = {p1.x+1, p1.y -1};
- surroundingVertecies[i] = temp;
- i++;
- }
- if(isVertex(p1.x,p1.y-1)){
- point temp = {p1.x, p1.y-1};
- surroundingVertecies[i] = temp;
- i++;
- }
- if(isVertex(p1.x-1,p1.y)){
- point temp = {p1.x-1, p1.y};
- surroundingVertecies[i] = temp;
- i++;
- }
- if(isVertex(p1.x-1,p1.y+1)){
- point temp = {p1.x-1, p1.y+1};
- surroundingVertecies[i] = temp;
- i++;
- }
- for(i=0; i<3; i++){
- if(!isOnBoard(surroundingVertecies[i].x, surroundingVertecies[i].y)){
- surroundingVertecies[i].x = -100;
- surroundingVertecies[i].y = -100;
- }
- }
- }