Exemple #1
0
// test getMostArcs
void test5(void) {
    printf("\n\n\n\n");
    action a;
    int disciplines[] = {4,2,5,4,2,2,3,5,1,3,5,4,4,4,3,5,4,0,5};
    int dice[] = {8,10,8,9,6,4,4,5,12,3,11,6,3,11,2,7,5,6,5};
    Game g = newGame(disciplines, dice);
    throwDice(g, 7);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "L", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 0, a.disciplineTo = 0;
    makeAction(g, a);
    assert(getMostARCs(g) == 1);
}
Exemple #2
0
//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;
}
Exemple #3
0
void testInitialisation (Game testGame){
   
   action testAction;
   
   printf ("Testing initial conditions.\n");
   
   printf ("Testing getDiscipline.\n");
   assert (getDiscipline(testGame, 0) == STUDENT_BQN);
   assert (getDiscipline(testGame, 1) == STUDENT_MMONEY);
   assert (getDiscipline(testGame, 2) == STUDENT_MJ);
   assert (getDiscipline(testGame, 3) == STUDENT_MMONEY);
   assert (getDiscipline(testGame, 4) == STUDENT_MJ);
   assert (getDiscipline(testGame, 5) == STUDENT_BPS);
   assert (getDiscipline(testGame, 6) == STUDENT_MTV);
   assert (getDiscipline(testGame, 7) == STUDENT_MTV);
   assert (getDiscipline(testGame, 8) == STUDENT_BPS);
   assert (getDiscipline(testGame, 9) == STUDENT_MTV);
   assert (getDiscipline(testGame, 10) == STUDENT_BQN);
   assert (getDiscipline(testGame, 11) == STUDENT_MJ);
   assert (getDiscipline(testGame, 12) == STUDENT_BQN);
   assert (getDiscipline(testGame, 13) == STUDENT_THD);
   assert (getDiscipline(testGame, 14) == STUDENT_MJ);
   assert (getDiscipline(testGame, 15) == STUDENT_MMONEY);
   assert (getDiscipline(testGame, 16) == STUDENT_MTV);
   assert (getDiscipline(testGame, 17) == STUDENT_BQN);
   assert (getDiscipline(testGame, 18) == STUDENT_BPS);
   
   printf ("Testing getDiceValue\n");
   assert (getDiceValue(testGame, 0) == 9);
   assert (getDiceValue(testGame, 1) == 10);
   assert (getDiceValue(testGame, 2) == 8);
   assert (getDiceValue(testGame, 3) == 12);
   assert (getDiceValue(testGame, 4) == 6);
   assert (getDiceValue(testGame, 5) == 5);
   assert (getDiceValue(testGame, 6) == 3);
   assert (getDiceValue(testGame, 7) == 11);
   assert (getDiceValue(testGame, 8) == 3);
   assert (getDiceValue(testGame, 9) == 11);
   assert (getDiceValue(testGame, 10) == 4);
   assert (getDiceValue(testGame, 11) == 6);
   assert (getDiceValue(testGame, 12) == 4);
   assert (getDiceValue(testGame, 13) == 7);
   assert (getDiceValue(testGame, 14) == 9);
   assert (getDiceValue(testGame, 15) == 2);
   assert (getDiceValue(testGame, 16) == 8);
   assert (getDiceValue(testGame, 17) == 10);
   assert (getDiceValue(testGame, 18) == 5);
   
   printf ("Testing Most ARC\n");
   assert (getMostARCs(testGame) == NO_ONE);
   
   printf ("Testing most publications\n");
   assert (getMostPublications (testGame) == NO_ONE);
   
   printf ("Testing turnNumber\n");
   assert (getTurnNumber(testGame) == -1);
   
   printf ("Testing whoseTurn.\n");
   assert (getWhoseTurn (testGame) == NO_ONE);

   printf("Testing getCampus (content of given vertex) \n");
   assert (getCampus (testGame, "RLBLR") == VACANT_VERTEX);
   assert (getCampus (testGame, "RLBBR") == VACANT_VERTEX);
   assert (getCampus (testGame, "LRL") == VACANT_VERTEX);
   
   printf("Testing getARC (content of given edge) \n");
   assert (getARC (testGame, "L") == VACANT_ARC);
   assert (getARC (testGame, "R") == VACANT_ARC);
   assert (getARC (testGame, "LR") == VACANT_ARC);
   assert (getARC (testGame, "RR") == VACANT_ARC);
   
   printf ("Testing isLegalAction\n");
   assert (isLegalAction (testGame, testAction) == FALSE);
   
   printf ("Testing KPI points\n");
   assert (getKPIpoints (testGame, UNI_A) == 0);
   assert (getKPIpoints (testGame, UNI_B) == 0);
   assert (getKPIpoints (testGame, UNI_C) == 0);
   
   printf ("Testing getARCs (number of ARC grants) \n");
   assert (getARCs (testGame, UNI_A) == 0);
   assert (getARCs (testGame, UNI_B) == 0);
   assert (getARCs (testGame, UNI_C) == 0);
   
   printf ("Testing GO8 (number of G08 campus) \n");
   assert (getGO8s (testGame, UNI_A) == 0);
   assert (getGO8s (testGame, UNI_B) == 0);
   assert (getGO8s (testGame, UNI_C) == 0);
   
   printf ("Testing getCampuses (number of normal campuses)\n");
   assert (getCampuses (testGame, UNI_A) == 2);
   assert (getCampuses (testGame, UNI_B) == 2);
   assert (getCampuses (testGame, UNI_C) == 2);
   
   printf ("Testing IPs (number of IP patent) \n");
   assert (getIPs(testGame, UNI_A) == 0);
   assert (getIPs(testGame, UNI_B) == 0);
   assert (getIPs(testGame, UNI_C) == 0);
   
   printf ("Testing publications\n");
   assert (getPublications(testGame, UNI_A) == 0);
   assert (getPublications(testGame, UNI_B) == 0);
   assert (getPublications(testGame, UNI_C) == 0);
 
   printf ("Testing number of students of UNI_A\n");
   assert (getStudents (testGame, UNI_A, STUDENT_THD) == 0);
   assert (getStudents (testGame, UNI_A, STUDENT_BPS) == 3);
   assert (getStudents (testGame, UNI_A, STUDENT_BQN) == 3);
   assert (getStudents (testGame, UNI_A, STUDENT_MJ) == 1);
   assert (getStudents (testGame, UNI_A, STUDENT_MTV) == 1);
   assert (getStudents (testGame, UNI_A, STUDENT_MMONEY) == 1);

   printf ("Testing number of students of UNI_B\n");
   assert (getStudents (testGame, UNI_B, STUDENT_THD) == 0);
   assert (getStudents (testGame, UNI_B, STUDENT_BPS) == 3);
   assert (getStudents (testGame, UNI_B, STUDENT_BQN) == 3);
   assert (getStudents (testGame, UNI_B, STUDENT_MJ) == 1);
   assert (getStudents (testGame, UNI_B, STUDENT_MTV) == 1);
   assert (getStudents (testGame, UNI_B, STUDENT_MMONEY) == 1);
   
   printf ("Testing number of students of UNI_C\n");
   assert (getStudents (testGame, UNI_C, STUDENT_THD) == 0);
   assert (getStudents (testGame, UNI_C, STUDENT_BPS) == 3);
   assert (getStudents (testGame, UNI_C, STUDENT_BQN) == 3);
   assert (getStudents (testGame, UNI_C, STUDENT_MJ) == 1);
   assert (getStudents (testGame, UNI_C, STUDENT_MTV) == 1);
   assert (getStudents (testGame, UNI_C, STUDENT_MMONEY) == 1);
   

   printf ("Testing getExchangeRate for UNI_A\n");
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MTV) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MMONEY) == 3);
   
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MMONEY) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MTV) == 3);
   
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MTV) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MMONEY) == 3);
   
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MTV) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MMONEY) == 3);
   
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MTV) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MMONEY) == 3);
  
   printf ("All tests passed\n\n");
   
   
}
int main(int argc, char *argv[]) {

   int discipline[6] = {STUDENT_THD, STUDENT_BPS, STUDENT_BQN,
                        STUDENT_MJ, STUDENT_MTV, STUDENT_MMONEY}
   int dice[6] = {1, 2, 3, 4, 5, 6}

   newGame(*discipline[], dice[]);

   //Tests void makeAction
   action a;
   a.actionCode = BUILD_CAMPUS;
   a.destination = L;
   a.disciplineFrom = STUDENT_BPS;
   a.disciplineTo = STUDENT_MTV;
   
   assert(a.actionCode == BUILD_CAMPUS);
   assert(a.destination == L);
   assert(a.disciplineFrom == STUDENT_BPS);
   assert(a.discplineTo == STUDENT_MTV);




   //Tests void throwDice
   assert(diceScore >= 2 && diceScore <= 12);

   //Tests int getDiscipline
   assert (getDiscipline(Game g, 0) == STUDENT_BGN); 
   assert (getDiscipline(Game g, 1) == STUDENT_MMONEY);
   assert (getDiscipline(Game g, 2) == STUDENT_MJ);
   assert (getDiscipline(Game g, 3) == STUDENT_MMONEY);
   assert (getDiscipline(Game g, 4) == STUDENT_MJ); 
   assert (getDiscipline(Game g, 5) == STUDENT_BPS);
   assert (getDiscipline(Game g, 6) == STUDENT_MTV);
   assert (getDiscipline(Game g, 7) == STUDENT_MTV);
   assert (getDiscipline(Game g, 8) == STUDENT_BPS);
   assert (getDiscipline(Game g, 9) == STUDENT_MTV);
   assert (getDiscipline(Game g, 10) == STUDENT_BQN);
   assert (getDiscipline(Game g, 11) == STUDENT_MJ);
   assert (getDiscipline(Game g, 12) == STUDENT_BQN);
   assert (getDiscipline(Game g, 13) == STUDENT_THD);
   assert (getDiscipline(Game g, 14) ==  STUDENT_MJ);
   assert (getDiscipline(Game g, 15) == STUDENT_MMONEY);
   assert (getDiscipline(Game g, 16) == STUDENT_MTV);
   assert (getDiscipline(Game g, 17) == STUDENT_BQN);
   assert (getDiscipline(Game g, 18) == STUDENT_BPS);

   //Tests int getDiceValue
   assert (getDiceValue(Game g, 0) == 9); 
   assert (getDiceVale(Game g, 1) == 10);
   assert (getDicevalue(Game g, 2) == 8);
   assert (getDiceValue(Game g, 3) == 12);
   assert (getDiceValue(Game g, 4) == 6); 
   assert (getDiceValue(Game g, 5) == 5);
   assert (getDiceValue(Game g, 6) == 3);
   assert (getDiceValue(Game g, 7) == 11);
   assert (getDiceValue(Game g, 8) == 3);
   assert (getDiceValue(Game g, 9) == 11);
   assert (getDiceValue(Game g, 10) == 4);
   assert (getDiceValue(Game g, 11) == 6);
   assert (getDiceValue(Game g, 12) == 4);
   assert (getDiceValue(Game g, 13) == 7);
   assert (getDiceValue(Game g, 14) ==  9);
   assert (getDiceValue(Game g, 15) == 2);
   assert (getDiceValue(Game g, 16) == 8);
   assert (getDiceValue(Game g, 17) == 10);
   assert (getDiceValue(Game g, 18) == 5);



   //Tests int getMostARCs (Game g)
   assert(getMostARCs(newGame) == NO_ONE);

   //Tests int getMostPublications (Game g)
   assert(getMostPublications(newGame) == No_ONE);

   //Tests int getTurnNumber (Game g)
   assert(getTurnNumber(newGame) == -1);

   //Tests int getWhoseTurn (Game g)
   assert(getWhoseTurn(newGame) == NO_ONE);

   //Tests int getCampus(Game g, path pathToVertex)
   assert (getCampus(Game g, path {\0}) == CAMPUS_A);
   assert (getCampus(Game g, path {‘R’, ‘R’, ‘L’, ‘R’, ‘L’,\0}) == CAMPUS_B);
   assert (getCampus(Game g, path {‘L’, ‘R’, ‘L’, ‘R’, ‘L’, ‘R’,\0}) == CAMPUS_C);


   //Tests int getARC(Game g, path pathToEdge)
   assert (getARC(Game g, path {\0}) == VACANT_ARC);
   assert (getARC(Game g, path {‘R’,\0}) == ARC A);
   assert (getARC(Game g, path {‘R’, ‘R’, ‘L’, ‘R’, ‘L’, ‘L’,\0}) == ARC B);
   assert (getARC(Game g, path {‘L’, ‘R’, ‘L’, ‘R’, ‘L’, ‘R’, ‘B’,\0}) == ARC C);


   //Tests int isLegalAction (Game g, action a)
   if (actionCode != PASS) {
      assert (actionCode >= 0 && actionCode <= 7);

      if (actionCode == BUILD_CAMPUS) {
         assert ((sizeof(destination)-1)/4 >= 0 && (sizeof(destination) - 1)/4 <= PATH_LIMIT);
         assert (getCampus(Game g, path destination) == VACANT_VERTEX);
         assert (getArc(Game g, (destination + 'B')) == ARC_A &&
                 getCampus(Game g, (destination + 'L')) == VACANT_VERTEX &&
                 getCampus(Game g, (destination + 'R')) == VACANT_VERTEX);
         assert (students[STUDENT_BPS] >= 1);
         assert (students[STUDENTS_BQN] >= 1);
         assert (students[STUDENTS_MJ] >= 1);
         assert (students[STUDENTS_MTV] >= 1);
      }
      
      if (actionCode == BUILD_GO8) {
         assert ((sizeof(destination)-1)/4 >= 0 && (sizeof(destination) - 1)/4 <= PATH_LIMIT);
         assert (getCampus(Game g, path destination) == CAMPUS_A);
         assert (students[STUDENTS_MJ] >= 2);
         assert (students[STUDENTS_MMONEY] >= 3);         
      }
      
      if (actionCode == OBTAIN_ARC) {
         assert ((sizeof(destination)-1)/4 >= 0 && (sizeof(destination) - 1)/4 <= PATH_LIMIT);
         assert (getArc(Game g, (destination + 'B')) == ARC_A);
      }
      
      if (actionCode == START_SPINNOFF) {
         assert (students[STUDENT_MJ] >= 1);
         assert (students[STUDENT_MTV] >= 1);
         assert (students[STUDENT_MMONEY] >= 1);
      }
      
      if (actionCode == RETRAIN_STUDENTS) {
         assert (students[disciplineFrom] >= getExchangeRate(Game g, int player, 
                 int disciplineFrom, int disciplineTo));
         assert (disciplineFrom != STUDENT_THD);
         assert (disciplineTo != STUDENT_THD);
      }
//Sample out testing simple things
void testInitialState(Game g){
   printf("Testing initialState!\n");
   int disciplines[] = DEFAULT_DISCIPLINES;
   int dice[] = DEFAULT_DICE;
   //Check each region produces correct disciplines
   int regionID = 0;
   while (regionID < NUM_REGIONS) {
      assert(getDiscipline(g,regionID) == disciplines[regionID]);
      regionID ++;
   }

   //Check what dice value produces students in the specified region
   regionID = 0;
   while (regionID < NUM_REGIONS) {
      assert(getDiceValue(g,regionID) == dice[regionID]);
      regionID ++;
   }

   assert(getMostARCs(g) == NO_ONE);
   assert(getMostPublications(g) == NO_ONE);
   assert(getTurnNumber(g) == -1);
   assert(getWhoseTurn(g) == NO_ONE);

   //Check individual uni values
   int uni = UNI_A;
   while(uni <= UNI_C){

      //Check Uni's exchange rates
      int testStudentFrom = STUDENT_BPS;
      int testStudentTo = STUDENT_BPS;
      while (testStudentFrom <= STUDENT_MMONEY) {
         while (testStudentTo <= STUDENT_MMONEY) {
            if (testStudentFrom != testStudentTo) {
               assert(getExchangeRate (g, uni, testStudentFrom, testStudentTo) == 3);
            }
            testStudentTo ++;
         }
         testStudentFrom ++;
         testStudentTo = STUDENT_BPS;
      }

      assert(getKPIpoints(g,uni) == 20);
      assert(getARCs(g,uni) == 0);
      assert(getGO8s(g,uni) == 0);
      assert(getCampuses(g,uni) == 2);
      assert(getPublications(g,uni) == 0);
      assert(getIPs(g,uni) == 0);

      //Check initial student values
      assert(getStudents(g,uni,STUDENT_THD)==0);
      assert(getStudents(g,uni,STUDENT_BPS)==3);
      assert(getStudents(g,uni,STUDENT_BQN)==3);
      assert(getStudents(g,uni,STUDENT_MJ)==1);
      assert(getStudents(g,uni,STUDENT_MTV)==1);
      assert(getStudents(g,uni,STUDENT_MMONEY)==1);

      uni++;
   }
   //Test isLegalAction at Terra Nullis
   action passAction;
   action CampusAction;
   action GO8Action;
   action ARCAction;
   action spinoffAction;
   action publicationAction;
   action patentAction;
   action retrainAction;
   passAction.actionCode = PASS;
   CampusAction.actionCode = BUILD_CAMPUS;
   GO8Action.actionCode = BUILD_GO8;
   ARCAction.actionCode = OBTAIN_ARC;
   spinoffAction.actionCode = START_SPINOFF;
   publicationAction.actionCode = OBTAIN_PUBLICATION;
   patentAction.actionCode = OBTAIN_IP_PATENT;
   retrainAction.actionCode = RETRAIN_STUDENTS;
   assert(isLegalAction(g, passAction) == FALSE);
   assert(isLegalAction(g, CampusAction) == FALSE);
   assert (isLegalAction(g, GO8Action) == FALSE);
   assert(isLegalAction(g, ARCAction) == FALSE);
   assert(isLegalAction(g, spinoffAction) == FALSE);
   assert(isLegalAction(g, publicationAction) == FALSE);
   assert(isLegalAction(g, patentAction) == FALSE);
   assert(isLegalAction(g, retrainAction) == FALSE);
   printf ("All initialState tests passed!\n");
}