Exemplo n.º 1
0
//Just one possibility for mixing in AI and human
//Students can modify however they like.
action getMove(Game g){

  action move;
  if(getWhoseTurn(g) == UNI_A || getWhoseTurn(g) == UNI_B){
     move = decideAction(g); //AI
  } else {
      move = getUserMove(g);
  }
  return move;
}
Exemplo n.º 2
0
//DONE
//given destination --> must have campus of that player on it
//given resources
static int isLegalBuildGO8(Game g, action a) {
    int isLegal = TRUE;
    int player = getWhoseTurn(g);
    //if path is actual a legal path
    if(isLegalPathToCamp(a.destination) == FALSE) {
        isLegal = FALSE;
    }
    if(isLegal == TRUE) {
        if((getGO8s(g, UNI_A) + getGO8s(g, UNI_B) +
                    getGO8s(g, UNI_C))  >=  8) {
            isLegal = FALSE;
        }
    }
    //if vertex doesnt have campus owned by player
    if(isLegal == TRUE) {
        if(getCampus(g, a.destination) != player) {
            isLegal = FALSE;
        }
    }
    //if not enough resources
    if(g->students[player][STUDENT_MJ] < 2 ||
       g->students[player][STUDENT_MMONEY] < 3) {
        isLegal = FALSE;
    }
    return isLegal;
}
Exemplo n.º 3
0
// builds an ARC for the current player in the location specified
static void buildARC(Game g, action a) {
    int numEdges = getTotalEdges(g);
    edge location = pathToEdgeF(a.destination);
    int player = getWhoseTurn(g);
    g->gameBoard->edgesUsed[numEdges] = malloc (sizeof (struct _edge));
    assert(g->gameBoard->edgesUsed[numEdges] != NULL);
    g->gameBoard->edgesUsed[numEdges]->ARC = g->players[player - 1];
    g->gameBoard->edgesUsed[numEdges]->x = location.x;
    g->gameBoard->edgesUsed[numEdges]->y = location.y;

    g->players[player - 1]->ARCGrants++;
    g->players[player - 1]->students[STUDENT_BPS]--;
    g->players[player - 1]->students[STUDENT_BQN]--;
    // Give 'em a couple of points for a road
    g->players[player - 1]->KPIs = g->players[player - 1]->KPIs + 2;

    if (g->players[player - 1]->ARCGrants  > g->mostARCs->ARCGrants) {
        if (g->mostARCs->ARCGrants == 0) {
            free(g->mostARCs);
            g->mostARCs = g->players[player - 1];
            g->mostARCs->KPIs += 10;
        } else {
            g->mostARCs->KPIs += -10;
            g->mostARCs = g->players[player - 1];
            g->mostARCs->KPIs += 10;
        }
    }
}
Exemplo n.º 4
0
// retrains the current player's students
static void retrainStudents(Game g, action a) {
    int player = getWhoseTurn(g);
    int ratio = getExchangeRate(g, player,
        a.disciplineFrom, a.disciplineTo);
    g->players[player - 1]->students[a.disciplineFrom] += -1 * ratio;
    g->players[player - 1]->students[a.disciplineTo]++;
}
Exemplo n.º 5
0
// gives current player a patent
static void addPatent(Game g, action a) {
    int player = getWhoseTurn(g);
    g->players[player - 1]->patents++;
    g->players[player - 1]->students[STUDENT_MJ]--;
    g->players[player - 1]->students[STUDENT_MTV]--;
    g->players[player - 1]->students[STUDENT_MMONEY]--;
    // Give 'em some points for some special paper
    g->players[player - 1]->KPIs = g->players[player - 1]->KPIs + 10;
}
Exemplo n.º 6
0
//DONE
//given resources
static int isLegalSpinoff(Game g, action a) {
    int isLegal = TRUE;
    int player = getWhoseTurn(g);
    //if not enough resources
    if(g->students[player][STUDENT_MJ] < 1 ||
       g->students[player][STUDENT_MTV] < 1 ||
       g->students[player][STUDENT_MMONEY] < 1) {
        isLegal = FALSE;
    }
    return isLegal;
}
Exemplo n.º 7
0
// builds a GO8 campus for the current player in the location specified
static void buildGO8(Game g, action a) {
    point location = pathToPoint(a.destination);
    assert(location.x >= 0);
    int player = getWhoseTurn(g);
    g->gameBoard->points[location.x][location.y]->contents = player + 3;
    g->players[player - 1]->campuses--;
    g->players[player - 1]->GO8Campuses++;
    g->players[player - 1]->students[STUDENT_MJ] += -2;
    g->players[player - 1]->students[STUDENT_MMONEY] += -3;
    // Give 'em an extra 10 per KPI
    g->players[player - 1]->KPIs = g->players[player - 1]->KPIs + 10;
}
Exemplo n.º 8
0
// builds a campus for the current player in the location specified
static void buildCampus(Game g, action a) {
    point location = pathToPoint(a.destination);
    assert(location.x >= 0);
    int player = getWhoseTurn(g);
    g->gameBoard->points[location.x][location.y]->contents = player;
    g->players[player - 1]->campuses++;
    g->players[player - 1]->students[STUDENT_BPS]--;
    g->players[player - 1]->students[STUDENT_BQN]--;
    g->players[player - 1]->students[STUDENT_MJ]--;
    g->players[player - 1]->students[STUDENT_MTV]--;
    // 10 KPI per campus
    g->players[player - 1]->KPIs = g->players[player - 1]->KPIs + 10;
}
Exemplo n.º 9
0
action decideAction (Game g) {

    action nextAction;
    nextAction.actionCode = PASS;
    int player = getWhoseTurn(g);
    int turnNumber = getTurnNumber(g);
    
    printf("TURN NUMBER %d, PLAYER %d IS SPIN2WIN\n", turnNumber, player);
    if (canAffordCampus(g, player) && determineCampusPath(g, player) != NULL) {
        nextAction.actionCode = BUILD_CAMPUS;
        strncpy(nextAction.destination, determineCampusPath(g, player), PATH_LIMIT);
        printf("SPIN2WIN IS BUILDING CAMPUS\n");
        
    } else if (canAffordARC(g, player) && determineARCPath(g, player) != NULL) {

        nextAction.actionCode = OBTAIN_ARC;
        strncpy(nextAction.destination, determineARCPath(g, player), PATH_LIMIT);
        printf("SPIN2WIN IS BUILDING ARC at %s\n", nextAction.destination);
        

    } else if (canAffordSpinOff(g, player)) {
        nextAction.actionCode = START_SPINOFF;
        printf("SPIN2WIN IS BUILDING SPIN\n");
        
    } else {
        
        nextAction.actionCode = RETRAIN_STUDENTS;
        if (determineCampusPath(g, player) != NULL &&
            tradeForCampus(g, player, 
            &nextAction.disciplineFrom, &nextAction.disciplineTo)) {
       // } else if (determineARCPath(g, player) != NULL &&
       //     tradeForARC(g, player, 
       //     &nextAction.disciplineFrom, &nextAction.disciplineTo)) {

        } else if (tradeForSpinOff(g, player, 
            &nextAction.disciplineFrom, &nextAction.disciplineTo)) {

        } else if (canTradeJunkResources(g, player)) {
            
            nextAction.disciplineFrom = 
            canTradeJunkResources(g,player);
            nextAction.disciplineTo = 
            resourcesWeNeed(g, player, nextAction.disciplineFrom);
        } else {
            nextAction.actionCode = PASS;
        }
    }
    
    return nextAction;

}
Exemplo n.º 10
0
//DONE
//must have an arc connected to it & not blocked by campus
//given destination --> if there is an arc on it --> cannot place
//given resources
static int isLegalBuildARC(Game g, action a) {
    int isLegal = TRUE;
    int arcTests[3] = {TRUE, TRUE, TRUE};
    int player = getWhoseTurn(g);
    coordinates xycoord1;
    coordinates xycoord2;
    //if path is actual a legal path
    if(isLegalPathToARC(a.destination) == FALSE) {
        isLegal = FALSE;
    }
    //if already owned
    if(isLegal == TRUE) {
        if(getARC(g, a.destination) != 0) {
            isLegal = FALSE;
        }
    }
    //if not enough resources
    if(g->students[player][STUDENT_BPS] < 1 ||
       g->students[player][STUDENT_BQN] < 1) {
        isLegal = FALSE;
    }

    //Board state exceptions
    xycoord1 = getCoords(a.destination);
    xycoord2 = newCoords(xycoord1, 'B');
    //test if arc has campus next to it
    //test if has path but not blocked by campus
    //get what coordinate it is on and then get next coordinate
    //then test if next coordinates has arcs next to them
    if(hasVertexARC(g, xycoord1) == FALSE  &&
       (!(getCampusWithCoord(g, xycoord2) == player  ||
       getCampusWithCoord(g, xycoord2) == player + 3))) {
        arcTests[0] = FALSE;
    } 
    if(hasVertexARC(g, xycoord2) == FALSE  &&
       (!(getCampusWithCoord(g, xycoord1) == player  ||
       getCampusWithCoord(g, xycoord1) == player + 3))) {
        arcTests[1] = FALSE;
    }
    if((hasVertexARC(g, xycoord1) == FALSE  &&
       hasVertexARC(g, xycoord2) == FALSE)) {
        arcTests[2] = FALSE;
    }
    if(isLegal == TRUE) {
        if(!(arcTests[0] || arcTests[1] || arcTests[2])) {
            isLegal = FALSE;
        }
    }
    return isLegal;
}
Exemplo n.º 11
0
//DONE
//given resources
//given disciplineFrom & disciplineTo
//calulate number to convert
//cant be THD
static int isLegalRetrain(Game g, action a) {
    int isLegal = TRUE;
    int player = getWhoseTurn(g);
    //if trying to retrain a thd student
    if(a.disciplineFrom <= STUDENT_THD  ||  a.disciplineFrom >= NUM_STUDENT_TYPES  ||
       a.disciplineTo < STUDENT_THD  ||  a.disciplineTo >= NUM_STUDENT_TYPES) {
        isLegal = FALSE;
    }
    //if not enough resources
    if(isLegal == TRUE) {
        if(g->students[player][a.disciplineFrom] <
           getExchangeRate(g, player, a.disciplineFrom, a.disciplineTo)) {
            isLegal = FALSE;
        }
    }
    return isLegal;
}
Exemplo n.º 12
0
//DONE
//must also be 2 away from another campus
//given destination is there a campus on that
//must be attached to a path
//given resources
static int isLegalBuildCamp(Game g, action a) {
    int isLegal = TRUE;
    int player = getWhoseTurn(g);
    int i = 0;
    int j = 0;
    coordinates testingCoords = getCoords(a.destination);
    //if path is actual a legal path
    if(isLegalPathToCamp(a.destination) == FALSE) {
        isLegal = FALSE;
    }
    testingCoords.x--;
    testingCoords.y--;
    //testing if there is a campus next to that point
    //for all points in a 3x3 square around it
    while(i < 3) {
        j = 0;
        while(j < 3) {
            if(testingCoords.x >= 0  &&  testingCoords.x <= 11  &&
               testingCoords.y >= 0  &&  testingCoords.y <= 10) {
                if(getCampusWithCoord(g, testingCoords) != 0) {
                    isLegal = FALSE;
                }
            }
            testingCoords.x++;
            j++;
        }
        testingCoords.x -= 3;
        testingCoords.y++;
        i++;
    }
    //if not enough resources
    if(g->students[player][STUDENT_BPS] < 1 ||
       g->students[player][STUDENT_BQN] < 1 ||
       g->students[player][STUDENT_MJ] < 1 ||
       g->students[player][STUDENT_MTV] < 1) {
        isLegal = FALSE;
    }
    //testing if it is next to an arc
    //by testing if the arcs next to that point are of that player
    testingCoords = getCoords(a.destination);
    if(hasVertexARC(g, testingCoords) == FALSE) {
        isLegal = FALSE;
    }
    return isLegal; 
}
Exemplo n.º 13
0
// gives current player a publication
static void addPub(Game g, action a) {
    int player = getWhoseTurn(g);
    g->players[player - 1]->papers++;
    g->players[player - 1]->students[STUDENT_MJ]--;
    g->players[player - 1]->students[STUDENT_MTV]--;
    g->players[player - 1]->students[STUDENT_MMONEY]--;

    if (g->players[player - 1]->papers  > g->mostPubs->papers) {
        if (g->mostPubs->papers == 0) {
            free(g->mostPubs);
            g->mostPubs = g->players[player - 1];
            g->mostPubs->KPIs += 10;
        } else {
            g->mostPubs->KPIs += -10;
            g->mostPubs = g->players[player - 1];
            g->mostPubs->KPIs += 10;
        }
    }
}
Exemplo n.º 14
0
//DONE
//tests for a vertex if the sides joined
//to it are owned by the current player
static int hasVertexARC(Game g, coordinates xy) {
    int isLegal = FALSE;
    int i = 0;
    xy.direction = 0;
    //tests if there are arcs next to where you want to place
    while(i < 6) {
        coordinates xysides = convertToSides(xy);
        if(xysides.x >= 0  &&  xysides.x <= 10  &&
           xysides.y >= 0  &&  xysides.y <= 20) {
            if(getARCWithCoord(g, convertToSides(xy)) ==
               getWhoseTurn(g)) {
                isLegal = TRUE;
            }
        }
        xy.direction++;
        i++;
    }
    return isLegal;
}
Exemplo n.º 15
0
void printScore (Game g) {
    int player = getWhoseTurn (g);
    printf ("============== YOUR STUFF ==============\n");
    printf ("Students:\n");
    printf ("THD: %d ", getStudents (g, player, STUDENT_THD));
    printf ("BPS: %d ", getStudents (g, player, STUDENT_BPS));
    printf ("BQN: %d ", getStudents (g, player, STUDENT_BQN));
    printf ("MJ: %d ", getStudents (g, player, STUDENT_MJ));
    printf ("MTV: %d ", getStudents (g, player, STUDENT_MTV));
    printf ("M$: %d\n", getStudents (g, player, STUDENT_MMONEY));
    printf ("Your current score:\n");
    printf ("KPI: %d ", getKPIpoints (g, player));
    printf ("Pubs: %d ", getPublications (g, player));
    printf ("IPs: %d\n", getIPs (g, player));
    printf ("Built:\n");
    printf ("ARCs: %d ", getARCs (g, player));
    printf ("Campuses: %d ", getCampuses (g, player));
    printf ("GO8s: %d\n", getGO8s (g, player));
    printf ("========================================\n");
}
Exemplo n.º 16
0
//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;
}
Exemplo n.º 17
0
action decideAction (Game g) {

    action nextAction;
    int student[6];
    student[STUDENT_THD] = getStudents(g, getWhoseTurn(g), STUDENT_THD);
    student[STUDENT_BPS] = getStudents(g, getWhoseTurn(g), STUDENT_BPS);
    student[STUDENT_BQN] = getStudents(g, getWhoseTurn(g), STUDENT_BQN);
    student[STUDENT_MJ] = getStudents(g, getWhoseTurn(g), STUDENT_MJ);
    student[STUDENT_MTV] = getStudents(g, getWhoseTurn(g), STUDENT_MTV);
    student[STUDENT_MMONEY] = getStudents(g, getWhoseTurn(g),
                                          STUDENT_MMONEY);

    if(student[STUDENT_MJ] > 0  &&  student[STUDENT_MTV] > 0  &&
       student[STUDENT_MMONEY] > 0) {
        nextAction.actionCode = START_SPINOFF;
    } else {
        nextAction.actionCode = PASS;
    }

    return nextAction;
}
Exemplo n.º 18
0
action decideAction (Game g) {
   
   int turn = getWhoseTurn(g);

   path aiPathARC = {0};

   if (turn == UNI_B) {
      strcpy(aiPathARC, "RRLRLL");
      char prev = 'L';
      char *next = 0;

      if (getARC(g, aiPathARC) != NO_ONE) {
         strcat(aiPathARC, "L");
      } else {
         strcat(aiPathARC, "L");

         int i = 0;
         while (i <= 30 && getARC(g, aiPathARC) != NO_ONE) {
           if (prev == 'R') {
               next = "L";
               prev = 'L';
           } else {
               next = "R";
               prev = 'R';
           }
           strcat(aiPathARC, next);
           i++;
         }
      }  
   } else if (turn == UNI_C) {
      strcpy(aiPathARC, "LRLRLB");
      char prev = 'B';
      char *next = 0;

      int i = 0;
      while (i <= 30 && getARC(g, aiPathARC) != NO_ONE) {
        if (prev == 'R') {
            next = "L";
            prev = 'L';
        } else if (prev == 'L') {
            next = "R";
            prev = 'R';
        } else {
            next = "L";
            prev = 'L';
        }
        strcat(aiPathARC, next);
        i++;
      } 
   } else {
    //for the first arc
      strcpy(aiPathARC, "R");
      char prev = 'R';
      char *next = 0;

      int i = 0;
      while (i <= 30 && getARC(g, aiPathARC) != NO_ONE) {
        if (prev == 'R'){
            next = "L";
            prev = 'L';
        } else if (prev == 'L') {
            next = "R";
            prev = 'R';
        } else {
            next = "L";
            prev = 'L';
        }
        strcat(aiPathARC, next);
        i++;
       }
    }


   path aiPathCampus = {0};

   //next part is simialer to arc pathing above
   //but since 2 campuses can't be made adjacent it 
   //works slightly differently
   //needs to be checked

   if (turn == UNI_B) {
      strcpy(aiPathCampus, "RRLRLLL");
      char *next = "RL";
   
      int i = 0;
      while (i <= 30 && getCampus(g, aiPathCampus) != NO_ONE){

          strcat(aiPathCampus, next);
          i++;
      }
   } else if (turn == UNI_C) {
      strcpy(aiPathCampus, "LRLRLB");
      char *next = "LR";
   
      int i = 0;
      while (i <= 30 && getCampus(g, aiPathCampus) != NO_ONE){
      
         strcat(aiPathCampus, next);
         i++;
      }
   
   } else {
      strcpy(aiPathCampus, "R");
      char *next = "LR";
      
      int i = 0;
      while (i <= 30 && getCampus(g, aiPathCampus) != NO_ONE) {

         strcat(aiPathCampus, next);
         i++;
      }
   }
   

   action nextAction;
   int actionChosen = FALSE;

  if(turn != NO_ONE ) {
   
   //Build Campus
    nextAction.actionCode = BUILD_CAMPUS;
    strncpy(nextAction.destination, aiPathCampus, PATH_LIMIT);
    
    if (isLegalAction(g, nextAction)) {
      actionChosen = TRUE;
    }
   
   //Build Arc
   nextAction.actionCode = OBTAIN_ARC;
   strncpy(nextAction.destination, aiPathARC, PATH_LIMIT);

   if (!actionChosen && isLegalAction(g, nextAction) == TRUE) {
      actionChosen = TRUE;
   }
   
   //Spinoff
   nextAction.actionCode = START_SPINOFF;

   if (!actionChosen && isLegalAction(g, nextAction) == TRUE) {
      actionChosen = TRUE;
   }
   //before pass when we can we should add something that can
   //convert students so we can do more of the above actions
   //(maybe a while loop encompasing all actions)

   //Pass
   if (!actionChosen) {
      nextAction.actionCode = PASS;
   }
  
  }
     return nextAction;
}
Exemplo n.º 19
0
// NOTE:  IS MAKEACTION(g, PASS_ACTION) required to end turn?  or just THROWDICE?
// Unsure on this, might ahve to ask a tutor.
void testStudentAllocationAndMakeAction (void) {

    printf ("Now testing updating of students after dice throws and actions.\n");

    // Create game:
    int disciplines[] = DEFAULT_DISCIPLINES;
    int dice[] = DEFAULT_DICE;
    Game g = newGame (disciplines, dice);

    // Throw the dice once, not giving any players students, to move the
    // current turn to '0' rather than '-1':
    throwDice(g, 3);

    // Allocate 300 students to each player through numerous dice throws!
    int throws = 0;
    while (throws < 150) {

        // Trigger each hexagon with an adjoined campus:

        throwDice(g, 11); // 1 MTV to player 1
        throwDice(g, 6);  // 1 MJ to player 1

        throwDice(g, 9); // 1 BQN to player 2
        throwDice(g, 9); // 1 BQN to player 2
        throwDice(g, 9); // 1 BQN to player 2
        throwDice(g, 5); // 1 BPS to player 2
        throwDice(g, 5); // 1 BPS to player 2
        throwDice(g, 5); // 1 BPS to player 2

        throwDice(g, 8); // 1 MJ and 1 MTV to player 3
    }

    /* At this point:
     *  - Turn number is [150 * 9 = ] 1350
     *  - Number of turns mod 3 is 0, therefore player 1's (UNI_A) turn to roll.
     *  - Player 1 has 150 MJs and 150 MTVs
     *  - Player 2 has 450 BQNs and 450 BPSs
     *  - Player 3 has 150 MJs and 150 MTVs
    */

    // Ensure game state has been updated correctly:

    printf ("Ensuring 'getTurnNumber' and 'getWhoseTurn' return correct values.\n");
    assert (getTurnNumber(g) == 750);
    assert (getWhoseTurn(g) == UNI_A);

    printf ("Ensuring UNI_A has been allocated the correct number of players.\n");
    assert (getStudents(g, UNI_A, STUDENT_BPS)    == 0);
    assert (getStudents(g, UNI_A, STUDENT_BQN)    == 0);
    assert (getStudents(g, UNI_A, STUDENT_MJ)     == 150);
    assert (getStudents(g, UNI_A, STUDENT_MTV)    == 150);
    assert (getStudents(g, UNI_A, STUDENT_MMONEY) == 0);
    assert (getStudents(g, UNI_A, STUDENT_THD)    == 0);

    printf ("Ensuring UNI_B has been allocated the correct number of players.\n");
    assert (getStudents(g, UNI_B, STUDENT_BPS)    == 450);
    assert (getStudents(g, UNI_B, STUDENT_BQN)    == 450);
    assert (getStudents(g, UNI_B, STUDENT_MJ)     == 0);
    assert (getStudents(g, UNI_B, STUDENT_MTV)    == 0);
    assert (getStudents(g, UNI_B, STUDENT_MMONEY) == 0);
    assert (getStudents(g, UNI_B, STUDENT_THD)    == 0);

    printf ("Ensuring UNI_C has been allocated the correct number of players.\n");
    assert (getStudents(g, UNI_C, STUDENT_BPS)    == 0);
    assert (getStudents(g, UNI_C, STUDENT_BQN)    == 0);
    assert (getStudents(g, UNI_C, STUDENT_MJ)     == 150);
    assert (getStudents(g, UNI_C, STUDENT_MTV)    == 150);
    assert (getStudents(g, UNI_C, STUDENT_MMONEY) == 0);
    assert (getStudents(g, UNI_C, STUDENT_THD)    == 0);



    // Convert UNI_B's BQNs and BPSs into MJs and MTVs, so that each
    // UNI has the same numbers of students:
    printf ("Testing basic student conversion.\n");

    // Move turn to UNI_B from UNI_A (without giving the UNIs students):
    throwDice(g, 3);

    action convertStudents;
    convertStudents.actionCode = RETRAIN_STUDENTS;

    // Convert BPSs into MJs:
    convertStudents.disciplineFrom = STUDENT_BPS;
    convertStudents.disciplineTo = STUDENT_MJ;

    int numConversions = 0;
    while (numConversions < 150) {
        makeAction(g, convertStudents);
    }

    // Ensure the counts have been updated correctly:
    assert (getStudents(g, UNI_B, STUDENT_BPS) == 0);
    assert (getStudents(g, UNI_B, STUDENT_MJ)  == 150);


    // Convert BQNs into MTVs:
    convertStudents.disciplineFrom = STUDENT_BQN;
    convertStudents.disciplineTo = STUDENT_MTV;

    int numConversions = 0;
    while (numConversions < 150) {
        makeAction(g, convertStudents);
    }

    // Ensure the counts have been updated correctly:
    assert (getStudents(g, UNI_B, STUDENT_BQN) == 0);
    assert (getStudents(g, UNI_B, STUDENT_MTV) == 150);


    // Now each UNI has 150 MTVs and 150 MJs.

    // Set turn to UNI_A:
    throwDice(g, 3); // Now UNI_C's turn
    throwDice(g, 3); // Now UNI_A's turn



    // Get each UNI to perform path-based and path-less actions:
    int activeUNI = UNI_A;
    while (activeUNI != NO_ONE) {

        action testAction;

        testAction.actionCode = PASS


        // Set activeUNI to the next UNI
        // Note: incrementing not used because the values of the
        //       constants are not guaranteed.
        throwDice(g, 3);
        if (activeUNI == UNI_A) {
            activeUNI = UNI_B;
        } else if (activeUNI == UNI_B) {
            activeUNI = UNI_C;
        } else {
            activeUNI = NO_ONE;
        }
    }



    disposeGame (g);
    printf ("Passed\n");
}
Exemplo n.º 20
0
//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");
}
Exemplo n.º 21
0
//DONE  [DO NOTHING MIGHT NOT WORK]
void makeAction (Game g, action a) {
    //function protection
    assert(g != NULL);
    assert(isLegalMoves(g, a) == TRUE);

    coordinates xycoord = getCoords(a.destination);
    coordinates xysides = convertToSides(xycoord);
    int player = getWhoseTurn(g);
    if(a.actionCode == PASS) {
        //do nothing
    } else if(a.actionCode == BUILD_CAMPUS) {
        //given coordinate 
        //put campus + player on to that vertex
        //remove resources from player
        g->vertices[xycoord.x][xycoord.y] = player;
        g->campuses[player]++;
        g->students[player][STUDENT_BPS]--;
        g->students[player][STUDENT_BQN]--;
        g->students[player][STUDENT_MJ]--;
        g->students[player][STUDENT_MTV]--;
    } else if(a.actionCode == BUILD_GO8) {
        //given coordinate
        //put GO8 + player on to that vertex
        //remove resources from player
        g->vertices[xycoord.x][xycoord.y] = player + 3;
        g->GO8s[player]++;
        g->campuses[player]--;
        g->students[player][STUDENT_MJ] -= 2;
        g->students[player][STUDENT_MMONEY] -= 3;
    } else if(a.actionCode == OBTAIN_ARC) {
        //given coordinate
        //put arc + player on that side
        //remove resources from player
        g->sides[xysides.x][xysides.y] = player;
        g->ARCs[player]++;
        g->students[player][STUDENT_BPS]--;
        g->students[player][STUDENT_BQN]--;
    } else if(a.actionCode == OBTAIN_PUBLICATION) {
        g->students[player][STUDENT_MJ]--;
        g->students[player][STUDENT_MTV]--;
        g->students[player][STUDENT_MMONEY]--;
        g->pubs[player]++;
    } else if(a.actionCode == OBTAIN_IP_PATENT) {
        g->students[player][STUDENT_MJ]--;
        g->students[player][STUDENT_MTV]--;
        g->students[player][STUDENT_MMONEY]--;
        g->IPs[player]++;
    } else if(a.actionCode == RETRAIN_STUDENTS) {
        //given discipline from and dicipline to
        //get retrain value from function
        //if value = 2 --> -2 --> + 1
        //if value = 3 --> -3  --> + 1
        int retrainvalue = getExchangeRate(g, getWhoseTurn(g),
                a.disciplineFrom, a.disciplineTo);
        if(retrainvalue == 2) {
            g->students[player][a.disciplineFrom] -= 2;
            g->students[player][a.disciplineTo]++;
        } else if(retrainvalue == 3) {
            g->students[player][a.disciplineFrom] -= 3;
            g->students[player][a.disciplineTo]++;
        }
    }
    setMostPublications(g);
    setMostARCs(g);
    calculateKPI(g);
}
Exemplo n.º 22
0
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);
      }
Exemplo n.º 23
0
int main(int argc, char *argv[]) {
   // miscellaneous
   /*int disciplines[NUM_REGIONS];
   int dice[NUM_REGIONS];*/
   Game g;
   
   // store the winner of each game
   int winner;
   
   // store game states within the game
   int keepPlaying;
   int turnFinished;
   int diceRollAmount;
   
   // random
   char *actions[] = ACTION_NAMES;
   int diceRoll;
   
   int passedTurns = 0;
            
   // seed rand!
   srand(time(NULL));
   
   // while the game is wanting to be played, create new game, etc.
   keepPlaying = TRUE;
   while (keepPlaying == TRUE) {
      // create the game
      //randomDisciplines(disciplines);
      //randomDice(dice);
      
      // you can change this to randomiseDisciplines() and randomiseDice() later
      int disciplines[NUM_REGIONS] = {CYAN,PURP,YELL,PURP,YELL,RED ,GREE,GREE, RED ,GREE,CYAN,YELL,CYAN,BLUE,YELL,PURP,GREE,CYAN,RED };
      int dice[NUM_REGIONS] = {9,10,8,12,6,5,3,7,3,11,4,6,4,9,9,2,8,10,5};

      // rig board like the real game
      rigBoard(disciplines, dice);
      g = newGame(disciplines, dice);
      
      printf("Game created! Now playing...\n");
      
      // start the game with noone as the winner
      winner = NO_ONE;
      while (winner == NO_ONE) {
         printLineBreak();
         // start new turn by setting turnFinished to false then
         // rolling the dice
         
         diceRollAmount = 0;
         diceRoll = 0;
         while (diceRollAmount < DICE_AMOUNT) {
            diceRoll += rollDice();
            diceRollAmount++;
         }
         
         throwDice(g, diceRoll);
         
         // new turn means new line break!
         printf("[Turn %d] The turn now belongs to University %c!\n", 
            getTurnNumber(g),
            getWhoseTurn(g) + UNI_CHAR_NAME);
//         printf("The dice has casted a %d!\n", diceRoll);
         
         printf("\n");
         
         
         // keep going through the player's turn until
         // he/she decided to pass and finish the turn
         turnFinished = FALSE;
         while (turnFinished == FALSE && passedTurns < MAX_PASS) {
            // processes requests and all subrequests for a move and
            // checks if they are legal. only gives a move within the
            // scope of the defined actionCodes that is legal
            int turnPerson = getWhoseTurn(g);
/*            printf("Stats for %c:\n", turnPerson + UNI_CHAR_NAME);
            printf("KPIs: %d\n", getKPIpoints(g, turnPerson));
            printf("ARCs: %d\n", getARCs(g, turnPerson));
            printf("Campuses: %d\n", getCampuses(g, turnPerson));
            printf("GO8s: %d\n", getGO8s(g, turnPerson));
            printf("Publications: %d\n", 
               getPublications(g, turnPerson));
            printf("Patents: %d\n", 
               getIPs(g, turnPerson));
            int discipleIndex = 0;
            char *discipleNames[] = DISCIPLE_NAMES;
            while (discipleIndex < NUM_DISCIPLINES) {
               printf("Type %s: %d\n", discipleNames[discipleIndex],
                  getStudents(g, turnPerson, discipleIndex));
               discipleIndex++;
            } 
*/            printf("\n");
            
            action a = decideAction(g);
            
            // if not passing, make the move; otherwise end the turn
            if (a.actionCode == PASS) {
               turnFinished = TRUE;
               printf("You have passed onto the next person.\n");
            } else {
              
               // write what the player did, for a logs sake.
 /*              printf("The action '%s' has being completed.\n", 
                       actions[a.actionCode]);
               if (a.actionCode == BUILD_CAMPUS 
                   || a.actionCode == OBTAIN_ARC 
                   || a.actionCode == BUILD_GO8) {
                  printf(" -> Destination: %s\n", a.destination);
               } else if (a.actionCode == RETRAIN_STUDENTS) {
                  printf(" -> DisciplineTo: %d\n", a.disciplineTo);
                  printf(" -> DisciplineFrom: %d\n", a.disciplineFrom);
               }
*/
               assert(isLegalAction(g, a));                                   
            
               // break this and the code dies. trololol!
               if (a.actionCode == START_SPINOFF) {
                  if (rand() % 3 <= 1) {
                     a.actionCode = OBTAIN_PUBLICATION;
                  } else {
                     a.actionCode = OBTAIN_IP_PATENT;               
                  }
               }

               makeAction(g, a);
               
               if (a.actionCode == PASS) {
                  passedTurns++;
               } else {
                  passedTurns = 0;
               }
               
               if (passedTurns >= MAX_PASS || getKPIpoints(g, turnPerson) >= WINNING_KPI) {
                  turnFinished = TRUE;
                  
               }
            }
            
            // if there is not a winner or pass, add a seperating line
            // to seperate actions being clumped together
            if (turnFinished == FALSE) {
               printf("\n");
            }
         }
         
         // check if there is a winner
         winner = checkForWinner(g);
      }
      
      if (passedTurns >= MAX_PASS) {
         printf("AI passes too much.\n");
         return EXIT_FAILURE;
      }
      
      printLineBreak();
      printf("GAME OVER!\n");
      printf("Vice Chanceller %c Won in %d Turns!!\n", 
             winner + UNI_CHAR_NAME,
             getTurnNumber(g));
             
      printf("\n");
      int counter = UNI_A;
      while (counter < NUM_UNIS + UNI_A) {
         printf("Uni %c scored %d KPIs\n", counter + UNI_CHAR_NAME,
                getKPIpoints(g, counter));
         counter++;
      }
      printLineBreak();
      
      disposeGame(g);
      
      // ask to play again
      printf("Ctrl+C will exit the game.\nOtherwise, the game will "
             "recommence by hitting enter.");
      int a = scanf("%*c");
      a++;
   }     
   
   return EXIT_SUCCESS;
}
Exemplo n.º 24
0
int main(int argc, char * argv[]){
    int disciplines[] = DEFAULT_DISCIPLINES;
    int dice[] = DEFAULT_DICE;
    int turnOver = FALSE;
    int winner = NO_ONE;
    int diceValue;
    action move;
    int whoseTurn = NO_ONE;

    srand(time(NULL)); //initialises a seed
    Game g = newGame(disciplines,dice);

    while (winner == NO_ONE) {

        diceValue = rollDice(2,6);

        throwDice(g,diceValue);

        printf("[Turn %d] The turn now belongs to University %d!\n",
            getTurnNumber(g),
            getWhoseTurn(g));
        printf("The dice casted a %d!\n", diceValue);

        whoseTurn = getWhoseTurn(g);
        //loop until player action is PASS
        turnOver = FALSE;
        while (!turnOver) {
            move = getMove(g);
            //print info about move
            printf("Move %d \n",move.actionCode);
            assert(isLegalAction(g, move));

            if (move.actionCode == START_SPINOFF) {

                //decide if outcome is patent or publication
                if (rand() % 3 <= 1) {
                    move.actionCode = OBTAIN_PUBLICATION;
                } else {
                    move.actionCode = OBTAIN_IP_PATENT;
                }
            }

            if(move.actionCode == PASS){
                 turnOver = TRUE;
                 printf("Pass\n");
            }
            makeAction(g, move);


            if(getKPIpoints(g, whoseTurn) >= WINNING_KPI){
                winner = whoseTurn;
                turnOver = TRUE;
                printf("Winner %d\n",whoseTurn);
            }

        }
    }


    // TODO print statistics

    // TODO free memory

    return EXIT_SUCCESS;
}
Exemplo n.º 25
0
int main (int argc, char * argv[]) {

	int disciplines[19] = {STUDENT_BQN, STUDENT_MMONEY, STUDENT_MJ, \
		STUDENT_MMONEY, STUDENT_MJ, STUDENT_BPS, STUDENT_MTV, \
		STUDENT_MTV, STUDENT_BPS,STUDENT_MTV, STUDENT_BQN, \
		STUDENT_MJ, STUDENT_BQN, STUDENT_THD, STUDENT_MJ, \
		STUDENT_MMONEY, STUDENT_MTV, STUDENT_BQN, STUDENT_BPS};

	int dice[19] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};

	Game g = newGame (disciplines, dice);
	action a;
//	int score = 0; //This stores the KPI points of current player 
	int curPlayer = NO_ONE; 
	int curTurn = 0; 
	int playerKPI = 0;
	int numStudents[MAX_STU_TYPES];
	int legal = 0;
	int diceScore = 0; 
	int spinoffDice = 0;
	//int discipline = 0;
	int counter = 0; 

	char *degrees[] = \
		  {"THDs", "BPSs", "BQNs", "MJs", "MTVs", "MMONEYs"};
	


	printf ("New game created, variables are initialized.\n");
	printf ("Let the game begin!\n\n");

	while (playerKPI < MAX_KPIPTS) {
		
		//To simulate an actual real life dice, we throw two dice 
		diceScore = rollDice();
		throwDice (g, diceScore);

		curTurn = getTurnNumber (g);
		curPlayer = getWhoseTurn (g);
		printf ("Turn number: %d\n", curTurn);
		printf ("Player %d's turn. Rolling dice.\n", curPlayer);
		printf ("The two dice rolled a %d! \n", diceScore);

		printf ("You currently have: \n");
		counter = 0;
		while (counter < MAX_STU_TYPES) {
			numStudents[counter] = getStudents (g, curPlayer, counter);
			printf ("    %d: %s\n", numStudents[counter],\
								    degrees[counter]);
			counter ++;
		}
		actionOptions ();
		a = actionPrompt (g);
		legal = isLegalAction (g, a);

		while (a.actionCode != PASS) {
			while (legal == FALSE) {
				printf ("The chosen action is illegal, try again.\n");
				actionPrompt (g);
				legal = isLegalAction (g, a);
			}

			if (a.actionCode == START_SPINOFF) {
				//Ensures dice returns 1, 2 or 3.
				spinoffDice = (rand()%3 + 1);
				if (spinoffDice == 1) {
					a.actionCode = OBTAIN_IP_PATENT;
				} else {
					a.actionCode = OBTAIN_PUBLICATION;
				}
			}

			makeAction (g, a);
			printf("Action made!");

			printf ("Your current stats:\n");
			printf ("    ARC Grants: %d\n", getARCs (g, curPlayer));
			printf ("    No of Campuses: %d\n", getCampuses (g, curPlayer));
			printf ("    No of G08s: %d\n", getGO8s (g, curPlayer));
			printf ("    No of Pubs: %d\n", getPublications (g, curPlayer));
			printf ("    No of IP Patents: %d\n", getIPs (g, curPlayer));

			playerKPI = getKPIpoints (g, curPlayer);
			printf ("Player %d KPI Score: %d\n\n", curPlayer, playerKPI);
		}

		printf ("Next player's turn.\n\n");

	}

	printf ("Congratulations, player %d won.\n", curPlayer);
	printf ("Game completed. Disposing game.\n");
	
	disposeGame (g);

	return EXIT_SUCCESS;
}
Exemplo n.º 26
0
action decideAction(Game g) {
	vertex vertices[NUM_INT_VERTICES];
	arc arcs[NUM_INT_ARCS];

	int currentPlayer = getWhoseTurn(g);

	int myCampus = 0;
	int myGO8 = 0;
	int myARC = 0;

	if (currentPlayer == UNI_A) {
		myCampus = CAMPUS_A;
		myGO8 = GO8_A;
		myARC = ARC_A;
	} else if (currentPlayer == UNI_B) {
		myCampus = CAMPUS_B;
		myGO8 = GO8_B;
		myARC = ARC_B;
	} else if (currentPlayer == UNI_C) {
		myCampus = CAMPUS_C;
		myGO8 = GO8_C;
		myARC = ARC_C;
	}

	char allPaths[NUM_INT_VERTICES][PATH_LIMIT] = ALL_PATHS;
	char arcPaths[NUM_INT_ARCS - NUM_INT_VERTICES][PATH_LIMIT] = ARC_PATHS;

	// Populate database

	int i = 0;

	while (i < NUM_INT_VERTICES) {
		vertex newVertex;
		arc newArc;

		strcpy(newVertex.path, allPaths[i]);
		strcpy(newArc.path, allPaths[i]);

		newVertex.object = getCampus(g, allPaths[i]);
		newArc.object = getARC(g, allPaths[i]);

		vertices[i] = newVertex;
		arcs[i] = newArc;

		i++;
	}

	while (i < NUM_INT_ARCS) {
		arc newArc;

		strcpy(newArc.path, arcPaths[i - NUM_INT_VERTICES]);
		newArc.object = getARC(g, newArc.path);

		arcs[i] = newArc;

		i++;
	}

	// printf("Populated database\n");

	// If we have more than 5 campuses, plan for building GO8s
	// If we have enough resources to build a GO8...
	//    Upgrade the most valued campus to a GO8


	// Note that this AI will only build ARCs and campuses together at the same time
	// If we have enough resources to build an ARC and campus...
	// Get a list of all the "edge" vertices
	// Iterate through each connecting edge vertices, and give them a value
	// based off the hexes they are connected to.
	// For every campus of already existing resource, a point is subtracted
	// Their values is summed of the vertices they're connected to, too.
	// Cumalative values are halved for every vertex travelled to a maximum of 4 jumps
	// Then pick the highest scoring sub-vertex.
	// If there are multiple highest scoring sub-vertices, pick the one with the lowest index

	// Find vertices we own

	int myVertices[NUM_INT_VERTICES]; // Array of vertices that we own

	i = 0;
	int numMyVertices = 0;

	while (i < NUM_INT_VERTICES) {
		myVertices[i] = -1;

		if (vertices[i].object == myCampus || vertices[i].object == myGO8) {
			myVertices[numMyVertices] = i;
			numMyVertices++;
			// printf("%d\n", i);
		}
		i++;
	}

	// printf("Found our vertices\n");

	// Now scan through each vertex and store neighbours

	// Array of vertices that are accessible and aren't owned
	fromToArc considerations[NUM_INT_VERTICES][2];

	i = 0;
	int numConsiderations = 0;

	while (i < numMyVertices) {
		trio neighbouring = getNeighbouringVertices(myVertices[i]);

		if (neighbouring.a >= 0 && vertices[neighbouring.a].object == VACANT_VERTEX) {
			int arcId = getArcIdFromVertices(myVertices[i], neighbouring.a);

			if (arcs[arcId].object == VACANT_ARC || arcs[arcId].object == myARC) {
				considerations[numConsiderations][0].from = myVertices[i];
				considerations[numConsiderations][0].to = neighbouring.a;

				if (arcs[arcId].object == myARC) {
					considerations[numConsiderations][0].alreadyOwned = TRUE;
				} else {
					considerations[numConsiderations][0].alreadyOwned = FALSE;
				}

				numConsiderations++;
			}
		}
		if (neighbouring.b >= 0 && vertices[neighbouring.b].object == VACANT_VERTEX) {
			int arcId = getArcIdFromVertices(myVertices[i], neighbouring.b);
			if (arcs[arcId].object == VACANT_ARC || arcs[arcId].object == myARC) {
				considerations[numConsiderations][0].from = myVertices[i];
				considerations[numConsiderations][0].to = neighbouring.b;

				if (arcs[arcId].object == myARC) {
					considerations[numConsiderations][0].alreadyOwned = TRUE;
				} else {
					considerations[numConsiderations][0].alreadyOwned = FALSE;
				}

				numConsiderations++;
			}
		}
		if (neighbouring.c >= 0 && vertices[neighbouring.c].object == VACANT_VERTEX) {
			int arcId = getArcIdFromVertices(myVertices[i], neighbouring.c);

			if (arcs[arcId].object == VACANT_ARC || arcs[arcId].object == myARC) {
				considerations[numConsiderations][0].from = myVertices[i];
				considerations[numConsiderations][0].to = neighbouring.c;

				if (arcs[arcId].object == myARC) {
					considerations[numConsiderations][0].alreadyOwned = TRUE;
				} else {
					considerations[numConsiderations][0].alreadyOwned = FALSE;
				}

				numConsiderations++;
			}
		}

		i++;
	}

	fromToArc subConsiderations[NUM_INT_VERTICES][2];

	i = 0;
	int numSubConsiderations = 0;

	while (i < numConsiderations) {
		trio neighbouring = getNeighbouringVertices(considerations[i][0].to);

		if (neighbouring.a >= 0 && vertices[neighbouring.a].object == VACANT_VERTEX) {
			// Check that it's not within any other verticie
			if (canBuildCampusOn(vertices, neighbouring.a)) {
				int arcId = getArcIdFromVertices(considerations[i][0].to, neighbouring.a);

				if (arcs[arcId].object == VACANT_ARC || arcs[arcId].object == myARC) {
					subConsiderations[numSubConsiderations][0] = considerations[i][0];
					subConsiderations[numSubConsiderations][1] = considerations[i][1];

					subConsiderations[numSubConsiderations][1].from = considerations[i][0].to;
					subConsiderations[numSubConsiderations][1].to = neighbouring.a;

					if (arcs[arcId].object == myARC) {
						subConsiderations[numSubConsiderations][1].alreadyOwned = TRUE;
					} else {
						subConsiderations[numSubConsiderations][1].alreadyOwned = FALSE;
					}

					numSubConsiderations++;
				}
			}
		}

		if (neighbouring.b >= 0 && vertices[neighbouring.b].object == VACANT_VERTEX) {
			// Check that it's not within any other verticie
			if (canBuildCampusOn(vertices, neighbouring.b)) {
				int arcId = getArcIdFromVertices(considerations[i][0].to, neighbouring.b);

				if (arcs[arcId].object == VACANT_ARC || arcs[arcId].object == myARC) {
					subConsiderations[numSubConsiderations][0] = considerations[i][0];
					subConsiderations[numSubConsiderations][1] = considerations[i][1];

					subConsiderations[numSubConsiderations][1].from = considerations[i][0].to;
					subConsiderations[numSubConsiderations][1].to = neighbouring.b;

					if (arcs[arcId].object == myARC) {
						subConsiderations[numSubConsiderations][1].alreadyOwned = TRUE;
					} else {
						subConsiderations[numSubConsiderations][1].alreadyOwned = FALSE;
					}

					numSubConsiderations++;
				}
			}
		}

		if (neighbouring.c >= 0 && vertices[neighbouring.c].object == VACANT_VERTEX) {
			// Check that it's not within any other verticie
			if (canBuildCampusOn(vertices, neighbouring.c)) {
				int arcId = getArcIdFromVertices(considerations[i][0].to, neighbouring.c);

				if (arcs[arcId].object == VACANT_ARC || arcs[arcId].object == myARC) {
					subConsiderations[numSubConsiderations][0] = considerations[i][0];
					subConsiderations[numSubConsiderations][1] = considerations[i][1];

					subConsiderations[numSubConsiderations][1].from = considerations[i][0].to;
					subConsiderations[numSubConsiderations][1].to = neighbouring.c;

					if (arcs[arcId].object == myARC) {
						subConsiderations[numSubConsiderations][1].alreadyOwned = TRUE;
					} else {
						subConsiderations[numSubConsiderations][1].alreadyOwned = FALSE;
					}

					numSubConsiderations++;
				}
			}
		}

		i++;
	}

	// printf("Determined considerations\n");

	// Remove duplicate paths to the same vertex

	i = 0;
	int numPossibilities = 0;
	fromToArc possibilities[NUM_INT_VERTICES][2];

	while (i < numSubConsiderations) {
		// First result dominates others, unless it has an alreadyOwned flag
		// printf("%d: %d\n", i, considerations[i][1].to);

		int search = subConsiderations[i][1].to;

		int removeAll = FALSE;

		if (search >= 0) {
			possibilities[numPossibilities][0] = subConsiderations[i][0];
			possibilities[numPossibilities][1] = subConsiderations[i][1];

			int j = 0;
			while (j < numSubConsiderations) {
				if (subConsiderations[j][1].to == search) {
					// Same
					if (!removeAll && (subConsiderations[j][0].alreadyOwned ||
						subConsiderations[j][1].alreadyOwned)) {
						// Better option
						removeAll = TRUE;

						fromToArc pos1 = subConsiderations[j][0];
						fromToArc pos2 = subConsiderations[j][1];

						possibilities[numPossibilities][0] = pos1;
						possibilities[numPossibilities][1] = pos2;

						subConsiderations[j][1].to = -1;

						numPossibilities++;
					}
					subConsiderations[j][1].to = -1;
				}

				j++;
			}

			if (!removeAll) {
				numPossibilities++;
			}
		}

		i++;
	}

	// Now get the weight values of each consideration


	weightedVertex sortedWeights[numPossibilities];

	i = 0;
	while (i < numPossibilities) {
		int weight = getRecursiveVertexWeight(g, vertices, myVertices, numMyVertices,
			possibilities[i][1].to);
		weightedVertex newVertex;
		newVertex.weight = weight;
		newVertex.arcPath[0] = possibilities[i][0];
		newVertex.arcPath[1] = possibilities[i][1];

		sortedWeights[i] = newVertex;

		i++;
	}

	sortWeights(sortedWeights, numPossibilities);

	// printf("Weighted considerations\n");

	// Buy in order of weighting

	// i = 0;

	// while (i < numPossibilities) {
	// 	printf("%d\n", sortedWeights[i].arcPath[1].to);
	// 	i++;
	// }

	int attempt = 0;
	int domination = FALSE;

	if (numPossibilities == 0) {
		printf("Reached campus domination\n");
		domination = TRUE;
	}

	int GO8domination = FALSE;

	if (domination) {
		// Build GO8s
		weightedVertex sortedMyCampuses[numMyVertices];
		int numMyCampuses = 0;

		i = 0;
		while (i < numMyVertices) {
			if (vertices[myVertices[i]].object == myCampus) {
				int weight = getSingleVertexWeight(g, vertices, myVertices,
					numMyVertices, myVertices[i]);

				weightedVertex newVertex;
				newVertex.weight = weight;

				fromToArc newDestination = {0};
				newDestination.to = myVertices[i];
				newVertex.arcPath[0] = newDestination;

				sortedMyCampuses[numMyCampuses] = newVertex;

				numMyCampuses++;
			}

			i++;
		}

		sortWeights(sortedMyCampuses, numMyCampuses);

		int totalGO8s = getGO8s(g, UNI_A) + getGO8s(g, UNI_B) +
			getGO8s(g, UNI_C);

		if (numMyCampuses == 0 || totalGO8s >= 8) {
			printf("Reached GO8 Domiation\n");
			GO8domination = TRUE;
			numMyCampuses = 0;
		}

		i = 0;
		while (i < numMyCampuses) {
			if (enoughToBuildGO8(g, currentPlayer)) {
				action go8Action;
				go8Action.actionCode = BUILD_GO8;

				strcpy(go8Action.destination,
					vertices[sortedMyCampuses[i].arcPath[0].to].path);

				if (isLegalAction(g, go8Action)) {
					return go8Action;
					printf("Built GO8 at %d\n",
						sortedMyCampuses[i].arcPath[0].to);
				} else {
					printf("Could not build GO8 at %d\n",
						sortedMyCampuses[i].arcPath[0].to);
				}
			}

			i++;
		}
	}

	if (GO8domination) {
		// Wow pls, make spinoffs
		while (enoughToStartSpinoff(g, currentPlayer)) {
			action spinoffAction;
			spinoffAction.actionCode = START_SPINOFF;

			return spinoffAction;
		}
	}

	while (attempt < numPossibilities &&
		enoughToBuildCampus(g, currentPlayer, sortedWeights[attempt].arcPath)) {
		int firstArc = getArcIdFromVertices(sortedWeights[attempt].arcPath[0].from,
			sortedWeights[attempt].arcPath[0].to);

		if (firstArc < 0) {
			printf("Could not find path between %d and %d!\n",
				sortedWeights[attempt].arcPath[0].from,
				sortedWeights[attempt].arcPath[0].to);
		} else {
			if (!sortedWeights[attempt].arcPath[0].alreadyOwned) {
				action pathAction;

				pathAction.actionCode = OBTAIN_ARC;
				strcpy(pathAction.destination, arcs[firstArc].path);

				if (!isLegalAction(g, pathAction)) {
					printf("ARC between %d and %d is not legal?\n",
						sortedWeights[attempt].arcPath[0].from,
						sortedWeights[attempt].arcPath[0].to);
				} else {
					printf("Bought ARC between %d and %d\n",
					sortedWeights[attempt].arcPath[0].from,
					sortedWeights[attempt].arcPath[0].to);
					return pathAction;
				}
			}

			int secondArc = getArcIdFromVertices(sortedWeights[attempt].arcPath[1].from,
				sortedWeights[attempt].arcPath[1].to);

			if (secondArc < 0) {
				printf("Could not find path between %d and %d!\n",
					sortedWeights[attempt].arcPath[1].from,
					sortedWeights[attempt].arcPath[1].to);
			} else {
				if (!sortedWeights[attempt].arcPath[1].alreadyOwned) {
					action pathAction;

					pathAction.actionCode = OBTAIN_ARC;
					strcpy(pathAction.destination, arcs[secondArc].path);

					if (!isLegalAction(g, pathAction)) {
						printf("ARC between %d and %d is not legal?\n",
							sortedWeights[attempt].arcPath[1].from,
							sortedWeights[attempt].arcPath[1].to);
					} else {
						printf("Bought ARC between %d and %d\n",
						sortedWeights[attempt].arcPath[1].from,
						sortedWeights[attempt].arcPath[1].to);
						return pathAction;
					}
				}

				int vertexId = sortedWeights[attempt].arcPath[1].to;

				action campusAction;

				strcpy(campusAction.destination, vertices[vertexId].path);
				campusAction.actionCode = BUILD_CAMPUS;

				if (!isLegalAction(g, campusAction)) {
					printf("Campus at %d is not legal?\n", vertexId);
				} else {
					printf("Built campus at %d\n", vertexId);
					return campusAction;
				}
			}
		}

		attempt++;
	}

	action passAction;
	passAction.actionCode = PASS;

	return passAction;
}
Exemplo n.º 27
0
// 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]++;
    }
}
Exemplo n.º 28
0
// returns TRUE if it is legal for the current
// player to make the specified action, FALSE otherwise->
//
// "legal" means everything is legal:
//   * that the action code is a valid action code which is legal to
//     be made at this time
//   * that any path is well formed and legal ie consisting only of
//     the legal direction characters and of a legal length,
//     and which does not leave the island into the sea at any stage->
//   * that disciplines mentioned in any retraining actions are valid
//     discipline numbers, and that the university has sufficient
//     students of the correct type to perform the retraining
//
// eg when placing a campus consider such things as:
//   * is the path a well formed legal 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)
// you can assume that any pths passed in are NULL terminated strings->
int isLegalAction(Game g, action a) {
    int isLegal = TRUE;
    printf("Checking if an action is legal\n");
    int player = getWhoseTurn(g);
    int flag = 1;
    // Protect from stupid shit
    if ((a.actionCode < PASS) || (a.actionCode > RETRAIN_STUDENTS)) {
        printf("Invalid Action Code\n");
        flag = 0;
    } else if (a.actionCode == RETRAIN_STUDENTS) {
        printf("You've Called a retrain, checking if discipline");
        printf("within the bounds\n");
        // If it's a retrain action make sure the to
        // and from are in a nice range.
        if ((a.disciplineTo < STUDENT_THD)
            || (a.disciplineTo > STUDENT_MMONEY)) {
            printf("Invalid Discpline Code\n");
            flag = 0;
        }
        if ((a.disciplineFrom < STUDENT_THD)
            || (a.disciplineFrom > STUDENT_MMONEY)) {
            printf("Invalid Discpline Code\n");
            flag = 0;
        }
    }

    printf("The Flag when testing is %d\n", flag);

    if (flag == 1) {
        // Check all the basic stuff
        if (getTurnNumber(g) == TERRA_NULLIS) {
            isLegal = FALSE;
        } else if ((a.actionCode < 0) || (a.actionCode > MAX_ACTION)) {
            isLegal = FALSE;
        } else if ((getWhoseTurn(g) < 0) || (getWhoseTurn(g) > NUM_UNIS)) {
            isLegal = FALSE;
        } else if (a.actionCode == OBTAIN_IP_PATENT ||
            a.actionCode == OBTAIN_PUBLICATION) {
            isLegal = FALSE;
        }
        if (a.actionCode <= 3 && a.actionCode > 0 && isLegal) {
            if (validString(a.destination) == FALSE) {
                isLegal = FALSE;
            } else if (validPoint(pathToPoint(a.destination).x,
                pathToPoint(a.destination).y) == FALSE) {
                isLegal = FALSE;
            }
        }

        // edge actionEdge = pathToEdgeF (a.destination);

        // Check that someone can get an arc
        if (a.actionCode == OBTAIN_ARC && isLegal) {
            printf("Checking if the arc is legal. Arc:%s\n", a.destination);
            if (validNewEdge(g, pathToEdgeF(a.destination), player) == FALSE) {
                printf("Geographically Valid Edge\n");
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_BQN) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_BPS) < 1) {
                isLegal = FALSE;
            }
        }

        // Check that someone can get a Campus
        if (a.actionCode == BUILD_CAMPUS && isLegal) {
            if (validNewContents(g, a.destination, player) == FALSE) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_BQN) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_BPS) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MJ) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MTV) < 1) {
                isLegal = FALSE;
            }
        }

        if (a.actionCode == BUILD_GO8 && isLegal) {
            point actionPoint =  pathToPoint(a.destination);
            if (g->gameBoard->points[actionPoint.x][actionPoint.y]->contents !=
                player) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MJ) < 2) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MMONEY) < 3) {
                isLegal = FALSE;
            } else if (getTotalGO8s(g) == 8) {
                isLegal = FALSE;
            }
        }

        if (a.actionCode == START_SPINOFF && isLegal) {
            if (getStudents(g, player, STUDENT_MJ) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MTV) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MMONEY) < 1) {
                isLegal = FALSE;
            }
        }

        if (a.actionCode == RETRAIN_STUDENTS && isLegal) {
            int exchange = getExchangeRate(g, player, a.disciplineFrom,
                a.disciplineTo);
            if (getStudents(g, player, a.disciplineFrom) < exchange) {
                isLegal = FALSE;
            } else if (a.disciplineFrom == STUDENT_THD) {
                isLegal = FALSE;
            }
        }
    } else if (flag == 0) {
        isLegal = FALSE;
    }
    return isLegal;
}
Exemplo n.º 29
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");
   
   
}
Exemplo n.º 30
0
action decideAction (Game g) {

        int me = getWhoseTurn (g);
        
        //Number of students resources
        int engineer = getStudents (g, me, STUDENT_BPS);
        int scientist = getStudents (g, me, STUDENT_BQN);
        int jobOwner = getStudents (g, me, STUDENT_MJ);
        int tvStar = getStudents (g, me, STUDENT_MTV);
        int moneyMaker = getStudents (g, me, STUDENT_MMONEY);
        
        //Exchange rate - Retraining Conditions
        //Last argument unnecessary as only disciplineFrom is important
        int costSci = getExchangeRate (g, me, STUDENT_BQN, STUDENT_MJ);
        int costEng = getExchangeRate (g, me, STUDENT_BPS, STUDENT_MJ);
        int costJob = \
            getExchangeRate (g, me, STUDENT_MJ, STUDENT_BPS);
        int costTv = getExchangeRate (g, me, STUDENT_MTV, STUDENT_BPS);
        int costMon = \
            getExchangeRate (g, me, STUDENT_MMONEY, STUDENT_BPS);
            
        //Possible actions to do:
        //Spinoffs -> 1 MJ + 1 MTV + 1 MMNY
        //Build ARCs -> 1 BPS + 1 BQN
        action nextAction;
        if (tvStar > costTv || jobOwner > costJob \
            || moneyMaker > costMon || scientist >= costSci \
            || engineer >= costEng) {
            // > to keep some MMONEY and MJOBS and MTVs,
            // to use for future spinoffs
            // >= to get rid of all BPS and BQNs
            
            nextAction.actionCode = RETRAIN_STUDENTS;
            //determine which student to retrain to
            if (jobOwner <= tvStar && jobOwner <= moneyMaker) {
                nextAction.disciplineTo = STUDENT_MJ;
            } else if (tvStar <= jobOwner && tvStar <= moneyMaker) {
                nextAction.disciplineTo = STUDENT_MTV;
            } else {
                nextAction.disciplineTo = STUDENT_MMONEY;
            }
            
            //Find out which student to retrain from
            /*Order is 
              MJ -> MTV -> MMONEY -> BQN -> BPS
              this ensures that BQN/BPS are retrained first*/ 
            if (jobOwner > costJob) {
                nextAction.disciplineFrom = STUDENT_MJ;
            } else if (tvStar > costTv) {
                nextAction.disciplineFrom = STUDENT_MTV;
            } else if (moneyMaker > costMon) {
                nextAction.disciplineFrom = STUDENT_MMONEY;
            } else if (scientist >= costSci) {
                nextAction.disciplineFrom = STUDENT_BQN;
            } else {
                nextAction.disciplineFrom = STUDENT_BPS;
            }
            
        } else if ((jobOwner * tvStar * moneyMaker) > 0) {
            //create a spinoff
            nextAction.actionCode = START_SPINOFF;
        } else {
            //no resources so end turn
            nextAction.actionCode = PASS;
        }
        
        return nextAction;
}