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

C++ PutSeed函数代码示例

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

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



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

示例1: initializeGame

int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed,
		   struct gameState *state) {

	int i;
	int j;
	int it;			
	//set up random number generator
	SelectStream(1);
	PutSeed((long)randomSeed);
  
	//check number of players
	if (numPlayers > MAX_PLAYERS || numPlayers < 2)
		{
			return -1;
		}

	//set number of players
	state->numPlayers = numPlayers;

	//check selected kingdom cards are different
	for (i = 0; i < 10; i++)
		{
			for (j = 0; j < 10; j++)
				{
					if (j != i && kingdomCards[j] == kingdomCards[i])
						{
							return -1;
						}
				}
		}


	//initialize supply
	///////////////////////////////

	//set number of Curse cards
	if (numPlayers == 2)
		{
			state->supplyCount[curse] = 10;
		}
	else if (numPlayers == 3)
		{
			state->supplyCount[curse] = 20;
		}
	else
		{
			state->supplyCount[curse] = 30;
		}

	//set number of Victory cards
	if (numPlayers == 2)
		{
			state->supplyCount[estate] = 8;
			state->supplyCount[duchy] = 8;
			state->supplyCount[province] = 8;
		}
	else
		{
			state->supplyCount[estate] = 12;
			state->supplyCount[duchy] = 12;
			state->supplyCount[province] = 12;
		}

	//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

//.........这里部分代码省略.........
开发者ID:cs362sp16,项目名称:cs362sp16_minnerp,代码行数:101,代码来源:mutant101082_dominion.c


示例2: main

 int main () {

  int n, p, i;
  struct gameState G;
  time_t t;
  srand((unsigned)time(&t));
  printf ("Testing Adventurer.\n");

  printf ("RANDOM TESTS.\n");

  SelectStream(2);
  PutSeed(3);

  for (n = 0; n < 2000; n++) {
	int* k=kingdomCards(1,2,3,4,5,6,7,8,9,10);
	G.numPlayers=rand() % 3+1;
	initializeGame(G.numPlayers,k,1000,&G);
	p = rand() % 2+1;
	G.numPlayers=rand() % 3+1;
    G.deckCount[p] = rand() % MAX_DECK;
    G.discardCount[p] = rand() % MAX_DECK;
    G.handCount[p] = rand() % MAX_HAND;
	G.supplyCount[adventurer]=rand()%10;
    testAdventurer(&G,p);
  }
	
    printf ("Fixed tests for adventurer():\n");
	for (i=0;i<50;i++)
	{
		int* k=kingdomCards(1,2,3,4,5,6,7,8,9,10);
		memset(&G, 23, sizeof(struct gameState));   // clear the game state
		initializeGame(2, k, 1000, &G); // initialize a new game
		G.handCount[0]=0;
	#if (NOISY_TEST == 1)
		printf ("Playing adventurer card 1 time\n");
	#endif	
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	 
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	
		adventurerCard(1,&G);
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
//.........这里部分代码省略.........
开发者ID:cr8zd,项目名称:cs362w16,代码行数:101,代码来源:randomTestAdventurer.c


示例3: main

int main()
{
  int i;
  int cards[10] = {adventurer, council_room, feast, gardens, mine,
   remodel, smithy, village, baron, great_hall};

  int testCount = 100;
  printf("*-------\nBegin Adventurer Card Random Testing\n-------*\n");

  //Set up the random number generator
  int seed = 12125;
  SelectStream(1);
  PutSeed((long)seed);

  for(i = 0; i < testCount; ++i)
  {
    int j, pos, preTreasure = 0, postTreasure = 0, err = 0;
    //Build a gamestate to test with
    struct gameState *state = malloc(sizeof(struct gameState));
    struct gameState *prev = malloc(sizeof(struct gameState));
    seed = floor((Random() * 12125) + 1);

    int numPlayer = floor((Random() * 3) + 2);
    initializeGame(numPlayer, cards, seed, state);

    state->whoseTurn = floor(Random() * numPlayer);
    state->handCount[state->whoseTurn] = floor(Random() * (MAX_HAND / 3));
    state->deckCount[state->whoseTurn] = floor(Random() * (MAX_DECK / 3));
    state->discardCount[state->whoseTurn] = floor(Random() * (MAX_DECK / 3));
    state->playedCardCount = floor(Random() * 5);

    //Fill the hand with random cards 0 - 17
    for(j = 0; j < state->handCount[state->whoseTurn]; ++j)
    {
      state->hand[state->whoseTurn][j] = floor(Random() * 17);
    }

    //Fill the deck with random cards 0 - 17
    for(j = 0; j < state->deckCount[state->whoseTurn]; ++j)
    {
      state->deck[state->whoseTurn][j] = floor(Random() * 17);
    }

    //Fill the discard pile with random cards 0 - 17
    for(j = 0; j < state->discardCount[state->whoseTurn]; ++j)
    {
      state->discard[state->whoseTurn][j] = floor(Random() * 17);
    }

    //Randomly select a position, set that card to adventurer for our use
    pos = floor(Random() * state->handCount[state->whoseTurn]);
    state->hand[state->whoseTurn][pos] = adventurer;

    printf("\nPre-State:\nhandCount: %i\ndeckCount: %i\ndiscardCount: %i\n",
      state->handCount[state->whoseTurn],
      state->deckCount[state->whoseTurn],
      state->discardCount[state->whoseTurn]);

    printf("Cardpos: %i\nPlayer: %i\nplayedCardCount: %i\n",
      pos,
      state->whoseTurn,
      state->playedCardCount);

    //Copy the gamestate
    memcpy(prev, state, sizeof(struct gameState));

    //Call the adventurer card
    cardAdventurer(state->whoseTurn, state);

    //Count up the treasure cards in the players hand before playing the adventurer
    for(j = 0; j < prev->handCount[prev->whoseTurn]; ++j)
    {
      if(prev->hand[prev->whoseTurn][j] == copper ||
         prev->hand[prev->whoseTurn][j] == silver ||
         prev->hand[prev->whoseTurn][j] == gold)
      {
        ++preTreasure;
      }
    }

    //Count up the treasure cards in the players hand after playing the adventurer
    for(j = 0; j < state->handCount[state->whoseTurn]; ++j)
    {
      if(state->hand[state->whoseTurn][j] == copper ||
         state->hand[state->whoseTurn][j] == silver ||
         state->hand[state->whoseTurn][j] == gold)
      {
        ++postTreasure;
      }
    }

    if((prev->deckCount[prev->whoseTurn] + prev->discardCount[prev->whoseTurn] - 2) !=
     (state->deckCount[state->whoseTurn] + state->discardCount[state->whoseTurn]))
    {
      printf("FAILURE: The total number of cards in the deck and discard are incorrect.\n");
      printf("Prev: %i, Post: %i, Seed: %i\n",
        prev->deckCount[prev->whoseTurn] + prev->discardCount[prev->whoseTurn],
        state->deckCount[state->whoseTurn] + state->discardCount[state->whoseTurn],
        seed);
      err = 1;
//.........这里部分代码省略.........
开发者ID:orst-iqbald,项目名称:cs362s15,代码行数:101,代码来源:randomtestadventurer.c


示例4: main

int main(){
	SelectStream(2);
	PutSeed(time(NULL));

	int num_tests = 5000;
	struct gameState state, previous;
#if(NOISY_TEST == 1)
	printf("Testing Adventurer against %d random gamestates\n", num_tests);
#endif
	for(int test = 0; test < num_tests; test++){
		for(int p = 0; p < MAX_PLAYERS; p++){
			//start adventurer specific counters
			int drawnTreasure = 0;
			int cardDrawn = 0;
			int tempHand[MAX_HAND];
			int z = 0;
			//end adventurer specific counters
			int treasures_in_deck = 0;
			int treasures_in_hand = 0;
			int prev;
			random_gamestate(&state);
			int adventurer_pos = (int)(Random()*state.handCount[p]);	//random adventurer position
			state.hand[p][adventurer_pos] = adventurer;
			int d = state.deckCount[p];
			previous = state;
		
			//count treasures in deck
			for(int i = 0; i < state.deckCount[p]; i++)
				if(state.deck[p][i] == copper || state.deck[p][i] == silver || state.deck[p][i] == gold)
					treasures_in_deck+=1;
			
#if(NOISY_TEST == 1)
			printf("Randomly generated deck contains %d treasure cards\n", treasures_in_deck);
#endif
			
			//count treasures in hand
			for(int i = 0; i < state.handCount[p]; i++)
				if(state.hand[p][i] == copper || state.hand[p][i] == silver || state.hand[p][i] == gold)
					treasures_in_hand+=1;
#if(NOISY_TEST == 1)
			printf("Randomly generated hand contains %d treasure cards\n", treasures_in_hand);
#endif
			zzzadventurercardplay(drawnTreasure, p, cardDrawn, tempHand, z, &state);


			//check hand size
			if(d<2){
				if(treasures_in_deck >= d){
#if(NOISY_TEST == 1)
					printf("Hand Size: %d, Expected: %d\n", state.handCount[p], previous.handCount[p] -1 + d);
#endif
#if(ASSERTS == 1)
					assert(state.handCount[p] == previous.handCount[p] - 1 + d);
#endif
				}else{
#if(NOISY_TEST == 1)
					printf("Hand Size: %d, Expected: %d\n", state.handCount[p], previous.handCount[p] -1 + treasures_in_deck);
#endif
#if(ASSERTS == 1)
					assert(state.handCount[p] == previous.handCount[p] - 1 + treasures_in_deck);
#endif
			}}
			else{
				if(treasures_in_deck < 2){
#if(NOISY_TEST == 1)
					printf("Hand Size: %d, Expected: %d\n", state.handCount[p], previous.handCount[p] -1 + treasures_in_deck);
#endif
#if(ASSERTS == 1)
					assert(state.handCount[p] == previous.handCount[p] -1 + treasures_in_deck);
#endif
				}else{
#if(NOISY_TEST == 1)
					printf("Hand Size: %d, Expected: %d\n", state.handCount[p], previous.handCount[p] +1);
#endif
#if(ASSERTS == 1)
					assert(state.handCount[p] == previous.handCount[p] +1);
#endif
			}}		

			//check deck size
			if(d<2){
				if(treasures_in_deck >= d){
#if(NOISY_TEST == 1)
					printf("Deck + Discard + Played: %d, Expected: %d\n", state.discardCount[p] + state.playedCardCount + state.deckCount[p], previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - d );
#endif
#if(ASSERTS == 1)
					assert(state.discardCount[p] + state.playedCardCount + state.deckCount[p] == previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - d);
#endif
				}else{
#if(NOISY_TEST == 1)
					printf("Deck + Discard + Played: %d, Expected: %d\n", state.discardCount[p] + state.playedCardCount + state.deckCount[p], previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - treasures_in_deck );	
#endif
#if(ASSERTS == 1)
					assert(state.discardCount[p] + state.playedCardCount + state.deckCount[p] == previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - treasures_in_deck);
#endif
			}}
			else{
				if(treasures_in_deck < 2){
#if(NOISY_TEST == 1)
					printf("Deck + Discard + Played: %d, Expected: %d\n", state.discardCount[p] + state.playedCardCount + state.deckCount[p], previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - treasures_in_deck);	
//.........这里部分代码省略.........
开发者ID:tylerhadley,项目名称:CS362-unittests,代码行数:101,代码来源:randomtestadventurer.c


示例5: initializeGame

int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed,
		   struct gameState *state) {

  int i;
  int j;
  int it;			
  //set up random number generator
  SelectStream(1);
  PutSeed((long)randomSeed);
  
  //check number of players
  if (numPlayers > MAX_PLAYERS || numPlayers < 2)
    {
      return -1;
    }

  //set number of players
  state->numPlayers = numPlayers;

  //check selected kingdom cards are different
  for (i = 0; i < 10; i++)
    {
      for (j = 0; j < 10; j++)
        {
	  if (j != i && kingdomCards[j] == kingdomCards[i])
	    {
	      return -1;
	    }
        }
    }


  //initialize supply
  ///////////////////////////////

  //set number of Curse cards
  if (numPlayers == 2)
    {
      state->supplyCount[curse] = 10;
    }
  else if (numPlayers == 3)
    {
      state->supplyCount[curse] = 20;
    }
  else
    {
      state->supplyCount[curse] = 30;
    }

  //set number of Victory cards
  if (numPlayers == 2)
    {
      state->supplyCount[estate] = 8;
      state->supplyCount[duchy] = 8;
      state->supplyCount[province] = 8;
    }
  else
    {
      state->supplyCount[estate] = 12;
      state->supplyCount[duchy] = 12;
      state->supplyCount[province] = 12;
    }

  //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

//.........这里部分代码省略.........
开发者ID:cs362sp16,项目名称:cs362sp16_broderij,代码行数:101,代码来源:mutant100344_dominion.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PutString函数代码示例发布时间:2022-05-30
下一篇:
C++ PutRow函数代码示例发布时间: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