Ejemplo n.º 1
0
int calcScore(int p, struct gameState * gs) {
	int i;
	int totalScore = 0;		//total score
	int cardsInDeck = gs->deckCount[p] + gs->handCount[p] + gs->discardCount[p]; 
	
	//Deck
	for (i = 0; i < gs->deckCount[p]; i++) {
		totalScore += getCardScore(gs->deck[p][i], cardsInDeck);
	}
	
	//Hand
	for (i = 0; i < gs->handCount[p]; i++) {
		totalScore += getCardScore(gs->hand[p][i], cardsInDeck);
	}
	
	//Discard
	for (i = 0; i < gs->discardCount[p]; i++) {
		totalScore += getCardScore(gs->discard[p][i], cardsInDeck);
	}
	
	return totalScore;
}
Ejemplo n.º 2
0
int main() 
{
    srand(time(NULL));
    int numPlayer = 2;
    int seed = rand() % 9999;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    
    struct gameState G;
    printf ("TESTING scoreFor():\n");
    memset(&G, 23, sizeof(struct gameState));
    assert(initializeGame(numPlayer, k, seed, &G) == 0); 
    int p, i;
    int score;
    int handRandom, deckRandom, discardRandom;
    for (p = 0; p < numPlayer; p++) //initiate hand, deck and discard cards
    {
        score = 0;
        handRandom = rand() % MAX_HAND;
        G.handCount[p] = handRandom;
        for (i = 0; i < handRandom; i++) 
        {
            G.hand[p][i] = rand() % 27;
        }
        
        deckRandom = rand() % MAX_DECK;
        G.deckCount[p] = deckRandom;
        for (i = 0; i < deckRandom; i++) 
        {
            G.deck[p][i] = rand() % 27;
        }
 
        discardRandom = rand () % MAX_DECK;
        G.discardCount[p] = discardRandom;
        for (i = 0; i < discardRandom; i++) 
        {
            G.discard[p][i] = rand() % 27;
        }
        //sum up the score of all cards
         for (i = 0; i < handRandom; i++) 
        {
            score += getCardScore(G.hand[p][i], &G, p);
        }

        for (i = 0; i < deckRandom; i++) 
        {
            score += getCardScore(G.deck[p][i], &G, p);
        }

        for (i = 0; i < discardRandom; i++) 
        {
            score += getCardScore(G.discard[p][i], &G, p);
        }
        if (scoreFor(p, &G) == score)
        {
            printf("Testing scoreFor() passed! for user: %d\n", p);
        } else {
            printf("Testing scoreFor() failed for user: %d \n", p);
        }
    }
 
    return 0;
}