您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ updateCoins函数代码示例

51自学网 2021-06-03 09:13:21
  C++
这篇教程C++ updateCoins函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中updateCoins函数的典型用法代码示例。如果您正苦于以下问题:C++ updateCoins函数的具体用法?C++ updateCoins怎么用?C++ updateCoins使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了updateCoins函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: cardEffect

int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus){        int i;        int j;        int k;        int x;        int index;        int currentPlayer = whoseTurn(state);        int nextPlayer = currentPlayer + 1;        int tributeRevealedCards[2] = {-1, -1};        int temphand[MAX_HAND];// moved above the if statement        int drawntreasure=0;        // int cardDrawn;        int z = 0;// this is the counter for the temp hand        if (nextPlayer > (state->numPlayers - 1)) {                nextPlayer = 0;        }        //uses switch to select card and perform actions        switch( card )        {        case adventurer:                return adventurerEffect(state, drawntreasure, z, temphand);        case council_room:                //+4 Cards                for (i = 0; i < 4; i++)                {                        drawCard(currentPlayer, state);                }                //+1 Buy                state->numBuys++;                //Each other player draws a card                for (i = 0; i < state->numPlayers; i++)                {                        if ( i != currentPlayer )                        {                                drawCard(i, state);                        }                }                //put played card in played card pile                discardCard(handPos, currentPlayer, state, 0);                return 0;        case feast:                //gain card with cost up to 5                //Backup hand                for (i = 0; i <= state->handCount[currentPlayer]; i++) {                        temphand[i] = state->hand[currentPlayer][i];//Backup card                        state->hand[currentPlayer][i] = -1;//Set to nothing                }                //Backup hand                //Update Coins for Buy                updateCoins(currentPlayer, state, 5);                x = 1;//Condition to loop on                while( x == 1) {//Buy one card                        if (supplyCount(choice1, state) <= 0) {                                if (DEBUG)                                        printf("None of that card left, sorry!/n");                                if (DEBUG) {                                        printf("Cards Left: %d/n", supplyCount(choice1, state));                                }                        }                        else if (state->coins < getCost(choice1)) {                                printf("That card is too expensive!/n");                                if (DEBUG) {                                        printf("Coins: %d < %d/n", state->coins, getCost(choice1));                                }                        }                        else{                                if (DEBUG) {                                        printf("Deck Count: %d/n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);                                }                                gainCard(choice1, state, 0, currentPlayer);//Gain the card                                x = 0;//No more buying cards                                if (DEBUG) {                                        printf("Deck Count: %d/n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);                                }                        }                }                //Reset Hand                for (i = 0; i <= state->handCount[currentPlayer]; i++) {                        state->hand[currentPlayer][i] = temphand[i];                        temphand[i] = -1;                }                //Reset Hand//.........这里部分代码省略.........
开发者ID:TheTallPaul,项目名称:cs362sp16_melloc,代码行数:101,


示例2: initializeGame

//.........这里部分代码省略.........        //set number of Treasure cards        state->supplyCount[copper] = 60 - (7 * numPlayers);        state->supplyCount[silver] = 40;        state->supplyCount[gold] = 30;        //set number of Kingdom cards        for (i = adventurer; i <= treasure_map; i++)  //loop all cards        {                for (j = 0; j < 10; j++)    //loop chosen cards                {                        if (kingdomCards[j] == i)                        {                                //check if card is a 'Victory' Kingdom card                                if (kingdomCards[j] == great_hall || kingdomCards[j] == gardens)                                {                                        if (numPlayers == 2) {                                                state->supplyCount[i] = 8;                                        }                                        else{ state->supplyCount[i] = 12; }                                }                                else                                {                                        state->supplyCount[i] = 10;                                }                                break;                        }                        else //card is not in the set choosen for the game                        {                                state->supplyCount[i] = -1;                        }                }        }        ////////////////////////        //supply intilization complete        //set player decks        for (i = 0; i < numPlayers; i++)        {                state->deckCount[i] = 0;                for (j = 0; j < 3; j++)                {                        state->deck[i][j] = estate;                        state->deckCount[i]++;                }                for (j = 3; j < 10; j++)                {                        state->deck[i][j] = copper;                        state->deckCount[i]++;                }        }        //shuffle player decks        for (i = 0; i < numPlayers; i++)        {                if ( shuffle(i, state) < 0 )                {                        return -1;                }        }        //draw player hands        for (i = 0; i < numPlayers; i++)        {                //initialize hand size to zero                state->handCount[i] = 0;                state->discardCount[i] = 0;                //draw 5 cards                // for (j = 0; j < 5; j++)                //	{                //	  drawCard(i, state);                //	}        }        //set embargo tokens to 0 for all supply piles        for (i = 0; i <= treasure_map; i++)        {                state->embargoTokens[i] = 0;        }        //initialize first player's turn        state->outpostPlayed = 0;        state->phase = 0;        state->numActions = 1;        state->numBuys = 1;        state->playedCardCount = 0;        state->whoseTurn = 0;        state->handCount[state->whoseTurn] = 0;        //int it; move to top        //Moved draw cards to here, only drawing at the start of a turn        for (it = 0; it < 5; it++) {                drawCard(state->whoseTurn, state);        }        updateCoins(state->whoseTurn, state, 0);        return 0;}
开发者ID:TheTallPaul,项目名称:cs362sp16_melloc,代码行数:101,


示例3: cardEffect

int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus){  int i;  int j;  int k;  int x;  int index;  int currentPlayer = whoseTurn(state);  int nextPlayer = currentPlayer + 1;  int tributeRevealedCards[2] = {-1, -1};  int temphand[MAX_HAND];// moved above the if statement  int drawntreasure=0;  int cardDrawn;  int z = 0;// this is the counter for the temp hand  if (nextPlayer > (state->numPlayers - 1)){    nextPlayer = 0;  }  	  //uses switch to select card and perform actions  switch( card )     {    case adventurer:      while(drawntreasure<2){	if (state->deckCount[currentPlayer] <1){//if the deck is empty we need to shuffle discard and add to deck	  shuffle(currentPlayer, state);	}	drawCard(currentPlayer, state);	cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card.	if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold)	  drawntreasure++;	else{	  temphand[z]=cardDrawn;	  state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one).	  z++;	}      }      while(z-1>=0){	state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn	z=z-1;      }      return 0;			    case council_room:      //+4 Cards      for (i = 0; i < 4; i++)	{	  drawCard(currentPlayer, state);	}			      //+1 Buy      state->numBuys++;			      //Each other player draws a card      for (i = 0; i < state->numPlayers; i++)	{	  if ( i != currentPlayer )	    {	      drawCard(i, state);	    }	}			      //put played card in played card pile      discardCard(handPos, currentPlayer, state, 0);			      return 0;			    case feast:      //gain card with cost up to 5      //Backup hand      for (i = 0; i <= state->handCount[currentPlayer]; i++){	temphand[i] = state->hand[currentPlayer][i];//Backup card	state->hand[currentPlayer][i] = -1;//Set to nothing      }      //Backup hand      //Update Coins for Buy      updateCoins(currentPlayer, state, 5);      x = 1;//Condition to loop on      while( x == 1) {//Buy one card	if (supplyCount(choice1, state) <= 0){	  if (DEBUG)	    printf("None of that card left, sorry!/n");	  if (DEBUG){	    printf("Cards Left: %d/n", supplyCount(choice1, state));	  }	}	else if (state->coins < getCost(choice1)){	  printf("That card is too expensive!/n");	  if (DEBUG){	    printf("Coins: %d < %d/n", state->coins, getCost(choice1));	  }	}	else{	  if (DEBUG){	    printf("Deck Count: %d/n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);//.........这里部分代码省略.........
开发者ID:agroce,项目名称:cs362w16core,代码行数:101,


示例4: cardEffect

//.........这里部分代码省略.........			//increase supply count for choosen card by amount being discarded			state->supplyCount[state->hand[currentPlayer][choice1]] += choice2;						//each other player gains a copy of revealed card			for (i = 0; i < state->numPlayers; i++)				{					if (i != currentPlayer)						{							gainCard(state->hand[currentPlayer][choice1], state, 0, i);						}				}			//discard played card from hand			discardCard(handPos, currentPlayer, state, 0);						//trash copies of cards returned to supply			for (j = 0; j < choice2; j++)				{					for (i = 0; i < state->handCount[currentPlayer]; i++)						{							if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1])								{									discardCard(i, currentPlayer, state, 1);									break;								}						}				}						return 0;				case cutpurse:			updateCoins(currentPlayer, state, 2);			for (i = 0; i < state->numPlayers; i++)				{					if (i != currentPlayer)						{							for (j = 0; j < state->handCount[i]; j++)								{									if (state->hand[i][j] == copper)										{											discardCard(j, i, state, 0);											break;										}									if (j == state->handCount[i])										{											for (k = 0; k < state->handCount[i]; k++)												{													if (DEBUG)														printf("Player %d reveals card number %d/n", i, state->hand[i][k]);												}												break;										}										}											}								}							//discard played card from hand			discardCard(handPos, currentPlayer, state, 0);						return 0;		
开发者ID:cs362sp16,项目名称:cs362sp16_minnerp,代码行数:65,


示例5: main

int main(){	int randomPlayer, seed, i, j, numPlayers;    int runStatus;    int k[10] = {adventurer, council_room, feast, gardens, mine               , remodel, smithy, village, baron, great_hall};    struct gameState G;	srand(time(NULL));	for (i = 0; i < 2000; i++)	{		seed = (rand()%100) + 1;		//Pick a random player 0,1,2,3		randomPlayer = (rand()% 4);		//Random number of players 2,3,4		numPlayers = (rand()% 3) + 2;		if (randomPlayer > numPlayers - 1)			numPlayers = randomPlayer + 1;		//Initialize game		runStatus = initializeGame(numPlayers, k, seed, &G);		//Check if initialize successful		assert(runStatus == 0);		//Set player turn		G.whoseTurn = randomPlayer;		//Set random game state		//Hand count 0-20		G.handCount[randomPlayer] = (rand() % 21);		//Deck count 10-100		G.deckCount[randomPlayer] = (rand() % 91) + 10;		//Discard count 0-20		G.discardCount[randomPlayer] = (rand() % 21);		//Played count 0-20		G.playedCardCount = (rand() % 21);		//Sets card to hand, deck, discard pile		for(j = 0; j < G.handCount[randomPlayer]; j++)		{			G.hand[randomPlayer][j] = rand() % 27;		}		for(j = 0; j < G.deckCount[randomPlayer]; j++)		{			G.deck[randomPlayer][j] = rand() % 27;		}		for(j = 0; j < G.discardCount[randomPlayer]; j++)		{			G.discard[randomPlayer][j] = rand() % 27;		}		//Add a smithy card to be played		G.hand[randomPlayer][G.handCount[randomPlayer]] = smithy;		G.handCount[randomPlayer]++;		//Set defaults for card counts		int cardCount = G.handCount[randomPlayer];		int pCardCount = G.playedCardCount;		int dCardCount = G.discardCount[randomPlayer];		int coinCount = 0;		int deCardCount = G.deckCount[randomPlayer];		//Loop through hand to count how many treasures for coin count		for(j = 0; j < G.handCount[randomPlayer]; j++){			if(G.hand[randomPlayer][j] == copper)				coinCount++;			else if(G.hand[randomPlayer][j] == silver)				coinCount+=2;			else if(G.hand[randomPlayer][j] == gold)				coinCount+=3;		}		//Coin count check		updateCoins(randomPlayer, &G, 0);		assert(G.coins == coinCount);		//Loops through the first 3 cards at the top of the deck for treasure cards		for(j = G.deckCount[randomPlayer] - 1; j >= G.deckCount[randomPlayer] - 3; j--){			if(G.deck[randomPlayer][j] == copper)				coinCount++;			else if(G.deck[randomPlayer][j] == silver)				coinCount+=2;			else if(G.deck[randomPlayer][j] == gold)				coinCount+=3;		}		//Play smithyCard, add one to played pile, add (3-1) cards to hand count, remove 3 from deck count		smithy_(G.handCount[randomPlayer]-1, &G);		pCardCount++;		cardCount+=2;		deCardCount-=3;		//Update coin count		updateCoins(randomPlayer, &G, 0);		if(G.handCount[randomPlayer] != cardCount)			printf("randomtestcard.c: FAIL/r/nG.handCount[randomPlayer] == %d/r/nExpected:G.handCount[randomPlayer] == %d/r/n", G.handCount[randomPlayer], cardCount);		if(G.playedCardCount != pCardCount)			printf("randomtestcard.c: FAIL/r/nG.playedCardCount == %d/r/nExpected:G.playedCardCount == %d/r/n", G.playedCardCount, pCardCount);		if(G.discardCount[randomPlayer] != dCardCount)//.........这里部分代码省略.........
开发者ID:tyl-,项目名称:Sample-programs,代码行数:101,


示例6: Actions

/*Feast:  Trash this card. Gain a card costing up to 5 Coins.Additional Rules: The gained card goes into your Discard pile. It has to be a card from the Supply.You cannot use coins from Treasures or previous Actions (like the Market) to increase the cost of the card that you gain.If you use Throne Room on Feast, you will gain two cards, even though you can only trash Feast once.Gaining the card isn't contingent on trashing Feast; they're just two things that the card tries to make you do.This adds 5 coins to the player, but does not subtract them should the chosen card be too expensive.Also the code checks that the player has the coins needed but the rules do not alow usingadditional coins to increase the value of the gained card.*/int playFeast(int currentPlayer, struct gameState *state, int choice1){	int temphand[MAX_HAND];	int cardNotBought;	int i;	//Backup hand	for (i = 0; i <= state->handCount[currentPlayer]; i++)	{		temphand[i] = state->hand[currentPlayer][i];//Backup card		state->hand[currentPlayer][i] = EMPTY_CARD;//Set to nothing	}	//Update Coins for Buy (adds 5 which is the incorect behavor)	updateCoins(currentPlayer, state, FEAST_MAX_COST);	cardNotBought = NOT_BOUGHT;//Condition to loop on	while( cardNotBought == NOT_BOUGHT) {//Buy one card		if (supplyCount(choice1, state) <= EMPTY_SUPPLY)		{			if (DEBUG)			{				printf("None of that card left, sorry!/n");				printf("Cards Left: %d/n", supplyCount(choice1, state));			}		}		else if (state->coins < getCost(choice1))		{			printf("That card is too expensive!/n");			if (DEBUG)			    printf("Coins: %d < %d/n", state->coins, getCost(choice1));		}		else		{			if (DEBUG)			{			    printf("Deck Count: %d/n",				state->handCount[currentPlayer]				+ state->deckCount[currentPlayer]				+ state->discardCount[currentPlayer]				);	  		}			gainCard(choice1, state, TO_DISCARD, currentPlayer);//Gain the card			cardNotBought = BOUGHT;//No more buying cards	  		if (DEBUG){	    		printf("Deck Count: %d/n",				state->handCount[currentPlayer]				+ state->deckCount[currentPlayer]				+ state->discardCount[currentPlayer]				);			}		}//printf("Card not bought feast choice 1: %d/n", choice1);	}	//Reset Hand	for (i = 0; i <= state->handCount[currentPlayer]; i++)	{		state->hand[currentPlayer][i] = temphand[i];		temphand[i] = EMPTY_CARD;	}	return EFFECT_SUCCESS;}
开发者ID:JLBR,项目名称:School-Projects,代码行数:83,



注:本文中的updateCoins函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ updateColor函数代码示例
C++ updateChildList函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。