这篇教程C++ villageEffect函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中villageEffect函数的典型用法代码示例。如果您正苦于以下问题:C++ villageEffect函数的具体用法?C++ villageEffect怎么用?C++ villageEffect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了villageEffect函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mainint main() { srand(time(NULL)); int randNum = rand(); int status; int testNum = 1; int player = 1; struct gameState gs; int k[10] = {adventurer, smithy, ambassador, embargo, gardens, great_hall, tribute, steward, sea_hag, minion}; printf("~~~~~BEGIN TESTING village ~~~~~/n"); status = initializeGame(2, k, randNum, &gs); assert(status == 0); int initialHand = gs.handCount[player]; int initialDeck = gs.deckCount[player]; int initialActions = gs.numActions; villageEffect(0, player, &gs); /* Test 1: Check if one card was added to hand */ status = gs.handCount[player] == initialHand + 1; statusCheck(status, testNum); testNum++; /* Test 2: Check if one card was removed from deck */ status = gs.deckCount[player] == initialDeck - 1; statusCheck(status, testNum); testNum++; /* Test 3: Check if number of actions is increased by 2 */ status = gs.numActions == initialActions + 2; statusCheck(status, testNum); testNum++; printf("~~~~~FINISH TESTING village ~~~~~/n"); return 0;}
开发者ID:welborau,项目名称:CS362Su2015,代码行数:42,
示例2: cardEffect//.........这里部分代码省略......... gainCard(choice2, state, 2, currentPlayer); endPlayed(state, 0); return 0; case remodel: if (choice1 >= state->handCount[currentPlayer] || choice1 < 0 || choice1 == handPos) return -1; if (choice2 < curse || choice2 > treasure_map) return -1; if ((getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2)) { return -1; } playedCard(handPos, &choice1, NULL, state); //trash choice discardCard(choice1, currentPlayer, state, 1); //gain new card gainCard(choice2, state, 0, currentPlayer); endPlayed(state, 0); return 0; case smithy: return smithyEffect(currentPlayer, handPos, state); case village: return villageEffect(currentPlayer, handPos, state); case baron: if (!(choice1 == 1 || choice1 == 2)) return -1; if (choice1 == 1) {//Boolean true or going to discard an estate int p = 0;//Iterator for hand! int card_not_discarded = 1;//Flag for discard set! while (card_not_discarded) { if (p >= state->handCount[currentPlayer]) { if (DEBUG) { printf("No estate cards in your hand, invalid choice/n"); } return -1; } else if (state->hand[currentPlayer][p] == estate) {//Found an estate card! playedCard(handPos, &p, NULL, state); *bonus += 4;//Add 4 coins to the amount of coins discardCard(p, currentPlayer, state, 0); card_not_discarded = 0;//Exit the loop } else { p++;//Next card } } } else { playedCard(handPos, NULL, NULL, state); gainCard(estate, state, 0, currentPlayer);//Gain an estate } state->numBuys++;//Increase buys by 1!
开发者ID:cs362sp16,项目名称:cs362sp16_berezam,代码行数:67,
示例3: mainint main() { /* set up game state */ int i; int numPlayer = 2; int handCount; int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall}; struct gameState G; int maxHandCount = 5; /* initialize decks */ testInitializeGame(2, k, &G); /* set up hand for Player 0 */ G.hand[0][0] = copper; G.hand[0][1] = copper; G.hand[0][2] = copper; G.hand[0][3] = copper; G.hand[0][4] = village; G.handCount[0] = 5; printf("Setup complete./n"); /* test */ printf("Testing Village Card.../n"); /* save game state */ struct gameState Save; Save.numActions = G.numActions; Save.numBuys = G.numBuys; Save.handCount[0] = G.handCount[0]; /* play village */ int villageResult = villageEffect(&G, 0, 4); /* confirm village played */#if (PRINT_TEST == 1) printf("Village Result: %d ",villageResult); if (villageResult == 0) printf("Pass!/n"); else printf("Fail!/n");#endif #if (ENABLE_ASSERTS == 1) assert(villageResult == 0);#endif /* confirm +1 card * because village has been discarded, the number of cards in hand * should be the same */#if (PRINT_TEST == 1) if (G.handCount[0] - Save.handCount[0] == 0) printf("+1 card: Pass!/n"); else printf("+1 card: Fail!/n");#endif #if (ENABLE_ASSERTS == 1) assert(G.handCount[0] - Save.handCount[0] == 0);#endif /* confirm +2 Actions */#if (PRINT_TEST == 1) if (G.numActions - Save.numActions == 2) printf("+2 Actions: Pass!/n"); else printf("+2 Actions: Fail!/n");#endif #if (ENABLE_ASSERTS == 1) assert(G.numActions - Save.numActions == 2);#endif #if (ENABLE_ASSERTS == 1) printf("All tests passed!/n");#endif return 0;}
开发者ID:Jmmyr41,项目名称:cs362f15,代码行数:82,
示例4: mainint main(){ int k[10] = { adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy }; int i = 0, player = 0, players = 0, seed = 0; int the_test = 0, handCount = 0; int numActions = 0;#ifdef SEG_FAULT int currentPlayer = 0, handPos = 0;#endif struct gameState *aGame = NULL; srand(time(NULL)); // init libc random seed for (i = 0; i < MAX_TESTS; i++) { // set up game state aGame = newGame(); // allocate new memory seed = rand(); // any value will do players = (rand() % 3) + 2; // 2 to 4 players player = rand() % players; // randomly pick a player to play initializeGame(players, k, seed, aGame); aGame->whoseTurn = player; // set player as active player aGame->hand[player][0] = village; // set up player hand to between a minimum of 5 and max hand; do { handCount = rand() % (MAX_HAND + 1); } while( (handCount < 5)); aGame->handCount[player] = handCount;#ifdef SEG_FAULT currentPlayer = rand(); handPos = rand();#endif printf("Test %d: ", i);#ifdef SEG_FAULT if (currentPlayer > player) fprintf(stderr, "current player out of bounds, likely seg fault.../n"); if (handPos > handCount) fprintf(stderr, "hand position out of bounds, likely seg fault.../n");#endif numActions = aGame->numActions;#ifdef SEG_FAULT villageEffect(currentPlayer, aGame, handPos);#endif villageEffect(player, aGame, 0); the_test = (handCount == aGame->handCount[player]); printf("drew a card, discarded a card..."); test(the_test, "hand size changed incorrectly"); the_test = ((numActions + 2) == aGame->numActions); printf("...actions increased by two..."); test(the_test, "number actions did not change by two."); printf("/n"); //clean up free(aGame); player = 0, players = 0; seed = 0; the_test = 0, numActions = 0; handCount = 0; } return EXIT_SUCCESS;}
开发者ID:cs362sp15,项目名称:projects,代码行数:69,
示例5: cardEffect//.........这里部分代码省略......... return 0; case remodel: j = state->hand[currentPlayer][choice1]; //store card we will trash if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) { return -1; } gainCard(choice2, state, 0, currentPlayer); //discard card from hand discardCard(handPos, currentPlayer, state, 0); //discard trashed card for (i = 0; i < state->handCount[currentPlayer]; i++) { if (state->hand[currentPlayer][i] == j) { discardCard(i, currentPlayer, state, 0); break; } } return 0; case smithy: smithyEffect(state, currentPlayer, handPos); break; case village: villageEffect(state, currentPlayer, handPos); break; case baron: state->numBuys++;//Increase buys by 1! if (choice1 > 0){//Boolean true or going to discard an estate int p = 0;//Iterator for hand! int card_not_discarded = 1;//Flag for discard set! while(card_not_discarded){ if (state->hand[currentPlayer][p] == estate){//Found an estate card! state->coins += 4;//Add 4 coins to the amount of coins state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; state->discardCount[currentPlayer]++; for (;p < state->handCount[currentPlayer]; p++){ state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; } state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; state->handCount[currentPlayer]--; card_not_discarded = 0;//Exit the loop } else if (p > state->handCount[currentPlayer]){ if(DEBUG) { printf("No estate cards in your hand, invalid choice/n"); printf("Must gain an estate if there are any/n"); } if (supplyCount(estate, state) > 0){ gainCard(estate, state, 0, currentPlayer); state->supplyCount[estate]--;//Decrement estates if (supplyCount(estate, state) == 0){ isGameOver(state); } } card_not_discarded = 0;//Exit the loop
开发者ID:Jmmyr41,项目名称:cs362f15,代码行数:67,
示例6: mainint main(int argc, char *argv[]) { struct gameState state, // initialized game state for testing backup; // backup game state for comparisons // array of kingdom cards for game initialization int kingdomCards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; int randomSeed = 10000, numTests = 1000, numPlayers = 2, isValidDraw = 1, isValidActions = 1, isValidDiscard = 1, currentPlayer = 0, handpos, i = 0, j = 0, numPassed = 0, numFailed = 0; for (i = 0; i < numTests; i++) { // reset validation check to 1, 0 if test fails isValidDraw = 1; isValidActions = 1; isValidDiscard = 1; // setup working copy of game initializeGame(numPlayers, kingdomCards, randomSeed, &state); // randomize number of cards in player's hand state.handCount[currentPlayer] = (rand() % 10) + 1; // randomize position of village card and place it in hand handpos = rand() % state.handCount[currentPlayer]; // randomize the player's deck count state.deckCount[currentPlayer] = rand() % 5; // fill in the rest of the cards in the player's hand for (j = 0; j < state.handCount[currentPlayer]; j++) { if (j != handpos) state.hand[currentPlayer][j] = rand() % 26; else state.hand[currentPlayer][j] = village; } // copy game state to backup for error detection memcpy(&backup, &state, sizeof(struct gameState)); // call village card effect villageEffect(currentPlayer, &state, handpos); // check drawcard component if (state.handCount[currentPlayer] != (backup.handCount[currentPlayer])) isValidDraw = 0; if (state.deckCount[currentPlayer] != backup.deckCount[currentPlayer] - 1) { isValidDraw = 0; } if (state.hand[currentPlayer][state.handCount[currentPlayer] - 1] == -1) { isValidDraw = 0; } // check additional actions if (state.numActions != backup.numActions + 2) { isValidActions = 0; } // check village card is discarded if (state.playedCards[state.playedCardCount - 1] != village) { isValidDiscard = 0; } // print test conditions if the test failed if (isValidDraw == 0 || isValidActions == 0 || isValidDiscard == 0) { printf("TEST %i/n", i + 1); printf("Function Used: villageEffect(%i, &state, %i);/n", currentPlayer, handpos); printf("Position of village card: %i/n", handpos); printf("Number of Cards in Hand: %i/n", backup.handCount[currentPlayer]); printf("Starting deck count: %i/n", backup.deckCount[currentPlayer]); printf("Cards in hand: "); for (j = 0; j < backup.handCount[currentPlayer]; j++) { printf("%i, ", backup.hand[currentPlayer][j]); } printf("/n"); printf("Random Seed: %i/n", randomSeed); printf("Failed Item(s): /n"); if (isValidDraw == 0) printf("Invalid draw card operation/n"); if (isValidActions == 0) printf("Invalid number of actions/n"); if (isValidDiscard == 0) printf("Invalid discard operation/n"); numFailed++; } else { numPassed++; } randomSeed++; } printf("/nTotal Tests: %i/n", numTests); printf("Total Passed: %i/n", numPassed); printf("Total Failed: %i/n", numFailed); return 0;}
开发者ID:cr8zd,项目名称:cs362w16,代码行数:94,
示例7: testVillageCard/*Village card unit tests*/int testVillageCard(){ int numPlayer = 2; //players in the game 2-4 int player = 0; //current player int handCount = 5; //Number of cards player starts with int i; //counting index for loops int hasVillage = 0; //Determines if Village card is in player's hand or not. char cardName[20]; //name of card /*Kingdom cards in this game*/ int k[10] = {adventurer, council_room, feast, gardens, mine , remodel, smithy, village, baron, great_hall}; /*starts new game*/ struct gameState state; /*create hand*/ int hand[handCount]; hand[0] = copper; hand[1] = silver; hand[2] = gold; hand[3] = estate; hand[4] = village; printf ("Testing villageEffect():/n"); initializeGame(numPlayer, k, 1000, &state); //initialize a new game state.handCount[player] = handCount; //set the number of cards in hand memcpy(state.hand[player], hand, sizeof(int) * handCount); //give hand to player /*checks if village is in player's hand*/ for(i = 0; i < state.handCount[player]; i++){ cardNumToName(state.hand[player][i], cardName); //get name from card num printf("%s ", name); if(strcmp(name, "village") == 0){ hasVillage = 1; //village card is in player's hand } } if (hasVillage == 1){ printf ("Player has village/n"); printf ("Using village card/n"); villageEffect(player, state, i); //uses village card /*Village adds 1 card and discards itself*/ if (state.handCount[player] == 5) printf ("Player has the correct number of cards!/n"); else printf("Player has the incorrect number of cards./n"); /*Village takes one action to play and gives 2 actions 1-1+2=2*/ if (state.numActions == 2) printf("Player has the correct number of actions!/n"); else printf("Player has the incorrect number of actions./n"); } else{ printf ("Player does not have village/n"); } return 0;}
开发者ID:Jmmyr41,项目名称:cs362f15,代码行数:62,
注:本文中的villageEffect函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ vim_strchr函数代码示例 C++ vif_to_intf函数代码示例 |