Ejemplo n.º 1
0
//Testing initializeGame and default deal
int main() {
	struct gameState g, orig;

	int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,mine,ambassador,
			   outpost,baron,tribute};

	int r = 0;
	//3 player game this time
	initializeGame(3, k, 1, &orig);
	//Trevor's suggestion, saving game state for testing purposes
	memcpy(&g, &orig, sizeof(struct gameState));	
	
	//first hand of player 0 is {4 coppers, 1 estate}. 4 coins
	buyCard(gardens, &g); //player 0 buys a garden
	endTurn(&g);
	buyCard(curse, &g); //player 1 buys a curse
	endTurn(&g);
	//Not doing anything on player 3 turn
	endTurn(&g);
	
	r = scoreFor(3, &g);
	myAssert(r == -9999, "Player should not exist but did", __LINE__);
	r = scoreFor(0, &g);
	myAssert(r == 5, "Player should have a base 5 points", __LINE__);
	
	
	
	

	if(r == 0)
		printf("Tests completed successfully!\n");

	return 0;
}
int main(){

  struct gameState state;
  int s;
  int k[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

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

  state.numBuys = 0;

  s = buyCard(5, &state);

  assert(s == -1);

  state.numBuys = 5;

  state.coins = 0;

  s = buyCard(5, &state);

  assert(s == -1);

  state.coins = 100;

  s = buyCard(5, &state);

  assert(s == 0);

  printf("buyCard test passed\n");
  return 0;
}
Ejemplo n.º 3
0
int randBuy(struct gameState *game){
  int card;
  if (game->coins >= getCost(province))
    card = province;
  else
    card = floor(Random()*(treasure_map+1));

  if (game->coins == 0){
    game->numBuys = 0;
    return 0;
  }


  if (getCost(card) > game->coins || game->supplyCount[card] <= 0) {
    if (buyCard(card,game) == 0) {
      printf("Bad attempt to buy card was successfull: ");
      printCard(card);
      printf("\n\r");
      return -1;
    }
    else
      return 0;
  }


  printf("Card to buy: ");
  printCard(card);
  printf("\n\r");
  return buyCard(card,game);
}
Ejemplo n.º 4
0
void buyCost5(struct gameState *p, int * k){
	int i = 0;
	int counter = 0;
	int j = 0;
	for(;i<10;i++){
		if (k[i] == outpost || k[i] == minion || k[i] == duchy)
			counter++;
		else if(k[i] == council_room || k[i] == mine || k[i] == tribute)
			counter++;
	}
	int * costFive = malloc(sizeof(int)*counter);
	for(i =0; i<10;i++){
		if (k[i] == outpost || k[i] == minion || k[i] == duchy)
			costFive[j] = k[i];
		else if(k[i] == council_room || k[i] == mine || k[i] == tribute)
			costFive[j] = k[i];
	}
	if(counter != 0){
		int num = rand() % counter;
		buyCard(costFive[num],p);
		printf("%s bought\n",printCard(costFive[num]));
		}
	else{
		buyCard(silver,p);
		printf("%s bought\n",printCard(silver));
		}
}
Ejemplo n.º 5
0
void buyCost4(struct gameState *p, int * k){
	int i = 0;
	int counter = 0;
	int j = 0;
	for(;i<10;i++){
		if (k[i] == cutpurse || k[i] == baron || k[i] == feast)
			counter++;
		else if(k[i] == gardens || k[i] == remodel || k[i] == smithy)
			counter++;
		else if(k[i] == salvager || k[i] == sea_hag || k[i] == treasure_map)
			counter++;
	}
	int * costFour = malloc(sizeof(int)*counter);
	for(i =0; i<10;i++){
		if (k[i] == cutpurse || k[i] == baron || k[i] == feast){
			costFour[j] = k[i];
			j++;}
		else if(k[i] == gardens || k[i] == remodel || k[i] == smithy){
			costFour[j] = k[i];
			j++;}
		else if(k[i] == salvager || k[i] == sea_hag || k[i] == treasure_map){
			costFour[j] = k[i];
			j++;}
	}
	if(counter != 0){
		int num = rand() % counter;
		buyCard(costFour[num],p);
		printf("%s bought\n",printCard(costFour[num]));
		}
	else{
		buyCard(silver,p);
		printf("%s bought\n",printCard(silver));
		}
}
Ejemplo n.º 6
0
void buy_card(struct gameState* p, int not_bought[10], int k[10])
{

    int money = 0, j;
    for(j = 0; j < numHandCards(p); j++)
    {
        if(handCard(j,p) == copper)
        {
            playCard(j, -1, -1, -1, p);
            money++;
        }    
        if(handCard(j,p) == silver)
        {
            playCard(j, -1, -1, -1, p);
            money += 2;
        }
        if(handCard(j,p) == gold)
        {
            playCard(j, -1, -1, -1, p);
            money += 3;
        }
    }
    
    if(money > 7)
    {
        buyCard(province, p);
        printf("%d Bought province\n", p->whoseTurn);
    }
    else if(money > 5)
    {
        for(j = 0; j < 10; j++)
        {
            if(!(bought(not_bought, p, k[j])))
            {
                buyCard(k[j], p);
                printf("%d Bought %s\n", p->whoseTurn, get_name(k[j]));
                j = 10;
            }
        }
    }
    else if(money > 5)
    {
        buyCard(gold, p);
        printf("%d Bought gold\n", p->whoseTurn);
    }
    else if(money > 2)
    {
        buyCard(silver, p);
        printf("%d Bought silver\n", p->whoseTurn);
    }
    else
    {
        buyCard(copper, p);
        printf("%d Bought copper\n", p->whoseTurn);
    }
}
Ejemplo n.º 7
0
//testing buyCard()
int main() {
	int seed = 1;//the seed for initializeGame
    int numPlayer;
	int players, handCount, i, j, tempCount;
	int cardCount = 10;//the number of cards initially given to a player
	
    int cards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
    struct gameState game;

	printf ("Testing buyCard():\n\n");
	
	for(numPlayer = 2; numPlayer <= 4; numPlayer++) {//checking for all possible number of players (2-4) {
		initializeGame(numPlayer, cards, seed, &game); // initialize a new game
		for (players = 0; players < numPlayer; players++)//drawing all cards for each player
		{   
			for (i = 0; i < cardCount; i++){//drawing entire deck
				drawCard(players, &game);//drawing a card	
			}
			
			game.numBuys = 1;
			game.whoseTurn = players;
			updateCoins(players, &game, 0);
			buyCard(smithy, &game);//note:smithy cost 4, less than coppers originally given
			
			if(fullDeckCount(players, smithy, &game) != 1) {//checking that the user can buy an affordable card
				printf("ERROR BUYING AFFORDABLE CARD: player: %i, buy: %i, expected cards after buy: %i, actual cards = %i\n\n", players, 1, 1, fullDeckCount(players, smithy, &game));
				printf("user has in hand %i\n", game.handCount[players]);
			}
			
			game.numBuys = 1;
			game.whoseTurn = players;
			buyCard(smithy, &game);//note:smithy cost 4, more than money left
			
			if(fullDeckCount(players, smithy, &game) != 1) {//checking that the user can't buy an unaffordable card
				printf("ERROR BUYING UNAFFORDABLE CARD: player: %i, buy: %i, expected cards after buy: %i, actual cards = %i\n\n", players, 2, 1, fullDeckCount(players, smithy, &game));
			}
			
			game.numBuys = 1;
			game.whoseTurn = players;
			
			tempCount = game.supplyCount[smithy];
			game.supplyCount[smithy] = 0;//removing smithy cards
			buyCard(smithy, &game);
			if(fullDeckCount(players, smithy, &game) != 1) {//checking that the user can't buy an absent
				printf("ERROR BUYING ABSENT CARD: player: %i, buy: %i, expected cards after buy: %i, actual cards = %i\n\n", players, 3, 1, fullDeckCount(players, smithy, &game));
			}
			
			game.supplyCount[smithy] = tempCount;//returning smithy cards
			
		}
	}
	return 0;
}
Ejemplo n.º 8
0
int main() {
	
	int i, test1=0, scoreTrack=10;
	int currentPlayer, money;
	struct gameState G;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
	int r = initializeGame(2, k, 2, &G);
	assert (r ==0);
	
	///// ----------------------- game -----------------------
	while (!isGameOver(&G)) 
	{
		money=0;
		for (i = 0; i < numHandCards(&G); i++) 
		{
			if (handCard(i, &G) == copper)
				money++;
			else if (handCard(i, &G) == silver)
				money += 2;
			else if (handCard(i, &G) == gold)
				money += 3;
		}	
		
		if ((supplyCount(gold, &G)==0) && (supplyCount(silver, &G)==0))
		{
			if (money >= 8) 
			{
				buyCard(province, &G);
				scoreTrack=scoreTrack+6;
			}
		}
		else if (money >= 6) 
		{
			buyCard(gold, &G);
		}
		else if (money >= 3) 
		{ 
			buyCard(silver, &G);
		}
		endTurn(&G);
	}

	//------------------------------------------------------------------
	//total score
	test1= scoreFor(0, &G) + scoreFor(1, &G);
	//score we tracked
	printf("Score for: %i", scoreFor);
	printf("Score trac: %i", scoreTrack);
	//assert( test1== scoreTrack);
	//scoreFor is acting strange
	
	return 0;
}
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);
    }
Ejemplo n.º 10
0
int testSmithyCard () {
    //
    // Tests that fullDeckCount works properly
    
    //

    // Status of test
    // set to 0 if the test didn't crash,
    // set to -1 if the test fails to finish,
    int status = -1;

    // Create play variable
    int p = 0;

    // RFC 1149.5 specifies 4 as the standard IEEE-vetted random number.
    int rand = 4;

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

    // Create gamestate
    struct gameState G;

    status = initializeGame(2, k, rand, &G);

    myAssert (status == 0);

    int choices[3] = {0};
    int pos;
    buyCard(smithy, &G);
    buyCard(smithy, &G);
    int loops = 0, cardFound = 0;
    while(cardFound == 0 && loops < 5) {
        for (pos=0, loops++; pos<numHandCards(&G); pos++)
            if (handCard(pos, &G) == smithy)
                cardFound = 1;
        endTurn(&G);
    }
    status = cardEffect(smithy,
                        choices[0], choices[1], choices[2],
                        &G, pos, NULL);

    myAssert (status == 0);


    printf ("testSmithyCard passes.\n");

    status = 0;
    return status;
}
Ejemplo n.º 11
0
//test baron
int main()
{
	int kCards[10] = {adventurer, gardens, embargo, village, minion, baron, cutpurse, sea_hag, tribute, smithy};
	struct gameState g, orig;
	int r;

	//for consistancy make randomSeed=1
	initializeGame(2, kCards, 1, &orig);

	//turn 1 of player 0 is {4 coppers, 1 estate}. 4 coins
	gainCard(baron, &orig, 2, 0);
	memcpy(&g, &orig, sizeof(struct gameState));

	//play baron normal, discard estate. get 4 coins
	r = supplyCount(estate, &g);
	playCard(5, 1, 0, 0, &g);
	myAssert(r == supplyCount(estate, &g), "Baron gained estate while discarding", __LINE__);
	myAssert(numHandCards(&g) == 4, "Did not properly discard", __LINE__);
	for(int i = 0; i < numHandCards(&g); ++i)
		myAssert(handCard(i, &g) == copper, "Did not properly discard", __LINE__);
	//have 8 coins total
	r = buyCard(gold, &g);
	myAssert(r == 0, "Did not have 6 coins to buy gold", __LINE__);
	r = buyCard(silver, &g);
	myAssert(r == -1, "Bought silver, had more than 8 coins", __LINE__);
	r = buyCard(estate, &g);
	myAssert(r == 0, "Did not have 8 coins or 2 buys for estate", __LINE__);
	r = buyCard(copper, &g);
	myAssert(r == -1, "Got more than +1 buy from baron", __LINE__);

	//play baron normal, dont discard estate so gain one
	memcpy(&g, &orig, sizeof(struct gameState));
	r = supplyCount(estate, &g);
	playCard(5, 0, 0, 0, &g);
	myAssert(r-1 == supplyCount(estate, &g), "Baron did not gain estate", __LINE__);
	myAssert(handCard(4, &g) == estate, "Baron discarded estate in hand while gaining", __LINE__);
	r = buyCard(duchy, &g);
	myAssert(r == -1, "Bought duchy, gained coins when gaining estate", __LINE__);

	//play baron, discard estate but have none so gain one
	discardCard(4, 0, &orig, 0);
	r = supplyCount(estate, &orig);
	playCard(4, 1, 0, 0, &orig);
	r = myAssert(r-1 == supplyCount(estate, &orig), "Did not gain with no estates in hand", __LINE__);

	//done
	if(r == 0)
		printf("Tests completed successfully!\n");

	return 0;
}
Ejemplo n.º 12
0
int main(){
    struct gameState game;
    int numplayers = 4;
    int i = 0;

    // initiate
    game.numPlayers = numplayers;

    // starting hand
    game.whoseTurn = 0;
    game.phase = 0;
    game.handCount[0] = 1;
    game.discardCount[0] = 0;
    game.deckCount[0] = 0;
    game.hand[0][0] = smithy;
    game.numBuys = 2;
    game.numActions = 1;
    game.coins = 0;
    for(i = 0; i <= treasure_map; i++)
        if (i != smithy)
						// all cards
            game.supplyCount[i] = 10;
        else // there are no smithy cards
            game.supplyCount[i] = 0;
		// will not be able to purchase
    myassert(buyCard(silver, &game) == -1);

    // gold to purchase with
    game.hand[0][0] = gold;
    game.coins = 3;
		// no smithys
    myassert(buyCard(smithy, &game) == -1);
    myassert(buyCard(village, &game) == 0);
		// discard contains 1
    myassert(game.discardCount[0] == 1);
		// subtract from supply
    myassert(game.supplyCount[village] == 9);
		// no more coins
    myassert(game.coins == 0);
		// subtract buy
    myassert(game.numBuys == 1);


    if (!failed){
        printf("buyCard() test passed successfully!\n");
    }else{
        printf("buyCard() test FAILED\n");
    }
    return 0;
}
Ejemplo n.º 13
0
//test buyCard()
int main()
{
	int kCards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
	struct gameState orig, g;
	int r, count;

	//for consistancy make randomSeed=1
	initializeGame(2, kCards, 1, &orig);
	//keep copy of original state for testing purposes
	memcpy(&g, &orig, sizeof(struct gameState));

	//first hand of player 0 is {4 coppers, 1 estate}. 4 coins
	count = supplyCount(curse, &g);
	r = buyCard(-1, &g);
	myAssert(r == -1, "Bought a non-existant card", __LINE__);
	r = buyCard(council_room, &g);
	myAssert(r == -1, "Bought council room which is not in supply", __LINE__);
	r = buyCard(gold, &g);
	myAssert(r == -1, "Gold costs 6 coins, bought with 4", __LINE__);
	r = buyCard(embargo, &g);
	myAssert(r == 0, "Could not buy an embargo with 4 coins", __LINE__);
	r = buyCard(copper, &g);
	myAssert(r == -1, "Bought more than one card on first turn", __LINE__);
	myAssert(count == supplyCount(curse, &g), "curse gained before embargo played", __LINE__);

	//player 0 gets embargo in hand buy turn 4 in handPos 3
	//advance to turn 4 for player 0
	for(int i = 0; i < 6; ++i)
		endTurn(&g);
	myAssert(handCard(3, &g) == embargo, "Did not properly gain bought embargo", __LINE__);
	playCard(3, copper, 0, 0, &g); //put an embargo on coppers
	endTurn(&g);
	//hand of player 1 turn 4 is {4 coppers, 1 estate}. 4 coins
	count = supplyCount(curse, &g);
	r = buyCard(copper, &g);
	myAssert(r == 0, "Try Buying a copper with a curse on it", __LINE__);
	myAssert(count-1 == supplyCount(curse, &g), "Improper amount of curses removed from supply", __LINE__);
	//advance to turn 5 where curse should appear in handPos 0
	for(int i = 0; i < 2; ++i)
		endTurn(&g);
	r = handCard(0, &g);
	myAssert(r == curse, "Player 1 did not recieve curse", __LINE__);

	//restart game
	buyCard(smithy, &orig);
	//smithy will show up in turn 4 in handPos 3
	//turn 4 player 0 hand is {4 coppers, 1 smithy}
	for(int i = 0; i < 6; ++i)
		endTurn(&orig);
	buyCard(silver, &orig);
	r = playCard(3, 0, 0, 0, &orig);
	r = myAssert(r == -1, "buyCard could not advance the phase", __LINE__);

	//done
	if(r == 0)
		printf("Tests completed successfully!\n");

	return 0;
}
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 
}
Ejemplo n.º 15
0
int main (int argc, char** argv) {

	struct gameState G;
	int playerNum;
  
	srand(time(NULL));
	playerNum = rand() % MAX_PLAYERS;//random player num index
	
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
						sea_hag, tribute, smithy};
		   
	printf ("\nStarting Unit Test 3: buyCard() ...\n");
	
	G.whoseTurn = playerNum;
	G.supplyCount[estate] = 9;
	G.numBuys = 1;
	G.coins = 1000;
	
	int r = initializeGame(4, k, 142, &G);//initialized for a 4 player game
	
	int cardBought = buyCard(estate,  &G);
	
	assert (cardBought == 0);
	
	printf("Passed\n");
	
	assert (r == 0);
	return 0;
}
Ejemplo n.º 16
0
//Testing endGame
int main() {
	struct gameState g, orig;
	
	int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,mine,ambassador,
			   outpost,baron,tribute};
	int p[3]; //should be set in dominion.c
	int r = 0;
	int i;
	int count;
	//3 player game this time
	initializeGame(3, k, 1, &orig);
	//Trevor's suggestion, saving game state for testing purposes
	memcpy(&g, &orig, sizeof(struct gameState));	
	
	//buy an estate to gain victory points and "win"
	buyCard(estate, &g);
	//get to player 2's turn and end
	//Loop until end
	for(i = 0; i < 2; ++i){
		endTurn(&g);
	}
	getWinners(p, &g);
	myAssert(p[1] == 0 && p[2] == 0, "Player 1 and 2 should have lost but did not", __LINE__);
	myAssert(p[3] == -9999, "Player 4 should not exist but did", __LINE__);
	myAssert(p[0] == 1, "Player 0 did not win", __LINE__);
	
	
	
	

	if(r == 0)
		printf("Tests completed successfully!\n");

	return 0;
}
Ejemplo n.º 17
0
}

int main(int argc, char** argv){
   struct gameState *G;
      int numplayers, money, handpos, rseed, rcard, choice1, choice2, choice3, coinflip, i, numtests,r;
      int *k;
      int players[4];
      numtests=1;
      for(i=0; i<numtests; i++){
	 G=newGame();
	    rseed=atoi(argv[1]);
	    k = malloc(sizeof(int)*10);
	    numplayers=rand()%3+2;
	    chooseKingdomCards(k);
	    initializeGame(numplayers, k, rseed, G);

	    printf("FOR SEED %d\n", rseed);
	    if(isGameOver(G)){
	       printf("game creation error\n");
	       printf("test %d failed\n",i);
	    }
	    else{
	       while(!isGameOver(G)){
                printf("player %d turn start\n", whoseTurn(G));
		  handpos=-1;
		     coinflip=rand()%10;
		  rcard=chooseHandCard(G, k, &handpos);
		     choice1=rand()%2;
		     choice2=0;
		     if(choice1==0){
			choice2=1;
		     }
		  choice3=rand()%2;
		     if(rcard!=-1 || rcard==curse){
			r=playCard(handpos, choice1,choice2,choice3,G);
			printf("player %d played ", whoseTurn(G));
			printCard(rcard, r);
		     }
		  money=countMoney(G);
		     printf("money: %d\n", money);
		     rcard=randomBuyCard(G, money, k);
		     if(coinflip!=9){			//small chance to not buy anything
			r=buyCard(rcard, G);
			printf("player %d bought ", whoseTurn(G));
			printCard(rcard, r);
		     }
		     printf("player %d hand\n", whoseTurn(G));
		     printhand(G);
		     printf("player %d score: %d\n", whoseTurn(G), scoreFor(whoseTurn(G),G));
		     printf("player %d turn ending\n", whoseTurn(G));
		     endTurn(G);
		     if(isGameOver(G)){
			printf("game over player %d won\n", getWinners(players, G));
		     }
	       }
	       free(k);
	       free(G);
	       printf("test %d passed\n", i);
	    }
      }
Ejemplo n.º 18
0
//test council room
int main()
{
	int kCards[10] = {adventurer, gardens, embargo, village, minion, council_room, cutpurse, sea_hag, tribute, smithy};
	struct gameState g;
	int r;

	//for consistancy make randomSeed=1
	initializeGame(4, kCards, 1, &g);

	//turn 1 of player 0 is {4 coppers, 1 estate}. 4 coins
	gainCard(council_room, &g, 2, 0);
	r = playCard(5, 0, 0, 0, &g);
	myAssert(r == 0, "councilRoom failed", __LINE__);
	for(int i = 0; i < numHandCards(&g); ++i)
		myAssert(handCard(i, &g) != council_room, "Did not discard council room", __LINE__);
	for(int i = 0; i < 2; ++i)
	{
		r = buyCard(copper, &g);
		myAssert(r == 0, "Does not have 2 buy's. Should have got extra buy from council room", __LINE__);
	}
	myAssert(numHandCards(&g) == 9, "Player 0 does not have 9 cards", __LINE__);
	for(int i = 0; i < 3; ++i)
	{
		endTurn(&g);
		r = myAssert(numHandCards(&g) == 6, "Other players did not draw an extra card", __LINE__);
	}

	//done
	if(r == 0)
		printf("Tests completed successfully!\n");

	return 0;
}
Ejemplo n.º 19
0
//testing for playCard test: #1
int main(){

    struct gameState g;

    int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,mine,ambassador,outpost,baron,tribute};

	initializeGame(2, k, 5, &g);
    int buyCards = buyCard(copper, &g);

    if(buyCards == 0){
        printf("Buy Successfully\n");
    }else{
        printf("Fail to buy\n");
    }
    int previousBuys = g.numBuys;
    int previousCoins = g.coins;

    if(g.numBuys == (previousBuys - 1)){
        printf("Buy Successfully\n");
    }else{
        printf("Fail to buy");
    }
    if(g.coins == (previousCoins - (getCost(copper)))){
        printf("Buy Successfully\n");
    }else{
        printf("Not enough coins to buy\n");
    }

	printf("Test Successfully \n");
    return 0;
}
Ejemplo n.º 20
0
int main (int argc, char** argv) {
  struct gameState G;
  
  // Setting up the game state
  G.numPlayers = 1;
  G.numBuys = 1;
  G.whoseTurn = 0;
  G.supplyCount[smithy] = 1;
  G.coins = 10;
  G.discardCount[0] = 0;

  // Calling buyCard (our function to test)
  int result = -99;
  result = buyCard(smithy, &G);

  // Checking the results
  assert(result == 0);
  assert(G.numBuys == 0);

  printf("UNIT TEST 1: BUYCARD-------------\n");
  printf("Value (expected): Actual\n");
  printf("result (0): %i\n", result);
  printf("numBuys (0): %i\n", G.numBuys);
  printf("discardCount (1): %i\n", G.discardCount[0]);
  printf("discard[0] (13): %i\n", G.discard[0][0]);
  printf("coins (6): %i\n", G.coins);



  return 0;
}
Ejemplo n.º 21
0
int main()
{
	printf("UNIT TEST THREE -- RUNNING\n");

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

	initializeGame(2, k, 5, &g);

	testfun("supplyCount");

	//assert # silvers in supply is 40
	r = supplyCount(silver, &g);
	cassert(r == 40, "# silvers in supply is 40");

	//printf("%d\n", g.coins);
	buyCard(silver, &g);

	r = supplyCount(silver, &g);
	cassert(r == 39, "# silvers in supply is 39 after 1 is bought");

	printf("UNIT TEST THREE -- FINISHED\n\n");

	return 0;
}
Ejemplo n.º 22
0
//buyCard
int main()
{
	struct gameState* gstate = malloc(sizeof(struct gameState));
	int i,j,k;
	int supplyPos;
	int testNumBuys;
	int* supply = malloc(sizeof(int)*27);
	int maxPlayers = 4;
	SelectStream(2);
	PutSeed(3);
	for (j = 1; j <= maxPlayers; j++)
	{	
		gstate->numPlayers = j;
		for(supplyPos = 0; supplyPos < 27; supplyPos++ )
		{
			for(i = 0; i< 27; i++)
			{
				gstate->supplyCount[i] = 10;
				supply[i] = gstate->supplyCount[i];
			}
			gstate->coins = 8;
			gstate->numBuys = 1;
			k = buyCard(supplyPos,gstate);
			if (k != 0  || gstate->numBuys != 0 || supply[supplyPos] - 1 != gstate->supplyCount[supplyPos])
				printf("test failed\n");
			else
				printf("test passed\n");
		}
	}
	return 0;
}
Ejemplo n.º 23
0
int main(){

	struct gameState G;

  srand(time(NULL));

  int k[10] = {curse,estate,duchy,adventurer, sea_hag,baron, smithy, village, minion, steward};
  int p, r;

  initializeGame(2, k, 3, &G);
  
  for(p = 0; p < 10; p++){

    G.numBuys = 1;
    
    r = rand() % 10; // pseudo random card generation
    G.coins =  rand() % 10; // pseudo random coin generation

    if(G.coins >= getCost(k[r])){
      if(buyCard(k[r], &G) != 0){
        printf("\nbuyCard() is not properly working.\n");
        exit(0);
      }
    }
    
  }

  printf("\nbuyCard() is properly working!!\n");

  return 0;
}
Ejemplo n.º 24
0
void CardShop::cbCommDlg(CCObject* pSender)
{
    CommDlgRet* pRet = (CommDlgRet*)pSender;
    
    if(m_commDlg != NULL){
        removeChild(m_commDlg, true);
        m_commDlg = NULL;
    }

    if (pRet->bOk)
    {
        switch (m_ReqType)
        {
            case enReqSCBuy:
                buyCard();
                break;
                
            case enReqSCGetAllCard:
                if (CGameData::Inst()->allCardRequest())
                    scheduleUpdate();
                break;
                
            default:
                break;
        }
    }
    else
    {
        CGameData::Inst()->clearReqStat();
        MainScene::Inst()->enableBottomPanel(true);
    }
}
Ejemplo n.º 25
0
//tests buyCard
int main()
{
	struct gameState G;

	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
	
	int r = initializeGame(2, k, 12, &G);
	
	G.coins = 15;
	G.numBuys = 3;

	buyCard(gold, &G);		//buys gold, 9 coins and 2 buys left
	buyCard(mine, &G);		//buys mine, 4 coins and 1 buy left
	buyCard(adventurer ,&G);	//SHOULD NOT BUY! not enough coins
	buyCard(smithy, &G);		//buys smithy, 0 coins and o buys left

	assert(G.discardCount[0] == 3);
}
Ejemplo n.º 26
0
int main() {
	
	int i, test1=0;
	int currentPlayer, money;
	struct gameState G;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
	int r = initializeGame(2, k, 2, &G);
	assert (r ==0);
	
	///// ----------------------- game -----------------------
	while (!isGameOver(&G)) 
	{
		money=0;
		for (i = 0; i < numHandCards(&G); i++) 
		{
			if (handCard(i, &G) == copper)
				money++;
			else if (handCard(i, &G) == silver)
				money += 2;
			else if (handCard(i, &G) == gold)
				money += 3;
		}	
		
		if ((supplyCount(gold, &G)==0) && (supplyCount(silver, &G)==0))
		{
			if (money >= 8) 
			{
				buyCard(province, &G);
			}
		}
		else if (money >= 6) 
		{
			buyCard(gold, &G);
		}
		else if (money >= 3) 
		{ 
			buyCard(silver, &G);
		}
		endTurn(&G);
	}
	//yes the game ends
	
	//assert(isGameover == 0)
}
Ejemplo n.º 27
0
void functionTest(int arguments)
{
	struct gameState G;
	//struct gameState *p = &G;
	
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
		sea_hag, tribute, smithy};
	
	int playerOne = 0;
	int currentPlayer = 0;

	int buy = 0;
	
	
	int randomNumber = rand() % 10 + 11;
		
	int r = initializeGame(2, k, arguments, &G);	
	
	for(int i = 0; i < 10; i++)
	{
		int supply = rand() % 5 + 1;
		currentPlayer = whoseTurn(&G);
		printf("Current Turn is = %d", currentPlayer);
		
		if(currentPlayer == playerOne)
		{
			printf("\nCurrently First Player's Turn\n");
			G.numBuys = rand() % 2 + 1;
			G.coins = rand() % 25 + 1;
			G.phase = 0;

			
		}
		else
		{
			printf("\nOther Player's Turn\n");
			G.numBuys = rand() % 4 + 1;
			G.coins = rand() % 5 + 1;
			G.phase = 0;
		}
		
		buy = buyCard(supply, &G);

		printf("\nbuy = %d\n", buy);
		if (buy != 0)
		{
			printf("\n\nASSERTION FAILED, BUY != 0!\n");
		}
		
		
		//randomNumber = rand() % 10 + 11;
		endTurn(&G);
	}
		
		
}
Ejemplo n.º 28
0
int main()
{

  	struct gameState *state = newGame();
    char* testPass;
    int result = 1;

  	
  	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
  	sea_hag, tribute, smithy};
  	
  	
  	assert(initializeGame(2, k, 84, state) == 0);
  	
  	// Not enough buys
  	state->whoseTurn = 0;
  	state->numBuys = 0;
  	state->supplyCount[feast] = 3;
  	state->coins = 10;
  	
  	assert( buyCard(feast, state) == -1 );
    result  &=  buyCard(feast, state) == -1;
  	
  	// Not enough supply
  	state->numBuys = 3;
  	state->supplyCount[feast] = 0;
  	state->coins = 10;
  	
  	assert( buyCard(feast, state) == -1 );
    result  &=  buyCard(feast, state) == -1;
  	
  	// Not enough coin
  	state->numBuys = 3;
  	state->supplyCount[feast] = 6;
  	state->coins = 0;
  	
  	assert( buyCard(feast, state) == -1 );
    result  &=  buyCard(feast, state) == -1;
  	
    // No problems here
  	state->numBuys = 3;
  	state->supplyCount[feast] = 7;
  	state->coins = 10;
  	
  	assert( buyCard(feast, state) == 0 );
    result  &=  buyCard(feast, state) == 0;
    
    testPass = result ? PASS : FAIL;
    printf( "LOG - Unit Test 1:\t%s\n", testPass );
  	
  	return 0;
}
Ejemplo n.º 29
0
int testBuyCard(int* failed){
    struct gameState g;

    int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,mine,ambassador,
	       outpost,baron,tribute};

    int r = initializeGame(2, k, 5, &g);

    g.whoseTurn = 1;
    g.numBuys = 1;
    g.coins = 10;
    (g.supplyCount)[curse] = 1;
    
    myassert(failed, supplyCount(curse, &g) == 1, "Supply count should be 1");
    myassert(failed, buyCard(curse, &g) == 0, "You can't buy a card when you should be able to");
    myassert(failed, supplyCount(curse, &g) == 0, "Supply count should be 0");
    myassert(failed, buyCard(curse, &g) != 0, "You bought a card with 0 in supply");

    return 0;
}
Ejemplo n.º 30
0
void checkBuyCard(int card, struct gameState *game, char *msg)
{
	int player;
	int ret, expectedRet;
	struct gameState expectedState;

	// Make a copy of the given game state.
	memcpy(&expectedState, game, sizeof(struct gameState));

	// Generate the actual game state.
	ret = buyCard(card, game);

	// Generate the expected game state.
	{
		// Conditions for buying a given card:
		// (1) It is purchased during the buy phase.
		// (2) It can only be bought if the current player has buy points.
		// (3) It exists within the enumerated list of cards.
		// (4) It is available in the game.
		// (5) It does not cost more than the current player's amount of coins.
		expectedRet = -1;
		player = expectedState.whoseTurn;
		if (expectedState.phase == 1                // (1)
		    && expectedState.numBuys > 0            // (2)
		    && card >= 0 && card < treasure_map     // (3)
		    && expectedState.supplyCount[card] > 0  // (4)
		    && expectedState.coins >= getCost(card) // (5)
		) {
			// The given card can be bought.
			expectedRet = 0;

			// Pay for the given card.
			expectedState.coins -= getCost(card);
			expectedState.numBuys--;

			// Move the given card from the supply deck to the current player's
			// discard deck.
			expectedState.supplyCount[card]--;
			expectedState.discard[player][expectedState.discardCount[player]] = card;
			expectedState.discardCount[player]++;
		}
	}

	// Compare the actual game state against the expected game state, and
	// check the return value.
	if (memcmp(game, &expectedState, sizeof(struct gameState)) == 0
	    && ret == expectedRet
	) {
		printf("buyCard() PASSED: %s\n", msg);
	} else {
		printf("buyCard() FAILED: %s\n", msg);
	}
}