//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; }
void runGame (void) { // create a dummy game int disciplines[] = DEFAULT_DISCIPLINES; int dice[] = DEFAULT_DICE; Game g = newGame (disciplines, dice); printf ("Running a test game...\n"); // roll the dice int diceScore; diceScore = rollDice (); // progress the game throwDice (g, diceScore); printf ("Deciding on the action...\n"); action newAction; newAction = decideAction (g); while (!getWinner (g)) { // if the player PASSES if (newAction.actionCode == PASS) { diceScore = rollDice (); // progress the game throwDice (g, diceScore); } else { if (isLegalAction (g, newAction)) { makeAction (g, newAction); } else { printf (">>> I'm sorry but you can't do that!\n"); } } // get the next turn newAction = decideAction (g); } // the game is over printf ("\nGame over. Player %d wins\n", getWinner (g)); disposeGame (g); }
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; }
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; printf ("New game created, variables are initialized.\n"); printf ("Let the game begin!\n\n"); while (score < 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: %d \n", counter, numStudents[counter]); counter ++; } a = decideAction (g); printf ("You chose move %d.\n", a.actionCode); legal = isLegalAction (g, a); while (a.actionCode != PASS) { while (legal != TRUE) { printf ("The chosen action is illegal, try again.\n"); a = decideAction (g); printf ("You chose move %d.\n", a.actionCode); legal = isLegalAction (g, a); printf ("Legal here is.. %d.\n", legal); } 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 %d made!\n", a.actionCode); 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)); printf (" No of Students: \n"); counter = 0; while (counter < MAX_STU_TYPES) { numStudents[counter] = getStudents (g, curPlayer, counter); printf (" %d: %d \n", counter, numStudents[counter]); counter ++; } playerKPI = getKPIpoints (g, curPlayer); printf ("Player %d KPI Score: %d\n\n", curPlayer, score); } 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; }
static action getAIAction(Game g) { action newAction; newAction = decideAction(g); return newAction; }