Ejemplo n.º 1
0
int main(int argc, char* argv[])
{
  int coins;
  int who;
  struct gameState* s = newGame();
  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
    		sea_hag, tribute, smithy};
  
  initializeGame(2, k, 3, s);
  coins = s->coins;
  who = s->whoseTurn;
  s->hand[who][6] = steward;
  s->handCount[who]++;

  assert(playCard(6, 1, 0, 0, s) == 0);
  assert(s->handCount[who] == 7);
   
  s = newGame();
  initializeGame(2, k, 3, s);
  coins = s->coins;
  who = s->whoseTurn;
  s->hand[who][6] = steward;
  s->handCount[who]++;
  assert(playCard(6, 0, 0, 1, s) == 0);
  assert(s->handCount[who] == 3);
  
  printf("stewardEffect Passed. \n");
}
Ejemplo n.º 2
0
unsigned int Scopa::strategyPlay(std::function<Card()> strategyCard, std::function<CardGroup(std::vector<CardGroup>)> strategyCapture) {
    Card cardToPlay = strategyCard();
    std::vector<CardGroup> captures = possibleCaptures(cardToPlay.value);
    if( captures.size() == 0 ) { return playCard(currentTurn, cardToPlay, CardGroup()); }
    else if( captures.size() == 1 ) { return playCard(currentTurn, cardToPlay, captures.front()); }
    else { return playCard(currentTurn, cardToPlay, strategyCapture(captures)); }
}
Ejemplo n.º 3
0
int main() {
  printf("Running unit test for card \"steward\"...\n");

  struct gameState G;
  struct gameState *p = &G;

  int seed = 123456789;
  int coinsBefore;
  int numHandCardsBefore;
  int k[10] = {steward, gardens, embargo, village, minion, mine, cutpurse, 
    sea_hag, tribute, smithy};
  
  initializeGame(2, k, seed, p);
  p->hand[0][0] = steward;
  coinsBefore = p->coins;
  assertTrue(playCard(0, 0, 0, 0, p) == 0, "playCard(0, 0, 0, 0, p) == 0");
  assertTrue(p->coins == coinsBefore + 2, "p->coins == coinsBefore + 2");  //BUG: coin values not updating

  initializeGame(2, k, seed, p);
  p->hand[0][0] = steward;
  numHandCardsBefore = numHandCards(p);
  assertTrue(playCard(0, 1, 0, 0, p) == 0, "playCard(0, 1, 0, 0, p) == 0");
  assertTrue(numHandCards(p) == numHandCardsBefore + 2 - 1, "numHandCards(p) == numHandCardsBefore + 2 - 1");

  initializeGame(2, k, seed, p);
  p->hand[0][0] = steward;
  numHandCardsBefore = numHandCards(p);
  assertTrue(playCard(0, 2, 0, 0, p) == 0, "playCard(0, 2, 0, 0, p) == 0");
  assertTrue(numHandCards(p) == numHandCardsBefore - 3 , "numHandCards(p) == numHandCardsBefore - 3");

  return 0;
}
Ejemplo n.º 4
0
int main(){
  struct gameState g;
  int k[10] = {steward, smithy, adventurer, gardens, embargo, cutpurse, mine,
               outpost, baron, tribute};

  int choice2 = 0;
  int choice3 = 0;
  int handPos = 0;

  initializeGame(2, k, 5, &g);
  g.hand[0][0] = steward;
  g.whoseTurn = 0;  

  int num = numHandCards(&g);
  playCard(handPos, 1, choice2, choice3, &g);
  int numa = numHandCards(&g);
  
  // Steward adds two cards to the hand if choice1 == 1
  assertTF(numa = num + 2, "Add 2 card to hand\n");

  int coins = g.coins;
  // Steward adds two coins if choice1 == 2
  printf("coins b: %d\n", g.coins);
  playCard(handPos, 2, choice2, choice3, &g);
  assertTF(g.coins == coins + 2, "Add 2 coins\n");
  printf("coins a: %d\n", g.coins);

  num = numHandCards(&g);
  // Steward trashes two cards if choice1 == 3
  playCard(handPos, 3, choice2, choice3, &g); 
  numa = numHandCards(&g);
  assertTF(numa == num - 3, "Trash 2 cards\n");

  checkasserts();
}
Ejemplo n.º 5
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;
}
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);
    }
}
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.º 8
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.º 9
0
//test council room card
int main(){
	printf("Start to test minion card.\n");
	struct gameState state;
	int numCard0, numCard1, numCard2, numCard3, numAct0;
	int kindom[10] = {1,2,3,4,5,6,7,8,9,10};
	initializeGame(4, kindom, 2, &state);
	//player0 get2 2 cards in hand
	state.handCount[0] = 2;
	state.handCount[1] = 2;
	state.handCount[2] = 5;
	//the first card is minion
	state.hand[0][0] = minion;
	//player 0's turn
	state.whoseTurn = 0;
	//card number for 3 players
	numCard0 = state.handCount[0];
	numCard1 = state.handCount[1];
	numCard2 = state.handCount[2];
	numCard3 = state.handCount[3];
	//action of current player
	numAct0 = state.numActions;
	//printf("numCard1 is: %d\n", numCard1 );
	playCard(0, 0, 1, 0, &state);
	//draw 4 card and discard 1 card
	//printf("numCard1 is now: %d\n", state.handCount[1]);
	printf("Testing handCount for player1 choice2 .\n");
	assert (state.handCount[0] == 4);
	printf("Passed.\n");
	printf("Testing handCount for other players, choice2.\n");
	assert (state.handCount[1] == numCard1);
	assert (state.handCount[2] == 4);
	printf("Passed.\n");
	printf ("Testing the number of action.\n");
	assert (numAct0 == state.numActions);
	printf ("Passed.\n");
	printf("Testing coins, choice1.\n");
	state.handCount[0] = 1;
	state.coins = 0;	
	state.hand[0][0] = minion;
	state.whoseTurn = 0;
	playCard(0, 1, 0, 0, &state);
	printf("coins=");
	assert (state.coins == 2);
	printf("Bug found in line 910 of dominion.c.\n");
	//assert (state.numBuys == numBuy + 1);
	printf("Passed.\n");
	printf("Card minion is working.\n");
}
Ejemplo n.º 10
0
int main (int argc, char** argv)
{
	struct gameState g;

	int players, seed, fails, deck, hand, check, test = 0;

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

	printf ("Starting tests.\n");
  
	while(test<MAX_TESTS)
	{
		if(!argc)
			seed = rand();
		else
			seed = 42;
		players = rand() % 4;
		initializeGame(players, k, seed, &g);
		deck = rand() % MAX_DECK;
		hand = rand() % MAX_HAND;
		g.whoseTurn = players;
		g.deckCount[players] = deck;
		g.handCount[players] = hand;
		
		addCardToHand(players, smithy, &g);
		check = g.handCount[players];
		playCard(hand, 0, 0, 0, &g);
		if(check+2!=g.handCount[players])
			fails++;

		test++;
	}
	printf ("Test finished with %d fails out of %d tests.\n",fails,test);
	return 0;
}
int main()
{
	printf("CARD TEST THREE -- RUNNING\n");
	
	struct gameState g;
    int r, prevcoins;
    int k[10] = {village, smithy, cutpurse, minion, council_room, sea_hag,treasure_map, ambassador, tribute, salvager};
    initializeGame(2, k, 5, &g);
	prevcoins = g.coins;
	printf("# coins before minion = %d\n", prevcoins);
	//give player 0 a minion
	gainCard(minion, &g, 2, 0);
	r = g.hand[0][5];
	cassert(r == minion, "card 5 in hand is minion");

	testfun("playCard with card = minion, +2 coins");
	r = playCard(5, 1, 0, 0, &g); //choice 1; +2 coins
	cassert(r == 0, "minion played");

	r = g.numActions;
	cassert(r == 1, "# actions = 1"); //assert # actions is 1

	printf("# coins after minion = %d\n", g.coins);
	r = g.coins;
	cassert(r != prevcoins, "# coins changed"); //assert # coins is 2 more

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

	return 0;
}
Ejemplo n.º 12
0
int main() {

  printf("Testing card: feast...\n");

  // Setup

  struct gameState G;
  int k[10] = {village, smithy, feast, mine, outpost, adventurer, baron, cutpurse, tribute, embargo};

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

  G.whoseTurn = 1;
  G.hand[1][0] = feast;
  int handCount = G.handCount[1];
  int deckCount = G.deckCount[1];
  int discardCount = G.discardCount[1];

  // Do something

  // playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state)
  playCard(0, village, 0, 0, &G);

  // Did something, now check it
  my_assert(G.handCount[1] == handCount, "Wrong number of cards in hand");
  my_assert(G.deckCount[1] == deckCount, "Wrong number of cards in deck");
  my_assert(G.discardCount[1] == discardCount + 1, "Wrong number of cards in discard");
  my_assert(G.discard[1][0] == village, "Village card not in discard");
}
Ejemplo n.º 13
0
int main(int argc, char *argv[]){
	
	struct gameState g;
	int seed, test_max, num_playaz, player, deck_size, hand_size, output, turn, i;
	int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,mine,ambassador,outpost,baron,tribute};
	
	if(argc = 3){
		seed = atoi(argv[1]);
		test_max = atoi(argv[2]);
		output = atoi(argv[3]);	
	}
		
	for(i = 0; i < test_max; i++){		
		num_playaz = rand() %3 + 2;
		
		initializeGame(num_playaz, k, seed, &g);
	
		//randomly test players
		player = rand() % num_playaz;
		deck_size = rand() % MAX_DECK;
		hand_size = rand() % MAX_HAND;
		
		g.whoseTurn = player;
		g.deckCount[player] = deck_size;
		g.handCount[player] = hand_size;
		
		addCardToHand(player, smithy, &g);
		playCard(hand_size, 0, 0, 0, &g);
		
		printf("Smithy Test #%d: Players [%d] Player [%d] Deck Count [%d] Hand Count [%d + 1]\n", i, num_playaz, player, deck_size, hand_size);	
	}
}
Ejemplo n.º 14
0
int main(){
	
	printf("\nCardtest4: great_hall\n");
	struct gameState G;
	
	int k[10] = {duchy, council_room, great_hall, province, baron, adventurer, smithy, minion, village, steward};
	int hcBefore, hcAfter, actions_before, actions_after;
	
	initializeGame(2, k, 3, &G);

	G.hand[0][0] = great_hall;
	
	hcBefore = G.handCount[0];
	actions_before = G.numActions;

	playCard(1, -1, -1, -1, &G);

	hcAfter = G.handCount[0];
	actions_after = G.numActions;

	my_assert(hcAfter == hcBefore, "Handcounts."); //play 1 draw 1;
	my_assert(actions_after == actions_before, "Actions."); //action +1 -1 

	printf("End Caretest4.\n");
	
	return 0;
}
Ejemplo n.º 15
0
int main (int argc, char** argv) {
  struct gameState G;
  
  // Setting up the game state
  G.numPlayers = 1;
  G.whoseTurn = 0;
  G.numBuys = 1;
  G.numActions = 1;
  G.coins = 0;
  G.supplyCount[duchy] = 2;
  // Player 0 stuff
  G.handCount[0] = 3;
  G.hand[0][0] = steward;
  G.hand[0][1] = estate;
  G.hand[0][2] = estate;
  G.deckCount[0] = 2;
  G.deck[0][0] = duchy;
  G.deck[0][1] = duchy;
  G.discardCount[0] = 0;

  // Calling playCard with steward
  int result;
  result = playCard(0, 2, 1, 2, &G);

  // Checking the results
  printf("CARD TEST 4: STEWARD-------------\n");
  printf("Value (expected): Actual\n");
  printf("result (0): %i\n", result);
  printf("handCount[0] (2): %i\n", G.handCount[0]);
  printf("numActions (0): %i\n", G.numActions);
  printf("coins (2): %i\n", G.coins);
  printf("discardCount (3): %i\n", G.discardCount[0]);

  return 0;
}
Ejemplo n.º 16
0
int main (int argc, char *argv[]){
    int card = 13;
    enum CARD mycard = outpost;     
    int choice1 = 0;
    int choice2 = 0; 
    int choice3 = 0;
    struct gameState * GameState = newGame();
    int handPos = 0;
    int * bonus = 0;
    int initialcardnum = GameState->deckCount[0];
    int initialactions = GameState-> numActions;
    int myturn = whoseTurn(GameState);
    int mydeckcount = GameState -> deckCount[myturn];
    int k[10] =  {adventurer, council_room, feast, gardens, mine,
            remodel, smithy, village, baron, great_hall};
    printf("\n\nCardTest4\n");
    initializeGame(2, k, 14242, GameState);

    GameState->hand[myturn][0] = steward; 
    choice1 = 1;
    playCard(GameState->hand[myturn][0] , 1 , 0 , 0 , GameState);
    if (mydeckcount + 2 != GameState -> deckCount[myturn]){
        printf("FAILURE: Steward did not incrase cards by 2");
    }
        return 0;
}
Ejemplo n.º 17
0
int main (int argc, char** argv)
{
  struct gameState state;

  state.whoseTurn = 0;
  state.numActions = 1;
  state.handCount[0] = 1;
  state.hand[0][0] = great_hall;
  state.deckCount[0] = 1;
  state.deck[0][0] = province;
  state.discardCount[0] = 0;

  printf("Playing Great hall card.\n");
  playCard( 0, 0, 0, 0, &state);
  printf("Checking hand count... ");
  myassert(state.handCount[0] == 1);
  printf("Checking # of actions... ");
  myassert(state.numActions == 1);
  printf("Next two tests should fail because the Great Hall card has purposely been changed\n");
  printf("Checking deck size... ");
  myassert(state.deckCount[0] == 0);
  printf("Checking hand cards... ");
  myassert(state.hand[0][0] == province);

  return 0;
}
Ejemplo n.º 18
0
/**
 * MouseEvent for clicking on a humanCard or on the Stack
 * @brief Playground::mousePressEvent
 * @param event
 */
void Playground::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
    if (event->button() == Qt::LeftButton) {
        QGraphicsItem* item = itemAt(event->buttonDownScenePos(event->button()), QTransform());
        if (item != NULL) {

            //Clicked on Stack
            if (item == stack.createImg()) {
                players.value(PlayerItem::direction::HUMAN)->unsetPlayableCards();
                players.value(PlayerItem::direction::HUMAN)->setUnactive();
                emit drawCard();
            }
            //Clicked on Human Card
            PlayerItem* human = players.value(PlayerItem::direction::HUMAN);
            for (int j = 0; j < human->getCards()->size(); ++j) {
                CardItem* c = human->getCards()->at(j);
                if (c->createImg() == item && c->getPlayable()) {
                    history.write("You play a Card", c->getCard().getSuit(), c->getCard().getValue());
                    Card::cardSuit chosenColor = Card::NONE;
                    if (c->getCard().getValue() == wishSuitCard) {
                        chosenColor = chooseColor();
                    }
                    soundMgr.playCard();
                    updateDepotCard(*c, depot);
                    soundMgr.drawCard();
                    human->removeCard(c->getCard());
                    human->unsetPlayableCards();
                    human->setUnactive();
                    emit playCard(depot.getCard(), chosenColor);
                }
            }
        }
    }
}
Ejemplo n.º 19
0
int main (int argc, char** argv) {
	puts("Testing card gardens...");
	
	srand(time(NULL)); // Seed rand function
	/* Prepare arguments for initializeGame */
	int numPlayers = rand() % 3 + 2;
	int randomSeed = rand();
	int k[10] = {adventurer, gardens, embargo, village, minion,
		mine, cutpurse, sea_hag, tribute, smithy};
	struct gameState G;
	
	/* Run initializeGame function */
	initializeGame(numPlayers, k, randomSeed, &G);
	
	G.hand[0][0] = gardens;
	int handCountBefore = numHandCards(&G);
	
	int returnValue = playCard(0, 0, 0, 0, &G);
	assert(returnValue == 0);
	
	int handCountAfter = numHandCards(&G);
	// discard gardens
	assert(handCountAfter == (handCountBefore - 1));
	
	testStatus();
	
	return 0;
}
Ejemplo n.º 20
0
int main()
{
	int i;
	int seed = 1000;
	int numPlayers = 2;
	int player  = 0;
	int *deckZero,*deckOne;
	struct gameState preTest, postTest;
	int k[10] = {adventurer, council_room, feast, gardens, mine ,remodel, smithy, village, baron, great_hall};
	/* Test Specification Variables */
	int drawCountTestZero = 3;
	int drawCountTestOne = 0;

	initializeGame(numPlayers,k,seed,&postTest);
	printf("\n\nBeginning Test for Village...\n\n");
	memcpy(&preTest,&postTest,sizeof(struct gameState));
	insertCard(&postTest,player);
	playCard((postTest.handCount[player]-1),0,0,0,&postTest);
	testDraw(&preTest,&postTest,player);
	testHand(&preTest,&postTest,player);
	testDiscard(&preTest,&postTest,player);
	testSupply(&preTest,&postTest);
	testPlayed(&preTest,&postTest);
	testUtility(&preTest,&postTest);
	printf("\n\tTesting finished\n\n");
}
Ejemplo n.º 21
0
int main()
{
	printf("Start test: smithy\n");
	struct gameState G;
	 
	int k[10] = {council_room, smithy, gardens, village, baron, adventurer, great_hall, mine, embargo,
	       outpost};
  
	int x = initializeGame(2, k, 1, &G);
	
	assert(x == 0);
	
	// Add card
	G.hand[0][0] = smithy;
	
  	//int numCard = G.coins;
  	int buys = G.numBuys;
  	int hand = G.handCount[0];
	int actions = G.numActions;
	int playCount = G.playedCardCount;
	int coins = G.coins;
	
	
  	// int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) 
  	playCard(0, 0, 0, 0, &G);

  	my_assert(G.numBuys == buys, "Buys."); // ~
  	my_assert(G.handCount[0] == hand + 3 - 1, "Handcounts."); // +2
  	my_assert(G.numActions == actions - 1, "Actions."); // -1
  	my_assert(G.playedCardCount == playCount + 1, "Playcount."); // +1
  	my_assert(G.coins == coins, "Coins."); // ~
  	
  	printf("End test.\n");
  			
}
Ejemplo n.º 22
0
int main(){
	
	printf("\nCardtest2: village\n");
	struct gameState G;
	
	int k[10] = {duchy, council_room, great_hall, province, baron, adventurer, smithy, minion, village, steward};
	int actions_before, actions_after, pcBefore, pcAfter, hcBefore, hcAfter;
	
	initializeGame(2, k, 3, &G);

	G.hand[0][0] = village;
	
	actions_before = G.numActions;
	pcBefore = G.playedCardCount;
	hcBefore = G.handCount[0];
	
	playCard(1, -1, -1, -1, &G);
	
	actions_after = G.numActions;
	pcAfter = G.playedCardCount;
	hcAfter = G.handCount[0];
	
	my_assert(actions_after == (actions_before - 1 + 2), "Actions."); // play village action-1 getaction+2
	my_assert(pcAfter == (pcBefore + 1), "Playcard.");
	my_assert(hcAfter == hcBefore, "Handcounts."); 

	printf("End Caretest2.\n");

	return 0;
}
Ejemplo n.º 23
0
int main(){

	
		printf("*************start(steward)*************\n");
		//initial game reset everything for game and set 10 case to run
	struct gameState G;
	
int k[10] = {great_hall, duchy, remodel, province, ambassador, adventurer, smithy, cutpurse, village, sea_hag};	
int before, after, actions_before, actions_after;
	
	initializeGame(4, k, 2, &G);

	G.hand[0][0] = great_hall;
	
	before = G.handCount[0];
	actions_before = G.numActions;
	//test cards
	playCard(1, -1, -1, -1, &G);

	after = G.handCount[0];
	actions_after = G.numActions;
	//test actions
	my_assert(after == before, "Handcounts."); //test the cars
	my_assert(actions_after == actions_before, "Actions."); //test the actions
 printf("*************done*************\n");
	
	return 0;
}
Ejemplo n.º 24
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.º 25
0
// Tests playCard()
int main(){

	struct gameState g;
	int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,
						mine,ambassador,outpost,baron,tribute};
	
	int i;
	for(i = 0; i < 100; i++){
		int randSeed = rand % 5000;
		int randPlayers = rand % 4;
		int currPlayer = whoseTurn(&g);
		
		do{
			randPlayers = rand % 4;
		}while(randPlayers < 2);
		
		initializeGame(randPlayers, k, randSeed, &g);

		printf("playCard() TEST #%d\n", i+1);

		playCardCheck = playCard(currPlayer, 0, 0, 0, &g);

		myAssert(playCardCheck, "1");

		checkAsserts();
	}

	return 0;
}
Ejemplo n.º 26
0
int main () {
	printf("***Testing council_room***\n");
	struct gameState G;
	int k[10] = {salvager, smithy, gardens, tribute, baron, adventurer, cutpurse, mine, embargo,
			council_room};

	initializeGame(2, k, 3, &G);
	G.handCount[0] = 3;
	G.hand[0][0] = council_room;
	int preNumCards = G.handCount[0];
	int preNumBuys = G.numBuys;
	int preNumCards_P2 = G.handCount[1];


	printf("Testing if council_rooom draws 3 and increments NumBuys for player, and draws 1 for remaining players...\n");
	playCard(0, 1, 0, 0, &G);
	assert(G.handCount[0] == preNumCards + 3);
	assert(G.numBuys == preNumBuys + 1);
	assert(G.handCount[1] == preNumCards_P2 + 1 );

	printf("Test passes\n");

	//playCard(0, 1, 0, 0, NULL);


}
Ejemplo n.º 27
0
int main() {
	struct gameState* testState = newGame();
	int* myKingdomCards = kingdomCards(7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
	initializeGame(2, myKingdomCards, 3, testState);
	
	testState->hand[0][0] = remodel;
	
	assert(testState->coins == 3);
	assert(testState->handCount[0] == 5);
	
	playCard(0, copper, estate, 0, testState);
	
	assert(testState->coins == 2);
	assert(testState->handCount[0] == 3);
	assert(testState->discardCount[0] == 1);
	assert(testState->discard[0][0] == estate);

	
	endTurn(testState);
	
	assert(testState->discardCount[0] == 5);
	assert(testState->discard[0][0] == remodel);
	
	return 0;
}
Ejemplo n.º 28
0
int main()
{
    	int handPos;
        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, 26, state) == 0);
    	
    	state->numActions = 1;
    	state->handCount[0] = 1;
    	state->whoseTurn = 0;
    	state->hand[0][0] = great_hall;
    	handPos = 0;
    	
    	assert( playCard(handPos, 0, 1, 0, state) == 0);
    	
    	// Great Hall +1 Action
    	assert( state->numActions == 1 );
        result  &=  state->numActions == 1;
    
    	
    	// Great Hall Draw Card
    	assert( state->handCount[0] == 1 );
        result  &=  state->handCount[0] == 1;
    
        testPass = result ? PASS : FAIL;
        printf( "LOG - Card Test 1:\t%s\n", testPass );
    
    	return 0;
}
Ejemplo n.º 29
0
int main(){
  struct gameState g;
  int k[10] = {great_hall, smithy, adventurer, gardens, embargo, cutpurse, mine,
               outpost, baron, tribute};

  int choice1 = 0;
  int choice2 = 0;
  int choice3 = 0;
  int handPos = 0;

  initializeGame(2, k, 5, &g);
  g.hand[0][0] = great_hall;
  g.whoseTurn = 0;
  
  int num = numHandCards(&g);
  playCard(handPos, choice1, choice2, choice3, &g);
  int numa = numHandCards(&g);
  int actions = g.numActions;

  // Great Hall adds a card to the hand
  assertTF(numa = num, "Number of cards in hand should stay the same\n");
  // It also gives the player +1 actions
  assertTF(g.numActions == actions, "# of actions should stay the same\n");

  checkasserts();
}
Ejemplo n.º 30
0
void act(char *s) {
	int handPos;
	int choice1, choice2, choice3;
	int result;
	
	fgets(s, BUFFSIZE, rfs);
	while(strcmp(s, "a\n")) { // line is not "a\n"
		strtok(s, " ");
		handPos = (int) strtol(strtok(NULL, ","), (char**) NULL, 10);
		choice1 = (int) strtol(strtok(NULL, ","), (char**) NULL, 10);
		choice2 = (int) strtol(strtok(NULL, ","), (char**) NULL, 10);
		choice3 = (int) strtol(strtok(NULL, ","), (char**) NULL, 10);
		
		result = playCard(handPos, choice1, choice2, choice3, &gs);
		if (result == -1) {
			success = 0;
			printf("playCard returned -1:\nhandPos=%d\ncard=%d\nchoice1=%d\nchoice2=%d\nchoice3=%d\n",
				handPos, gs.hand[gs.whoseTurn][handPos], choice1, choice2, choice3);
		}
		sprintf(s, "A %d,%d,%d,%d\n", handPos, choice1,
			choice2, choice3);
		write(wfd, s, strlen(s));
		fgets(s, BUFFSIZE, rfs);
	} // line is "a\n"
}