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

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

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

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

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

示例1: handCard

int handCard(int handPos, struct gameState *state) {	int currentPlayer = whoseTurn(state);	return state->hand[currentPlayer][handPos];}
开发者ID:cs362sp16,项目名称:cs362sp16_minnerp,代码行数:4,


示例2: getWinners

int getWinners(int players[MAX_PLAYERS], struct gameState *state) {	int i;		int j;	int highScore;	int currentPlayer;	//get score for each player	for (i = 0; i < MAX_PLAYERS; i++)		{			//set unused player scores to -9999			if (i >= state->numPlayers)				{					players[i] = -9999;				}			else				{					players[i] = scoreFor (i, state);				}		}	//find highest score	j = 0;	for (i = 0; i < MAX_PLAYERS; i++)		{			if (players[i] > players[j])				{					j = i;				}		}	highScore = players[j];	//add 1 to players who had less turns	currentPlayer = whoseTurn(state);	for (i = 0; i < MAX_PLAYERS; i++)		{ /* MUTANT (rep_op) */			if ( players[i] == highScore && i == currentPlayer )				{					players[i]++;				}		}	//find new highest score	j = 0;	for (i = 0; i < MAX_PLAYERS; i++)		{			if ( players[i] > players[j] )				{					j = i;				}		}	highScore = players[j];	//set winners in array to 1 and rest to 0	for (i = 0; i < MAX_PLAYERS; i++)		{			if ( players[i] == highScore )				{					players[i] = 1;				}			else				{					players[i] = 0;				}		}	return 0;}
开发者ID:cs362sp16,项目名称:cs362sp16_minnerp,代码行数:67,


示例3: numHandCards

int numHandCards(struct gameState *state) {	return state->handCount[ whoseTurn(state) ];}
开发者ID:cs362sp16,项目名称:cs362sp16_minnerp,代码行数:3,


示例4: 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 f_adventurer(state,currentPlayer);	    case council_room:		return f_concil_room(state,currentPlayer,handPos);	    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      			      return 0;			    case gardens:      return -1;			    case mine:      j = state->hand[currentPlayer][choice1];  //store card we will trash      if (state->hand[currentPlayer][choice1] < copper || state->hand[currentPlayer][choice1] > gold)	{	  return -1;	}		      if (choice2 > treasure_map || choice2 < curse)	{	  return -1;	}      if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) )	{	  return -1;//.........这里部分代码省略.........
开发者ID:cs362sp16,项目名称:cs362sp16_fengzi,代码行数:101,


示例5: 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,


示例6: cardEffect

int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus){	int i;	int j;	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:		playedCard(handPos, NULL, NULL, state);		while (drawntreasure < 2) {			if (drawCard(currentPlayer, state) == -1)				break;			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->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1;				state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one).				z++;			}		}		while (z > 0) {			state->discard[currentPlayer][state->discardCount[currentPlayer]++] = temphand[z - 1]; // discard all cards in play that have been drawn			z--;		}		endPlayed(state, 0);		return 0;	case council_room:		return councilRoomEffect(currentPlayer, handPos, state);	case feast:		if (choice1 < curse || choice1 > treasure_map)			return -1;		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));			}			return -1;		}		else if (5 < getCost(choice1)) {			if (DEBUG) {				printf("That card is too expensive!/n");				printf("Coins: %d < %d/n", state->coins, getCost(choice1));			}			return -1;		}			playedCard(handPos, NULL, NULL, state);		if (DEBUG) {			printf("Deck Count: %d/n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);		}		gainCard(choice1, state, 0, currentPlayer);//Gain the card		if (DEBUG) {			printf("Deck Count: %d/n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);		}		//trash feast		endPlayed(state, 1);		return 0;	case gardens:		return -1;	case mine:		if (choice1 >= state->handCount[currentPlayer] || choice1 < 0 || choice1 == handPos)			return -1;		j = state->hand[currentPlayer][choice1];  //store card we will trash		if (state->hand[currentPlayer][choice1] < copper || state->hand[currentPlayer][choice1] > gold)		{			return -1;		}		if (choice2 > gold || choice2 < copper)		{//.........这里部分代码省略.........
开发者ID:cs362sp16,项目名称:cs362sp16_berezam,代码行数:101,


示例7: main

int main(int argc, char** argv) {	struct gameState G;	struct gameState *p = &G;	int k[10] = { adventurer, gardens, embargo, village, minion, mine, cutpurse,		sea_hag, tribute, smithy };	printf("Starting game./n");	initializeGame(2, k, atoi(argv[1]), p);	int money = 0;	int smithyPos = -1;	int adventurerPos = -1;	int i = 0;	int numSmithies = 0;	int numAdventurers = 0;	while (!isGameOver(p)) {		money = 0;		smithyPos = -1;		adventurerPos = -1;		for (i = 0; i < numHandCards(p); i++) {			if (handCard(i, p) == copper)				money++;			else if (handCard(i, p) == silver)				money += 2;			else if (handCard(i, p) == gold)				money += 3;			else if (handCard(i, p) == smithy)				smithyPos = i;			else if (handCard(i, p) == adventurer)				adventurerPos = i;		}		if (whoseTurn(p) == 0) {			if (smithyPos != -1) {				printf("0: smithy played from position %d/n", smithyPos);				playCard(smithyPos, -1, -1, -1, p);				printf("smithy played./n");				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("0: bought province/n");				buyCard(province, p);			}			else if (money >= 6) {				printf("0: bought gold/n");				buyCard(gold, p);			}			else if ((money >= 4) && (numSmithies < 2)) {				printf("0: bought smithy/n");				buyCard(smithy, p);				numSmithies++;			}			else if (money >= 3) {				printf("0: bought silver/n");				buyCard(silver, p);			}			printf("0: end turn/n");			endTurn(p);		}		else {			if (adventurerPos != -1) {				printf("1: adventurer played from position %d/n", adventurerPos);				playCard(adventurerPos, -1, -1, -1, p);				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;					}//.........这里部分代码省略.........
开发者ID:CS362-Winter-2016,项目名称:cs362w16_griffcon,代码行数:101,



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


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