本文整理汇总了C++中buyCard函数的典型用法代码示例。如果您正苦于以下问题:C++ buyCard函数的具体用法?C++ buyCard怎么用?C++ buyCard使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buyCard函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//Testing initializeGame and default deal
int main() {
struct gameState g, orig;
int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,mine,ambassador,
outpost,baron,tribute};
int r = 0;
//3 player game this time
initializeGame(3, k, 1, &orig);
//Trevor's suggestion, saving game state for testing purposes
memcpy(&g, &orig, sizeof(struct gameState));
//first hand of player 0 is {4 coppers, 1 estate}. 4 coins
buyCard(gardens, &g); //player 0 buys a garden
endTurn(&g);
buyCard(curse, &g); //player 1 buys a curse
endTurn(&g);
//Not doing anything on player 3 turn
endTurn(&g);
r = scoreFor(3, &g);
myAssert(r == -9999, "Player should not exist but did", __LINE__);
r = scoreFor(0, &g);
myAssert(r == 5, "Player should have a base 5 points", __LINE__);
if(r == 0)
printf("Tests completed successfully!\n");
return 0;
}
示例2: main
int main(){
struct gameState state;
int s;
int k[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
initializeGame(2, k, 2, &state);
state.numBuys = 0;
s = buyCard(5, &state);
assert(s == -1);
state.numBuys = 5;
state.coins = 0;
s = buyCard(5, &state);
assert(s == -1);
state.coins = 100;
s = buyCard(5, &state);
assert(s == 0);
printf("buyCard test passed\n");
return 0;
}
示例3: randBuy
int randBuy(struct gameState *game){
int card;
if (game->coins >= getCost(province))
card = province;
else
card = floor(Random()*(treasure_map+1));
if (game->coins == 0){
game->numBuys = 0;
return 0;
}
if (getCost(card) > game->coins || game->supplyCount[card] <= 0) {
if (buyCard(card,game) == 0) {
printf("Bad attempt to buy card was successfull: ");
printCard(card);
printf("\n\r");
return -1;
}
else
return 0;
}
printf("Card to buy: ");
printCard(card);
printf("\n\r");
return buyCard(card,game);
}
示例4: buyCost5
void buyCost5(struct gameState *p, int * k){
int i = 0;
int counter = 0;
int j = 0;
for(;i<10;i++){
if (k[i] == outpost || k[i] == minion || k[i] == duchy)
counter++;
else if(k[i] == council_room || k[i] == mine || k[i] == tribute)
counter++;
}
int * costFive = malloc(sizeof(int)*counter);
for(i =0; i<10;i++){
if (k[i] == outpost || k[i] == minion || k[i] == duchy)
costFive[j] = k[i];
else if(k[i] == council_room || k[i] == mine || k[i] == tribute)
costFive[j] = k[i];
}
if(counter != 0){
int num = rand() % counter;
buyCard(costFive[num],p);
printf("%s bought\n",printCard(costFive[num]));
}
else{
buyCard(silver,p);
printf("%s bought\n",printCard(silver));
}
}
示例5: buyCost4
void buyCost4(struct gameState *p, int * k){
int i = 0;
int counter = 0;
int j = 0;
for(;i<10;i++){
if (k[i] == cutpurse || k[i] == baron || k[i] == feast)
counter++;
else if(k[i] == gardens || k[i] == remodel || k[i] == smithy)
counter++;
else if(k[i] == salvager || k[i] == sea_hag || k[i] == treasure_map)
counter++;
}
int * costFour = malloc(sizeof(int)*counter);
for(i =0; i<10;i++){
if (k[i] == cutpurse || k[i] == baron || k[i] == feast){
costFour[j] = k[i];
j++;}
else if(k[i] == gardens || k[i] == remodel || k[i] == smithy){
costFour[j] = k[i];
j++;}
else if(k[i] == salvager || k[i] == sea_hag || k[i] == treasure_map){
costFour[j] = k[i];
j++;}
}
if(counter != 0){
int num = rand() % counter;
buyCard(costFour[num],p);
printf("%s bought\n",printCard(costFour[num]));
}
else{
buyCard(silver,p);
printf("%s bought\n",printCard(silver));
}
}
示例6: buy_card
void buy_card(struct gameState* p, int not_bought[10], int k[10])
{
int money = 0, j;
for(j = 0; j < numHandCards(p); j++)
{
if(handCard(j,p) == copper)
{
playCard(j, -1, -1, -1, p);
money++;
}
if(handCard(j,p) == silver)
{
playCard(j, -1, -1, -1, p);
money += 2;
}
if(handCard(j,p) == gold)
{
playCard(j, -1, -1, -1, p);
money += 3;
}
}
if(money > 7)
{
buyCard(province, p);
printf("%d Bought province\n", p->whoseTurn);
}
else if(money > 5)
{
for(j = 0; j < 10; j++)
{
if(!(bought(not_bought, p, k[j])))
{
buyCard(k[j], p);
printf("%d Bought %s\n", p->whoseTurn, get_name(k[j]));
j = 10;
}
}
}
else if(money > 5)
{
buyCard(gold, p);
printf("%d Bought gold\n", p->whoseTurn);
}
else if(money > 2)
{
buyCard(silver, p);
printf("%d Bought silver\n", p->whoseTurn);
}
else
{
buyCard(copper, p);
printf("%d Bought copper\n", p->whoseTurn);
}
}
示例7: main
//testing buyCard()
int main() {
int seed = 1;//the seed for initializeGame
int numPlayer;
int players, handCount, i, j, tempCount;
int cardCount = 10;//the number of cards initially given to a player
int cards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
struct gameState game;
printf ("Testing buyCard():\n\n");
for(numPlayer = 2; numPlayer <= 4; numPlayer++) {//checking for all possible number of players (2-4) {
initializeGame(numPlayer, cards, seed, &game); // initialize a new game
for (players = 0; players < numPlayer; players++)//drawing all cards for each player
{
for (i = 0; i < cardCount; i++){//drawing entire deck
drawCard(players, &game);//drawing a card
}
game.numBuys = 1;
game.whoseTurn = players;
updateCoins(players, &game, 0);
buyCard(smithy, &game);//note:smithy cost 4, less than coppers originally given
if(fullDeckCount(players, smithy, &game) != 1) {//checking that the user can buy an affordable card
printf("ERROR BUYING AFFORDABLE CARD: player: %i, buy: %i, expected cards after buy: %i, actual cards = %i\n\n", players, 1, 1, fullDeckCount(players, smithy, &game));
printf("user has in hand %i\n", game.handCount[players]);
}
game.numBuys = 1;
game.whoseTurn = players;
buyCard(smithy, &game);//note:smithy cost 4, more than money left
if(fullDeckCount(players, smithy, &game) != 1) {//checking that the user can't buy an unaffordable card
printf("ERROR BUYING UNAFFORDABLE CARD: player: %i, buy: %i, expected cards after buy: %i, actual cards = %i\n\n", players, 2, 1, fullDeckCount(players, smithy, &game));
}
game.numBuys = 1;
game.whoseTurn = players;
tempCount = game.supplyCount[smithy];
game.supplyCount[smithy] = 0;//removing smithy cards
buyCard(smithy, &game);
if(fullDeckCount(players, smithy, &game) != 1) {//checking that the user can't buy an absent
printf("ERROR BUYING ABSENT CARD: player: %i, buy: %i, expected cards after buy: %i, actual cards = %i\n\n", players, 3, 1, fullDeckCount(players, smithy, &game));
}
game.supplyCount[smithy] = tempCount;//returning smithy cards
}
}
return 0;
}
示例8: main
int main() {
int i, test1=0, scoreTrack=10;
int currentPlayer, money;
struct gameState G;
int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
int r = initializeGame(2, k, 2, &G);
assert (r ==0);
///// ----------------------- game -----------------------
while (!isGameOver(&G))
{
money=0;
for (i = 0; i < numHandCards(&G); i++)
{
if (handCard(i, &G) == copper)
money++;
else if (handCard(i, &G) == silver)
money += 2;
else if (handCard(i, &G) == gold)
money += 3;
}
if ((supplyCount(gold, &G)==0) && (supplyCount(silver, &G)==0))
{
if (money >= 8)
{
buyCard(province, &G);
scoreTrack=scoreTrack+6;
}
}
else if (money >= 6)
{
buyCard(gold, &G);
}
else if (money >= 3)
{
buyCard(silver, &G);
}
endTurn(&G);
}
//------------------------------------------------------------------
//total score
test1= scoreFor(0, &G) + scoreFor(1, &G);
//score we tracked
printf("Score for: %i", scoreFor);
printf("Score trac: %i", scoreTrack);
//assert( test1== scoreTrack);
//scoreFor is acting strange
return 0;
}
示例9: play
void play(struct gameState *p,int pcard, int favCard, int *pnumcard, int who, int money){
int i = 0;
char cardname[32];
cardNumToName(favCard, cardname);
printf("your fav card is %s\n",cardname);
if (pcard != -1) {
cardNumToName(favCard, cardname);
printf("%d: %s played from position %d\n",who, cardname, pcard);
playCard(pcard, 1, 1, 1, p);
printf("%s played.\n",cardname);
money = 0;
i=0;
while(i<numHandCards(p)){
if (handCard(i, p) == copper){
playCard(i, -1, -1, -1, p);
money++;
}
else if (handCard(i, p) == silver){
playCard(i, -1, -1, -1, p);
money += 2;
}
else if (handCard(i, p) == gold){
playCard(i, -1, -1, -1, p);
money += 3;
}
i++;
}
}
if (money >= 8) {
printf("%d: bought province\n",who);
buyCard(province, p);
}
else if (money >= 6) {
printf("%d: bought gold\n",who);
buyCard(gold, p);
}
else if ((money >= 4) && (*pnumcard < 2)) {
printf("%d: bought %s\n",who, cardname);
buyCard(favCard, p);
*pnumcard++;
}
else if (money >= 3) {
printf("%d: bought silver\n",who);
buyCard(silver, p);
}
printf("%d: end turn\n",who);
endTurn(p);
}
示例10: testSmithyCard
int testSmithyCard () {
//
// Tests that fullDeckCount works properly
//
// Status of test
// set to 0 if the test didn't crash,
// set to -1 if the test fails to finish,
int status = -1;
// Create play variable
int p = 0;
// RFC 1149.5 specifies 4 as the standard IEEE-vetted random number.
int rand = 4;
// Create cards variable
int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
sea_hag, tribute, smithy};
// Create gamestate
struct gameState G;
status = initializeGame(2, k, rand, &G);
myAssert (status == 0);
int choices[3] = {0};
int pos;
buyCard(smithy, &G);
buyCard(smithy, &G);
int loops = 0, cardFound = 0;
while(cardFound == 0 && loops < 5) {
for (pos=0, loops++; pos<numHandCards(&G); pos++)
if (handCard(pos, &G) == smithy)
cardFound = 1;
endTurn(&G);
}
status = cardEffect(smithy,
choices[0], choices[1], choices[2],
&G, pos, NULL);
myAssert (status == 0);
printf ("testSmithyCard passes.\n");
status = 0;
return status;
}
示例11: main
//test baron
int main()
{
int kCards[10] = {adventurer, gardens, embargo, village, minion, baron, cutpurse, sea_hag, tribute, smithy};
struct gameState g, orig;
int r;
//for consistancy make randomSeed=1
initializeGame(2, kCards, 1, &orig);
//turn 1 of player 0 is {4 coppers, 1 estate}. 4 coins
gainCard(baron, &orig, 2, 0);
memcpy(&g, &orig, sizeof(struct gameState));
//play baron normal, discard estate. get 4 coins
r = supplyCount(estate, &g);
playCard(5, 1, 0, 0, &g);
myAssert(r == supplyCount(estate, &g), "Baron gained estate while discarding", __LINE__);
myAssert(numHandCards(&g) == 4, "Did not properly discard", __LINE__);
for(int i = 0; i < numHandCards(&g); ++i)
myAssert(handCard(i, &g) == copper, "Did not properly discard", __LINE__);
//have 8 coins total
r = buyCard(gold, &g);
myAssert(r == 0, "Did not have 6 coins to buy gold", __LINE__);
r = buyCard(silver, &g);
myAssert(r == -1, "Bought silver, had more than 8 coins", __LINE__);
r = buyCard(estate, &g);
myAssert(r == 0, "Did not have 8 coins or 2 buys for estate", __LINE__);
r = buyCard(copper, &g);
myAssert(r == -1, "Got more than +1 buy from baron", __LINE__);
//play baron normal, dont discard estate so gain one
memcpy(&g, &orig, sizeof(struct gameState));
r = supplyCount(estate, &g);
playCard(5, 0, 0, 0, &g);
myAssert(r-1 == supplyCount(estate, &g), "Baron did not gain estate", __LINE__);
myAssert(handCard(4, &g) == estate, "Baron discarded estate in hand while gaining", __LINE__);
r = buyCard(duchy, &g);
myAssert(r == -1, "Bought duchy, gained coins when gaining estate", __LINE__);
//play baron, discard estate but have none so gain one
discardCard(4, 0, &orig, 0);
r = supplyCount(estate, &orig);
playCard(4, 1, 0, 0, &orig);
r = myAssert(r-1 == supplyCount(estate, &orig), "Did not gain with no estates in hand", __LINE__);
//done
if(r == 0)
printf("Tests completed successfully!\n");
return 0;
}
示例12: main
int main(){
struct gameState game;
int numplayers = 4;
int i = 0;
// initiate
game.numPlayers = numplayers;
// starting hand
game.whoseTurn = 0;
game.phase = 0;
game.handCount[0] = 1;
game.discardCount[0] = 0;
game.deckCount[0] = 0;
game.hand[0][0] = smithy;
game.numBuys = 2;
game.numActions = 1;
game.coins = 0;
for(i = 0; i <= treasure_map; i++)
if (i != smithy)
// all cards
game.supplyCount[i] = 10;
else // there are no smithy cards
game.supplyCount[i] = 0;
// will not be able to purchase
myassert(buyCard(silver, &game) == -1);
// gold to purchase with
game.hand[0][0] = gold;
game.coins = 3;
// no smithys
myassert(buyCard(smithy, &game) == -1);
myassert(buyCard(village, &game) == 0);
// discard contains 1
myassert(game.discardCount[0] == 1);
// subtract from supply
myassert(game.supplyCount[village] == 9);
// no more coins
myassert(game.coins == 0);
// subtract buy
myassert(game.numBuys == 1);
if (!failed){
printf("buyCard() test passed successfully!\n");
}else{
printf("buyCard() test FAILED\n");
}
return 0;
}
示例13: main
//test buyCard()
int main()
{
int kCards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
struct gameState orig, g;
int r, count;
//for consistancy make randomSeed=1
initializeGame(2, kCards, 1, &orig);
//keep copy of original state for testing purposes
memcpy(&g, &orig, sizeof(struct gameState));
//first hand of player 0 is {4 coppers, 1 estate}. 4 coins
count = supplyCount(curse, &g);
r = buyCard(-1, &g);
myAssert(r == -1, "Bought a non-existant card", __LINE__);
r = buyCard(council_room, &g);
myAssert(r == -1, "Bought council room which is not in supply", __LINE__);
r = buyCard(gold, &g);
myAssert(r == -1, "Gold costs 6 coins, bought with 4", __LINE__);
r = buyCard(embargo, &g);
myAssert(r == 0, "Could not buy an embargo with 4 coins", __LINE__);
r = buyCard(copper, &g);
myAssert(r == -1, "Bought more than one card on first turn", __LINE__);
myAssert(count == supplyCount(curse, &g), "curse gained before embargo played", __LINE__);
//player 0 gets embargo in hand buy turn 4 in handPos 3
//advance to turn 4 for player 0
for(int i = 0; i < 6; ++i)
endTurn(&g);
myAssert(handCard(3, &g) == embargo, "Did not properly gain bought embargo", __LINE__);
playCard(3, copper, 0, 0, &g); //put an embargo on coppers
endTurn(&g);
//hand of player 1 turn 4 is {4 coppers, 1 estate}. 4 coins
count = supplyCount(curse, &g);
r = buyCard(copper, &g);
myAssert(r == 0, "Try Buying a copper with a curse on it", __LINE__);
myAssert(count-1 == supplyCount(curse, &g), "Improper amount of curses removed from supply", __LINE__);
//advance to turn 5 where curse should appear in handPos 0
for(int i = 0; i < 2; ++i)
endTurn(&g);
r = handCard(0, &g);
myAssert(r == curse, "Player 1 did not recieve curse", __LINE__);
//restart game
buyCard(smithy, &orig);
//smithy will show up in turn 4 in handPos 3
//turn 4 player 0 hand is {4 coppers, 1 smithy}
for(int i = 0; i < 6; ++i)
endTurn(&orig);
buyCard(silver, &orig);
r = playCard(3, 0, 0, 0, &orig);
r = myAssert(r == -1, "buyCard could not advance the phase", __LINE__);
//done
if(r == 0)
printf("Tests completed successfully!\n");
return 0;
}
示例14: tryBuyCard
void tryBuyCard(struct gameState *state){
int cardToBuy = 0;
char name[100];
do{
cardToBuy = rand() % (treasure_map);
}while(state->supplyCount[cardToBuy] < 0);
//try to buy a silver if player has 3 coins
//and random choice is to buy a curse or copper
if(state->coins == 3 && (cardToBuy = 0 || cardToBuy == 4)){
if(state->supplyCount[silver] > 0){
cardToBuy = silver;
}
}
//if the player has enough to buy a province, and 1 buy they will
if(state->coins >= 8 && state->numBuys == 1){
if(state->supplyCount[province] > 0){
cardToBuy = province;
}
}
//they try to buy a card so long as it isn't a curse
if(cardToBuy != 0){
cardNumToName(cardToBuy,name);
printf("card to buy %s\n",name);
printf("card costs %d\n",getCost(cardToBuy));
buyCard(cardToBuy, state);
}
//Game info after the play
}
示例15: main
int main (int argc, char** argv) {
struct gameState G;
int playerNum;
srand(time(NULL));
playerNum = rand() % MAX_PLAYERS;//random player num index
int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
sea_hag, tribute, smithy};
printf ("\nStarting Unit Test 3: buyCard() ...\n");
G.whoseTurn = playerNum;
G.supplyCount[estate] = 9;
G.numBuys = 1;
G.coins = 1000;
int r = initializeGame(4, k, 142, &G);//initialized for a 4 player game
int cardBought = buyCard(estate, &G);
assert (cardBought == 0);
printf("Passed\n");
assert (r == 0);
return 0;
}