예제 #1
0
파일: cardtest4.c 프로젝트: cr8zd/cs362w16
void testHand(struct gameState *preTest, struct gameState *postTest, int player)
{
	int c,i;
	int flag = 0;
	int offSet[2] = {DRAWCOUNT0,DRAWCOUNT1};
	printf("\n\tTesting Hand Specifications\n");
	for(c = 0; c <= 1; c++) //player index
	{
		int *preHand = _getHand(preTest,player+c);
		int *postHand = _getHand(postTest,player+c);
		for(i = 0; i <= preTest->handCount[player+c] - offSet[player+c]-1; i++)
		{
			if(preHand[i] != postHand[i])
			{
				char name[50];
				char name2[50];
				cardNumToName(preHand[i],name);
				cardNumToName(postHand[i],name2);
				printf("Error, hand for player %d altered incorrectly. Card at position %d is %s. Should be %s\n",player+c,i,name2,name);
				flag = 1;
			}
		}
		free(preHand);
		free(postHand);
	}
	if(flag == 1)
	{
		printf("Hand Test failed\n");
	}
	else
	{
		printf("Hand Test passed\n");
	}
}
void play(struct gameState *p,int pcard, int favCard, int *pnumcard, int who, int money){
	int i = 0;
	char cardname[32];

	
	cardNumToName(favCard, cardname);
	printf("your fav card is %s\n",cardname);
    if (pcard != -1) {
	cardNumToName(favCard, cardname);
    printf("%d: %s played from position %d\n",who, cardname, pcard); 
	playCard(pcard, 1, 1, 1, p); 
	printf("%s played.\n",cardname);
	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("%d: bought province\n",who); 
        buyCard(province, p);
      }
      else if (money >= 6) {
        printf("%d: bought gold\n",who); 
        buyCard(gold, p);
      }
      else if ((money >= 4) && (*pnumcard < 2)) {
        printf("%d: bought %s\n",who, cardname); 
        buyCard(favCard, p);
        *pnumcard++;
      }
      else if (money >= 3) {
        printf("%d: bought silver\n",who); 
        buyCard(silver, p);
      }

      printf("%d: end turn\n",who);
      endTurn(p);
    }
예제 #3
0
파일: cardtest4.c 프로젝트: cr8zd/cs362w16
void testSupply(struct gameState *preTest,struct gameState *postTest)
{
	int i;
	char name[50];
	int flag = 0;
	int *supplyPre = _getSupp(preTest);
	int *supplyPost = _getSupp(postTest);
	int supplyCheck[7] = {CURSECHANGE,ESTATECHANGE,DUCHYCHANGE,PROVINCECHANGE,COPPERCHANGE,SILVERCHANGE,GOLDCHANGE};
	printf("\n\tTesting Supply Specifications\n");
	for(i = 0; i <= 6; i++)
	{
		if( (supplyPre[i]-supplyPost[i]) != supplyCheck[i])
		{
			cardNumToName(i,name);
			printf("Supply card: %s incorrectly altered to %d. Should be %d\n",name,supplyPost[i],supplyPost[i]+supplyCheck[i]);
			flag = 1;
		}
	}
	if(flag == 1)
	{
		printf("Supply Test failed.\n");
	}
	else
	{
		printf("Supply Test passed.\n");
	}
	free(supplyPre);
	free(supplyPost);
}
void tryBuyCard(struct gameState *state){
		int cardToBuy = 0;
		char name[100];
		do{	
			cardToBuy = rand() % (treasure_map);
		}while(state->supplyCount[cardToBuy] < 0);

		//try to buy a silver if player has 3 coins
		//and random choice is to buy a curse or copper
		if(state->coins == 3 && (cardToBuy = 0 || cardToBuy == 4)){
			if(state->supplyCount[silver] > 0){
				cardToBuy = silver;
			 }
		}
		//if the player has enough to buy a province, and 1 buy they will
		if(state->coins >= 8 && state->numBuys == 1){
			if(state->supplyCount[province] > 0){
				cardToBuy = province;
			}
		}
		
		//they try to buy a card so long as it isn't a curse
		if(cardToBuy != 0){
			cardNumToName(cardToBuy,name);
			printf("card to buy %s\n",name);
			printf("card costs %d\n",getCost(cardToBuy));
			buyCard(cardToBuy, state);
		}

		//Game info after the play 
}
예제 #5
0
/*Smithy card unit tests*/
int testSmithyCard(){
	int numPlayer = 2; //players in the game 2-4
	int player = 0; //current player
	int handCount = 5; //Number of cards player starts with
	int i; //counting index for loops
	int hasSmithy = 0; //Determines if Smithy card is in player's hand or not.
	char cardName[20]; //name of card
	
	/*Kingdom cards in this game*/
	int k[10] = {adventurer, council_room, feast, gardens, mine
				, remodel, smithy, village, baron, great_hall};
			   
	/*starts new game*/
	struct gameState state;
	
	/*create hand*/
	int hand[handCount];
	hand[0] = copper;
	hand[1] = silver;
	hand[2] = gold;
	hand[3] = estate;
	hand[4] = smithy;
	
	printf ("Testing smithyEffect():\n");

	initializeGame(numPlayer, k, 1000, &state); //initialize a new game
	state.handCount[player] = handCount; //set the number of cards in hand
	memcpy(state.hand[player], hand, sizeof(int) * handCount); //give hand to player

	/*checks if smithy is in player's hand*/
	for(i = 0; i < state.handCount[player]; i++){
		cardNumToName(state.hand[player][i], cardName); //get name from card num
		printf("%s ", name);
		if(strcmp(name, "smithy") == 0){
			hasSmithy = 1; //Smithy card is in player's hand
		}
	}
	
	if (hasSmithy == 1){
		printf ("Player has Smithy\n");
		printf ("Using Smithy card\n");
		smithyEffect(player, state, i); //uses smithy card

		/*Smithy adds 3 cards and discards itself 5+3-1==7*/
		if (state.handCount[player] == 7)
			printf ("Player has the correct number of cards!\n");
		else
			printf("Player has the incorrect number of cards.\n");
	}
	else{
		printf ("Player does not have Smithy\n");
	}
	
	return 0;
}
예제 #6
0
void printHand2(struct gameState g, int player) {
	int acard;
	char cardName[MAX_STRING_LENGTH];
	
	printf("  Printing hand...\n");
	for (acard = 0; acard < g.handCount[0]; acard++) {
		strcpy(cardName,"");
		cardNumToName(g.hand[player][acard], cardName);
		printf("Player[%d][%d] = %s\n", player, acard, cardName);
	}
}
예제 #7
0
파일: cardtest4.c 프로젝트: cr8zd/cs362w16
void testPlayed(struct gameState *preTest,struct gameState *postTest)
{
	int i;
	int card,card2;
	int diff = postTest->playedCardCount - (preTest -> playedCardCount + 1);
	char name[50];
	char name2[50];
	int flag = 0;
	printf("\n\tTesting Played Specifications\n");
	if(diff != PLAYEDCARDTEST)
	{
		printf("PlayedCardCount incorrect. Off by %d\n",diff-PLAYEDCARDTEST); //NEGATIVE VALUE INDICATES TOO FEW CARDS MOVED TO PLAYED PILE
		flag = 1;
	}
	
	if(postTest->playedCards[0] != TESTCARDVAL)
	{
		printf("Wrong card found in played pile.\n");
		flag = 1;
	}
	for(i = 0; i <= preTest->playedCardCount -1; i++) 
	{
		if(preTest->playedCards[i] != postTest->playedCards[i])
		{
			flag = 1;
			card = preTest->playedCards[i];
			card2 = postTest->playedCards[i];
			cardNumToName(card,name);
			cardNumToName(card2,name2);
			printf("Error in playedCards pile. Card found is %s, should be %s.\n",name,name2);
		}						
	}
	if(flag == 1)
	{
		printf("Played Test failed\n");
	}
	else
	{
		printf("Played Test passed.\n");
	} 		
}
예제 #8
0
int main() {
    int i;
    int numPlayer = 2;
    int p;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    char name[32];

    //printSupply(&G);
    //testing to see if all cards can be accounted for. 

    printf ("* * * * * * * * * * * * * * * * TESTING unittest2 fullDeckCount():* * * * * * * * * * * * * * * * \n");

    int arraySize = sizeof(k)/sizeof(k[0]);
    for (i = 0; i < arraySize; i++)
    {
        cardNumToName(k[i], name); 
    
        for (p = 0; p < numPlayer; p++)
        {
           //test to see if the deck count is correct for 0 cards
            printf ("Test: No %s's in for player %i \n", name, p);
            assert (fullDeckCount(p, k[i], &G) == 0);

           //test to see if the deck count is correct for 1 card in deck
            G.deck[p][0] = k[i];
            G.deckCount[p] = 1;

            printf ("Test: One %s in deck for player %i \n", name, p);
            assert (fullDeckCount(p, k[i], &G) == 1);

            //test to see if the deck count is correct for a card in both hand and deck. 
            G.hand[p][0] = k[i];
            G.handCount[p] = 1;

            printf ("Test: One %s in hand and deck for player %i \n", name, p);
            assert (fullDeckCount(p, k[i], &G) == 2); 

            //test to see if the deck count is correct for a card in hand, discard and deck. 
            G.discard[p][0] = k[i];
            G.discardCount[p] = 1;

            printf ("Test: One %s in discard, hand and deck for player %i \n", name, p);
            assert (fullDeckCount(p, k[i], &G) == 3); 
        }
    }


    printf("All tests passed!\n");

    return 0;
}
void printHand(int player, struct gameState *game) {
  int handCount = game->handCount[player];
  int handIndex;
  printf("Player %d's hand:\n", player);
  if(handCount > 0) printf("#  Card\n");
  for(handIndex = 0; handIndex < handCount; handIndex++) {
    int card = game->hand[player][handIndex];
    char name[MAX_STRING_LENGTH];
    cardNumToName(card, name);
    printf("%-2d %-13s\n", handIndex, name);
  }
  printf("\n");
}
void printPlayed(int player, struct gameState *game) {
  int playedCount = game->playedCardCount;
  int playedIndex;
  printf("Player %d's played cards: \n", player);
  if(playedCount > 0) printf("#  Card\n");
  for(playedIndex = 0; playedIndex < playedCount; playedIndex++) {
    int card = game->playedCards[playedIndex];
    char name[MAX_STRING_LENGTH];
    cardNumToName(card, name);
    printf("%-2d %-13s \n", playedIndex, name);
  }
  printf("\n");
}
void printDiscard(int player, struct gameState *game) {
  int discardCount = game->discardCount[player];
  int discardIndex;
  printf("Player %d's discard: \n", player);
  if(discardCount > 0) printf("#  Card\n");
  for(discardIndex = 0; discardIndex < discardCount; discardIndex++) {
    int card = game->discard[player][discardIndex];
    char name[MAX_STRING_LENGTH];
    cardNumToName(card, name);
    printf("%-2d %-13s \n", discardIndex, name);
  }
  printf("\n");
}
예제 #12
0
void printDeck(int player, gameState *game) {
  int deckCount = game->deckCount[player];
  int deckIndex;
  printf("Player %d's deck: \n", player);
  if(deckCount > 0) printf("#  Card\n");
  for(deckIndex = 0; deckIndex < deckCount; deckIndex++) {
    int card = game->deck[player][deckIndex];
    char name[MAX_STRING_LENGTH];
    cardNumToName(card, name);
    printf("%-2d %-13s\n", deckIndex, name);
  }
  printf("\n");
}
void printSupply(struct gameState *game) {
  int cardNum, cardCost, cardCount;
  char name[MAX_STRING_LENGTH];
  printf("#   Card          Cost   Copies\n");
  for(cardNum = 0; cardNum < NUM_TOTAL_K_CARDS; cardNum++){
    cardCount = game->supplyCount[cardNum];
    if(cardCount == -1) continue;
    cardNumToName(cardNum, name);
    cardCost = getCardCost(cardNum);
    printf("%-2d  %-13s %-5d  %-5d", cardNum, name, cardCost, cardCount);
    printf("\n");
  }
  printf("\n");
}
예제 #14
0
void cardtest1()
{

    int numPlayer = 2;
    int seed = 10000;
    int player = 0; // 0=player 1
    char cardName[20];


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

    struct gameState G;
    initializeGame(numPlayer, k, seed, &G);

    printf("\n********************************\n");
    printf("\nCardTest1 - testing smithy_ref()\n");
    printf("\n********************************\n");

    //printf("%d\n", G.handCount[player]); //print hand count

    //shuffle(player, &G);
    G.hand[player][0] = smithy;
    //printHand(player, &G); //print hand to check that smithy is available to play

    smithy_ref(&G, player, 0);
    //printHand(player, &G); //print updated hand to readily see if player hand updated correctly.

    if(G.handCount[player] == 7)
        printf("PASS: Player hand updated to %d cards after playing smithy (5+3- (1 played))\n", G.handCount[player]);
    else
        printf("FAIL: Player hand count of %d not equal to 7\n", G.handCount[player]);

    cardNumToName(G.playedCards[0], cardName);
    if(strcmp(cardName, "Smithy") == 0)
        printf("PASS: Smithy has been played and put into played pile.\n");
    else
        printf("FAIL: Smithy has not been put into played pile.\n");

//    for(i = 0; i < G.handCount[player]; i++)
//    {
//
//        cardNumToName(G.hand[player][i], cardName);
//        printf("%s\n", cardName);
//    }



}
void print_Supply(struct gameState *game) {
  int cardNum, cardCost, cardCount;
  char name[100];
 FILE * fp;
	fp = fopen("gameResults.out", "a");
	 fprintf(fp,"#   Card          Cost   Copies\n");
  for(cardNum = 0; cardNum < 26; cardNum++){
    cardCount = game->supplyCount[cardNum];
    if(cardCount == -1) continue;
    cardNumToName(cardNum, name);
    cardCost = getCardCost(cardNum);
   fprintf(fp,"%-2d  %-13s %-5d  %-5d", cardNum, name, cardCost, cardCount);
    fprintf(fp,"\n");
  }
  fprintf(fp,"\n");
	fclose(fp);
}
int main (int argc, char** argv) {
    int i;
    int j;
    int valid;
    int numPlayers;
    int k[10];
    int result;
    int seed;
    char cardName[100];
    struct gameState *state = newGame();
    int currentPlayer;



    printf ("------------------ Starting game --------------------\n");
    //set the seed
    srand(1);
    seed = rand();
    //2-4 players
    numPlayers = rand() % 3 + 2;

    printf("Number of Players: %d\n", numPlayers);

    for (i = 0; i < 10; i++) {
        valid = 0;
        while (k[i] == feast || k[i] == tribute || k[i] == council_room || valid == 0) {
            k[i] = rand() % (treasure_map - adventurer + 1) + adventurer;
            valid = 1;
            for(j = 0; j < i; j++) {
                if(k[i] == k[j]) {
                    valid = 0;
                }
            }
        }
    }

    printf("Kingdom Cards:\n");
    for(i = 0; i < 10; i++) {
        printf("Test.\n");
        cardNumToName(k[i], cardName);
        printf("Test..\n");
        printf("%s\n", cardName);
    }

    if(initializeGame(numPlayers, k, seed, state) != 0) {
        printf("Error when calling initializeGame\n");
        exit(1);
    }

    int money = 0;
    int actionCard = 0;
    int currentCard = 0;

    while (!isGameOver(state)) {

        currentPlayer = state->whoseTurn;
        printf("Player %d's Turn:\n", currentPlayer);

        printf("----------- Action phase -----------\n");

        actionCard = 0;
        for(i = 0; i < numHandCards(state); i++) {
            if((handCard(i, state) < treasure_map) && (handCard(i, state) >= adventurer) && (handCard(i, state) != feast) && (handCard(i, state) != tribute)) {
                actionCard = i;
                break;
            }
        }

        while(state->numActions > 0 && actionCard != 0) {
            currentCard = handCard(actionCard, state);
            cardNumToName(currentCard, cardName);

            if(playCard(actionCard, -1, -1, -1, state) == -1) {
                discardCard(actionCard, currentPlayer, state, 0);
            }
            else {
                printf("Played Card: %s, %d\n", cardName, currentCard );
            }

            if(state->numActions <= 0) {
                printf("All actions used, move to buy phase\n");
                break;
            }
            for(i = actionCard; i < numHandCards(state); i++) {
                if(handCard(i, state) < treasure_map && handCard(i, state) >= adventurer && handCard(i, state) != feast && handCard(i, state) != tribute) {
                    actionCard = i;
                    break;
                }
                else {
                    actionCard = 0;
                }
            }
        }

        printf("----------- Buy phase -----------\n");
        money = countHandCoins(state->whoseTurn, state);
        int buy_card;

        while(state->numBuys > 0 && money > 0) {
            do {
                if(money >= 8) {
                    buy_card = province;
                }
                else {
                    buy_card = rand() % treasure_map;
                    if(buy_card == 4) {
                        if(rand() % 4 != 0) {
                            buy_card++;
                        }
                    }
                }

            } while(buyCard(buy_card, state) != 0);

            cardNumToName(buy_card, cardName);
            printf("Buying card: %s\n", cardName);
        }
        printf("End Turn\n");
        endTurn(state);

    }

    printScores(state);

    return 0;
}
예제 #17
0
int main() {

	srand(time(NULL));
	int gameSeed = rand() % 1000 + 1;
	int p = 0; //player 1
	int numPlayer = 4;
	int k[10] = {adventurer, council_room, feast, gardens, mine,
				 remodel, smithy, village, baron, great_hall};

	struct gameState* GS = newGame();

	initializeGame(numPlayer, k, gameSeed, GS);

	GS->hand[p][4] = council_room; //5th card in hand is council room

	printf("Playing Council Room card and testing...\n");

	/*Checking handcount and cards in hand before playing council room*/
	printf("Hand count before council room is %d...\n", GS->handCount[p]);
	int i = 0, cardStatus;
	char c[25];
	for(i = 0; i < GS->handCount[p]; i++){
		cardNumToName(GS->hand[p][i], c);	//Converts card number to string
		printf( "%s, ", c);
		if(strcmp(c, "Council Room") == 0){
			cardStatus = 1;	//Card is present in hand
		}
	}

	/*Check if council room card is in hand before use*/
	if(cardStatus == 1){
		printf("\nTest PASSED, card is present in player %d's hand\n\n", p);
	} else {
		printf("\nTest FAILED, card is NOT present in player %d's hand\n\n", p);
	}

	councilRoomCard(p, GS, 4);	//Play council room card

	cardStatus = 0; //Reset to zero

	/*Checking handcount and cards in hand after playing council room*/
	printf("Hand count after council room is %d...\n", GS->handCount[p]);
	for(i = 0; i < GS->handCount[p]; i++){
		cardNumToName(GS->hand[p][i], c);	//Converts card number to string
		printf( "%s, ", c);
		if(strcmp(c, "Council Room") == 0){
			cardStatus = 1;	//Card is present in hand
		}
	}

	/*Check if council room card is in hand*/
	if(cardStatus == 0){
		printf("\nTest PASSED, card is NOT present in player %d's hand\n\n", p);
	} else {
		printf("\nTest FAILED, card is present in player %d's hand\n\n", p);
	}

	printf("Testing for correct number of cards drawn...\n");
	/*Check current state player's handcount +4 cards after discard is 8 cards*/
	if(GS->handCount[p] == 8){
		printf("Test PASSED, Player %d drew +4 cards\n\n", p);
	} else {
		printf("Test FAILED, Player %d drew incorrect amount of cards\n\n", p);
	}

	printf("Testing for correct number of numBuys...\n");
	/*Check if numbuys is incremented*/
	if(GS->numBuys == 2){
		printf("Test PASSED, Player %d has +1 numBuys\n\n", p);
	} else {
		printf("Test FAILED, Player %d has incorrect number of numBuys\n\n", p);
	}

	printf("Checking if card is in played pile...\n");
	/*Check if card is in played pile*/
	if(GS->playedCards[p] == council_room){
		printf("Test PASSED, Council Room is in played pile\n\n");
	} else {
		printf("Test FAILED, Council Room is NOT in played pile\n\n");
	}

	return 0;

}
예제 #18
0
//Random test for adventurer
int main() {
	
	int i, j, acard, foundTreasure, totalCards, prevHandCount, prevDeckDiscardCount, playerTreasure, numFailed;
	struct gameState g;
	char cardName[MAX_STRING_LENGTH];
	
	//Create gameStates with random properties
	for (i = 0; i < NUMTESTS; i++) {
		
		CreateGameState(&g);
		
		/*
		-- Now we have everything setup, lets start testing!
		-- We will check for these conditions:
		--		- Handcount increases by number of treasure found
		--		- Deck + Discard count descreases by number of treasure found
		--		- Check that the cards in the hand contain the treasure found
		--
		*/
		
		foundTreasure = 0;
		totalCards = CountCards(&g);
		prevHandCount = g.handCount[0];
		prevDeckDiscardCount = g.deckCount[0] + g.discardCount[0];
		playerTreasure = CountTreasure(&g);
		for (j = 0; j < g.deckCount[0]; j++) {
			if (g.deck[0][j] == copper || g.deck[0][j] == silver || g.deck[0][j] == gold) {
				if (foundTreasure >= 2)
					break;
				foundTreasure++;
			}
		}
		for (j = 0; j < g.discardCount[0]; j++) {
			if (g.discard[0][j] == copper || g.discard[0][j] == silver || g.discard[0][j] == gold) {
				if (foundTreasure >= 2)
					break;
				foundTreasure++;
			}
		}

		playCard(0, 0, 0, 0, &g);
		
		if (g.handCount[0] != prevHandCount + foundTreasure - 1) {
			printf("Test %d:Incorrect hand count. %d treasure in player's deck. Handcount is %d but should be %d\n", i, foundTreasure, g.handCount[0], prevHandCount + foundTreasure - 1);
			numFailed++;
			if (foundTreasure = 0) {
				printHand2(g, 0);
			}
		}
		if (g.deckCount[0] + g.discardCount[0] != prevDeckDiscardCount - foundTreasure) {
			printf("Test %d:Incorrect deck and discard count. %d treasure in player's deck. Deck + discard count is %d but should be %d\n", i, foundTreasure, g.deckCount[0] + g.discardCount[0], prevDeckDiscardCount - foundTreasure);
			numFailed++;
		}
		if (foundTreasure == 2) {
			//Treasure cards are going to be in first and last indicies
			acard = g.hand[0][g.handCount[0] - 1];
			if (acard != copper && acard != silver && acard != gold) {
				strcpy(cardName,"");
				cardNumToName(acard, cardName);
				printf("Test %d:Incorrect cards at position %d. %d treasure in player's deck. Last card in hand should be %s, %s, or %s, is %s\n", i, g.handCount[0] - 1, foundTreasure, "copper", "silver", "gold", cardName);
				printHand2(g, 0);
				numFailed++;
			}
			acard = g.hand[0][0];
			if (acard != copper && acard != silver && acard != gold) {
				strcpy(cardName,"");
				cardNumToName(acard, cardName);
				printf("Test %d:Incorrect cards at position %d. %d treasure in player's deck. First card in hand should be %s, %s, or %s, but is %s\n", i, 0, foundTreasure, "copper", "silver", "gold", cardName);
				printHand2(g, 0);
				numFailed++;
			}
		}
		else if (foundTreasure == 1) {
			acard = g.hand[0][0];
			if (acard != copper && acard != silver && acard != gold) {
				strcpy(cardName,"");
				cardNumToName(acard, cardName);
				printf("Test %d:Incorrect cards at position %d. %d treasure in player's deck. First card in hand should be %s, %s, or %s, but is %s\n", i, 0, foundTreasure, "copper", "silver", "gold", cardName);
				printHand2(g, 0);
				numFailed++;
			}
		}
	}
	
	printf("%d of %d test were successful.\n", NUMTESTS - numFailed, NUMTESTS);
	
	return 0;
}
예제 #19
0
int main(int argc, char *argv[])
{
	struct gameState state;
	int k[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};
	
	int seed = rand() % 100;
	int player_num = rand() % 3 + 2;
	int i;
	char card_name[64];
	
	srand(time(0));

	printf("Starting to test complete dominion ......\n");
	printf("\n$$$$$ Starting to show entire process of playing this Dominion Game $$$$$\n\n");
	
	if(strcmp(argv[1], "--test") == 0)
	{
		printf("Numbers of players: %d\n", player_num);	
		
		for(i = 0; i < 10; i ++)
		{
			cardNumToName(k[i], card_name);
			printf("Kingdom Card %d: %d (%s)\n", i + 1, k[i], card_name);
		}
	}
	
	if(strcmp(argv[1], "--game") == 0)
	{
		printf("\nInitializing dominion ......\n\n");
		initializeGame(player_num, k, seed, &state);
			
		while(!isGameOver(&state))
		{
			int after_draw, after_buy, add_card;
			int choice = rand() % 3;
			int hand_count = state.handCount[state.whoseTurn];
			int card_draw;
								
			cardNumToName(hand_count, card_name);
				
			switch(choice)
			{
				case 0: 
					{
						card_draw = hand_count;
						cardNumToName(card_draw, card_name);
						after_draw = playCard(card_draw, 0, 0, 0, &state);					
						print_info(state);
					}
					break;
				case 1:
					{
						add_card = rand() % 20;
						after_buy = buyCard(add_card, &state);
						print_info(state);
					}
					break;
				case 2:
					{
						printf("It's turn to next Player %d\n", state.whoseTurn);
						endTurn(&state);
					}
					break;
				default:
					printf("!!!!! Choice Error !!!!!");
					exit(EXIT_FAILURE);
			}
				
			if(choice == 0 || choice == 1)
			{
				if(after_draw == -1)
					printf("Player %d is drawing card [%s]\n", state.whoseTurn, card_name);
				else
					printf("Turn to next player\n");
			}
		}
			
		print_info(state);
	}
	printf("Ending to test complete dominion ......\n");
	
	return EXIT_SUCCESS;
}
int main(int argc, char** argv){

  //srand(time(NULL));

  struct gameState *p = newGame();

	int a, b, c, d, gs, k[10];
  int ActCardVal, numPlayers, cardPos;
	char *cardTitle;
  char card_string[32];


  for (a=0 ; a < MAX_TESTS ; a++){

      printf("\n************************** STARTING GAME %i **************************\n\n", a+1);

      // RANDOMIZE NUMBER OF PLAYERS ------------------------
      numPlayers = (rand() % 3) + 2; // 2-4 Players


      // RANDOMIZE KINGDOM CARDS ----------------------------
      printf("KingdomCards: \n");
      for (b=0 ; b<10 ; b++){
        ActCardVal = (rand()%20)+7;
        c=0;
        while (c<b){ // check previous actions cards
          if (k[c]==ActCardVal){
            ActCardVal = (rand()%20)+7;
            c=0;
          }
          c++;
        }
        k[b]=ActCardVal;
        cardNumToName(k[b],card_string);
        printf( "%d --> %s (%i) \n" , b+1 , card_string, ActCardVal);
      }
      printf("\n");


      // INITIALIZE GAME ------------------------------------
      gs = initializeGame(numPlayers, k, 2, p);

      int money = 0;
      int smithyPos = -1;
      int adventurerPos = -1;
      int i=0;

      int numSmithies = 0;
      int numAdventurers = 0;

      while (!isGameOver(p))
		{
			printf("------------------------------------------\n");
			money = 0;
			smithyPos = -1;
			adventurerPos = -1;
			for (i = 0; i < numHandCards(p); i++)
			{
				if (handCard(i, p) == copper)
					money++;
				else if (handCard(i, p) == silver)
					money += 2;
				else if (handCard(i, p) == gold)
					money += 3;
				else if (handCard(i, p) == smithy)
					smithyPos = i;
				else if (handCard(i, p) == adventurer)
					adventurerPos = i;
			}

			if ((rand() % 5) == 0)		
			{
				if (smithyPos != -1)
				{
					printf("Player %i: smithy (%i) played from position %i\n", whoseTurn(p), ActCardVal, smithyPos);
					playCard(smithyPos, -1, -1, -1, p);
					if (ActCardVal < 0 || ActCardVal > 26) {
						printf("--> Card play failed\n");
					} else {
            printf("--> Card play successful\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("Player %i: bought province\n", whoseTurn(p));
					buyCard(province, p);
				}
				else if (money >= 6)
				{
					printf("Player %i: bought gold\n", whoseTurn(p));
					buyCard(gold, p);
				}
				else if ((money >= 4) && (numSmithies < 2))
				{
					printf("Player %i: bought smithy\n", whoseTurn(p));
					buyCard(smithy, p);
					numSmithies++;
				}
				else if (money >= 3)
				{
					printf("Player %i: bought silver\n", whoseTurn(p));
					buyCard(silver, p);
				}

				printf("Player %i: end turn\n", whoseTurn(p));
				endTurn(p);
			}
			else if ((rand() % 5) == 1)
			{
				if (adventurerPos != -1)
				{
					printf("Player %i: adventurer (%i) played from position %i\n", whoseTurn(p), ActCardVal, adventurerPos);
					gs = playCard(adventurerPos, -1, -1, -1, p);
					if (ActCardVal < 0 || ActCardVal > 26)
					{
						printf("--> Card play failed!\n");
					} else {
            printf("--> Card play successful\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("Player %i: bought province\n", whoseTurn(p));
					buyCard(province, p);
				}
				else if ((money >= 6) && (numAdventurers < 2))
				{
					printf("Player %i: bought adventurer\n", whoseTurn(p));
					buyCard(adventurer, p);
					numAdventurers++;
				}
				else if (money >= 6)
				{
					printf("Player %i: bought gold\n", whoseTurn(p));
					buyCard(gold, p);
				}
				else if (money >= 3)
				{
					printf("Player %i: bought silver\n", whoseTurn(p));
					buyCard(silver, p);
				}
				printf("Player %i: endTurn\n", whoseTurn(p));
				endTurn(p);
			}
			else
			{
				cardPos = rand() % numHandCards(p);
				ActCardVal = p->hand[whoseTurn(p)][cardPos];
				cardTitle = print_card_name(ActCardVal);
				printf("Player %i: %s (%i) played from %i\n", whoseTurn(p), cardTitle, ActCardVal, cardPos);
				gs = playCard(ActCardVal, rand() % numHandCards(p), rand() % numHandCards(p), rand() % numHandCards(p), p);
				if (ActCardVal < 0 || ActCardVal > 26)
				{
					printf("--> Card play failed!\n");
				} else {
          printf("--> Card play successful\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("Player %i: bought province\n", whoseTurn(p));
					buyCard(province, p);
				}
				else if ((money >= 6) && (numAdventurers < 2))
				{
					printf("Player %i: bought adventurer\n", whoseTurn(p));
					buyCard(adventurer, p);
					numAdventurers++;
				}
				else if (money >= 6)
				{
					printf("Player %i: bought gold\n", whoseTurn(p));
					buyCard(gold, p);
				}
				else if (money >= 3)
				{
					printf("Player %i: bought silver\n", whoseTurn(p));
					buyCard(silver, p);
				}
				printf("Player %i: endTurn\n", whoseTurn(p));
				endTurn(p);

			}
		}

    printf ("\n###################\n# FINAL SCORE \n");
    int tempScore;
    for (d=0 ; d<numPlayers ; d++){
      tempScore = scoreFor(d,p);
      printf("# Player %i: %i\n", d,tempScore);
    }
    printf ("###################\n\n");
	}

	return 0;

}
예제 #21
0
int main(int argc, char* argv[]) {
		char *add  = "add";
	char *buyC = "buy";
	char *endT = "end";
	char *exit = "exit";
	char *help = "help";
	char *init = "init";
	char *numH = "num";
	char *play = "play";
	char *resign  = "resi";
	char *show = "show";
	char *stat = "stat";
	char *supply = "supp";
	char *whos = "whos";
		
	char command[MAX_STRING_LENGTH];
	char line[MAX_STRING_LENGTH];
	char cardName[MAX_STRING_LENGTH];

	//Array to hold bot presence 
	int isBot[MAX_PLAYERS] = { 0, 0, 0, 0};

	int players[MAX_PLAYERS];
	int playerNum;
	int outcome;
	int currentPlayer;
	int gameOver = FALSE;
	int gameStarted = FALSE;
	int turnNum = 0;

	int randomSeed = atoi(argv[1]);

	//Default cards, as defined in playDom
	int kCards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};

	gameState g;
	gameState * game = &g;

	memset(game,0,sizeof(gameState));
		
	if(argc != 2){
		printf("Usage: player [integer random number seed]\n");
		return EXIT_SUCCESS;
	}

	if(randomSeed <= 0){
		printf("Usage: player [integer random number seed]\n");
		return EXIT_SUCCESS;
	}	
	
	initializeGame(2,kCards,randomSeed,game);

	printf("Please enter a command or \"help\" for commands\n");
	

	while(TRUE) {
		int arg0 = UNUSED;
		int arg1 = UNUSED;
		int arg2 = UNUSED;
		int arg3 = UNUSED;

		outcome = FAILURE;
		strcpy(line,"");
		strcpy(command,"");
		strcpy(cardName,"");
		
		currentPlayer = game->whoseTurn;
		
		//If you are getting a seg fault comment this if block out
		gameOver = isGameOver(game); 		
		if(gameStarted == TRUE && gameOver == TRUE){
			printScores(game);
			getWinners(players, game);
			printf("After %d turns, the winner(s) are:\n", turnNum);
			for(playerNum = 0; playerNum < game->numPlayers; playerNum++){
				if(players[playerNum] == WINNER) printf("Player %d\n", playerNum);
			}
		for(playerNum = 0; playerNum < game->numPlayers; playerNum++){
				printHand(playerNum, game);
				printPlayed(playerNum, game);
				printDiscard(playerNum, game);
				printDeck(playerNum, game);
			}
			
			break; //Exit out of the game/while loop
		}         
		

		if(isBot[currentPlayer] == TRUE) {
				executeBotTurn(currentPlayer, &turnNum, game);
				continue;
		}
		
		printf("$ ");
		fgets(line, MAX_STRING_LENGTH, stdin);
		sscanf(line, "%s %d %d %d %d", command, &arg0, &arg1, &arg2, &arg3);


		if(COMPARE(command, add) == 0) {
			outcome = addCardToHand(currentPlayer, arg0, game);
			cardNumToName(arg0, cardName);
			printf("Player %d adds %s to their hand\n\n", currentPlayer, cardName);
		} else
		if(COMPARE(command, buyC) == 0) {
			outcome = buyCard(arg0, game);
			cardNumToName(arg0, cardName);
			if(outcome == SUCCESS){
				printf("Player %d buys card %d, %s\n\n", currentPlayer, arg0, cardName);
			} else {
				printf("Player %d cannot buy card %d, %s\n\n", currentPlayer, arg0, cardName);
			}
		} else
		if(COMPARE(command, endT) == 0) {
			if(gameStarted == TRUE) {
				if(currentPlayer == (game->numPlayers -1)) turnNum++;
				endTurn(game);
				currentPlayer = game->whoseTurn;
				printf("Player %d's turn number %d\n\n", currentPlayer, turnNum);
			}

		} else			
		if(COMPARE(command, exit) == 0) {
			break;
		} else
		if(COMPARE(command, help) == 0) {
			printHelp();
		} else
		if(COMPARE(command, init) == 0) {
			int numHuman = arg0 - arg1;
			for(playerNum = numHuman; playerNum < arg0; playerNum++) {
				isBot[playerNum] = TRUE;
			}			
	//		selectKingdomCards(randomSeed, kCards);  //Comment this out to use the default card set defined in playDom.
			outcome = initializeGame(arg0, kCards, randomSeed, game);
			printf("\n");
			if(outcome == SUCCESS){
				gameStarted = TRUE;
				currentPlayer = game->whoseTurn;
				printf("Player %d's turn number %d\n\n", currentPlayer, turnNum);
			}

		} else
		if(COMPARE(command, numH) == 0) {
			int numCards = numHandCards(game);
			printf("There are %d cards in your hand.\n", numCards);
		} else
		if(COMPARE(command, play) == 0) {
			int card = handCard(arg0,game);
			outcome = playCard(arg0, arg1, arg2, arg3, game);
			cardNumToName(card, cardName);
			if(outcome == SUCCESS){
				printf("Player %d plays %s\n\n", currentPlayer, cardName);
			} else {
				printf("Player %d cannot play card %d\n\n", currentPlayer, arg0);
			}

		} else
		if(COMPARE(command, resign) == 0) {
			endTurn(game);
			printScores(game);
			break;
		} else
		if(COMPARE(command, show) == 0) {
			if(gameStarted == FALSE) continue;
			printHand(currentPlayer, game);
			printPlayed(currentPlayer, game);
			//printDiscard(currentPlayer, game);
			//printDeck(currentPlayer, game);
		} else
		if(COMPARE(command, stat) == 0) {
			if(gameStarted == FALSE) continue;
			printState(game);
		} else
		if(COMPARE(command, supply) == 0) {
			printSupply(game);
		} else
		if(COMPARE(command, whos) == 0) {
			int playerNum =	game->whoseTurn;
			printf("Player %d's turn\n", playerNum);
		} 
    	}
	
    	return EXIT_SUCCESS;

}
예제 #22
0
int main() {

    int mineCardLoc;
    int i;

    //initialize the game
    struct gameState G;
    struct gameState D;

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

    initializeGame(2, k, 2, &G);

    //copper, silver, gold, estate (to check bounds), and minecard to hand.
    G.hand[0][0] = copper;
    G.hand[0][1] = silver;
    G.hand[0][2] = gold;
    G.hand[0][3] = estate;
    G.hand[0][4] = mine;

    //save default
    D = G;

    // check state of game before calling function
    // printState(&G);
    //  printSupply(&G);
    // // printScores(&G);
    // printHand(0, &G);
    // // printPlayed(0, &G);
    // printDeck(0, &G);
    // printf ("Number of cards in hand %i \n", numHandCards(&G));


    printf("* * * * * * * * * * * * * * * * Testing mineCard card* * * * * * * * * * * * * * * * \n");

    //keeps track of the mine card's location.
    mineCardLoc = 4;
    // loop through each type of coin and swap it for each available coin.
    int coin;
    char name[32];

    for (i = 0; i < 3; i++)
    {
        for (coin = copper; coin < gold + 1; coin++)
        {
            //reset
            G = D;
            cardNumToName(coin, name);
            //get cost of coin to be swapped



            printf ("Testing swapping position %i for %s \n", i, name);
            printf ("code returned: %i \n", playCard(mineCardLoc, i, coin, -1, &G));
            printf ("cost of choice1 is %i \n", getCardCost(G.hand[0][i]));

            //verify that you can only play swap affordable cards
            if (getCardCost(G.hand[0][i]) + 3 > getCardCost(coin))
            {
                int playedIndex;
                int foundMine = 0;
                int foundCoin = 0;
                printf ("affordable \n");
                //assert (G.hand[0][i] == coin);
                printf ("################################################### \n Error: Expected coin in hand location %i. \n ################################################### \n", i);

                //verify that mine card is out of hand
                //assert (G.hand[0][mineCardLoc] != mine);
                printf ("################################################### \n Error: expected non-mine card in hand location %i. \n ################################################### \n", mineCardLoc);

                //verify that the minecard is in the played
                for (playedIndex = 0; playedIndex < G.playedCardCount; playedIndex++)
                {
                    if (G.playedCards[playedIndex] == mine)
                    foundMine = 1;
                    if (G.playedCards[playedIndex] == mine)
                    foundCoin = 1;
                }
                // assert (foundMine == 1);
                printf ("################################################### \n Error: expected mine card in played area. \n ################################################### \n");

                //assert (foundCoin == 1);
                printf ("################################################### \n Error: expected a coin card in played area. \n ################################################### \n");


            }
            else
            {
                int playedIndex;
                int foundMine = 0;
                int foundCoin = 0;

                printf ("unaffordable \n");
                assert (G.hand[0][i] != coin);
                //verify that mine card is still in hand
                assert (G.hand[0][mineCardLoc] == mine);

                //verify that the minecard hasn't been played
                for (playedIndex = 0; playedIndex < G.playedCardCount; playedIndex++)
                {
                    if (G.playedCards[playedIndex] == mine)
                    foundMine = 1;
                    if (G.playedCards[playedIndex] == mine)
                    foundCoin = 1;
                }
                assert (foundMine == 0);
                assert (foundCoin == 0);

            }
        }
    }

    //Try playing illegal choice1 for coin
    G = D;
    cardNumToName(copper, name);
    assert (playCard(mineCardLoc, 3, coin, -1, &G) == -1);

    G = D;
    //Try playing illegal choice2 for treasure
    // assert (playCard(mineCardLoc, 0, estate, -1, &G) == -1);
    printf ("################################################### \n Error: allows user to choose a non treasure card to buy. \n ################################################### \n");

    printf("All tests passed!\n");

    
    
    return 0;
}
int main(int argc, char* argv[]) {
	int test;
	int seed = atoi(argv[1]);
	
	//Create gameStates with random properties
	for (test = 0; test < NUMTESTS; test++) {
		
		int i, acard, init, command, numPlayers, playerNum, outcome, currentPlayer, turnNum;
		int kCards[10];
		struct gameState * g;
		
		char line[MAX_STRING_LENGTH];
		char cardName[MAX_STRING_LENGTH];
		int players[MAX_PLAYERS];
		
		int gameOver = FALSE;
		int arg0 = UNUSED;
		int arg1 = UNUSED;
		int arg2 = UNUSED;
		int arg3 = UNUSED;
		
		printf("------===================******* Game %d of %d ********==================--------\n", test + 1, NUMTESTS);
		
		//Pick random cards
		for (i = 0; i < 10; i++) {
			acard = floor(Random() * 20 + 7);
			if (ValInArr(acard, kCards, 10) || acard == feast)
				i--;
			else
				kCards[i] = acard;
		}
		kCards[6] = mine; //force choose mine
		printf("Cards chosen for game %d:\n", test + 1);
		for (i = 0; i < 10; i++) {
			strcpy(cardName,"");
			cardNumToName(kCards[i], cardName);
			printf("  (%d) - %s\n", kCards[i], cardName);
		}
		
		//Create game state
		g = (struct gameState*)malloc(sizeof(struct gameState));
		numPlayers = floor(Random() * (2 + 1) + 2);
		init = initializeGame(numPlayers, kCards, seed, g);
		assert(init > -1);
		
		
		currentPlayer = whoseTurn(g);
		PrintGameInfo(g, turnNum);
		PrintTurnInfo(g, turnNum);
		while(1) {
			
			outcome = FAILURE;
			strcpy(line,"");
			strcpy(cardName,"");
			
			gameOver = isGameOver(g); 		
			if(gameOver == TRUE)
				break; //Exit out of the game
			
			//Choose action for turn
			command = GetCommand();
			
			if (command == cmdPlay) {
				arg0 = floor(Random() * g->handCount[currentPlayer]);
				arg1 = floor(Random() * (treasure_map + 1));
				arg2 = floor(Random() * (treasure_map + 1));
				arg3 = floor(Random() * (1 + 1));
				strcpy(cardName,"");
			    cardNumToName(g->hand[currentPlayer][arg0], cardName);
				outcome = playCard(arg0, arg1, arg2, arg3, g);
				if (outcome == SUCCESS){
					printf("-Player %d plays %s...args: %d, %d, %d, %d\n\n", currentPlayer, cardName, arg0, arg1, arg2, arg3);
					PrintTurnInfo(g, turnNum);
				} else {
					printf("-Player %d cannot play card %s...args: %d, %d, %d, %d\n\n", currentPlayer, cardName, arg0, arg1, arg2, arg3);
					PrintTurnInfo(g, turnNum);
				}
			} else
			if (command == cmdBuy) {
				arg0 = floor(Random() * (treasure_map + 1));
				outcome = buyCard(arg0, g);
				strcpy(cardName,"");
			    cardNumToName(arg0, cardName);
				if(outcome == SUCCESS){
					printf("-Player %d buys card %d: %s...args: %d, %d, %d, %d\n\n", currentPlayer, arg0, cardName, arg0, arg1, arg2, arg3);
					PrintTurnInfo(g, turnNum);
				} else {
					printf("-Player %d cannot buy card %d: %s...args: %d, %d, %d, %d\n\n", currentPlayer, arg0, cardName, arg0, arg1, arg2, arg3);
					PrintTurnInfo(g, turnNum);
				}
			} else
			if (command == cmdEnd) {
				printf("-Player %d ends turn %d...args: %d, %d, %d, %d\n\n", whoseTurn(g), turnNum, arg0, arg1, arg2, arg3);
				turnNum++;
				endTurn(g);
				currentPlayer = whoseTurn(g);
				PrintGameInfo(g, turnNum);
			}
		}
		
		printScores(g);
		getWinners(players, g);
		printf("After %d turns, the winner(s) are:\n", turnNum);
		for(playerNum = 0; playerNum < g->numPlayers; playerNum++)
			if(players[playerNum] == WINNER) printf("Player %d\n", playerNum);
		PrintGameInfo(g, turnNum);
		free(g);
		printf("Game %d of %d complete\n", test + 1, NUMTESTS);
	}
	
	printf("All games complete\n\n");
	//printf("%d of %d test were successful.\n", NUMTESTS * (NUMPLAYERS-1) - numFailed, NUMTESTS * (NUMPLAYERS-1));
	
	return 0;
}
예제 #24
0
int main(int argc, char *argv[]) {
    
    // initialize variables
    int i = 0, j = 0, n = 0;
    int numPlayers = 0;
    int kingdomCards[10] = {8, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    int card = 0;
    char *cardName = (char*)malloc(sizeof(char) * 20);
    int check = 0;
    int seed = 0;
    int result = 1;
    int winners[4];
    
    // do this so I can just put "state" in method calls, much cleaner
    struct gameState G;
    struct gameState *state = &G;
    
    // get seed
    if (argc != 2) {
        printf("NEED ONLY A SEED");
        return 1;
    }
    
    printf("***Initializing Game ***\n");
    
    // seed random
    seed = atoi(argv[1]);
    srand(seed);
    
    // get number of players (from 2 - 4)
    numPlayers = (rand() % 3) + 2;
    
    // get kingdom cards
    for (i = 0; i < 10; i++) {
        card = (rand() % 20) + 7;
        
        // check if card already in deck
        for (j = 0; j < i; j++) {
            if (card == kingdomCards[j]) {
                check = 1;
            } else {
                check = 0;
            }
            
            // if card is in deck @ j, decrement i to choose new card, break out of j loop
            if (check) {
                i--;
                break;
            } else {
                kingdomCards[i] = card;
                char *handCard = (char*)malloc(sizeof(char) * 20);
                cardNumToName(card, cardName);
                cardNumToName(kingdomCards[i], handCard);
                if (i == 0) { printf("Card: %s\nHand: %s\n", cardName, handCard); }
            }
        }
    }
    
    // initialize dominion.c
    result = initializeGame(numPlayers, kingdomCards, seed, state);
    if (result != 0) {
        printf("Game failed to initialize\n");
        return 2;
    }
    
    // print initialized values
    printf("Initialized game with values:\n");
    printf("Players: %i\n", numPlayers);
    printf("Cards: ");
    for (i = 0; i < 10; i++) {
        cardNumToName(kingdomCards[i], cardName);
        if (i == 0) {
            printf("%s", cardName);
        } else {
            printf(", %s", cardName);
        }
    }
    printf("\n");
    
    // start playing game
    printf("***Starting Game***\n");
    
    while (!isGameOver(state)) {
        int currentCard = 0;
        int actualCard = 0;
        int playersTurn = whoseTurn(state);
        printf("Player %i's turn\n", playersTurn + 1);
        
        //start actions
        printf("*Action Phase*\n");
        for (i = 0; i < numHandCards(state); i++) {
            // make sure card is a kingdom card
            if (handCard(i, state) >= adventurer && handCard(i, state) <= treasure_map && handCard(i, state) != feast && handCard(i, state) != tribute) {
                currentCard = i;
                actualCard = handCard(currentCard, state);
                cardNumToName(actualCard, cardName);
                printf("Card: %s\n", cardName);
                break;
            }
        }
        
        // perform actions
        printf("Actions left: %i\n", state->numActions);
        while (state->numActions > 0 && currentCard != 0) {
            cardNumToName(actualCard, cardName);
            
            // select random cards, better than static
            int one = rand() % state->handCount[playersTurn] + 1;
            int two = rand() % state->handCount[playersTurn] + 1;
            int three = rand() % state->handCount[playersTurn] + 1;
            result = playCard(currentCard, one, two, three, state);
            if (result == -1) {
                printf("Error: Could not play %s\n", cardName);
                discardCard(0, playersTurn, state, 0);
                break;
            } else {
                printf("Played: %s\n", cardName);
            }
            
            if (state->numActions == 0) {
                printf("Out of actions! Move to buy phase\n");
                break;
            }
            
            for (i = currentCard; i < numHandCards(state); i++) {
                if (handCard(i, state) >= adventurer && handCard(i, state) <= treasure_map && handCard(i, state) != feast && handCard(i, state) != tribute) {
                    currentCard = i;
                    actualCard = handCard(currentCard, state);
                    cardNumToName(actualCard, cardName);
                    printf("Other Card: %s\n", cardName);
                    break;
                } else {
                    currentCard = 0;
                }
            }
        }
        
        //start buy phase
        printf("*Buy Phase*\n");
        
        // figure out how many coins the user has
        int coins = 0;
        for (i = 0; i < numHandCards(state); i++) {
            if (handCard(i, state) == copper) {
                coins += 1;
            } else if (handCard(i, state) == silver) {
                coins += 2;
            } else if (handCard(i, state) == gold) {
                coins += 3;
            }
        }
        state->coins = coins;
        
        printf("Number of buys: %i\n", state->numBuys);
        
        // perform random buys
        int m = 0;
        while (state->numBuys > 0) {
            do {
                int available = 0;
                while (!available) {
                    // buy random card from kingdom cards
                    int randCard = rand() % 28;
                    // if rand card is a global kingdom card, check if available this round
                    if (randCard >= adventurer) {
                        for (i = 0; i < 10; i++) {
                            if (randCard == kingdomCards[i]) {
                                available = 1;
                                currentCard = randCard;
                                break;
                            }
                        }
                        // if not king card, try to buy
                    } else {
                        available = 1;
                        currentCard = randCard;
                    }
                }
                
                // Move on to buying specific items if taking too long
                m++;
                if (m == 20) {
                    currentCard = gold;
                } else if (m == 21) {
                    currentCard = silver;
                } else if (m > 21) {
                    currentCard = copper;
                }
                
            } while (buyCard(currentCard, state) != 0);
            
            cardNumToName(currentCard, cardName);
            printf("Bought %s\n", cardName);
        }
        
        printf("Out of buys! Next player's turn\n\n");
        endTurn(state);
        
        // stop game if each player has had 100 turns, no winners
        n++;
        if (n > 200) {
            break;
        }
    }
    
    getWinners(winners, state);
    for (i = 0; i < numPlayers; i++) {
        if (winners[i] == 1) {
            printf("Player %i wins!\nScore: %i\n", i + 1, scoreFor(i, state));
            break;
        }
    }
    
    printf("\n****Game Ended****\n");
    
    return 0;
}
int main (int argc, char** argv) {

	
	
	// Seed system with input
	int seed = atoi(argv[1]);
	srand(seed);
	
	struct gameState G;
	struct gameState *p = &G;
	
	struct gameState F;
	struct gameState *startState = &F;
	
	struct gameState T;
	struct gameState *tempState = &T;
	
	
	char string[20];

	
	
  
	for(int i=0; i<=MAX_TESTS-1; i++){
		
		printf ("Starting game # %d\n", i+1);
		
		// Random # Players
		int numPlayers = rand()%3+2;
		//printf("players: %d \n", numPlayers);
		
		// Select Random Cards
		int k[10];
		int first = rand()%8 + 8;
		for (int j = 0; j < 10; j++){ k[j] = first+j; } 
		//Print Cards
		for (int j = 0; j < 10; j++) {
		cardNumToName(k[j], string);
		//printf("card at position %d is %s\n", j, string);
		}
		
		
		int initGame = initializeGame(numPlayers, k, rand(), p);
		assert(initGame == 0);
		
		
		F = G;
		
		printf("\n\n Initalization Test:\n");
		CardCons(p,startState);
		
		
		
		int treasure = 0;
		int buys = -1;
		int cheap = 99999;
		int v=0;int w=0;int x=0;int y=0;int z=0;
	
		for (z = 0; z < 10; z++) {
			if (cheap > getCost(k[z]))
			cheap = getCost(k[z]);
		}
		
		while (!isGameOver(p)) {


//printf("\nCheck1:\n");
	T=G;
			for (y = 0; y < numHandCards(p); y++) {
				if ((handCard(y, p) != gold) && (handCard(y, p) != silver) && (handCard(y, p) != copper) && (handCard(y, p) != estate) && (handCard(y, p) != province)) {
					cardNumToName(handCard(y, p), string);
				//	printf("card: %s \n",string);
					playCard(y, -1, -1, -1, p);
					cardNumToName(handCard(y, p), string);
					break;
				}
			}
		//printf("\n\n Temp 1 Test:\n");
		if(CardCons(p,tempState)){;}
		else{return 1;}
//printf("\nCheck2:\n");
			treasure = 0;
			x = 0;
		T=G;	
			//Treasure Count
	      	while (x < numHandCards(p)) {
				if (handCard(x, p) == copper){
					playCard(x, -1, -1, -1, p);
					treasure++;
				}
				else if (handCard(x, p) == silver){
					playCard(x, -1, -1, -1, p);
					treasure += 2;
				}
				else if (handCard(x, p) == gold){
					playCard(x, -1, -1, -1, p);
					treasure += 3;
				}
			x++;
			}
		printf("\n\n Temp 2 Test:\n");
		if(CardCons(p,tempState)){;}
		else{return 1;}
		
	//	    printf("Treasure: %d \n", treasure);

			buys = -1;
//printf("\nCheck3:\n");
	T=G;
			if (treasure >= 8) {
	//			printf("province.\n\n");
				buyCard(province, p);
			}
			else if (treasure >= 6) {
	//			printf("gold.\n\n");
				buyCard(gold, p);
			}
			else if (treasure >= 3 && (rand()%2 == 0)) {
	//			printf("silver.\n\n");
				buyCard(silver, p);
			}
			else if (treasure < cheap) {
		//		printf("failure to buy \n");
		//		printf("\n");
			}

			else {
				while(buys == -1) {
					for (w = 0; w < 10; w++) {
						buys = buyCard(k[w], p);
						if (buys != -1) {
							break;
						}
					}
					break;
				}
			}
			//printf("\n\n Temp 3 Test:\n");
		CardCons(p,tempState);		
			
			//printf("Next");
			
			endTurn(p);


		}

				
	int xx = sizeof(p->supplyCount);
	//printf("\n\n FUUUUUUUUUK: %d \n\n\n",xx);
		
		//printf ("Game Over\n\n");
		//printf("Game number %d\n Score 1: %d Score 2: %d\n\n", i -1, scoreFor(0, p), scoreFor(1, p));
		//printf("\n\n\n\n");
		

	}
	return 20;
}
예제 #26
0
int main(){
    int seed = 1000;
    int numPlayer = 2;
    int p, r, score;
    int errors;
    int numOfCards, handIndex;
    int expected, vType;
    int discardIndex, deckIndex;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    //this will hold some of the victory cards. The numbers are taken from 
    //the enumeration in dominion.h
    //curse and gardens are not included since they are special cases
    //1=estate, 2=duchy, 3=province, 16= greathall
    int victoryCardsArr[4] = {1, 2, 3, 16}; 
    char cardName[4][20] = {"estate", "duchy", "province", "great hall"}; 
    struct gameState G;
    
    int maxHandCount = 8;
    printf("----------------- Testing scoreFor() ----------------\n");
    printf("\n");
    
//    printf("Test players hand\n");
    
    //loop through the victory cards in the victoryCardsArr
    //specifically estate, duchy, province, great hall
    for(vType=0; vType < 4; vType++){
        //loop over the players
        for (p = 0; p <numPlayer; p++){
            //with two players there are 8 of each card
            for(numOfCards = 0; numOfCards <= 8; numOfCards++){
 //               printf("Test player %d Hand with %d %s victory card(s).\n", p, numOfCards, cardName[vType]);

                memset(&G, 23, sizeof(struct gameState)); // clear the game state  

                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game

                G.handCount[p] = numOfCards;        //set the number of cards on hand
                //G.discardCount[p] = numOfCards;     //set the number of card in discard
                //G.deckCount[p] = numOfCards;             //set the number of card in the deck
                
                //set all the cards in players hand to the appropriate card
                int cardNum;
                for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
                    G.hand[p][cardNum] = victoryCardsArr[vType]; 
                    //G.discard[p][cardNum] = estate;     
                    //G.deck[p][cardNum] = estate;    
                }

                int handCount = G.handCount[p];  //get current num of cards in hand
 #if (NOISY_TEST == 1)
                printf("HandCount is %d\n", handCount);
                
                //print players hand for error checking. 
                printf("Player %d's hand:\n", p);
                if(handCount > 0) printf("#  Card\n");
                for(handIndex = 0; handIndex < handCount; handIndex++) {
                    int card = G.hand[p][handIndex];
                    char name[MAX_STRING_LENGTH];
                    cardNumToName(card, name);
                    printf("%-2d %-13s\n", handIndex, name);
                }
                printf("\n");
 #endif               
                
                score = scoreFor(p, &G);   //call scoreFor
                //find the expected score accourding to the card
                if(vType == 0)
                    {expected = numOfCards * 1;}    //estate
                if(vType == 1)
                    {expected = numOfCards * 3;}    //duchy
                if(vType == 2)
                    {expected = numOfCards * 6;}    //province
                if(vType == 3)
                    {expected = numOfCards * 1;}   //great hall
                 

                if(score != expected){//check if score is correct
                    printf("****FAIL Hand score = %d, expected = %d\n", score, expected);
                    errors++;
                }  
#if (NOISY_TEST == 1)
                else{
                    printf("PASS Hand score = %d, expected = %d\n", score, expected);}
#endif                
            }
        }
        
    }
    
    
//    printf("Testing Discard Deck\n");
    
    //loop through the victory cards in the victoryCardsArr
    //specifically estate, duchy, province, great hall
    for(vType = 0; vType < 4; vType++){
        //loop over the players
        for (p = 0; p < numPlayer; p++){
            //with two players there are 8 of each card
            for(numOfCards = 0; numOfCards <= 8; numOfCards++){
  //              printf("Test player %d Discard with %d %s victory card(s).\n", p, numOfCards, cardName[vType]);

                memset(&G, 23, sizeof(struct gameState)); // clear the game state  

                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game

                //G.handCount[p] = numOfCards;        //set the number of cards on hand
                G.discardCount[p] = numOfCards;     //set the number of card in discard
                //G.deckCount[p] = numOfCards;             //set the number of card in the deck
                
                //set all the cards in players hand to the appropriate card
                //fill deck and hand with copper so there are no random victory
                //cards inserted. 
                int cardNum;
                for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
                    G.hand[p][cardNum] = copper; 
                    G.discard[p][cardNum] = victoryCardsArr[vType];     
                    G.deck[p][cardNum] = copper;    
                }

                int discardCount = G.discardCount[p];  //get current num of cards in hand
#if (NOISY_TEST == 1)
                printf("DiscardCount is %d\n", discardCount);
                
                //print players discard for error checking. 
                printf("Player %d's discard hand:\n", p);
                if(discardCount > 0) printf("#  Card\n");
                for(discardIndex = 0; discardIndex < discardCount; discardIndex++) {
                    int card = G.discard[p][discardIndex];
                    char name[MAX_STRING_LENGTH];
                    cardNumToName(card, name);
                    printf("%-2d %-13s\n", discardIndex, name);
                }
                printf("\n");
#endif                    
                
                score = scoreFor(p, &G);   //call scoreFor
                //find the expected score accourding to the card
                if(vType == 0)
                    {expected = numOfCards * 1;}    //estate
                if(vType == 1)
                    {expected = numOfCards * 3;}    //duchy
                if(vType == 2)
                    {expected = numOfCards * 6;}    //province
                if(vType == 3)
                    {expected = numOfCards * 1;}   //great hall
                 

                if(score != expected){//check if score is correct
                    printf("****FAIL Discard score = %d, expected = %d\n", score, expected); 
                    errors++;
                }  
#if (NOISY_TEST == 1)   
                else{
                    printf("PASS Discard score = %d, expected = %d\n", score, expected);}
#endif
            }
        }
        
    }
    
    
//     printf("Testing Deck\n");
    
    //loop through the victory cards in the victoryCardsArr
    //specifically estate, duchy, province, great hall
    for(vType = 0; vType < 4; vType++){
        //loop over the players
        for (p = 0; p < numPlayer; p++){
            //with two players there are 8 of each card
            for(numOfCards = 0; numOfCards <= 8; numOfCards++){
//                printf("Test player %d Deck with %d %s victory card(s).\n", p, numOfCards, cardName[vType]);

                memset(&G, 23, sizeof(struct gameState)); // clear the game state  

                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game

                //G.handCount[p] = numOfCards;        //set the number of cards on hand
                //G.discardCount[p] = numOfCards;     //set the number of card in discard
                G.deckCount[p] = numOfCards;             //set the number of card in the deck
                
                //set all the cards in players hand to the appropriate card
                //fill discard and hand with copper so there are no random victory
                //cards inserted. 
                int cardNum;
                for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
                    G.hand[p][cardNum] = copper; 
                    G.discard[p][cardNum] = copper;    
                    G.deck[p][cardNum] = victoryCardsArr[vType];    
                }

                int deckCount = G.deckCount[p];  //get current num of cards in hand
 #if (NOISY_TEST == 1)
                printf("DeckCount is %d\n", deckCount);
                
                //print players deck for error checking. 
                printf("Player %d's deck:\n", p);
                if(deckCount > 0) printf("#  Card\n");
                for(deckIndex = 0; deckIndex < deckCount; deckIndex++) {
                    int card = G.deck[p][deckIndex];
                    char name[MAX_STRING_LENGTH];
                    cardNumToName(card, name);
                    printf("%-2d %-13s\n", deckIndex, name);
                }
                printf("\n");
 #endif                   
                
                score = scoreFor(p, &G);   //call scoreFor
                //find the expected score accourding to the card
                if(vType == 0)
                    {expected = numOfCards * 1;}    //estate
                if(vType == 1)
                    {expected = numOfCards * 3;}    //duchy
                if(vType == 2)
                    {expected = numOfCards * 6;}    //province
                if(vType == 3)
                    {expected = numOfCards * 1;}   //great hall
                 

                if(score != expected){//check if score is correct
                    printf("****FAIL Deck score = %d, expected = %d\n", score, expected); 
                    errors++;
                }  
#if (NOISY_TEST == 1) 
                else{
                    printf("PASS Deck score = %d, expected = %d\n", score, expected);}
#endif
            }
        }
        
    }
    
 //   printf("Testing for curse victory card\n");
    for (p = 0; p < numPlayer; p++){
      
      for(numOfCards = 0; numOfCards <= 8; numOfCards++){
        memset(&G, 23, sizeof(struct gameState)); // clear the game state  
        r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
         
        G.handCount[p] = numOfCards;        //set the number of cards on hand
        G.discardCount[p] = numOfCards;     //set the number of card in discard
        G.deckCount[p] = numOfCards;             //set the number of card in the deck

        //set all the cards in players hand to the appropriate card
        int cardNum;
        for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
            G.hand[p][cardNum] = curse; 
            G.discard[p][cardNum] = copper;     
            G.deck[p][cardNum] = copper;    
        }
  //      printf("Test player %d Deck with %d curse card(s).\n", p, numOfCards);   
        int handCount = G.handCount[p];  //get current num of cards in hand
#if (NOISY_TEST == 1)
        printf("HandCount is %d\n", handCount);

        //print players hand for error checking. 
        printf("Player %d's hand:\n", p);
        if(handCount > 0) printf("#  Card\n");
        for(handIndex = 0; handIndex < handCount; handIndex++) {
            int card = G.hand[p][handIndex];
            char name[MAX_STRING_LENGTH];
            cardNumToName(card, name);
            printf("%-2d %-13s\n", handIndex, name);
        }
        printf("\n");
#endif

        score = scoreFor(p, &G);   //call scoreFor
        //find the expected score accourding to the card
        expected = -(1 * numOfCards);


        if(score != expected){//check if score is correct
            printf("****FAIL Hand score = %d, expected = %d\n", score, expected);
            errors++;
        }  
#if (NOISY_TEST == 1) 
          else{
            printf("PASS Hand score = %d, expected = %d\n", score, expected);}
#endif          
          
 //       printf("Test player %d Discard with %d curse card(s).\n", p, numOfCards);   
        
        for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
            G.hand[p][cardNum] = copper; 
            G.discard[p][cardNum] = curse;     
            G.deck[p][cardNum] = copper;    
        }
        int discardCount = G.discardCount[p];  //get current num of cards in hand
 #if (NOISY_TEST == 1)
          printf("DiscardCount is %d\n", discardCount);

        //print players discard for error checking. 
        printf("Player %d's discard hand:\n", p);
        if(discardCount > 0) printf("#  Card\n");
        for(discardIndex = 0; discardIndex < discardCount; discardIndex++) {
            int card = G.discard[p][discardIndex];
            char name[MAX_STRING_LENGTH];
            cardNumToName(card, name);
            printf("%-2d %-13s\n", discardIndex, name);
        }
        printf("\n");  
#endif          
        score = scoreFor(p, &G);   //call scoreFor
        //find the expected score accourding to the card
        expected = -(1 * numOfCards);


        if(score != expected){//check if score is correct
            printf("****FAIL Discard score = %d, expected = %d\n", score, expected);
            errors++;
        }  
#if (NOISY_TEST == 1)   
          else{
            printf("PASS Discard score = %d, expected = %d\n", score, expected);}
          
        printf("Test player %d Deck with %d curse card(s).\n", p, numOfCards);   
#endif      
        for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
            G.hand[p][cardNum] = copper; 
            G.discard[p][cardNum] = copper;     
            G.deck[p][cardNum] = curse;    
        }
        
        int deckCount = G.deckCount[p];  //get current num of cards in hand
 #if (NOISY_TEST == 1)
        printf("DeckCount is %d\n", deckCount);

        //print players deck for error checking. 
        printf("Player %d's deck:\n", p);
        if(deckCount > 0) printf("#  Card\n");
        for(deckIndex = 0; deckIndex < deckCount; deckIndex++) {
            int card = G.deck[p][deckIndex];
            char name[MAX_STRING_LENGTH];
            cardNumToName(card, name);
            printf("%-2d %-13s\n", deckIndex, name);
        }
        printf("\n");  
 #endif
          score = scoreFor(p, &G);   //call scoreFor
        //find the expected score accourding to the card
        expected = -(1 * numOfCards);


        if(score != expected){//check if score is correct
            printf("****FAIL Deck score = %d, expected = %d\n", score, expected);
            errors++;
        }  
#if (NOISY_TEST == 1)
          else{
            printf("PASS Deck score = %d, expected = %d\n", score, expected);}  
#endif
      }
        
    }
    
//   printf("Testing for gardens victory card\n");
    for (p = 0; p < numPlayer; p++){
      for(numOfCards = 0; numOfCards <= 8; numOfCards++){ 
      memset(&G, 23, sizeof(struct gameState)); // clear the game state  
        r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
        G.handCount[p] = numOfCards;        //set the number of cards on hand
        G.discardCount[p] = numOfCards;     //set the number of card in discard
        G.deckCount[p]=numOfCards;  
        //set all the cards in players hand to the appropriate card
        int cardNum;
        for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
            G.hand[p][cardNum] = gardens; 
            G.discard[p][cardNum] = copper;     
            G.deck[p][cardNum] = copper;    
        }
 //       printf("Test player %d Deck with %d gardens card(s).\n", p, numOfCards);   
        int handCount = G.handCount[p];  //get current num of cards in hand
#if (NOISY_TEST == 1)
        printf("HandCount is %d\n", handCount);

        //print players hand for error checking. 
        printf("Player %d's hand:\n", p);
        if(handCount > 0) printf("#  Card\n");
        for(handIndex = 0; handIndex < handCount; handIndex++) {
            int card = G.hand[p][handIndex];
            char name[MAX_STRING_LENGTH];
            cardNumToName(card, name);
            printf("%-2d %-13s\n", handIndex, name);
        }
        printf("\n");
#endif

        score = scoreFor(p, &G);   //call scoreFor
        //gardens victory card is worth 1 estate for every 10 cards
        // the score is then added on, but since we don't have an 
        // additional score now, the division is enough  
        expected = (fullDeckCount(p, 0, &G)/10); 
        if(score != expected){//check if score is correct
            printf("****FAIL Deck score = %d, expected = %d\n", score, expected); 
            errors++;
        }  
#if (NOISY_TEST == 1)    
          else{
            printf("PASS Deck score = %d, expected = %d\n", score, expected);}  
          
        printf("Test player %d Discard with %d gardens card(s).\n", p, numOfCards);   
#endif        
        for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
            G.hand[p][cardNum] = copper; 
            G.discard[p][cardNum] = gardens;     
            G.deck[p][cardNum] = copper;    
        }
        int discardCount = G.discardCount[p];  //get current num of cards in hand
 #if (NOISY_TEST == 1)
          printf("DiscardCount is %d\n", discardCount);

        //print players discard for error checking. 
        printf("Player %d's discard hand:\n", p);
        if(discardCount > 0) printf("#  Card\n");
        for(discardIndex = 0; discardIndex < discardCount; discardIndex++) {
            int card = G.discard[p][discardIndex];
            char name[MAX_STRING_LENGTH];
            cardNumToName(card, name);
            printf("%-2d %-13s\n", discardIndex, name);
        }
        printf("\n");  
#endif          
        score = scoreFor(p, &G);   //call scoreFor
        //find the expected score accourding to the card
        expected = (fullDeckCount(p, 0, &G)/10); 

        if(score != expected){//check if score is correct
            printf("****FAIL Discard score = %d, expected = %d\n", score, expected); 
            errors++;
        }  
#if (NOISY_TEST == 1)  
          else{
            printf("PASS Discard score = %d, expected = %d\n", score, expected);}
          
        printf("Test player %d Deck with %d gardens card(s).\n", p, numOfCards);   
#endif        
        for(cardNum = 0; cardNum <= maxHandCount; cardNum++){
            G.hand[p][cardNum] = copper; 
            G.discard[p][cardNum] = copper;     
            G.deck[p][cardNum] = gardens;    
        }
        
        int deckCount = G.deckCount[p];  //get current num of cards in hand
 #if (NOISY_TEST == 1)
        printf("DeckCount is %d\n", deckCount);

        //print players deck for error checking. 
        printf("Player %d's deck:\n", p);
        if(deckCount > 0) printf("#  Card\n");
        for(deckIndex = 0; deckIndex < deckCount; deckIndex++) {
            int card = G.deck[p][deckIndex];
            char name[MAX_STRING_LENGTH];
            cardNumToName(card, name);
            printf("%-2d %-13s\n", deckIndex, name);
        }
        printf("\n");  
 #endif
          score = scoreFor(p, &G);   //call scoreFor
        //find the expected score accourding to the card
        expected = (fullDeckCount(p, 0, &G)/10); 

        if(score != expected){//check if score is correct
            printf("****FAIL Deck score = %d, expected = %d\n", score, expected); 
            errors++;
        }  
#if (NOISY_TEST == 1) 
          else{
            printf("PASS Deck score = %d, expected = %d\n", score, expected);}  
#endif          
      }
    }
    
    if(errors == 0){
     printf("ALL TESTS PASS for whoseTurn().\n");   
    }
    else{
     printf("FAIL: There are %d errors in scoreFor().\n", errors);   
    }
    
    return 0;
}
int main(){
	
	srand(time(NULL));
	int i = 0, counter = 0, tempkc = 0, appear = 0, numplayer = 0, seed = 0, temp = -1, check = 0, money = 0;
	int p0card = -1, p1card = -1, p2card = -1, p3card = -1, tempcard0 = 0, tempcard1 = 0, tempcard2 = 0, tempcard3 = 0;
	int p0numcard = 0, p1numcard = 0, p2numcard = 0, p3numcard = 0;
	int favCards[4];
	struct gameState G;
    struct gameState *p = &G;
	char cardName[32];

	// 0 to 26 index start at enum 7 
	//create k[] of of size 10
	int k[10] = {0,0,0,0,0,0,0,0,0,0};
	
	printf("generating a random set of kindom cards\n");
	do{
	//printf("tempkc was %d\n",tempkc);
	tempkc = randomsnum(26,7);
	//printf ("%d\n", tempkc);
	for (i = 0; i < 10; i++){
		if (k[i] == tempkc){
			appear++;
		}
	}
	
	if (appear == 0){
		//printf("k[%d] : %d\n", counter, k[counter]);
		k[counter] = tempkc;
		//printf("k[%d] : %d\n", counter, k[counter]);
		counter++;
	}
	
	appear = 0;
	
	}while(counter < 10);
	

	for (i = 0; i < 10; i++){
	cardNumToName(k[i],cardName);
	printf ("k[%d] : %d , %s\n", i, k[i], cardName);
	//printf ("ktest[%d] : %d\n", i, ktest[i]);
	}
	
	//assign random number of player
	numplayer = randomsnum(4,2);
	
	printf ("number of player is %d \n", numplayer);
	
	//assign see a random number between 0 and 27

	seed = randomsnum(9,1);
	
	//random fav card for player
	for (i = 0; i < numplayer; i++){
		favCards[i] = -1;
		temp = randomsnum(9,0);
		favCards[i] = k[temp];
	}
	
	
	initializeGame(numplayer, k, seed, p);
	do{
		
	 money = 0;

	 //set position of players card	
	 p0card = -1;
	 p1card = -1;
	 p2card = -1;
	 p3card = -1;
	 
	for (i = 0; i < numHandCards(p); i++) {
      if (handCard(i, p) == copper)
    money++;
      else if (handCard(i, p) == silver)
    money += 2;
      else if (handCard(i, p) == gold)
    money += 3;
      else if (handCard(i, p) == favCards[0])
    p0card = i;
      else if (handCard(i, p) == favCards[1])
    p1card = i;
      else if (handCard(i, p) == favCards[2])
    p2card = i;
      else if (handCard(i, p) == favCards[3])
    p3card = i;
    }
	
	//void play(struct gameState *p,int pcard, int favCard, int *pnumcard, int who, int money)
	int tempfav = 0;
	int who = 0;
	if (whoseTurn(p) == 0){
		who = 0;
		//printf("who is : %d\n", who);
		tempfav = favCards[0];
		play(p,p0card, tempfav,&p0numcard, who, money);
	}
	
	else if (whoseTurn(p) == 1){
		who = 1;
		//printf("who is : %d\n", who);
		tempfav = favCards[1];
		play(p,p1card, tempfav,&p1numcard, who, money);
	}
	
	else if (whoseTurn(p) == 2){
		who = 2;
		//printf("who is : %d\n", who);
		tempfav = favCards[2];
		play(p,p2card, tempfav,&p2numcard, who, money);
	}
	
	else if (whoseTurn(p) == 3){
		who = 3;
		//printf("who is : %d\n", who);
		tempfav = favCards[3];
		play(p,p3card, tempfav,&p3numcard, who, money);
	}
	check = isGameOver(p);	
	}while (!check);
	
	printf ("Finished game.\n");
	for (i = 0; i < numplayer; i++){
		 printf ("Player %d: %d\n", i, scoreFor(i, p));
	}
	
	
	return 0;
}
예제 #28
0
int main() {

	srand(time(NULL));
	int gameSeed = rand() % 1000 + 1;
	int p = 0; //player 1
	int numPlayer = 4;
	int k[10] = {adventurer, council_room, feast, gardens, mine,
				 remodel, smithy, village, baron, great_hall};

	struct gameState* GS = newGame();

	initializeGame(numPlayer, k, gameSeed, GS);

	GS->hand[p][4] = smithy; //5th card in hand is smithy

	printf("Playing Smithy card and testing...\n");

	/*Checking handcount and cards in hand before playing smithy*/
	printf("Hand count before Smithy is %d...\n", GS->handCount[p]);
	int i = 0, cardStatus;
	char c[25];
	for(i = 0; i < GS->handCount[p]; i++){
		cardNumToName(GS->hand[p][i], c);	//Converts card number to string
		printf( "%s, ", c);
		if(strcmp(c, "Smithy") == 0){
			cardStatus = 1;	//Card is present in hand
		}
	}

	/*Check if smithy card is in hand before use*/
	if(cardStatus == 1){
		printf("\nTest PASSED, card is present in player %d's hand\n\n", p);
	} else {
		printf("\nTest FAILED, card is NOT present in player %d's hand\n\n", p);
	}

	smithyCard(p, GS, 4);	//Play smithy card

	cardStatus = 0; //Reset to zero

	/*Checking handcount and cards in hand after playing smithy*/
	printf("Hand count after Smithy is %d...\n", GS->handCount[p]);
	for(i = 0; i < GS->handCount[p]; i++){
		cardNumToName(GS->hand[p][i], c);	//Converts card number to string
		printf( "%s, ", c);
		if(strcmp(c, "Smithy") == 0){
			cardStatus = 1;	//Card is present in hand
		}
	}

	/*Check if smithy card is in hand*/
	if(cardStatus == 0){
		printf("\nTest PASSED, card is NOT present in player %d's hand\n\n", p);
	} else {
		printf("\nTest FAILED, card is present in player %d's hand\n\n", p);
	}

	printf("Testing for correct number of cards drawn...\n");
	/*Check current state player's handcount +3 cards after discard is 5 cards*/
	if(GS->handCount[p] == 7){
		printf("Test PASSED, Player %d drew +3 cards\n\n", p);
	} else {
		printf("Test FAILED, Player %d drew incorrect amount of cards\n\n", p);
	}

	printf("Checking if Smithy Card is in played pile...\n");
	/*Check if card is in played pile*/
	if(GS->playedCards[p] == smithy){
		printf("Test PASSED, Smithy is in played pile\n\n");
	} else {
		printf("Test FAILED, Smithy is NOT in played pile\n\n");
	}

/*Check if smithy card has been discarded from hand after card effects*/
	for(i = 0; i < GS->handCount[p]; i++){
		cardNumToName(GS->hand[p][i], c);	//Converts card number to string
		printf( "%s, ", c);
		if(strcmp(c, "Smithy") != 0){
			cardStatus = 0;	//Card is NOT present in hand
		}
	}

	printf("\nTesting if card is discarded from hand...\n");
	if(cardStatus == 0){
		printf("Test PASSED, Smithy is discarded from player %d's hand after use\n\n", p);
	} else {
		printf("Test FAILED, Smithy card is NOT discarded from player %d's hand after use\n\n", p);
	}

	return 0;

}
예제 #29
0
/*Village card unit tests*/
void testVillageCard()
{
	int seed = 1000; /*Used for initializeGame parameter for setting up random # generator*/
    int numPlayer = 2; /*number of players in game. Maximum # of players is 4*/
    int p = 0; /*holds the value of the player, example player 0, player 1.*/
	int handCount = 5; /*Number of cards player starts with*/
	
	/*Kingdom cards used in this game*/
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
			   
    struct gameState G; /*start a new game*/
	
	/*create a custom hand to give to player */
    int custom_hand[handCount];
	
	custom_hand[0] = copper;
    custom_hand[1] = village;
	custom_hand[2] = silver;
	custom_hand[3] = gold;
	custom_hand[4] = mine;
    
    char name[20]; /*Holds card name when converting card number to string*/
	int inhand = 0; /*Determines if Village card is in player's hand or not.*/
	int actions_b = 0; /*Holds number of actions player has before using card*/
	int actions_a = 0; /*Holds number of actions player has after using card*/
	
	
    printf ("\nTESTING Village card:\n");
	
	printf("Test player %d with %d card(s) with 1 card being a Village card.\n", p, handCount);

	initializeGame(numPlayer, k, seed, &G); /*initialize a new game*/
	G.handCount[p] = handCount;             /*set the number of cards in hand*/
	memcpy(G.hand[p], custom_hand, sizeof(int) * handCount); /*Populate hand with cards*/
	actions_b = G.numActions;
	/*Print the cards in player's hand*/
	int i;
	for(i = 0; i < G.handCount[p]; i++)
	{
		cardNumToName(G.hand[p][i], name); /*Convert card number to cards name*/
		printf("%s%s", name, ", ");
		if(strcmp(name, "Village") == 0)
		{
			inhand = 1; /*Village card is in player's hand*/
		}
	}
	
	if (inhand == 1)
	{
		printf ("\nPASS - Village card is in player's hand\n");
	}
	else
	{
		printf ("\nFAIL - Village card is NOT in player's hand\n");
	}
	
	inhand = 0; /*reset value*/
	
	printf ("Using Village card...\n");
	cardEffect(village, 0, 0, 0, &G, 1, 0);
	actions_a = G.numActions; /*get number of actions*/
	
	/*checks if 1 cards added, 5 if card was discard and 6 if card was not discarded*/
	if(G.handCount[p] == 5 || G.handCount[p] == 6)
	{
		printf ("PASS - Player %d has received 1 card.\n", p);
	}
	else
	{
		printf ("FAIL - Player %d has not received a card.\n", p);
	}
	
	/*check if actions = 2 in case 1 action not removed and +1 if action was removed.*/
	if(actions_a == actions_b + 1)
	{
		printf ("PASS - Player %d has gained +2 actions.\n", p);
	}
	else if (actions_a == actions_b + 2)
	{
		printf ("FAIL - Player gained 2 actions but action to play card was not decremented.\n", p);
	}
	else
	{
		printf ("FAIL - Player %d has NOT gained +2 actions.\n", p);
	}
	
	for(i = 0; i < G.handCount[p]; i++)
	{
		cardNumToName(G.hand[p][i], name); /*Convert card number to cards name*/
		printf("%s%s", name, ", ");
		if(strcmp(name, "Village") == 0)
		{
			inhand = 1; /*Village card is in player's hand*/
		}
	}
	
	if (inhand == 0)
	{
		printf ("\nPASS - Village card has been discarded from player's hand\n");
	}
	else
	{
		printf ("\nFAIL - Village card has NOT been discarded from player's hand\n");
	}
}
예제 #30
0
/*scoreFor() unit tests*/
void testscoreFor()
{
	int seed = 1000; /*Used for initializeGame parameter for setting up random # generator*/
    int numPlayer = 2; /*number of players in game. Maximum # of players is 4*/
    int p = 0; /*holds the value of the player, example player 0, player 1.*/
	int handCount = 5; /*Number of cards player starts with*/
	
	/*Kingdom cards used in this game*/
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
			   
    struct gameState G; /*start a new game*/
	char name[20]; /*Holds card name when converting card number to string*/
	int score = 0; /*Holds return value from scoreFor()*/
	
	/*****************Cards for game where only Players hand contributes to score***********/
	/*create a custom hand to give to player */
    int custom_hand[handCount];
	custom_hand[0] = curse;
    custom_hand[1] = silver;
	custom_hand[2] = village;
	custom_hand[3] = gold;
	custom_hand[4] = duchy;
	
	/*create a custom discard pile to give to player */
	int custom_discard[handCount];
	custom_discard[0] = village;
    custom_discard[1] = smithy;
	custom_discard[2] = silver;
	custom_discard[3] = copper;
	custom_discard[4] = gold;
	
	/*create a custom deck pile to give to player */
    int custom_deck[handCount];
	custom_deck[0] = smithy;
    custom_deck[1] = feast;
	custom_deck[2] = village;
	custom_deck[3] = gold;
	custom_deck[4] = copper;
	
	/**************Cards for game where only discard pile contributes to score*****************/
	/*create a custom hand to give to player */
    int custom_hand2[handCount];
	custom_hand2[0] = smithy;
    custom_hand2[1] = silver;
	custom_hand2[2] = village;
	custom_hand2[3] = gold;
	custom_hand2[4] = mine;
	
	/*create a custom discard pile to give to player */
	int custom_discard2[handCount];
	custom_discard2[0] = village;
    custom_discard2[1] = smithy;
	custom_discard2[2] = estate;
	custom_discard2[3] = duchy;
	custom_discard2[4] = curse;
	
	/*use custom_deck*/
	
	/*******************Cards for game where only deck pile contributes to score***********/
	/*use custom_hand2*/
	/*use custom_discard*/
	
	/*create a custom deck pile to give to player */
    int custom_deck2[handCount];
	custom_deck2[0] = curse;
    custom_deck2[1] = curse;
	custom_deck2[2] = village;
	custom_deck2[3] = great_hall;
	custom_deck2[4] = province;
	
	
    printf ("\nTESTING scoreFor():\n");
	
	/*Get score from player's hand*/
	initializeGame(numPlayer, k, seed, &G); /*initialize a new game*/
	G.handCount[p] = handCount;             /*set the number of cards in hand*/
	memcpy(G.hand[p], custom_hand, sizeof(int) * handCount); /*Populate hand with cards*/
	memcpy(G.discard[p], custom_discard, sizeof(int) * handCount); /*Populate hand with cards*/
	memcpy(G.deck[p], custom_deck, sizeof(int) * handCount); /*Populate hand with cards*/

	printf ("\nPlayer Hand\n");
	int i;
	for(i = 0; i < G.handCount[p]; i++)
	{
		cardNumToName(G.hand[p][i], name); /*Convert card number to cards name*/
		printf("%s%s", name, ", ");
	}

	score = scoreFor(p, &G);
	
	printf("\nScore for Player's Hand is %d\n", score);
	
	if(score == 2)
	{
		printf ("PASS - Score correctly calculated for cards in Player's Hand\n");
	}
	else
	{
		printf ("FAIL - Score NOT correctly calculated for cards in Player's Hand\n");
	}
	
	/*Get score from player's discard pile*/
	memset(&G, 23, sizeof(struct gameState)); /*clear the game state*/
	initializeGame(numPlayer, k, seed, &G); /*initialize a new game*/
	G.handCount[p] = handCount;             /*set the number of cards in hand*/
	memcpy(G.hand[p], custom_hand2, sizeof(int) * handCount); /*Populate hand with cards*/
	memcpy(G.discard[p], custom_discard2, sizeof(int) * handCount); /*Populate hand with cards*/
	memcpy(G.deck[p], custom_deck, sizeof(int) * handCount); /*Populate hand with cards*/
	
	printf ("\nDiscard Pile\n");
	for(i = 0; i < G.handCount[p]; i++)
	{
		cardNumToName(G.discard[p][i], name); /*Convert card number to cards name*/
		printf("%s%s", name, ", ");
	}
	
	score = scoreFor(p, &G);
	
	printf("\nScore for Player's Discard pile is %d\n", score);
	
	if(score == 3)
	{
		printf ("PASS - Score correctly calculated for cards in Player's discard pile\n");
	}
	else
	{
		printf ("FAIL - Score NOT correctly calculated for cards in Player's discard pile\n");
	}
	
	/*Get score from player's deck pile*/
	memset(&G, 23, sizeof(struct gameState)); /*clear the game state*/
	initializeGame(numPlayer, k, seed, &G); /*initialize a new game*/
	G.handCount[p] = handCount;             /*set the number of cards in hand*/
	memcpy(G.hand[p], custom_hand2, sizeof(int) * handCount); /*Populate hand with cards*/
	memcpy(G.discard[p], custom_discard, sizeof(int) * handCount); /*Populate hand with cards*/
	memcpy(G.deck[p], custom_deck2, sizeof(int) * handCount); /*Populate hand with cards*/
	
	printf ("\nDeck Pile\n");
	for(i = 0; i < G.deckCount[p]; i++)
	{
		cardNumToName(G.deck[p][i], name); /*Convert card number to cards name*/
		printf("%s%s", name, ", ");
	}
	
	score = scoreFor(p, &G);
	
	printf("\nScore Player's Deck pile is %d\n", score);
	
	if(score == 5)
	{
		printf ("PASS - Score correctly calculated for cards in Player's deck pile\n");
	}
	else
	{
		printf ("FAIL - Score NOT correctly calculated for cards in Player's deck pile\n");
	}
}