Пример #1
0
Karte Hand::dropCard(int color,int number) {
	Karte k = findCard(color,number);
	if (hasCard(color,number)) {
		Karte x = k;
		int z = -1;
		for (int i = 0; i < karten.size(); i++) {
			if (karten[i].getNum() == number && karten[i].getColor() == color) {
				z = i;
				break;
			}
		}
		karten.erase(karten.begin()+z);
		return k;
	}
	throw "noSuchCard";
}
Пример #2
0
void MolapCCPreComputation::DFS( const int const cl[], int bPos, int ePos, int d )
{

	int i = 0;
	int j = 0;
	int k = 0;

	int *ucl = new int[dimsNum];
	for ( i = 0; i < dimsNum; ++i )
	{
		ucl[i] = cl[i];
	}

	//计算上界集 ucl
	for ( i = 0; i < dimsNum; ++i )
	{
		if ( cl[i] == ALL )
		{
			int diff = 0;
			for ( j = bPos + 1; j < ePos; ++j )
			{
				diff = dimDataDouble[dflag][j][i] - dimDataDouble[dflag][bPos][i];
				if (diff)
				{
					break;
				}
			}
			if (!diff)
			{
				ucl[i] = dimDataDouble[dflag][bPos][i];
				k ++;
			}
		}
		else
		{
			k ++;
		}
	}	

	//prune the cells which have been examined.
	for ( j = 0; j < d; ++j )
	{
		if ( cl[j] == ALL && ucl[j] != ALL )
		{
			delete []ucl;
			return;
		}
	}

	for ( i = 0; i < msrsNum; ++i )
	{
		msrValues[i] = ((this->*aggFunLib[aggFunOrder[i]]))(msrDataDouble[dflag], bPos, ePos, i);
	}
	
	outputTomsrDataFile(k, msrValues);
	for ( i = 0; i < dimsNum; ++i )
	{
		tmpData[k][i].push_back(ucl[i]);
	}

	++aggsNumPerLayer[k];            //第k层输出的上界集数+1

	++uclsNum;

	int* tmpucl = new int[dimsNum];
	for ( i = 0; i < dimsNum; ++i )
	{
		tmpucl[i] = ucl[i]; 
	}
	for ( i = d; i < dimsNum; ++i )
	{
		if ( ucl[i] == ALL )
		{
			int card = findCard(bPos, ePos, i);
			//Does it need to judge the card?
			int *freq = new int[card];
			Partition(bPos, ePos, i, card, freq);

			int tmpdflag  = dflag; 
			for ( j = 0; j < card - 1; ++j )
			{
				if (freq[j + 1] > freq[j])
				{
					ucl[i] = dimDataDouble[dflag][ freq[j] ][i];
					DFS(ucl, freq[j], freq[j + 1], i);	
				}
				dflag = tmpdflag;
			}
			delete[] freq;
		}
		for ( j = 0; j < dimsNum; ++j )
		{
			ucl[j] = tmpucl[j];
		}

	}

	delete []tmpucl;
	delete []ucl;
}
Пример #3
0
static void playTurn(Node **queue1, Node **queue2, struct gameState *state) {
  // action phase
  int handPos = findCardToPlay(state);
  if (state->numActions > 0 && handPos >= 0) {
    int choice1;
    int choice2;
    int choice3;
    int card = handCard(handPos, state);
    if (card == smithy) {
      // play smithy card
      choice1 = 0;
      choice2 = 0;
      choice3 = 0;
    } else if (card == mine) {
      // play mine card
      if (hasCard(state->hand[state->whoseTurn], numHandCards(state), copper)) {
        choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), copper);
        choice2 = silver;
        playCard(handPos, choice1, choice2, 0, state);
      } else if (hasCard(state->hand[state->whoseTurn], numHandCards(state), silver)) {
        choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), silver);
        choice2 = gold;
        playCard(handPos, choice1, choice2, 0, state);
      } else if (hasCard(state->hand[state->whoseTurn], numHandCards(state), gold)) {
        choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), gold);
        choice2 = gold;
      }
      choice3 = 0;
    } else if (card == village) {
      // play village card
      choice1 = 0;
      choice2 = 0;
      choice3 = 0;
    } else {
      Verify362(card == adventurer);
      // play adventurer card
      choice1 = 0;
      choice2 = 0;
      choice3 = 0;
    }
    char play[MAX_STR_LEN] = { '\0' };
    int result = playCard(handPos, choice1, choice2, choice3, state);
    sprintf(play, "playCard(%d, %d, %d, %d, state) = %d", handPos, choice1, choice2, choice3, result);
    recordResult(queue1, queue2, state, play);
  }

  // buy phase
  int supplyPos = findCardToBuy(state);
  if (supplyPos >= 0) {
    char play[MAX_STR_LEN] = { '\0' };
    int result = buyCard(supplyPos, state);
    sprintf(play, "buyCard(%d, state) = %d", supplyPos, result);
    recordResult(queue1, queue2, state, play);
  }

  // clean-up phase
  char play[MAX_STR_LEN] = { '\0' };
  int result = endTurn(state);
  sprintf(play, "endTurn(state) = %d", result);
  recordResult(queue1, queue2, state, play);
}
Пример #4
0
int main()
{
     int r;
     int player;
     int numPlayer = 2;

     int seed = 1000;
     int k[10] = { adventurer, council_room, feast, gardens, mine
          , remodel, smithy, village, baron, great_hall };

#if (NOISY_TEST == 1)
     const char* cards[] = //All 27 cards in game
     {
          "curse",
          "estate",
          "duchy",
          "province",
          "copper",
          "silver",
          "gold",
          "adventurer",
          "council_room",
          "feast",
          "gardens",
          "mine",
          "remodel",
          "smithy",
          "village",
          "baron",
          "great_hall",
          "minion",
          "steward",
          "tribute",
          "ambassador",
          "cutpurse",
          "embargo",
          "outpost",
          "salvager",
          "sea_hag",
          "treasure_map"
     };
#endif

     struct gameState prevState; //untouched game state to compare with after running tests
     struct gameState postState; //game state that will be used for tests


     int testResult;

     int numTests = 1; //how many test iterations to run.
     int failedTests = 0;
     int passedTests = 0;

     printf("==============================================\r\n");
     printf("    Beginning testing for playVillage()\r\n");
     printf("==============================================\r\n");


     int i;
     for (i = 0; i < numTests; i++)
     {
          memset(&prevState, 23, sizeof(struct gameState));   // clear the game state
          r = initializeGame(numPlayer, k, seed, &prevState); // initialize a new game

          for (player = 0; player < numPlayer; player++)
          {
               prevState.handCount[player] = 1;        // set the number of cards on hand
               int villageHand[1];
               villageHand[0] = village;
               memcpy(prevState.hand[player], villageHand, sizeof(int));

               prevState.deckCount[player] = 5;        // set the number of cards in deck
               int mixedDeck[5];
               mixedDeck[0] = copper;
               mixedDeck[1] = silver;
               mixedDeck[2] = gold;
               mixedDeck[3] = gardens;
               mixedDeck[4] = tribute;
               memcpy(prevState.deck[player], mixedDeck, sizeof(int) * 5);

               memcpy(&postState, &prevState, sizeof(struct gameState)); //create clone of game state to run tests on
               playVillage(player, &postState, 0);

               //Check that exactly 1 card was indeed added to current player's hand by comparing handCount value
#if (NOISY_TEST == 1)
               printf("---------------------------------------------------------------------------------------------------------------------------\r\n");
               printf("Testing that player[%d] handCount is still the same...\r\n", player);
#endif

               testResult = postState.handCount[player];

               if (testResult == prevState.handCount[player]) //due to village needing being discarded, handCount should still be the same
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }
#if (NOISY_TEST == 1)
               printf("handCount = %d, Expected = %d\r\n", testResult, prevState.handCount[player]);
               printf("Testing that player[%d] playedCardCount has increased by 1..\r\n", player);
#endif
               //Check that playedCardCount increased by 1

               testResult = postState.playedCardCount;

               if (testResult == prevState.playedCardCount + 1) //passed
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }
#if (NOISY_TEST == 1)
               printf("playedCardCount = %d, Expected = %d\r\n", testResult, prevState.playedCardCount + 1);
               printf("Checking that the village card was added to the played cards pile...\r\n");
#endif
               //Check that the village card was added to the played cards pile

               testResult = findCard(player, &postState, village, 0);

               if (testResult == -1) //failed, if variable is still -1, village was not found
               {
                    failedTests++;
               }
               else//passed
               {
                    passedTests++;
               }

#if (NOISY_TEST == 1)
               if (testResult == -1) //failed
               {
                    printf("Failed! village card was not found in played cards pile!\r\n");
               }
               else//passed
               {
                    printf("Passed! village card was found in played cards pile at position %d!\r\n", testResult);
               }
               printf("Checking that village card is not in player[%d]'s hand...\r\n", player);
#endif
               //Check that village card is not in player's hand

               testResult = findCard(player, &postState, village, 1);

               if (testResult == -1) //passed, if variable is still -1, village was not found
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }

#if (NOISY_TEST == 1)
               if (testResult == -1) //passed
               {
                    printf("Passsed! village card was not found in the player's hand!\r\n");
               }
               else//failed
               {
                    printf("Failed! village card was found in player's hand at position %d!\r\n", testResult);
               }
               printf("Checking that the card added came from the player's own deck...\r\n");
#endif


               //Check that the 1 card added came from the player's own deck


               //debug
               //int y;
               //for (y = 0; y < postState.handCount[player]; y++)
               //{
               //printf("%s Card at position %d \r\n", cards[postState.hand[player][y]], y);
               // }

               int card;
               int cardCount = 0;
               int foundCards[MAX_DECK];
               int j;
               for (j = 0; j < 5; j++)
               {

                    if (j == 0)
                    {
                         card = copper;
                    }
                    if (j == 1)
                    {
                         card = silver;
                    }
                    if (j == 2)
                    {
                         card = gold;
                    }
                    if (j == 3)
                    {
                         card = gardens;
                    }
                    if (j == 4)
                    {
                         card = tribute;
                    }

                    testResult = findCard(player, &postState, card, 1);

                    if (testResult != -1) //card found
                    {
                         cardCount++;
                         foundCards[cardCount - 1] = card;

#if (NOISY_TEST == 1)
                         printf("Found %s card in player[%d]'s hand at position %d! Number of cards found: %d\r\n", cards[card], player, testResult, cardCount);
#endif
                    }
               }

               if (cardCount == 1) //passed
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }

#if (NOISY_TEST == 1)
               printf("cardCount = %d, Expected = 1\r\n", cardCount);
#endif

               //check that the found cards are not in the deck anymore
               for (j = 0; j < cardCount; j++)
               {
                    testResult = findCard(player, &postState, foundCards[j], 2);

                    if (testResult == -1) //card not found
                    {
                         passedTests++;
                    }
                    else
                    {
                         failedTests++;
#if (NOISY_TEST == 1)
                         printf("Found %s card in player[%d]'s deck at position %d\r\n", cards[card], player, testResult);
#endif
                    }
               }
#if (NOISY_TEST == 1)
               printf("Testing that player[%d] deckCount has decreased by 1..\r\n", player);
#endif
               //Check that deckCount decreased by 1

               testResult = postState.deckCount[player];

               if (testResult == prevState.deckCount[player] - 1) //passed
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }
#if (NOISY_TEST == 1)
               printf("deckCount = %d, Expected = %d\r\n", testResult, prevState.deckCount[player] - 1);
               printf("Checking that the the number of actions have increased by 2...\r\n");
#endif


               //Check that number of actions have increased by 2

               testResult = postState.numActions;

               if (testResult == prevState.numActions + 2) //passed
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }
#if (NOISY_TEST == 1)
               printf("numActions = %d, Expected = %d\r\n", testResult, prevState.numActions + 2);
               printf("---------------------------------------------------------------------------------------------------------------------------\r\n");
#endif

          }
     }

     printf("%d out of %d tests passed!\r\n", passedTests, passedTests + failedTests);
     printf("%d out of %d tests failed!\r\n", failedTests, passedTests + failedTests);

     return 0;
}
Пример #5
0
int main() {
        /* initialize bare minimum game variables  */
        int seed = 101; // seed for game init
        int numPlayers = 2;     // number of players
        int kCards[10] = {adventurer, council_room, feast,      // kingdom cards
        gardens, mine, remodel, smithy, village, baron, great_hall};
        struct gameState gState;
        int r = initializeGame(numPlayers, kCards, seed, &gState);      // initialize a new game
        int s;  // exit status for function

        /* extra parameters specific to this function  */
        int currentPlayer;

        /*  game state variables used by this function  */   
        int card;
        int coins;
        int handCount;

        /*  counter variables  */


        // test over all players
        for(currentPlayer = 0; currentPlayer < numPlayers; currentPlayer++){
            // test over some choices of card to buy
            for(card = council_room; card < smithy; card++){
                // test over some initial hand counts
                for(handCount = 0; handCount < 3; handCount ++){
                    memset(&gState, 23, sizeof(struct gameState));          // clear the game state
                    r = initializeGame(numPlayers, kCards, seed, &gState);  // initialize the game

                    // set add'l game variables
                    initCopper(&gState, currentPlayer, handCount);	// initialze player's hand
                    gState.coins = 0;				// and 0 coins
                    gState.discardCount[currentPlayer] = 0;	// and 0 discards
                    updateCoins(currentPlayer, &gState, 0);	// and update for correct # of coins

                    // get # of coins before playing card
                    coins = gState.coins;

                    // call the function under test
                    s = cardFeast(&gState, currentPlayer, card);

                    // tests
                    // check for the purchased card in discard pile
                    if(findCard(&gState, currentPlayer, card) == 1){
                        printPass();
                    }
                    else printFail();
                    printTest("presence of purchased card in discard", 1, findCard(&gState, currentPlayer, card), currentPlayer);

                    // check # of coins
                    updateCoins(currentPlayer, &gState, 0);
                    if(coins == gState.coins){
                        printPass();
                    }
                    else printFail();
                    printTest("# of coins in game state", coins, gState.coins, currentPlayer);
                }
            }
        }
        return 0;
}