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

C++ shuffle函数代码示例

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

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



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

示例1: cardEffect


//.........这里部分代码省略.........
	}
			
      //discard card from hand
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
		
    case tribute:
      if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1){
	if (state->deckCount[nextPlayer] > 0){
	  tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
	  state->deckCount[nextPlayer]--;
	}
	else if (state->discardCount[nextPlayer] > 0){
	  tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1];
	  state->discardCount[nextPlayer]--;
	}
	else{
	  //No Card to Reveal
	  if (DEBUG){
	    printf("No cards to reveal\n");
	  }
	}
      }
	    
      else{
	if (state->deckCount[nextPlayer] == 0){
	  for (i = 0; i < state->discardCount[nextPlayer]; i++){
	    state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
	    state->deckCount[nextPlayer]++;
	    state->discard[nextPlayer][i] = -1;
	    state->discardCount[nextPlayer]--;
	  }
			    
	  shuffle(nextPlayer,state);//Shuffle the deck
	} 
	tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
	state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
	state->deckCount[nextPlayer]--;
	tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
	state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
	state->deckCount[nextPlayer]--;
      }    
		       
      if (tributeRevealedCards[0] == tributeRevealedCards[1]){//If we have a duplicate card, just drop one 
	state->playedCards[state->playedCardCount] = tributeRevealedCards[1];
	state->playedCardCount++;
	tributeRevealedCards[1] = -1;
      }

      for (i = 0; i <= 2; i ++){
	if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold){//Treasure cards
	  state->coins += 2;
	}
		    
	else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall){//Victory Card Found
	  drawCard(currentPlayer, state);
	  drawCard(currentPlayer, state);
	}
	else{//Action Card
	  state->numActions = state->numActions + 2;
	}
      }
	    
      return 0;
		
    case ambassador:
开发者ID:csDaniel,项目名称:cs362sp16,代码行数:67,代码来源:dominion.c


示例2: calculateNumBonusesToAdd

void CvMapGenerator::addUniqueBonusType(BonusTypes eBonusType)
{
	int* piAreaTried = new int[GC.getMapINLINE().getNumAreas()];

	for (int iI = 0; iI < GC.getMapINLINE().getNumAreas(); iI++)
	{
		piAreaTried[iI] = FFreeList::INVALID_INDEX;
	}

	CvBonusInfo& pBonusInfo = GC.getBonusInfo(eBonusType);

	int iBonusCount = calculateNumBonusesToAdd(eBonusType);

	bool bIgnoreLatitude = GC.getGameINLINE().pythonIsBonusIgnoreLatitudes();

	FAssertMsg(pBonusInfo.isOneArea(), "addUniqueBonusType called with non-unique bonus type");

	while (true)
	{
		int iBestValue = 0;
		int iLoop = 0;
		CvArea *pBestArea = NULL;
		CvArea *pLoopArea = NULL;

		for(pLoopArea = GC.getMapINLINE().firstArea(&iLoop); pLoopArea != NULL; pLoopArea = GC.getMapINLINE().nextArea(&iLoop))
		{
			bool bTried = false;

			for (int iI = 0; iI < GC.getMapINLINE().getNumAreas(); iI++)
			{
				if (pLoopArea->getID() == piAreaTried[iI])
				{
					bTried = true;
					break;
				}
			}

			if (!bTried)
			{
				int iNumUniqueBonusesOnArea = pLoopArea->countNumUniqueBonusTypes() + 1; // number of unique bonuses starting on the area, plus this one
				int iNumTiles = pLoopArea->getNumTiles();
				int iValue = iNumTiles / iNumUniqueBonusesOnArea;

				if (iValue > iBestValue)
				{
					iBestValue = iValue;
					pBestArea = pLoopArea;
				}
			}
		}

		if (pBestArea == NULL)
		{
			break; // can't place bonus on any area
		}

		for (int iI = 0; iI < GC.getMapINLINE().getNumAreas(); iI++)
		{
			if (piAreaTried[iI] == FFreeList::INVALID_INDEX)
			{
				piAreaTried[iI] = pBestArea->getID();
				break;
			}
		}

		// Place the bonuses:

		int* piShuffle = shuffle(GC.getMapINLINE().numPlotsINLINE(), GC.getGameINLINE().getMapRand());

		for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
		{
			CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(piShuffle[iI]);
			FAssertMsg(pPlot != NULL, "addUniqueBonusType(): pPlot is null");

			if (GC.getMapINLINE().getNumBonuses(eBonusType) >= iBonusCount)
			{
				break; // We already have enough
			}

			if (pBestArea == pPlot->area())
			{
				if (canPlaceBonusAt(eBonusType, pPlot->getX_INLINE(), pPlot->getY_INLINE(), bIgnoreLatitude))
				{
					pPlot->setBonusType(eBonusType);

					for (int iDX = -(pBonusInfo.getGroupRange()); iDX <= pBonusInfo.getGroupRange(); iDX++)
					{
						for (int iDY = -(pBonusInfo.getGroupRange()); iDY <= pBonusInfo.getGroupRange(); iDY++)
						{
							if (GC.getMapINLINE().getNumBonuses(eBonusType) < iBonusCount)
							{
								CvPlot* pLoopPlot	= plotXY(pPlot->getX_INLINE(), pPlot->getY_INLINE(), iDX, iDY);

								if (pLoopPlot != NULL && (pLoopPlot->area() == pBestArea))
								{
									if (canPlaceBonusAt(eBonusType, pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE(), bIgnoreLatitude))
									{
										if (GC.getGameINLINE().getMapRandNum(100, "addUniqueBonusType") < pBonusInfo.getGroupRand())
										{
											pLoopPlot->setBonusType(eBonusType);
//.........这里部分代码省略.........
开发者ID:RichterBelmont,项目名称:BadgameBTSMod,代码行数:101,代码来源:CvMapGenerator.cpp


示例3: 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:csDaniel,项目名称:cs362sp16,代码行数:101,代码来源:dominion.c


示例4: cardEffect


//.........这里部分代码省略.........
        case minion:
                return minionEffect(state, handPos, choice1, choice2);

        case steward:
                return stewardEffect(state, handPos, choice1, choice2, choice3);

        case tribute:
                if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) {
                        if (state->deckCount[nextPlayer] > 0) {
                                tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
                                state->deckCount[nextPlayer]--;
                        }
                        else if (state->discardCount[nextPlayer] > 0) {
                                tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1];
                                state->discardCount[nextPlayer]--;
                        }
                        else{
                                //No Card to Reveal
                                if (DEBUG) {
                                        printf("No cards to reveal\n");
                                }
                        }
                }

                else{
                        if (state->deckCount[nextPlayer] == 0) {
                                for (i = 0; i < state->discardCount[nextPlayer]; i++) {
                                        state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
                                        state->deckCount[nextPlayer]++;
                                        state->discard[nextPlayer][i] = -1;
                                        state->discardCount[nextPlayer]--;
                                }

                                shuffle(nextPlayer,state);//Shuffle the deck
                        }
                        tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
                        state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
                        state->deckCount[nextPlayer]--;
                        tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
                        state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
                        state->deckCount[nextPlayer]--;
                }

                if (tributeRevealedCards[0] == tributeRevealedCards[1]) {//If we have a duplicate card, just drop one
                        state->playedCards[state->playedCardCount] = tributeRevealedCards[1];
                        state->playedCardCount++;
                        tributeRevealedCards[1] = -1;
                }

                for (i = 0; i <= 2; i++) {
                        if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) {//Treasure cards
                                state->coins += 2;
                        }

                        else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) {//Victory Card Found
                                drawCard(currentPlayer, state);
                                drawCard(currentPlayer, state);
                        }
                        else{//Action Card
                                state->numActions = state->numActions + 2;
                        }
                }

                return 0;

        case ambassador:
开发者ID:TheTallPaul,项目名称:cs362sp16_melloc,代码行数:67,代码来源:mutant101454_dominion.c


示例5: cardEffect


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

	case tribute:
		playedCard(handPos, NULL, NULL, state);
		if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) {
			if (state->deckCount[nextPlayer] > 0) {
				tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer] - 1];
				state->deckCount[nextPlayer]--;
				state->discard[nextPlayer][state->discardCount[nextPlayer]] = tributeRevealedCards[0];
				state->discardCount[nextPlayer]++;
			}
			else if (state->discardCount[nextPlayer] > 0) {
				tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer] - 1];
			}
			else {
				//No Card to Reveal
				if (DEBUG) {
					printf("No cards to reveal\n");
				}
				endPlayed(state, 0);
				return 0;
			}
		}

		else {
			if (state->deckCount[nextPlayer] == 0) {
				j = state->discardCount[nextPlayer];
				for (i = 0; i < j; i++) {
					state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
					state->deckCount[nextPlayer]++;
					state->discard[nextPlayer][i] = -1;
					state->discardCount[nextPlayer]--;
				}

				shuffle(nextPlayer, state);//Shuffle the deck
			}
			tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer] - 1];
			state->deck[nextPlayer][state->deckCount[nextPlayer] - 1] = -1;
			state->deckCount[nextPlayer]--;

			if (state->deckCount[nextPlayer] == 0) {
				j = state->discardCount[nextPlayer];
				for (i = 0; i < j; i++) {
					state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
					state->deckCount[nextPlayer]++;
					state->discard[nextPlayer][i] = -1;
					state->discardCount[nextPlayer]--;
				}

				shuffle(nextPlayer, state);//Shuffle the deck
			}

			state->discard[nextPlayer][state->discardCount[nextPlayer]] = tributeRevealedCards[0];
			state->discardCount[nextPlayer]++;

			tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer] - 1];
			state->deck[nextPlayer][state->deckCount[nextPlayer] - 1] = -1;
			state->deckCount[nextPlayer]--;
			state->discard[nextPlayer][state->discardCount[nextPlayer]] = tributeRevealedCards[1];
			state->discardCount[nextPlayer]++;
		}

		if (tributeRevealedCards[0] == tributeRevealedCards[1]) {//If we have a duplicate card, just drop one 
			tributeRevealedCards[1] = -1;
		}

		for (i = 0; i < 2; i++) {
开发者ID:cs362sp16,项目名称:cs362sp16_berezam,代码行数:67,代码来源:mutant100945_dominion.c


示例6: __NWDSChangeObjectPasswordStep2

static NWDSCCODE __NWDSChangeObjectPasswordStep2(
		NWCONN_HANDLE conn,
		NWObjectID objectID,
		NWObjectID pseudoID,
		nuint8 rndseed[4],
		nuint8 *connPublicKey,
		const char* oldPassword,
		const char* newPassword
) {
	nuint8* privateKey;
	size_t privateKeyLen;
	nuint8 ec_newpwd[4096];
	size_t ec_newpwd_len;
	nuint8 oldPwdHash[16];
	nuint8 newPwdHash[16];
	NWDSCCODE err;
	NWDSCCODE gpk_err;
	size_t di;
	Buf_T *ib;
	Buf_T *ob;
	nuint8 tmpID[4];
	
	DSET_HL(tmpID, 0, pseudoID);
	shuffle(tmpID, oldPassword, strlen(oldPassword), oldPwdHash);
	shuffle(tmpID, newPassword, strlen(newPassword), newPwdHash);
	
	err = __NWDSGetPrivateKey(conn, connPublicKey, rndseed, objectID, oldPwdHash, NULL, &privateKey, &privateKeyLen);
	if (err != 0 && err != NWE_PASSWORD_EXPIRED)
		goto quit;
	if (privateKeyLen < 10) {
		err = ERR_INVALID_SERVER_RESPONSE;
		goto free_privkey;
	}
	DSET_LH(privateKey, 2, 1);
	WSET_LH(privateKey, 6, 2);

	gpk_err = err;
	ec_newpwd_len = sizeof(ec_newpwd);
	err = __NWEncryptWithSK(newPwdHash, 16, privateKey + 2, privateKeyLen - 2, ec_newpwd, &ec_newpwd_len);
	if (err)
		goto free_privkey;
	di = ec_newpwd_len + 0x34;
	
	err = NWDSAllocBuf(di + 8, &ib);
	if (err)
		goto free_privkey_ecnewpwd;
	NWDSBufPut(ib, rndseed, 4);
	NWDSBufPutBuffer(ib, oldPwdHash, 16);
	NWDSBufPutLE32(ib, strlen(newPassword));
	NWDSBufPutBuffer(ib, newPwdHash, 16);
	NWDSBufPutBuffer(ib, ec_newpwd, ec_newpwd_len);
	
	err = NWDSAllocBuf(di + 256, &ob);
	if (err)
		goto free_privkey_ecnewpwd_ib;
	err = rsa_crypt2(connPublicKey, ib, ob);
	if (err)
		goto free_privkey_ecnewpwd_ib_ob;
	err = __NWDSChangePasswordV0(conn, objectID, ob);
	if (!err)
		err = gpk_err;
free_privkey_ecnewpwd_ib_ob:;
	NWDSClearFreeBuf(ob);
free_privkey_ecnewpwd_ib:;
	NWDSClearFreeBuf(ib);
free_privkey_ecnewpwd:;
	memset(ec_newpwd, 0, sizeof(ec_newpwd));
free_privkey:;
	memset(privateKey, 0, privateKeyLen);
	free(privateKey);
quit:;
	memset(oldPwdHash, 0, sizeof(oldPwdHash));
	memset(newPwdHash, 0, sizeof(newPwdHash));
	return err;
}
开发者ID:AsylumCorp,项目名称:dsploit,代码行数:75,代码来源:setkeys.c


示例7: cardEffect


//.........这里部分代码省略.........
				}
			
			//discard card from hand
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case tribute:
			if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1){
				if (state->deckCount[nextPlayer] > 0){
					tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
					state->deckCount[nextPlayer]--;
				}
				else if (state->discardCount[nextPlayer] > 0){
					tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1];
					state->discardCount[nextPlayer]--;
				}
				else{
					//No Card to Reveal
					if (DEBUG){
						printf("No cards to reveal\n");
					}
				}
			}
	    
			else{
				if (state->deckCount[nextPlayer] == 0){
					for (i = 0; i < state->discardCount[nextPlayer]; i++){
						state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
						state->deckCount[nextPlayer]++;
						state->discard[nextPlayer][i] = -1;
						state->discardCount[nextPlayer]--;
					}
			    
					shuffle(nextPlayer,state);//Shuffle the deck
				} 
				tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
				state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
				state->deckCount[nextPlayer]--;
				tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
				state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
				state->deckCount[nextPlayer]--;
			}    
		       
			if (tributeRevealedCards[0] == tributeRevealedCards[1]){//If we have a duplicate card, just drop one 
				state->playedCards[state->playedCardCount] = tributeRevealedCards[1];
				state->playedCardCount++;
				tributeRevealedCards[1] = -1;
			}

			for (i = 0; i <= 2; i ++){
				if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold){//Treasure cards
					state->coins += 2;
				}
		    
				else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall){//Victory Card Found
					drawCard(currentPlayer, state);
					drawCard(currentPlayer, state);
				}
				else{//Action Card
					state->numActions = state->numActions + 2;
				}
			}
	    
			return 0;
		
		case ambassador:
开发者ID:cs362sp16,项目名称:cs362sp16_minnerp,代码行数:67,代码来源:mutant100497_dominion.c


示例8: shuffle

void ImageDataLayer<Dtype>::ShuffleImages() {
  caffe::rng_t* prefetch_rng =
      static_cast<caffe::rng_t*>(prefetch_rng_->generator());
  shuffle(lines_.begin(), lines_.end(), prefetch_rng);
}
开发者ID:ifp-uiuc,项目名称:caffe,代码行数:5,代码来源:image_data_layer.cpp


示例9: main

int main(void) {
    clock_t start, end;
    start = clock();
    
    int i, j, k,x;
    int current_count = 0;
    int setosa_count;
    int versicolor_count;
    int virginica_count;
    char answer_flower[20];
    
    Neuron *current_root, *answer;
    Neuron *root[TRIAL_NUM][10];
    
    // データの読み込み
    read_datums(data, flower_type);
    shuffle(150, data, flower_type);
    
    //rootの初期化
    for (i = 0; i<TRIAL_NUM; i++) {
        for (j = 0; j<10; j++) {
            root[i][j] = NULL;
        }
    }
    
    for (i = 0; i<TRIAL_NUM; i++) {
        for (j = 0; j<10; j++) {
            split_datums(
                         data,
                         flower_type,
                         traning_data,
                         traning_result,
                         testing_data,
                         testing_result,
                         j
                         );
            
            shuffle(135, traning_data, traning_result);
            
            current_root = create_tree(traning_data, traning_result);
            //	    show(current_root);
            
            root[i][j] = current_root;
            current_root = NULL;
            
            if (i % 5 == 0) {
                for (x = 0; x < 15; x++) {
                    setosa_count = virginica_count = versicolor_count = 0;
                    for (k = 0; k <= i; k++) {
                        answer = get_perhaps_nearest(root[k][j], testing_data[x]);
                        if (strcmp(answer->result, "setosa\n") == 0) {
                            setosa_count++;
                        }
                        else if (strcmp(answer->result, "virginica\n") == 0) {
                            virginica_count++;
                        }
                        else {
                            versicolor_count++;
                        }
                    }
                    //				printf("%d,%d,%d\n", setosa_count, virginica_count, versicolor_count);
                    
                    if (setosa_count > virginica_count) {                //a>b
                        if (setosa_count > versicolor_count) {		//a>b && a>c
                            //setosaが一番多いとき
                            strcpy(answer_flower, "setosa\n");
                        }
                        else {									//a>b && a<=c
                            //virginicaが一番少なく、setosaとversicolorが同数またはversicolorが一番多いとき
                            strcpy(answer_flower, "versicolor\n");
                        }
                    }
                    else if(setosa_count==virginica_count==versicolor_count){
                        //3つが同数のとき、一番最後に作ったツリーの答えを使う。
                        strcpy(answer_flower, answer->result);
                    }
                    else {										//b>=a
                        if (virginica_count < versicolor_count) { // b>=a && b<c
                            // versicolorが一番多いとき
                            strcpy(answer_flower, "versicolor\n");
                        }
                        else{	 //b>a && b>=c
                            // versicolorとvirginicaが同数か一番多いとき
                            strcpy(answer_flower, "virginica\n");
                        }
                    }
                    //					printf("%s%s", answer_flower, testing_result[x]);
                    if (strcmp(answer_flower, testing_result[x]) == 0) {
                        current_count++;
                    }
                }
            }
            for (x = 0; x < 135; x++) {
                for (k = 0; k < 4; k++) {
                    traning_data[x][k] = 0;
                }
                strcpy(traning_result[x],"0");
            }
        }
        if (i % 5 == 0) {
//.........这里部分代码省略.........
开发者ID:ether0x2ca,项目名称:neural_network,代码行数:101,代码来源:main.c


示例10: play_poker

int play_poker(card deck[52]) {
	int	flush_cnt = 0, hand_cnt = 0;
	int	i, j, x, y, done = FALSE, fold = FALSE, menu = TRUE;
	long	bet=0, pot=0;
	char    ch, buf[128];
	card	hand[NPLAYERS][5];	/* each player is dealt 5 cards */
	
	srand(time(NULL));	/* seed the random number generator */
	shuffle(deck);
	deal_the_cards(deck, hand);
	bet = 10;
	printf("Antie is $%ld\n\n", bet);
	if(character.trading_credits < 10) {
		printf("You don't even have enough to Antie.\n");
		printf("The dealer kicks you out of the game,\n");
		printf("And says \"Go Wumpus Hunting!\"\n\n");
		return 0;
	} else {
		printf("Welcome to poker.\n");
		printf("Game is five card, no draw.\n");
		printf("\nYou against the dealer.\n");
		printf("The dealer Anties 10 dollars.\n\n");
		character.trading_credits -= 10;
		pot += 20;
		Pause2();
	}
	
	while(!done) {
		if(menu) {
			printf("\nDealer's Hand\n");
			prn_facedown_hand();
			printf("\nYour Hand\n");			
			prn_faceup_hand(hand[1]);
   			printf("\x1b[0;35m    1        2        3        4        5\x1b[0m\n");

			printf("\n(r)=raise, (c)=call, (f)=fold\n");
        	}
        	printf("\nPot is %ld gold\n",pot);
        	printf("[(?)=help] -> ");
        	for(;;) {
        		/*****************/
        		/* get keys here */
        		/*****************/
			ch = GetKey(0);
			if(ch == '1' ||
			ch == '2' ||
			ch == '3' ||
			ch == '4' ||
			ch == '5' ||
			ch == 'f' ||
			ch == 'q' ||
			ch == 'r' ||
			ch == 'c' ||
			ch == '?') break;
        	}
        	switch(tolower(ch)) {
		case 'r':
			printf("raise..\n\n");
			
			printf("You have $%d in pocket\n\n", character.trading_credits);
			printf("Raise how much? ");
			GetStr(buf, 10, 0);
			bet = atol(buf);
			if(bet == 0) {
				printf("\nYou can't raise by zero trading_credits, try calling.\n\n");
				done = TRUE;
				break;
			} else if(character.trading_credits >= bet) {
				printf("\nBet Amount is now $%d\n", bet);
				character.trading_credits -= bet;
				pot += (bet * 2);
				printf("Dealer see's you and calls!\n");
				/***********************************/
				/* here the dealer has to decide   */
				/* if he is going to raise or call */
				/* the bet.                        */
				/***********************************/
			} else {
				printf("\nYou don't have enough trading_credits!\n");
			}
			menu = FALSE;
			done = FALSE;
			fold = FALSE;
			break;
		case 'c':
			printf("call..\n");
			
			printf("\nDealer calls as well.\n");
			/****************************/
			/* what does the dealer do? */
			/****************************/
			menu = FALSE;
			done = TRUE;
			fold = FALSE;
			break;
        	case 'q':
        	case 'f':
        		printf("fold..\n\n");
        		printf("\x1b[0mDealer's Hand\n");
        		prn_facedown_hand();
//.........这里部分代码省略.........
开发者ID:rabbitear,项目名称:Homebrew-bbs,代码行数:101,代码来源:poker.c


示例11: monte_Analysis

double  monte_Analysis(Deck *deck, Player *person){
	 int i, j, k, z, bestType = 0;
	 double avebucket = 0.0, maxave = 0.0, bestprob = 0.0, ave = 0.0, rank = 0.0, sum = 0.0;
	 double maxscale = 0;
	 int scalenum = 0;
	 int scale[10];
	 Player dummy = player_init("Dummy", 255);
	 int choices[][5] = {
		  {0,0,0,0,1},
		  {0,0,0,1,0},
		  {0,0,0,1,1},
		  {0,0,1,0,0},
		  {0,0,1,0,1},
		  {0,0,1,1,0},
		  {0,0,1,1,1},
		  {0,1,0,0,0},
		  {0,1,0,0,1},
		  {0,1,0,1,0},
		  {0,1,0,1,1},
		  {0,1,1,0,0},
		  {0,1,1,0,1},
		  {0,1,1,1,0},
		  {0,1,1,1,1},
		  {1,0,0,0,0},
		  {1,0,0,0,1},
		  {1,0,0,1,0},
		  {1,0,0,1,1},
		  {1,0,1,0,0},
		  {1,0,1,0,1},
		  {1,0,1,1,0},
		  {1,0,1,1,1},
		  {1,1,0,0,0},
		  {1,1,0,0,1},
		  {1,1,0,1,0},
		  {1,1,0,1,1},
		  {1,1,1,0,0},
		  {1,1,1,0,1},
		  {1,1,1,1,0},
		  {1,1,1,1,1},
		  {0,0,0,0,0},
	 };

	 dummy.hand[0] = person->hand[0];
	 dummy.hand[1] = person->hand[1];
	 dummy.hand[2] = person->hand[2];
	 dummy.hand[3] = person->hand[3];
	 dummy.hand[4] = person->hand[4];

	 for(i = 0;i<32;i++){
		  maxscale = 0;
		  scalenum = 0;
		  sum = 0;
		  for(z=0;z<10;z++){
				scale[z] = 0;
		  }
		  for(j = 0; j < MCTRIALS; j++){
				dummy.hand[0] = person->hand[0];
				dummy.hand[1] = person->hand[1];
				dummy.hand[2] = person->hand[2];
				dummy.hand[3] = person->hand[3];
				dummy.hand[4] = person->hand[4];
				shuffle(deck, 47);
				for(k = 0; k < HAND_SIZE; k++){
					 if(choices[i][k] == 1){
						  exchangeMC(deck, &dummy, k);
					 }
				}
				rank = handRank(&dummy);
				sum += (double)rank;
				if(rank <= 12){
					 scale[0]++;
				}
				else if(rank > 12 && rank <=25){
					 scale[1]++;
				}
				else if(rank > 25 && rank <=54){
					 scale[2]++;
				}
				else if(rank >54 && rank <=67){
					 scale[3]++;
				}
				else if(rank >67 && rank <=81){
					 scale[4]++;
				}
				else if(rank >81 && rank <=97){
					 scale[5]++;
				}
				else if(rank >97 && rank <=113){
					 scale[6]++;
				}
				else if(rank > 113 && rank <=127){
					 scale[7]++;
				}
				else if(rank > 127 && rank <= 139){
					 scale[8]++;
				}
				else if(rank == 140){
					 scale[9]++;

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


示例12: main

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

	int argv2;
	sscanf(argv[2], "%d", &argv2);


	// //variant 1 - peremewat' karti
	if (argv2 == 1) {

		// zapominaem file s kartami v strokovii massiv cards[][]
		char cards[NUM_CARDS][LEN_STRING];
		read_main_file(cards);

		//perezapisivaem massiv obratno v fail v sly4ainom poryadke
		shuffle(cards);
	}


	// razda4a kart igrokam
	if (argv2 == 2) {

		// zapominaem file s kartami v strokovii massiv cards[][]
		char cards[NUM_CARDS][LEN_STRING];
		read_main_file(cards);

		//izvlekaem koli4estvo igrokov i koli4estvo razdavaemih kart
		int argv3, argv4;
		sscanf(argv[3], "%d", &argv3);
		sscanf(argv[4], "%d", &argv4);

		int num_gamers = argv3;
		int num_cards_for_gamer = argv4;

		// generiruem imena failov igrokov 
		char file_list[num_gamers][LEN_STRING];
		generation_file_names(file_list, num_gamers);

		// zapisivaem karti v faili igrokov
		card_to_gamers(cards, file_list, num_gamers, num_cards_for_gamer);

		// perezapisivaem v fail nerozdannie karti 
		rest_cards(cards, num_gamers, num_cards_for_gamer);
	}


 	//zabiraem karti y igrokov
	if (argv2 == 3) {

		int argv3;
		sscanf(argv[3], "%d",&argv3);
		int num_gamers = argv3;

	//sozdaem massiv nazvanii failov igrokov
		char file_list[num_gamers][LEN_STRING];
		get_file_list(argv, file_list, num_gamers);

	//dopisivaem karti igrokov v fail s kolodoi kart
		return_cards(file_list, num_gamers);
	}

	return EXIT_SUCCESS;
}
开发者ID:sway4ka,项目名称:card-desk,代码行数:62,代码来源:cards.c


示例13: htrans


//.........这里部分代码省略.........
	/*
	 * do log2n reductions
	 *
	 * We're indexing a as a 2-D array with dimensions (nx,ny).
	 */
	nxtop = nx;
	nytop = ny;

	for (k = 0; k<log2n; k++) {
		oddx = nxtop % 2;
		oddy = nytop % 2;
		for (i = 0; i<nxtop-oddx; i += 2) {
			s00 = i*ny;				/* s00 is index of a[i,j]	*/
			s10 = s00+ny;			/* s10 is index of a[i+1,j]	*/
			for (j = 0; j<nytop-oddy; j += 2) {
				/*
				 * Divide h0,hx,hy,hc by 2 (1 the first time through).
				 */
				h0 = (a[s10+1] + a[s10] + a[s00+1] + a[s00]) >> shift;
				hx = (a[s10+1] + a[s10] - a[s00+1] - a[s00]) >> shift;
				hy = (a[s10+1] - a[s10] + a[s00+1] - a[s00]) >> shift;
				hc = (a[s10+1] - a[s10] - a[s00+1] + a[s00]) >> shift;

				/*
				 * Throw away the 2 bottom bits of h0, bottom bit of hx,hy.
				 * To get rounding to be same for positive and negative
				 * numbers, nrnd2 = prnd2 - 1.
				 */
				a[s10+1] = hc;
				a[s10  ] = ( (hx>=0) ? (hx+prnd)  :  hx        ) & mask ;
				a[s00+1] = ( (hy>=0) ? (hy+prnd)  :  hy        ) & mask ;
				a[s00  ] = ( (h0>=0) ? (h0+prnd2) : (h0+nrnd2) ) & mask2;
				s00 += 2;
				s10 += 2;
			}
			if (oddy) {
				/*
				 * do last element in row if row length is odd
				 * s00+1, s10+1 are off edge
				 */
				h0 = (a[s10] + a[s00]) << (1-shift);
				hx = (a[s10] - a[s00]) << (1-shift);
				a[s10  ] = ( (hx>=0) ? (hx+prnd)  :  hx        ) & mask ;
				a[s00  ] = ( (h0>=0) ? (h0+prnd2) : (h0+nrnd2) ) & mask2;
				s00 += 1;
				s10 += 1;
			}
		}
		if (oddx) {
			/*
			 * do last row if column length is odd
			 * s10, s10+1 are off edge
			 */
			s00 = i*ny;
			for (j = 0; j<nytop-oddy; j += 2) {
				h0 = (a[s00+1] + a[s00]) << (1-shift);
				hy = (a[s00+1] - a[s00]) << (1-shift);
				a[s00+1] = ( (hy>=0) ? (hy+prnd)  :  hy        ) & mask ;
				a[s00  ] = ( (h0>=0) ? (h0+prnd2) : (h0+nrnd2) ) & mask2;
				s00 += 2;
			}
			if (oddy) {
				/*
				 * do corner element if both row and column lengths are odd
				 * s00+1, s10, s10+1 are off edge
				 */
				h0 = a[s00] << (2-shift);
				a[s00  ] = ( (h0>=0) ? (h0+prnd2) : (h0+nrnd2) ) & mask2;
			}
		}
		/*
		 * now shuffle in each dimension to group coefficients by order
		 */
		for (i = 0; i<nxtop; i++) {
			shuffle(&a[ny*i],nytop,1,tmp);
		}
		for (j = 0; j<nytop; j++) {
			shuffle(&a[j],nxtop,ny,tmp);
		}
		/*
		 * image size reduced by 2 (round up if odd)
		 */
		nxtop = (nxtop+1)>>1;
		nytop = (nytop+1)>>1;
		/*
		 * divisor doubles after first reduction
		 */
		shift = 1;
		/*
		 * masks, rounding values double after each iteration
		 */
		mask  = mask2;
		prnd  = prnd2;
		mask2 = mask2 << 1;
		prnd2 = prnd2 << 1;
		nrnd2 = prnd2 - 1;
	}
	free(tmp);
	return(0);
}
开发者ID:5Zhiyong,项目名称:astropy,代码行数:101,代码来源:fits_hcompress.c


示例14: docset_check


//.........这里部分代码省略.........
    lDocWrite.deleted = 0;
    couchstore_save_local_document(db, &lDocWrite);
    couchstore_commit(db);
    couchstore_close_db(db);
    couchstore_open_db(testfilepath, 0, &db);
    couchstore_open_local_document(db, "_local/testlocal", 16, &lDocRead);
    assert(lDocRead);
    assert(lDocRead->json.size == 13);
    assert(memcmp(lDocRead->json.buf, "{\"test\":true}", 13) == 0);
    couchstore_free_local_document(lDocRead);
    couchstore_close_db(db);
cleanup:
    assert(errcode == 0);
}

static void test_open_file_error(void)
{
    fprintf(stderr, "opening nonexistent file errors... ");
    fflush(stderr);
    unlink(testfilepath);
    Db *db;
    int errcode = couchstore_open_db(testfilepath, 0, &db);

    if(errcode != 0) {
        print_os_err();
    }

    assert(errcode == COUCHSTORE_ERROR_NO_SUCH_FILE);

    // make sure os.c didn't accidentally call close(0):
    assert(lseek(0, 0, SEEK_CUR) >= 0 || errno != EBADF);
}

static void shuffle(Doc **docs, DocInfo **docinfos, size_t n)
{
    if (n > 1) {
        size_t i;
        for (i = 0; i < n - 1; i++) {
          size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
          DocInfo *docinfo;
          Doc *doc = docs[j];
          docs[j] = docs[i];
          docs[i] = doc;

          docinfo = docinfos[j];
          docinfos[j] = docinfos[i];
          docinfos[i] = docinfo;
        }
    }
}

static int docmap_check(Db *db, DocInfo *info, void *ctx)
{
    (void)db;
    char* docmap = (char*)ctx;
    int i;
    char buffer[100];
    memcpy(buffer, info->id.buf, info->id.size);
    buffer[info->id.size] = 0; // null terminate
    sscanf(buffer, "doc%d", &i);
    assert(docmap[i] == 0);
    docmap[i] = 1;
    return 0;
}

static void test_changes_no_dups(void)
开发者ID:avsej,项目名称:couchbase.deb,代码行数:67,代码来源:testapp.c


示例15: initializeGame


//.........这里部分代码省略.........
	  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

  //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++)
 /* MUTANT (rep_op) */        for (i = 0; i != numPlayers; i++)
      if ( shuffle(i, state) < 0 )
	{
	  return -1;
	}
    }
开发者ID:cs362sp16,项目名称:cs362sp16_broderij,代码行数:101,代码来源:mutant100357_dominion.c


示例16: processYUVImage

/////////////////////////////////////////////////////////
// processImage
//
/////////////////////////////////////////////////////////
void pix_puzzle :: processYUVImage(imageStruct &image)
{
  unsigned char *src = image.data;
  unsigned char *dest;

  int x, y, xx, yy, i;
  unsigned char *p, *q;

  if (m_force || (myImage.xsize*myImage.ysize*myImage.csize != image.xsize*image.ysize*image.csize)){
    myImage.clear();
    m_force = false;

    myImage.xsize = image.xsize;
    myImage.ysize = image.ysize;
    myImage.setCsizeByFormat(image.format);
    myImage.reallocate();

    makePuzzleBlocks(image.xsize, image.ysize, image.csize);
    shuffle();
  }

  myImage.xsize = image.xsize;
  myImage.ysize = image.ysize;
  myImage.setCsizeByFormat(image.format);

  dest = myImage.data;

  i=0;
  for (y=0; y<blockh; y++){
    for(x=0; x<blockw; x++) {
      p = &src[blockoffset[blockpos[i]]];
      q = &dest[blockoffset[i]];
      if(m_game && spacepos == i) { // leave one rectangle blank (for the puzzle game)
	for(yy=0; yy<blockysize; yy++) {
	  for(xx=0; xx<blockxsize*image.csize; xx++) {
	    q[xx] = 0;
	  }
	  q += image.xsize*image.csize;
	}
      } else {
	for(yy=0; yy<blockysize; yy++) {
	  for(xx=0; xx<blockxsize*image.csize; xx++) {
	    q[xx] = p[xx];
	  }
	  q += image.xsize*image.csize;
	  p += image.xsize*image.csize;
	}
      }
      i++;
    }
  }

  p = src +  blockw * blockxsize;
  q = dest + blockw * blockxsize;

  if(marginw) {
    for(y=0; y<blockh*blockysize; y++) {
      for(x=0; x<marginw; x++) {
	*q++ = *p++;
      }
      p += image.xsize - marginw;
      q += image.xsize - marginw;
    }
  }

  if(marginh) {
    p = src + (blockh * blockysize) * image.xsize;
    q = dest + (blockh * blockysize) * image.xsize;
    memcpy(p, q, marginh*image.xsize*image.csize);
  }

  image.data=myImage.data;
}
开发者ID:avilleret,项目名称:Gem,代码行数:77,代码来源:pix_puzzle.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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