• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ scoreFor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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++)
	{
		if (players[i] == highScore && i > currentPlayer)
		{
			players[i]++;
		}
	}

	//find new highest score
 /* MUTANT (rep_const) */	j = 1;
	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_berezam,代码行数:67,代码来源:mutant101263_dominion.c


示例2: main


//.........这里部分代码省略.........
		if(countTurn % numPlayers != p->whoseTurn){
			breakNum++;
			break;	
			}			//If a player gets skipped. end the game 
		structInitializer(pt);
		money = 0;
		money = setPos(pt,p); //gets card positions and money amount
		int hold = countPlayable(p); //counts action cards in hand
		int track = 0; //tracker that makes sure we don't check for another action card when all have been played
		int * playableCards = malloc(sizeof(int)*hold);
		int * cardPos = malloc(sizeof(int)*hold);
		makePlayable(p, playableCards);
		storePlayable(p,cardPos);
		if(hold != 0){ // if there is 1 or more action cards
			printf("Cards Played:");
			while(p->numActions != 0 && track < hold){ // while there are still actions left and not all the actions cards have been played
				playCard(playableCards[track], -1,-1,-1,p);
				if(printCard(cardPos[track]) != "Nothing")
					printf(" %s, ", printCard(playableCards[track]));
				track++;
			}
			printf("\n");
		}
		else
			printf("Nothing 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++;
			} 
		  printf("Total money: %d\n", money);
		  if (money >= 8) {
			buyCard(province, p);
			printf("%s bought\n",printCard(province));
		  }
		  else if (money >= 6) {
			z = rand() % 3;
			if(z == 0){
				buyCard(gold, p);
				printf("%s bought\n",printCard(gold));
				}
			else if(z == 1)
				buyCost5(p,k); //buys random kingdom card that is 5
		  }
		  else if ((money >= 4)) 
				buyCost4(p,k); //buys random card that costs 4
		  else if ((money >= 3)){
			z = rand() %2;
			if( z==0){
				buyCard(silver,p);
				printf("%s bought\n",printCard(silver));
				}
			else
				buyCost3(p,k); //buys random card that costs 3
		  
		  }
		  else if ((money >= 2)){
			z = rand() %2;
			if ( z == 0){
				buyCard(estate,p);
				printf("%s bought\n",printCard(estate));
				}
			else
				buyCost2(p,k);
			}
		  printf("%d: end turn\n", p->whoseTurn);
		  endTurn(p);
		for(l=0;l<numPlayers;l++)
			printf ("Player %d: %d\n", l, scoreFor(l, p));
		 // End of Game
		 countTurn++;
		}
		int * players;
		players = malloc(sizeof(int)*4);
		getWinners(players,p);
		printf ("Finished game.\n");
		for(l=0;l<numPlayers;l++)
			printf ("Score for Player %d: %d\n", l, scoreFor(l, p));
		for(l=0; l<4;l++){
			if(players[l] == 1)
				printf("Player %d wins!\n", l);
		}
		
	}
	printf("Of %d Games: Break was ran %d times.\n", NUM_GAMES, breakNum);
	printf("Number of money count loss: %d\n", moneyError);
	return 0;
}
开发者ID:cs362sp15,项目名称:projects,代码行数:101,代码来源:testdominion.c


示例3: scoreFor

int scoreFor (int player, struct gameState *state) {

  int i;
  int score = 0;
  //score from hand
  for (i = 0; i < state->handCount[player]; i++)
    {
      if (state->hand[player][i] == curse) { score = score - 1; };
      if (state->hand[player][i] == estate) { score = score + 1; };
      if (state->hand[player][i] == duchy) { score = score + 3; };
      if (state->hand[player][i] == province) { score = score + 6; };
      if (state->hand[player][i] == great_hall) { score = score + 1; };
      if (state->hand[player][i] == gardens) { score = score + ( fullDeckCount(player, 0, state) / 10 ); };
    }

  //score from discard
  for (i = 0; i < state->discardCount[player]; i++)
    {
      if (state->discard[player][i] == curse) { score = score - 1; };
      if (state->discard[player][i] == estate) { score = score + 1; };
      if (state->discard[player][i] == duchy) { score = score + 3; };
      if (state->discard[player][i] == province) { score = score + 6; };
      if (state->discard[player][i] == great_hall) { score = score + 1; };
      if (state->discard[player][i] == gardens) { score = score + ( fullDeckCount(player, 0, state) / 10 ); };
    }

  //score from deck
  for (i = 0; i < state->discardCount[player]; i++)
    {
      if (state->deck[player][i] == curse) { score = score - 1; };
      if (state->deck[player][i] == estate) { score = score + 1; };
      if (state->deck[player][i] == duchy) { score = score + 3; };
      if (state->deck[player][i] == province) { score = score + 6; };
      if (state->deck[player][i] == great_hall) { score = score + 1; };
 /* MUTANT (del_stmt) */      if (state->deck[player][i] == gardens) { score = score + ( fullDeckCount(player, 0, state) / 10 ); /*  }; */ 
    }

  return score;
}

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++)
    {
      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
//.........这里部分代码省略.........
开发者ID:agroce,项目名称:cs362w16core,代码行数:101,代码来源:mutant101024_dominion.c


示例4: main

int main() {

	printf("TEST: SCOREFOR\n\n");
	srand(RSEED);

	int players, numCurse, numEstate, numDuchy, numProvince, numGardens, numGreatHall, victoryCount, curseCount;
	players = rand() % (MAX_PLAYERS - 2) + 2;

	if (players == 2) {
		victoryCount = 8;
		curseCount = 10;
	}
	else if (players == 3) {
		victoryCount = 12;
		curseCount = 20;
	}
	else {
		victoryCount = 12;
		curseCount = 30;
	}


	struct gameState state;
	int cards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	customInit(players, cards, &state);
	printf("TEST: Cards in hand\n");

	int i, j, k;
	for (i = 0; i < players; i++) {
		printf("Player %d\n", i + 1);
		numCurse = rand() % (curseCount + 1);
		printf("Curse: %d\n", numCurse);
		numEstate = rand() % (victoryCount + 1);
		printf("Estate: %d\n", numEstate);
		numDuchy = rand() % (victoryCount + 1);
		printf("Duchy: %d\n", numDuchy);
		numProvince = rand() % (victoryCount + 1);
		printf("Province: %d\n", numProvince);
		numGardens = rand() % (victoryCount + 1);
		printf("Gardens: %d\n", numGardens);
		numGreatHall = rand() % (victoryCount + 1);
		printf("Great Hall: %d\n", numGreatHall);

		k = 0;
		j = 0;
		while (j < numCurse) {
			state.hand[i][k] = curse;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numEstate) {
			state.hand[i][k] = estate;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numDuchy) {
			state.hand[i][k] = duchy;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numProvince) {
			state.hand[i][k] = province;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numGardens) {
			state.hand[i][k] = gardens;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numGreatHall) {
			state.hand[i][k] = great_hall;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;

		int deck = state.deckCount[i] + state.handCount[i] + state.discardCount[i];
		printf("Total deck: %d\n", deck);
		int internalsum = internalPointsCalc(numCurse, numEstate, numDuchy, numProvince, numGardens, numGreatHall, deck);
		int score = scoreFor(i, &state);
		printf("Expected score: %d\n", internalsum);
		printf("Calculated score: %d\n", score);
		if (internalsum == score)
			printf("PASSED\n");
		else
			printf("FAILED\n");

	}
//.........这里部分代码省略.........
开发者ID:cr8zd,项目名称:cs362w16,代码行数:101,代码来源:unittest4.c


示例5: main

int main(){

	srand(1245);

	struct gameState G;
	struct gameState *p = &G;
	int numPlayers, i, j, r, ran, card, pass;
	int seed = 2;
	int turn = 0;
	int cont = 1;
	int k[10];
	FILE *fp;
	fp = fopen("gameResults.out", "w");

	printf("Initializing Dominion Game\n");

	pass = -1;
	while(pass == -1)
	{
		for(i = 0; i < 10; i++)
		{
			ran = rand() % 20 + 7;
			k[i] = ran;
		}
			
		numPlayers = rand() % 3 + 2;

		pass = initializeGame(numPlayers, k, seed, p);
	}

	printf("Hold onto your butt\n\n");

	printf("Number of Players: %d\n\n", numPlayers);
	
	while(!isGameOver(p))
	{

		fprintf(fp, "GAMESTATE\n");
		//GameState Currently
		fprintf(fp, "NumPlayers: %d\n\n", p->numPlayers);
		for(i = 0; i < numPlayers; i++)
		{
			fprintf(fp, "Player: %d\n", i);
			fprintf(fp, "HandCount: %d\n", p->handCount[i]);
			fprintf(fp, "Hand: ");
			for(j = 0; j < p->handCount[i]; j++)
			{
				fprintf(fp, "%d ", p->hand[i][j]);
			}
			fprintf(fp, "\nDeckCount: %d\nDiscardCount %d\n", p->deckCount[i], p->discardCount[i]);
			fprintf(fp, "Score: %d\n", scoreFor(i, p));
		}

		//Begin Turn
		if(whoseTurn(p) == 0)
		{
			if(turn == 1000)
			{
				return 0;
			}
			turn++;
			printf("\nROUND %d\n", turn);
			fprintf(fp, "\nROUND %d\n", turn);
		}
			
		printf("PLAYER %d TURN\n", p->whoseTurn);
		fprintf(fp, "PLAYER %d TURN\n", p->whoseTurn);
		updateCoins(whoseTurn(p), p, 0);

		//action phase
		cont = 1;
		ran = 0;
		while(p->numActions != 0)
		{
			cont = 0;
			for(j = 0; j < p->handCount[p->whoseTurn]; j++)
			{
				if((p->hand[p->whoseTurn][j] != curse) && (p->hand[p->whoseTurn][j] != estate) && (p->hand[p->whoseTurn][j] != duchy) && (p->hand[p->whoseTurn][j] != province) && (p->hand[p->whoseTurn][j] != copper) && (p->hand[p->whoseTurn][j] != silver) && (p->hand[p->whoseTurn][j] != gold))
				{
					cont = 1;
				}
			}
			if(cont == 0)
				break;

			r = -1;
			for(i = 0; i < p->handCount[p->whoseTurn]; i++)
			{
				for(j = 0; j < p->handCount[p->whoseTurn]; j++)
				{
					card = p->hand[p->whoseTurn][ran];
					r = playCard(ran, i, j, 1, p);
					fprintf(fp, "%d,%d ", i, j);
					if(r != -1)
						break;
				}
				if(r != -1)
					break;
			}

//.........这里部分代码省略.........
开发者ID:CS362-Winter-2016,项目名称:cs362w16_bowenjos,代码行数:101,代码来源:testdominion.c


示例6: main

int main(int argc, char**argv){

   struct gameState Game;
   struct gameState *Ga = &Game;
   int players, ranCard, i;
   int money, cardPos, curPlayer, useCard, returnCard, buyCa;
   int k[10];
   int pool[20] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall, minion, steward, tribute, ambassador, cutpurse, embargo, outpost, salvager, sea_hag, treasure_map};

   srand(atoi(argv[1]));
   players = rand()% 3 + 2;
   ranCard = rand() % 20;

   for(i=0;i<10;i++){
      k[i] = pool[(ranCard+i)%20];
   }

   printf("Starting Game\n");
   initializeGame(players,k,atoi(argv[1]),Ga);
   printf("Number of player %d\n",players);

   while(!isGameOver(Ga)){
      money = 0;
      cardPos = -1;
      curPlayer = whoseTurn(Ga);
      for(i=0;i<numHandCards(Ga);i++){
	 if (handCard(i,Ga) == copper)
	    money++;
	 else if(handCard(i,Ga) == silver)
	    money += 2;
	 else if(handCard(i,Ga) == gold)
	    money += 3;
	 else if(handCard(i,Ga) > 6)
	    cardPos = i;
      }
      if(cardPos != -1){
     	useCard = handCard(cardPos,Ga);
      	printf("Player %d: is playing card %d\n",curPlayer,useCard);
      	returnCard = playCard(cardPos,1,1,1,Ga);
      	if(returnCard== -1)
		 printf("Playing card Failed\n",useCard);
      	else
		 printf("Playing card %d Succeded\n",useCard);
      }
      buyCa = k[rand()%10];
      printf("Player %d has %d coins\n",curPlayer,money);

      if (money >= 8){
	 printf("Player %d is trying to buy province\n",curPlayer);
	 if(buyCard(province,Ga)==-1){
	    printf("Buying Province Failed\n");}
      }
      else if (money >= getCost(buyCa)){
	 printf("Player %d is trying to by card %d \n"layer,buyCa);
	 if(buyCard(buyCa,Ga)==-1){
	    printf("Buying %d Failed\n", buyCa);}
      }
      else if (money >= 6){
	 printf("Player %d is trying to buy gold\n",curPlayer);
	 if(buyCard(gold,Ga)==-1){
	    printf("Buying Gold Faile\n");}
      }
      else if (money >= 3){
	 printf("Player %d is trying to buy silver\n",curPlayer);
	 if (buyCard(silver,Ga)==-1){
	    printf("Buying Silver Failed\n");}
      }
      printf("Player %d has %d Cards in hand\n",curPlayer,numHandCards(Ga));
      printf("Player %d ends turn\n",curPlayer);
      endTurn(Ga);


   };
   
   for(i=0;i<players;i++){
      printf("Player %d Score: %d\n",i,scoreFor(i,Ga));
   }


   return 0;
}
开发者ID:CS362-Winter-2016,项目名称:cs362w16_wilsoale,代码行数:81,代码来源:input.c


示例7: main


//.........这里部分代码省略.........
    }

    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;
	  	 }
	  	i++;
		}
      }

      if (money >= 8) {
        printf("1: bought province\n");
        buyCard(province, p);
      }
      else if ((money >= 6) && (numAdventurers < 2)) {
        printf("1: bought adventurer\n");
		buyCard(adventurer, p);
		numAdventurers++;
      }else if (money >= 6){
        printf("1: bought gold\n");
	    buyCard(gold, p);
        }
      else if (money >= 3){
        printf("1: bought silver\n");
	    buyCard(silver, p);
      }
      printf("1: endTurn\n");
      
      endTurn(p);      
    }

      printf ("Player 0: %d\nPlayer 1: %d\n", scoreFor(0, p), scoreFor(1, p));
	    
  } // end of While

  printf ("Finished game.\n");
  printf ("Player 0: %d\nPlayer 1: %d\n", scoreFor(0, p), scoreFor(1, p));

  return 0;
}
开发者ID:cs362sp16,项目名称:cs362sp16_pengs,代码行数:101,代码来源:playdom.c


示例8: playDominion

int playDominion(struct gameState *state, int k[10]) {
	int i;
	int cardPos, curCard, returnCard, toBuyCard, curPlayer, money;
	int numPlayers = state->numPlayers;

	while (!isGameOver(state)) {
    money = 0;
    curPlayer = whoseTurn(state);
    cardPos = -1;

		printf("\nPlayer %d's turn.\n", curPlayer);

		//Check money 
		for (i = 0; i < numHandCards(state); i++) {
			if (handCard(i, state) == copper) {
				money++;
			} else if (handCard(i, state) == silver) {
				money += 2;
			} else if (handCard(i, state) == gold) {
				money += 3;
			} else if (handCard(i, state) > 6) {
				cardPos = i;
			}
		}

		if (cardPos != -1) {
			curCard = handCard(cardPos, state);
			printf("Player %d plays %d\n", curPlayer, curCard);
			returnCard = playCard(cardPos, 1, 1, 1, state);
			if (returnCard == -1) {
				printf("Playing card %d failed\n", curCard);
			} else {
				printf ("Playing card %d succeded\n", curCard);
			}
		}

		toBuyCard = k[rand() % 10];
		printf("Player %d has %d coins\n", curPlayer, money);

		if (money >= 8) {
			printf("Player %d is trying to buy a province\n", curPlayer);
			if(buyCard(province, state) == -1) {
				printf("Failed to buy a province");
			}
		} else if (money >= getCost(toBuyCard)) {
			printf("Player %d is trying to buy card %s\n", curPlayer, getName(toBuyCard));
			if (buyCard(toBuyCard, state) == -1) {
				printf("Buying %s failed\n", getName(toBuyCard));
			}
		} else if (money >= 6) {
			printf("Player %d is trying to buy gold\n", curPlayer);
			if (buyCard(gold, state) == -1) {
				printf("Failed to buy gold\n");
			}
		} else if (money >= 3) {
			printf("Player %d is trying to buy silver\n", curPlayer);
			if (buyCard(silver, state) == -1) {
				printf("Failed to buy silver\n");
			}
		}
  printf("Player %d has %d cards in hand\n", curPlayer, numHandCards(state));
  printf("Player %d ends turn\n", curPlayer);
  endTurn(state);
	}

  for (i = 0; i < numPlayers; i++) {
    printf("Player %d's score: %d\n", i, scoreFor(i, state));
  }

	return 0;

}
开发者ID:CS362-Winter-2016,项目名称:cs362w16_stinek,代码行数:72,代码来源:testdominion.c


示例9: main


//.........这里部分代码省略.........
				fp = fopen("gameResults.out", "a");
				fprintf(fp,"You cannot play that card: %d\n",state.numActions);
				fclose(fp);
				discardCard(track.cardPlace,i, &state,0); 
			}

			printf("Actions after playing card %d\n",state.numActions);	
			fp = fopen("gameResults.out", "a");
			fprintf(fp,"Game after playing card: %d\n",state.numActions);
			fclose(fp);

			printf("Hand after: ");
			for(hc = 0; hc < state.handCount[i]; hc++){
				printf("%d, ",state.hand[i][hc]);	
			}
			printf("\n");
			//don't keep looking for actions if their used up	
			if (state.numActions <= 0){
				break;
			}
			//otherwise, try to look for another action to play
			card = lookForAction(i,&state, &track);
			cardNumToName(card,name);	
			if(track.hasAction){
				printf("Player has at least one action card\n");
			}	
		}

		coinBonus = state.coins;
		fp = fopen("gameResults.out", "a");
		fprintf(fp,"Player %d has %d coin now\n",i+1,state.coins);
		fclose(fp);
		tryBuyCard(&state);
		fp = fopen("gameResults.out", "a");
		fprintf(fp,"Player %d has %d coin now after buy\n",i+1,state.coins);
		fclose(fp);
		//Entering the Buy Phase
		//pick a card to try to buy
	
		//Game info after the play 
		printPlayerInfoGR(i,&state);
		printGameInfo(i,&state);
		fp = fopen("gameResults.out", "a");
		for(i = 0; i < state.numPlayers; i ++){
			fprintf(fp,"score for player %d: %d\n",i+1, scoreFor(i, &state));
			track.estateScore = track.duchyScore = track.provinceScore = 0;
			for(j = 0; j < state.handCount[i]; j++){
				card  = state.hand[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}	
			} 	
			for(j = 0; j < state.deckCount[i]; j++){
				card  = state.deck[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}
			}	
			for(j = 0; j < state.discardCount[i]; j++){
				card  = state.discard[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}	
			}
			fprintf(fp,"estate %d, duchy %d, province %d \n",track.estateScore, track.duchyScore, track.provinceScore);
		}
		fclose(fp);		
	  


		//turn is over
		endTurn(&state);
		track.turns ++;
	}
	//when the Game is Over, print out the scores		
	for(i = 0; i < state.numPlayers; i ++){
		printf("score for player %d: %d\n",i+1, scoreFor(i, &state));	
	}		
	  
	printf("Tests Complete\n");
	return 0;
}
开发者ID:CS362-Winter-2016,项目名称:cs362w16_suderman,代码行数:101,代码来源:testdominion.c


示例10: main

int main (int argc, char** argv) {
  struct gameState G;
  struct gameState *p = &G;
  int *k,i, players, money = 0, chosenCard=0, playedCard=0, flag=0, buyc=0;
  

  printf ("Starting game.\n");
  k=randomKingdom();
 /* for(i=0; i<10; i++){
    printf("%d\n",k[i]);
  }*/
  players = rand() % 2 + 2;

  initializeGame(players, k, rand(), p);
  

  while (!isGameOver(p)) { //loop for every turn
    printf("#Player%d's turn ###################################\n", whoseTurn(p)+1);
    money = 0;

    printf("-Check hand for treaure.\n");
    for (i = 0; i < numHandCards(p); i++) { //check if the current player has any treasures
      if (handCard(i, p) == copper){
        money++;
        printf("get 1 coin with copper\n");
      }
      else if (handCard(i, p) == silver){
        money += 2;
        printf("get 2 coins with silver\n");
      }
      else if (handCard(i, p) == gold){
        money += 3;
        printf("get 3 coins with gold\n");

      }
    }
    printf("Current coins: %d\n", money);
    printf("Current num of cards (before) %d\n", p->handCount[whoseTurn(p));
      flag=1;
      for(i=0; i< p->handCount[whoseTurn(p)]; i++){
        if (p->hand[whoseTurn(p)][i]!=copper && p->hand[whoseTurn(p)][i] != silver && p->hand[whoseTurn(p)][i] != gold)
          flag=0;
      }
      if(flag==0){ //play a card
        while (flag==0){
          chosenCard=rand() % p->handCount[whoseTurn(p)];
          if (chosenCard!=copper && chosenCard != silver && chosenCard != gold)
            flag=1;
        }
        flag=0;

        playedCard=p->hand[whoseTurn(p)][chosenCard];
          printf("%s played from position %d\n", whichCard(playedCard), chosenCard); 
  	      playCard(chosenCard, 1, 1, 1, p); 
  	      printf("%s played.\n", whichCard(playedCard));
          printf("Current num of cards (after) %d\n", p->handCount[whoseTurn(p));
          if(playedCard==22){
            //printf("\n\n\nembargo\n\n\n\n\n");
            embargoTest(G, whoseTurn(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;
  	       }
  	       i++;
  	     }
        }
      

      buyc=random()%2-2;
      if(buyc==-1){
        int x=0;
        x=random()%3;
        if(x==0)
          buyc=copper;
        else if(x==1)
          buyc=silver;
        else
          buyc=gold;
      }
      else{
        buyc = k[random()%10];
      }
      printf("attempting to buy %s\n", whichCard(buyc)); 
      buyCard(buyc, p);
      


      printf ("Player %d's current score: %d\n", whoseTurn(p)+1, scoreFor(whoseTurn(p), p));
//.........这里部分代码省略.........
开发者ID:CS362-Winter-2016,项目名称:cs362w16_takahasb,代码行数:101,代码来源:testdominion.c


示例11: main

int main()
{
    const char* funcName = "scoreFor()";
    struct gameState* game = newGame();
    int* cardsInPlay = kingdomCards(adventurer, baron, smithy, mine, remodel, feast, steward, village, salvager, treasure_map);

    if(initializeGame(2, cardsInPlay, time(NULL), game) == -1)
    {
        printf("Couldn't intialize game!\n");
        exit(0);
    }

    int thisPlayer = whoseTurn(game);
    int otherPlayer = whoseTurn(game)^1;

    printf("**************Starting test on method: %s**************\n\n", funcName);
    // Initial Test to see if there are unexpected changes to the game
    struct gameState* initialState = malloc(sizeof(struct gameState));
    memcpy(initialState, game, sizeof(struct gameState));

    // Each player starts with three estate cards, so their score should be 3
    if( scoreFor(thisPlayer, game) != 3)
        printf("Error -%s shows this player's initial score is not 3!\n", funcName);

    /* Begin testing for unexpected changes in game state */
    if( initialState->numPlayers != game->numPlayers )
        printf("Error -%s changed the number of players!\n", funcName);

    int i;        // There are 26 possible cards, make sure the same are still in play
    for(i=0; i<=26; i++)
    {
        if( initialState->supplyCount[i] != game->supplyCount[i] )
        {
            if(i != adventurer)
                printf("Error -%s changed the number of other kingdom cards!\n", funcName);
        }
    }
    for(i=0; i<=26; i++)
    {
        if(initialState->embargoTokens[i] != game->embargoTokens[i])
            printf("Error -%s changed the Embargo Tokens in play!\n", funcName);
    }
    if( initialState->outpostPlayed != game->outpostPlayed)
        printf("Error -%s changed the \"Outpost Played\" status!\n", funcName);
    if( initialState->outpostTurn != game->outpostTurn)
        printf("Error -%s changed the \"Outpost Turn\" status!\n", funcName);
    if( initialState->whoseTurn != game->whoseTurn)
        printf("Error -%s changed the whose turn it is!\n", funcName);
    if( initialState->phase != game->phase)
        printf("Error -%s changed the game phase!\n", funcName);
    if( initialState->numActions != game->numActions)
        printf("Error -%s changed the number of actions for this turn!\n", funcName);
    if( initialState->coins != game->coins)
        printf("Error -%s changed the \"coins\" variable!\n", funcName);
    if( initialState->numBuys != game->numBuys)
        printf("Error -%s changed the number of Buy phases available!\n", funcName);
    if( initialState->handCount[thisPlayer] != game->handCount[thisPlayer])
        printf("Error -%s changed the number of cards in this player's hand!\n", funcName);
        // Toggle the bit to check for the other player's hand
    if( initialState->handCount[otherPlayer] != game->handCount[otherPlayer])
        printf("Error -%s changed the number of cards in the other player's hand!\n", funcName);

    for(i=0; i< game->handCount[thisPlayer]; i++)
    {
        if( initialState->hand[thisPlayer][i] != game->hand[thisPlayer][i])
            printf("Error -%s changed the cards in this player's hand!\n(If turn isn't changed)\n", funcName);
    }
    for(i=0; i<game->handCount[otherPlayer]; i++)
    {
        if( initialState->hand[otherPlayer][i] != game->hand[otherPlayer][i])
            printf("Error -%s changed the cards in the other player's hand!\n(If turn isn't changed)\n", funcName);
    }

    if(initialState->deckCount[thisPlayer] != game->deckCount[thisPlayer])
        printf("Error -%s changed the deck count for this player!\n", funcName);
    if(initialState->deckCount[otherPlayer] != game->deckCount[otherPlayer])
        printf("Error -%s changed the deck count for the other player!\n", funcName);


    for(i=0; i<game->deckCount[thisPlayer]; i++)
    {
        if(initialState->deck[thisPlayer][i] != game->deck[thisPlayer][i])
            printf("Error -%s changed the contents of this player's deck!\n", funcName);
    }
    for(i=0; i<game->deckCount[otherPlayer]; i++)
    {
        if(initialState->deck[otherPlayer][i] != game->deck[otherPlayer][i])
            printf("Error -%s changed the contents of the other player's deck!\n", funcName);
    }

    if(game->discardCount[thisPlayer] != initialState->discardCount[thisPlayer])
        printf("Error -%s changed the count for this player's discard pile!\n", funcName);
    if(initialState->discardCount[otherPlayer] != game->discardCount[otherPlayer])
        printf("Error -%s changed the count of the other player's discard pile!\n", funcName);


    for(i=0; i<initialState->discardCount[thisPlayer]; i++)
    {
        if(initialState->discard[thisPlayer][i] != game->discard[thisPlayer][i])
            printf("Error -%s changed the contents of this player's discard!\n", funcName);
//.........这里部分代码省略.........
开发者ID:wmaillard,项目名称:cs362sp16,代码行数:101,代码来源:unittest4.c


示例12: testScoreFor

void testScoreFor() {
    struct gameState gStateTest;
    int seed = 7;
    int discard = 1;
    int numPlayers = 2;
    int p = 0;
    int choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0, handPos = 0;
    int cardCount = 0, cardCountTest = 0;
    int i, j, total;

    int k[10] = {adventurer, embargo, village, minion, mine, cutpurse,
			sea_hag, tribute, smithy, council_room};

    initializeGame(numPlayers, k, seed, &gStateTest);
    for (i = 0; i < gStateTest.handCount[p]; i++) {
            gStateTest.hand[p][i] = province;
    }

    printf("==== TESTING: %s ====\n", TESTCARD);
    printf("\nCASE 1: Full hand of provinces\n");
    printf("        Expected vs Real\n");
    total = gStateTest.handCount[p] * 6;
    printf(" full hand province = %d vs %d\n", total, scoreFor(p, &gStateTest));
    assert(total == scoreFor(p, &gStateTest));

    initializeGame(numPlayers, k, seed, &gStateTest);
    for (i = 0; i < gStateTest.handCount[p]; i++) {
            gStateTest.hand[p][i] = great_hall;
    }

    printf("\nCASE 2: Full hand of great_hall\n");
    printf("        Expected vs Real\n");
    total = gStateTest.handCount[p] * 1;
    printf(" full hand province = %d vs %d\n", total, scoreFor(p, &gStateTest));
    assert(total == scoreFor(p, &gStateTest));

    initializeGame(numPlayers, k, seed, &gStateTest);

    gStateTest.handCount[p] = 6;
    gStateTest.discardCount[p] = 6;
    gStateTest.deckCount[p] = 6;

    for (i = 0; i < 6; i++) {
        if (i == 0) {
            gStateTest.hand[p][i] = curse;
            gStateTest.deck[p][i] = curse;
            gStateTest.discard[p][i] = curse;
        }
        if ( i == 1) {
            gStateTest.hand[p][i] = estate;
            gStateTest.deck[p][i] = estate;
            gStateTest.discard[p][i] = estate;
        }
        if ( i == 2) {
            gStateTest.hand[p][i] = duchy;
            gStateTest.deck[p][i] = duchy;
            gStateTest.discard[p][i] = duchy;
        }
        if ( i == 3) {
            gStateTest.hand[p][i] = province;
            gStateTest.deck[p][i] = province;
            gStateTest.discard[p][i] = province;
        }
        if (i == 4) {
            gStateTest.hand[p][i] = great_hall;
            gStateTest.deck[p][i] = great_hall;
            gStateTest.discard[p][i] = great_hall;
        }
        if (i == 5) {
            gStateTest.hand[p][i] = gardens;
            gStateTest.deck[p][i] = gardens;
            gStateTest.discard[p][i] = gardens;
        }
    }
    printf("\nCASE 3: 1 of every score card in hand, discard, deck\n");
    printf("        Expected vs Real\n");
    total = 0 -1 +1 + 3 + 6 + 1;
    total *= 3;
    total += (fullDeckCount(p, 0, &gStateTest) / 10);


    printf(" full hand province = %d vs %d\n", total, scoreFor(p, &gStateTest));
    assert(total == scoreFor(p, &gStateTest));

    printf("\nCASE 4: hand = estate, deck = duchy, discard = province\n");
    initializeGame(numPlayers, k, seed, &gStateTest);
    gStateTest.discardCount[p] = 3;
    gStateTest.deckCount[p] = 2;

    for (i = 0; i < gStateTest.handCount[p]; i++) {
            gStateTest.hand[p][i] = estate;
            gStateTest.deck[p][i] = duchy;
            gStateTest.discard[p][i] = province;
    }

    total = (1 * gStateTest.handCount[p]) + (3 * 2) + (6 * 3);
    printf(" full hand province = %d vs %d\n", total, scoreFor(p, &gStateTest));
    assert(total == scoreFor(p, &gStateTest));

    printf("\n      testScoreFor(): PASS\n");
//.........这里部分代码省略.........
开发者ID:csDaniel,项目名称:cs362sp16,代码行数:101,代码来源:unittest4.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ scprintf函数代码示例发布时间:2022-05-30
下一篇:
C++ scopy_函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap