Esempio n. 1
0
int main () {
	int i, j;
	int result;				//return value for function calls
	int failed, changed;	//flags for tests
	int cardsBefore[treasure_map];	//cards in hand before shuffle
	int cardsAfter[treasure_map];	//cards in hand after shuffle
	
	struct gameState *g = malloc(sizeof(struct gameState));		//working game state
	struct gameState *pre = malloc(sizeof(struct gameState));	//reference game state; stored before functions run
	int selectedCards[10] = {adventurer, council_room, feast, gardens, mine, smithy, village, tribute, salvager, sea_hag};	
	int seed = 10;


	//---Test deckCount = 0
	//---Expected result: error
	printf("*** Testing deckCount = 0 ***\n");
	printf("Errors: ");
	//Create clean game
	if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){
		printf("\nCould not initialize game. Testing aborted.");
		return -1;
	}
	//Draw all cards in deck
	while (g->deckCount[whoseTurn(g)] > 0){
		drawCard(whoseTurn(g), g);
	}	
	//Save current state
	memcpy(pre, g, sizeof(struct gameState));
	//Attempt to shuffle
	result = shuffle(whoseTurn(g), g);
	failed = 0;
	if (result != -1){
		printf("\nReturn value: %d, Expected: %d", result, -1);
		failed = 1;
	}
	//Check game state is unchanged
	if (checkGameState(pre, g) < 0){
		printf("\ngameState changed");
		failed = 1;
	} 
	//Final check
	if (failed){
		printf("\nResult: FAIL\n\n");
	} else {
		printf("none");
		printf("\nResult: PASS\n\n");
	}
	

	//---Test deckCount = 1
	//---Expected result: gameState is unchanged
	printf("*** Testing deckCount = 1 ***\n");
	printf("Errors: ");
	//Create clean game
	if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){
		printf("\nCould not initialize game. Testing aborted.");
		return -1;
	}
	//Draw all cards but 1 in deck
	while (g->deckCount[whoseTurn(g)] > 1){
		drawCard(whoseTurn(g), g);
	}	
	//Save current state
	memcpy(pre, g, sizeof(struct gameState));
	//Run shuffle and check results
	failed = 0;
	result = shuffle(whoseTurn(g), g);
	if (result == -1){
		printf("\nReturn value: %d, Expected: %d", result, 0);
		failed = 1;
	} 
	//Check game state is unchanged
	if (checkGameState(pre, g) < 0){
		printf("\ngameState changed");
		failed = 1;
	} 
	//Final check
	if (failed){
		printf("\nResult: FAIL\n\n");
	} else {
		printf("none");
		printf("\nResult: PASS\n\n");
	}
	
	
	
	//---Test deckCount > 1
	/*---Expected results: 
	     - Game and turn settings are unchanged
		 - Other player's cards (hand, deck, discard) are unchanged
		 - Current player's hand and discard are unchanged
		 - Played cards are unchanged
		 - Current player's deck Count is unchanged
		 - Current player's deck contains same cards as before shuffle
		 - Current player's deck cards are in different order than before shuffle
	*/
	printf("*** Testing deckCount > 1 ***\n");
	printf("Errors: ");
	//Create clean game
	if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){
		printf("\nCould not initialize game. Testing aborted.");
		return -1;
	} 
	//Confirm deckCount > 1
	if (g->deckCount[whoseTurn(g)] <= 1){
		printf("\nCould not create suitable game. Testing aborted.");
		return -1;
	}		
	//Save current state
	memcpy(pre, g, sizeof(struct gameState));
	//Initialize card count arrays
	for (i = 0; i < treasure_map; i++){
		cardsAfter[i] = 0;
		cardsBefore[i] = 0;
	}
	//Get before deck card counts
	for (i = 0; i < g->deckCount[(whoseTurn(g))]; i++){
		cardsBefore[g->deck[whoseTurn(g)][i]]++;
	}
	//Run shuffle and check results
	failed = 0;
	result = shuffle(whoseTurn(g), g);
	if (result == -1){
		printf("\nReturn value: %d, Expected: %d", result, 0);
		failed = 1;
	}
	//Check game/turn settings
	if (checkNumPlayers(pre, g) < 0){
		printf("\nNumPlayers: %d, Expected: %d", g->numPlayers, pre->numPlayers);
		failed = 1;
	}
	result = checkSupply(pre, g);
	if (result != 0){
		printf("\nSupply count for card %d: %d, Expected: %d", result, g->supplyCount[result], pre->supplyCount[result]);
		failed = 1;
	}
	result = checkEmbargo(pre, g);
	if (result != 0){
		printf("\nEmbargo for card %d: %d, Expected: %d", result, g->embargoTokens[result], pre->embargoTokens[result]);
		failed = 1;
	}
	if (checkOutpost(pre, g) < 0){
		printf("\noutpostPlayed: %d, Expected: %d", g->outpostPlayed, pre->outpostPlayed);
		printf("\noutpostTurn: %d, Expected: %d", g->outpostTurn, pre->outpostTurn);
		failed = 1;
	}	
	if (checkTurn(pre, g) < 0){
		printf("\nwhoseTurn: %d, Expected: %d", g->whoseTurn, pre->whoseTurn);
		failed = 1;
	}
	if (checkPhase(pre, g) < 0){
		printf("\nphase: %d, Expected: %d", g->phase, pre->phase);
		failed = 1;
	}	
	if (checkNumActions(pre, g) < 0){
		printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions);
		failed = 1;
	}	
	if (checkCoins(pre, g) < 0){
		printf("\ncoins: %d, Expected: %d", g->coins, pre->coins);
		failed = 1;
	}
	if (checkNumBuys(pre, g) < 0){
		printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys);
		failed = 1;
	}
	//Check all hand, discard, play cards unchanged
	if (checkHands(pre, g) < 0){
		printf("\nHands changed after shuffle\n");
		//Print expected and actual hand for each player
		for (i = 0; i < NUM_PLAYERS; i++){
			printf("    Hand for player %d:\n", i);
			printf("      Count: %d, Expected: %d\n", g->handCount[i], pre->handCount[i]);
			if (g->handCount[i] > 0){
				printf("      Actual Cards: ");
				for (j = 0; j < g->handCount[i]; j++){
					printf("%d ", g->hand[i][j]);
				}
				printf("\n      Expected Cards: ");
				for (j = 0; j < pre->handCount[i]; j++){
					printf("%d ", pre->hand[i][j]);
				}
			}
		}
		failed = 1;
	}
	if (checkDiscards(pre, g) < 0){
		printf("\nDiscards changed after shuffle\n");
		//Print expected and actual discards for each player
		for (i = 0; i < NUM_PLAYERS; i++){
			printf("    Discard pile for player %d:\n", i);
			printf("      Count: %d, Expected: %d\n", g->discardCount[i], pre->discardCount[i]);
			if (g->discardCount[i] > 0){
				printf("      Actual Cards: ");
				for (j = 0; j < g->discardCount[i]; j++){
					printf("%d ", g->discard[i][j]);
				}
				printf("\n      Expected Cards: ");
				for (j = 0; j < pre->discardCount[i]; j++){
					printf("%d ", pre->discard[i][j]);
				}
			}
		}
		failed = 1;
	}
	if (checkPlayed(pre, g) < 0){
		printf("\nPlayed cards changed after shuffle\n");
		//Print expected and actual discards for each player
		printf("    Played count: %d, Expected: %d\n", g->playedCardCount, pre->playedCardCount);
		if (g->playedCardCount > 0){
			printf("    Actual Cards: ");
			for (i = 0; i < g->playedCardCount; i++){
				printf("%d ", g->playedCards[i]);
			}
			printf("\n    Expected Cards: ");
			for (i = 0; i < pre->playedCardCount; i++){
				printf("%d ", pre->playedCards[i]);
			}
		}
		failed = 1;
	}
	//Check deck unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->deckCount[i] != g->deckCount[i]){
			printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->deckCount[i]; j++){
				if (pre->deck[i][j] != g->deck[i][j]){
					printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check current player's deck is same size
	if (pre->deckCount[whoseTurn(g)] != g->deckCount[whoseTurn(g)]){
		printf("\nCurrent player's deckCount: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)]);
		failed = 1;
	}
	//Check current player's deck contains same cards as before
	for (i = 0; i < g->deckCount[(whoseTurn(g))]; i++){
		cardsAfter[g->deck[whoseTurn(g)][i]]++;
	}	
	for (i = 0; i < treasure_map; i++){
		if (cardsBefore[i] != cardsAfter[i]){
			printf("\nCount for card %d in deck: %d, Expected: %d", i, cardsAfter[i], cardsBefore[i]);
			failed = 1;
			break;
		}
	}
	//Check current player's deck has cards in different order than before
	if (pre->deckCount[whoseTurn(g)] == g->deckCount[whoseTurn(g)]){
		changed = 0;
		for (i = 0; i < g->deckCount[whoseTurn(g)]; i++){
			if (pre->deck[whoseTurn(g)][i] != g->deck[whoseTurn(g)][i]){
				changed = 1;
				break;
			}
		}
		if (!changed){
			printf("\nCards in current player's deck not shuffled");
			failed = 1;
		}
	}
	//Final check
	if (failed){
		printf("\nResult: FAIL\n");
	} else {
		printf("none");
		printf("\nResult: PASS\n");
	}
	
	
	return 0;
}
Esempio n. 2
0
void Tank::update(float frameTime, int roadSpeed, std::vector<std::shared_ptr<Bullet>>& bullets, PlayerCar& player)
{
	Car::update(frameTime, roadSpeed);

	if (!_IsExploding) {
		if (driveToNextPosition(frameTime))
		{
			switch (_Movement) {
			case Movement::DRIVETODEFAULT:
				_Movement = Movement::LEFTRIGHT;
				_Speed = 200;
				_Attack = true;
				_PhaseClock.restart();
				break;
			case Movement::LEFTRIGHT:
				_MovementSwitch = !_MovementSwitch;
				if (_MovementSwitch) {
					_NextPosition = getPos() + sf::Vector2f((SCREENWIDTH - getPos().x - getWidth() / 2) * (std::rand() % 100) / 100.0f, 0.0f);
				}
				else {
					_NextPosition = getPos() - sf::Vector2f((getPos().x - getWidth() / 2) * (std::rand() % 100) / 100.0f, 0.0f);
				}
				break;
			default:
				break;
			}
		}

		if (_Attack)
		{
			float angle = getAngleFromVector(_GunOrientation);

			switch (_Pattern[_CurrentPhase].first) {
			case Phase::SIMPLESHOOT:
				_Event1Frequency = 4.25f + 1.25f * (float)_Difficulty;

				_GunOrientation = divideByLength(player.getPos() - getPos());

				if (getBossEvent() == 1) {
					BossCar::shootBullet(bullets, calcBulletPosition(), _GunOrientation);
				}
				break;
			case Phase::SALVE:
				
				_Event1Frequency = 1.0f + 0.75f * (float)_Difficulty;
				_Event2Frequency = 10.0f + 1.0f * (float)_Difficulty;

				_GunOrientation = divideByLength(player.getPos() - getPos());

				if (_Event1Switch) {
					if (getBossEvent() == 2) {
						BossCar::shootBullet(bullets, calcBulletPosition(), _GunOrientation);
						if (_Event1Counter + 1 < 3) {
							_Event1Counter += 1;
						}
						else {
							_Event1Switch = false;
							_Event1Counter = 0;
						}
					}
				}
				else {
					if (getBossEvent() == 1) {
						_Event1Switch = true;
					}
				}
				break;
			case Phase::SPIN:
				_Event1Frequency = 9.0f + 1.0f * (float)_Difficulty;
				if (_Event1Switch) {
					if (angle + frameTime * 100 > 180.0f) {
						_Event1Switch = false;
					}
					else {
						angle += frameTime * 100;
					}
				}
				else {
					if (angle - frameTime * 100 < 0.0f) {
						_Event1Switch = true;
				}
				else {
						angle -= frameTime * 100;
					}
				}
				_GunOrientation = divideByLength(sf::Vector2f(std::cos(angle * PI / 180), std::sin(angle * PI / 180)));

				if (getBossEvent() == 1) {
					BossCar::shootBullet(bullets, calcBulletPosition(), _GunOrientation);
				}
				break;
			case Phase::HARDCORESPAM:
				_Event1Frequency = 40.0f + 15.0f * (float)_Difficulty;
				if (getBossEvent() == 1) {
					_Event1Counter++;
					_GunOrientation = divideByLength(sf::Vector2f(((float)(std::rand() - (float)(RAND_MAX) / 2) / (float)(RAND_MAX)), 
						((float)(std::rand() - (float)(RAND_MAX) / 2) / (float)(RAND_MAX))));
					BossCar::shootBullet(bullets, calcBulletPosition(), _GunOrientation, (float)(_Event1Counter % 5 < 2) * _Volume);
				}
				break;
			}

		}
		_GunSprite.setPosition(getPos() + _GunPosition);
		_GunSprite.setRotation(getAngleFromVector(_GunOrientation) - 90);

		updateHealthBar();
		checkPhase();
	}
	else {
		updateExplosions(frameTime);
	}
}
Esempio n. 3
0
int main () {
	int i, j;			//loop controls
	int result;			//return value for function calls
	int failed;			//flags for tests
	
	struct gameState *g = malloc(sizeof(struct gameState));		//working game state
	struct gameState *pre = malloc(sizeof(struct gameState));	//reference game state; stored before functions run
	int selectedCards[10] = {adventurer, council_room, feast, gardens, mine, smithy, village, tribute, salvager, sea_hag};	
	int seed = 10;
	
	int choice1, choice2, choice3;	//choices for card effect
	int coin_bonus;					//coins added by card
	
	
//---Test adventurer with 2 treasure cards in deck
//---(all choices = -1, no bonus)
/*---Expected result: 
	- Game and turn settings are unchanged
	- Other player's cards (hand, deck, discard) are unchanged
	- Played card count increased by 1
	- Adventurer card added to played pile (in last position)
	- Adventurer card removed from hand
	- Current player's deck count decreased by 2 treasures + extras
	- Other cards in player's deck unchanged
	- Current player's discard count increased by extras
	- Current player's hand count increased by 1 (+2 treasures, -1 adventurer)
	- Cards added to player's hand are treasure
	- Cards added to player's discard are extras
	- No bonus coins
*/
	printf("*** Testing 2 treasure cards in deck ***\n");
	printf("Errors: ");
	//Setup card options
	choice1 = -1;
	choice2 = -1;
	choice3 = -1;
	coin_bonus = 0;
	//Create clean game
	if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){
		printf("\nCould not initialize game. Testing aborted.\n");
		return -1;
	}
	//Set deck to 5 extras - 2 treasures - 5 extras
	g->deckCount[whoseTurn(g)] = 0;
	for (i = 1; i <= EXTRA_COUNT; i++){
		g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD;
		g->deckCount[whoseTurn(g)]++;
	}
	for (i = 1; i <= 2; i++){
		g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = TREASURE;
		g->deckCount[whoseTurn(g)]++;
	}
	for (i = 1; i <= EXTRA_COUNT; i++){
		g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD;
		g->deckCount[whoseTurn(g)]++;
	}
	//Set test position in hand to test card
	g->hand[whoseTurn(g)][TEST_POS] = TEST_CARD;
	//Save current state
	memcpy(pre, g, sizeof(struct gameState));
	//Attempt to execute card
	result = cardEffect(TEST_CARD, choice1, choice2, choice3, g, TEST_POS, &coin_bonus);
	failed = 0;
	if (result != 0){
		printf("\nReturn value: %d, Expected: %d", result, 0);
		failed = 1;
	}
	//Check game/turn settings
	if (checkNumPlayers(pre, g) < 0){
		printf("\nNumPlayers: %d, Expected: %d", g->numPlayers, pre->numPlayers);
		failed = 1;
	}
	result = checkSupply(pre, g);
	if (result != 0){
		printf("\nSupply count for card %d: %d, Expected: %d", result, g->supplyCount[result], pre->supplyCount[result]);
		failed = 1;
	}
	result = checkEmbargo(pre, g);
	if (result != 0){
		printf("\nEmbargo for card %d: %d, Expected: %d", result, g->embargoTokens[result], pre->embargoTokens[result]);
		failed = 1;
	}
	if (checkOutpost(pre, g) < 0){
		printf("\noutpostPlayed: %d, Expected: %d", g->outpostPlayed, pre->outpostPlayed);
		printf("\noutpostTurn: %d, Expected: %d", g->outpostTurn, pre->outpostTurn);
		failed = 1;
	}	
	if (checkTurn(pre, g) < 0){
		printf("\nwhoseTurn: %d, Expected: %d", g->whoseTurn, pre->whoseTurn);
		failed = 1;
	}
	if (checkPhase(pre, g) < 0){
		printf("\nphase: %d, Expected: %d", g->phase, pre->phase);
		failed = 1;
	}	
	if (checkNumActions(pre, g) < 0){
		printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions);
		failed = 1;
	}	
	if (checkCoins(pre, g) < 0){
		printf("\ncoins: %d, Expected: %d", g->coins, pre->coins);
		failed = 1;
	}
	if (checkNumBuys(pre, g) < 0){
		printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys);
		failed = 1;
	}
	//Check discard unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->discardCount[i] != g->discardCount[i]){
			printf("\nPlayer %d's discardCount: %d, Expected: %d", i, g->discardCount[i], pre->discardCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->discardCount[i]; j++){
				if (pre->discard[i][j] != g->discard[i][j]){
					printf("\nPlayer %d's discard[%d]: %d, Expected: %d", i, j, g->discard[i][j], pre->discard[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check deck unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->deckCount[i] != g->deckCount[i]){
			printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->deckCount[i]; j++){
				if (pre->deck[i][j] != g->deck[i][j]){
					printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check hand unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->handCount[i] != g->handCount[i]){
			printf("\nPlayer %d's handCount: %d, Expected: %d", i, g->handCount[i], pre->handCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->handCount[i]; j++){
				if (pre->hand[i][j] != g->hand[i][j]){
					printf("\nPlayer %d's hand[%d]: %d, Expected: %d", i, j, g->hand[i][j], pre->hand[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check adventurer added to played pile
	if (g->playedCardCount != pre->playedCardCount + 1){
		printf("\nPlayed card count: %d, Expected: %d", g->playedCardCount, pre->playedCardCount + 1);
		failed = 1;
	} else if (g->playedCards[g->playedCardCount - 1] != TEST_CARD){
		printf("\nLast played card: %d, Expected: %d", g->playedCards[g->playedCardCount - 1], TEST_CARD);
		failed = 1;		
	}
	//Check 2 treasures + extras removed from deck; other cards remain
	if (g->deckCount[whoseTurn(g)] != pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 2){
		printf("\nCurrent player's deck count: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 2);
		failed = 1;		
	}
	for (i = 0; i < g->deckCount[whoseTurn(g)]; i++){
		if (g->deck[whoseTurn(g)][i] != EXTRA_CARD){
			printf("\nCurrent player's deck[%d]: %d, Expected: %d", i, g->deck[whoseTurn(g)][i], EXTRA_CARD);
			failed = 1;		
		}	
	}
	//Check 2 treasure cards added to hand, adventurer removed
	if (g->handCount[whoseTurn(g)] != pre->handCount[whoseTurn(g)] + 1){
		printf("\nCurrent player's hand count: %d, Expected: %d", g->handCount[whoseTurn(g)], pre->handCount[whoseTurn(g)] + 1);
		failed = 1;		
	}
	if ( (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1] != TREASURE) && (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2] != TREASURE) ){
		printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 1, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1], TREASURE);
		printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 2, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2], TREASURE);
		failed = 1;		
	}
	//Check extra cards added to discard
	if (g->discardCount[whoseTurn(g)] != pre->discardCount[whoseTurn(g)] + EXTRA_COUNT){
		printf("\nCurrent player's discard count: %d, Expected: %d", g->discardCount[whoseTurn(g)], pre->discardCount[whoseTurn(g)] + EXTRA_COUNT);
		failed = 1;		
	}
	for (i = 1; i <= EXTRA_COUNT; i++){
		if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i] != EXTRA_CARD){
			printf("\nCurrent player's discard[%d]: %d, Expected: %d", g->discardCount[whoseTurn(g)] - i, g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i], EXTRA_CARD);
			failed = 1;		
		}
	}
	//Check no bonus coins added
	if (coin_bonus != 0){
		printf("\nCoin bonus after adventurer: %d, Expected: %d", coin_bonus, 0);
		failed = 1;		
	}	
	//Final check
	if (failed){
		printf("\nResult: FAIL\n\n");
	} else {
		printf("none");
		printf("\nResult: PASS\n\n");
	}

//---Test adventurer with 1 treasure card in deck, 1 in discard
//---(all choices = -1, no bonus)
/*---Expected result: 
	- Game and turn settings are unchanged
	- Other player's cards (hand, deck, discard) are unchanged
	- Played card count increased by 1
	- Adventurer card added to played pile (in last position)
	- Adventurer card removed from hand
	- Current player's deck count decreased by 1 treasure + extras
	- Current player's discard count increased by extras, decreased by 1 treasure
	- Current player's hand count increased by 1 (+2 treasures, -1 adventurer)
 	- Cards added to player's hand are treasure
	- Cards added to player's discard are extras
	- No bonus coins

-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
NOTICE: Test disabled because of bug in current code causing infinite loop.
When deck is empty, adventurer code does not add discard pile to deck before shuffle.
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
*/
	printf("*** Testing 1 treasure in deck + 1 in discard ***\n");
	//printf("Errors: ");
	printf("Test disabled because of infinite loop\n");
	printf("Result: FAIL\n\n");
	/*
	//Setup card options
	choice1 = -1;
	choice2 = -1;
	choice3 = -1;
	coin_bonus = 0;
	//Create clean game
	if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){
		printf("\nCould not initialize game. Testing aborted.\n");
		return -1;
	}
	//Set deck to 1 treasure - 5 extras
	g->deckCount[whoseTurn(g)] = 0;
	g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = TREASURE;
	g->deckCount[whoseTurn(g)]++;
	for (i = 1; i <= EXTRA_COUNT; i++){
		g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD;
		g->deckCount[whoseTurn(g)]++;
	}
	//Set discard to 1 treasure
	g->discardCount[whoseTurn(g)] = 0;
	g->discard[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = TREASURE;
	g->discardCount[whoseTurn(g)]++;
	//Set test position in hand to test card
	g->hand[whoseTurn(g)][TEST_POS] = TEST_CARD;
	//Save current state
	memcpy(pre, g, sizeof(struct gameState));
	//Attempt to execute card
	result = cardEffect(TEST_CARD, choice1, choice2, choice3, g, TEST_POS, &coin_bonus);
	failed = 0;
	if (result != 0){
		printf("\nReturn value: %d, Expected: %d", result, 0);
		failed = 1;
	}
	//Check game/turn settings
	if (checkNumPlayers(pre, g) < 0){
		printf("\nNumPlayers: %d, Expected: %d", g->numPlayers, pre->numPlayers);
		failed = 1;
	}
	result = checkSupply(pre, g);
	if (result != 0){
		printf("\nSupply count for card %d: %d, Expected: %d", result, g->supplyCount[result], pre->supplyCount[result]);
		failed = 1;
	}
	result = checkEmbargo(pre, g);
	if (result != 0){
		printf("\nEmbargo for card %d: %d, Expected: %d", result, g->embargoTokens[result], pre->embargoTokens[result]);
		failed = 1;
	}
	if (checkOutpost(pre, g) < 0){
		printf("\noutpostPlayed: %d, Expected: %d", g->outpostPlayed, pre->outpostPlayed);
		printf("\noutpostTurn: %d, Expected: %d", g->outpostTurn, pre->outpostTurn);
		failed = 1;
	}	
	if (checkTurn(pre, g) < 0){
		printf("\nwhoseTurn: %d, Expected: %d", g->whoseTurn, pre->whoseTurn);
		failed = 1;
	}
	if (checkPhase(pre, g) < 0){
		printf("\nphase: %d, Expected: %d", g->phase, pre->phase);
		failed = 1;
	}	
	if (checkNumActions(pre, g) < 0){
		printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions);
		failed = 1;
	}	
	if (checkCoins(pre, g) < 0){
		printf("\ncoins: %d, Expected: %d", g->coins, pre->coins);
		failed = 1;
	}
	if (checkNumBuys(pre, g) < 0){
		printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys);
		failed = 1;
	}
	//Check discard unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->discardCount[i] != g->discardCount[i]){
			printf("\nPlayer %d's discardCount: %d, Expected: %d", i, g->discardCount[i], pre->discardCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->discardCount[i]; j++){
				if (pre->discard[i][j] != g->discard[i][j]){
					printf("\nPlayer %d's discard[%d]: %d, Expected: %d", i, j, g->discard[i][j], pre->discard[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check deck unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->deckCount[i] != g->deckCount[i]){
			printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->deckCount[i]; j++){
				if (pre->deck[i][j] != g->deck[i][j]){
					printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check hand unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->handCount[i] != g->handCount[i]){
			printf("\nPlayer %d's handCount: %d, Expected: %d", i, g->handCount[i], pre->handCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->handCount[i]; j++){
				if (pre->hand[i][j] != g->hand[i][j]){
					printf("\nPlayer %d's hand[%d]: %d, Expected: %d", i, j, g->hand[i][j], pre->hand[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check adventurer added to played pile
	if (g->playedCardCount != pre->playedCardCount + 1){
		printf("\nPlayed card count: %d, Expected: %d", g->playedCardCount, pre->playedCardCount + 1);
		failed = 1;
	} else if (g->playedCards[g->playedCardCount - 1] != TEST_CARD){
		printf("\nLast played card: %d, Expected: %d", g->playedCards[g->playedCardCount - 1], TEST_CARD);
		failed = 1;		
	}
	//Check 1 treasure + extras removed from deck
	if (g->deckCount[whoseTurn(g)] != pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 1){
		printf("\nCurrent player's deck count: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 1);
		failed = 1;		
	}
	//Check 2 treasure cards added to hand, adventurer removed
	if (g->handCount[whoseTurn(g)] != pre->handCount[whoseTurn(g)] + 1){
		printf("\nCurrent player's hand count: %d, Expected: %d", g->handCount[whoseTurn(g)], pre->handCount[whoseTurn(g)] + 1);
		failed = 1;		
	}
	if ( (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1] != TREASURE) && (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2] != TREASURE) ){
		printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 1, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1], TREASURE);
		printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 2, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2], TREASURE);
		failed = 1;		
	}
	//Check extra cards added to discard and treasure removed
	if (g->discardCount[whoseTurn(g)] != pre->discardCount[whoseTurn(g)] + EXTRA_COUNT - 1){
		printf("\nCurrent player's discard count: %d, Expected: %d", g->discardCount[whoseTurn(g)], pre->discardCount[whoseTurn(g)] + EXTRA_COUNT - 1);
		failed = 1;		
	}
	for (i = 1; i <= EXTRA_COUNT; i++){
		if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i] != EXTRA_CARD){
			printf("\nCurrent player's discard[%d]: %d, Expected: %d", g->discardCount[whoseTurn(g)] - i, g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i], EXTRA_CARD);
			failed = 1;		
		}
	}
	//Check no bonus coins added
	if (coin_bonus != 0){
		printf("\nCoin bonus after adventurer: %d, Expected: %d", coin_bonus, 0);
		failed = 1;		
	}	
	//Final check
	if (failed){
		printf("\nResult: FAIL\n\n");
	} else {
		printf("none");
		printf("\nResult: PASS\n\n");
	}
	*/

//---Test adventurer with 1 treasure card in deck (only 1 treasure total)
//---(all choices = -1, no bonus)
/*---Expected result: 
	- Game and turn settings are unchanged
	- Other player's cards (hand, deck, discard) are unchanged
	- Played card count increased by 1
	- Adventurer card added to played pile (in last position)
	- Adventurer removed from hand
	- Current player's deck count decreased by 1 treasure + extras
	- Other cards in player's deck unchanged
	- Current player's discard count increased by extras
	- Current player's hand count is unchanged (+1 treasure, -1 adventurer)
	- Card added to player's hand is treasure
	- Cards added to player's discard are extras
	- No bonus coins

-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
NOTICE: Test disabled because of bug in current code causing infinite loop. 
While loop does not have exit condition for case when only 1 treasure exists.
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
*/
	printf("*** Testing 1 treasure card in deck ***\n");
	//printf("Errors: ");
	printf("Test disabled because of infinite loop\n");
	printf("Result: FAIL\n");
	/*
	//Setup card options
	choice1 = -1;
	choice2 = -1;
	choice3 = -1;
	coin_bonus = 0;
	//Create clean game
	if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){
		printf("\nCould not initialize game. Testing aborted.\n");
		return -1;
	}
	//Set deck to 5 extras - 1 treasure - 5 extras
	g->deckCount[whoseTurn(g)] = 0;
	for (i = 1; i <= EXTRA_COUNT; i++){
		g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD;
		g->deckCount[whoseTurn(g)]++;
	}
	g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = TREASURE;
	g->deckCount[whoseTurn(g)]++;
	for (i = 1; i <= EXTRA_COUNT; i++){
		g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD;
		g->deckCount[whoseTurn(g)]++;
	}
	//Set test position in hand to test card
	g->hand[whoseTurn(g)][TEST_POS] = TEST_CARD;
	//Save current state
	memcpy(pre, g, sizeof(struct gameState));
	//Attempt to execute card
	result = cardEffect(TEST_CARD, choice1, choice2, choice3, g, TEST_POS, &coin_bonus);
	failed = 0;
	if (result != 0){
		printf("\nReturn value: %d, Expected: %d", result, 0);
		failed = 1;
	}
	//Check game/turn settings
	if (checkNumPlayers(pre, g) < 0){
		printf("\nNumPlayers: %d, Expected: %d", g->numPlayers, pre->numPlayers);
		failed = 1;
	}
	result = checkSupply(pre, g);
	if (result != 0){
		printf("\nSupply count for card %d: %d, Expected: %d", result, g->supplyCount[result], pre->supplyCount[result]);
		failed = 1;
	}
	result = checkEmbargo(pre, g);
	if (result != 0){
		printf("\nEmbargo for card %d: %d, Expected: %d", result, g->embargoTokens[result], pre->embargoTokens[result]);
		failed = 1;
	}
	if (checkOutpost(pre, g) < 0){
		printf("\noutpostPlayed: %d, Expected: %d", g->outpostPlayed, pre->outpostPlayed);
		printf("\noutpostTurn: %d, Expected: %d", g->outpostTurn, pre->outpostTurn);
		failed = 1;
	}	
	if (checkTurn(pre, g) < 0){
		printf("\nwhoseTurn: %d, Expected: %d", g->whoseTurn, pre->whoseTurn);
		failed = 1;
	}
	if (checkPhase(pre, g) < 0){
		printf("\nphase: %d, Expected: %d", g->phase, pre->phase);
		failed = 1;
	}	
	if (checkNumActions(pre, g) < 0){
		printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions);
		failed = 1;
	}	
	if (checkCoins(pre, g) < 0){
		printf("\ncoins: %d, Expected: %d", g->coins, pre->coins);
		failed = 1;
	}
	if (checkNumBuys(pre, g) < 0){
		printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys);
		failed = 1;
	}
	//Check discard unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->discardCount[i] != g->discardCount[i]){
			printf("\nPlayer %d's discardCount: %d, Expected: %d", i, g->discardCount[i], pre->discardCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->discardCount[i]; j++){
				if (pre->discard[i][j] != g->discard[i][j]){
					printf("\nPlayer %d's discard[%d]: %d, Expected: %d", i, j, g->discard[i][j], pre->discard[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check deck unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->deckCount[i] != g->deckCount[i]){
			printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->deckCount[i]; j++){
				if (pre->deck[i][j] != g->deck[i][j]){
					printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check hand unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->handCount[i] != g->handCount[i]){
			printf("\nPlayer %d's handCount: %d, Expected: %d", i, g->handCount[i], pre->handCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->handCount[i]; j++){
				if (pre->hand[i][j] != g->hand[i][j]){
					printf("\nPlayer %d's hand[%d]: %d, Expected: %d", i, j, g->hand[i][j], pre->hand[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check adventurer added to played pile
	if (g->playedCardCount != pre->playedCardCount + 1){
		printf("\nPlayed card count: %d, Expected: %d", g->playedCardCount, pre->playedCardCount + 1);
		failed = 1;
	} else if (g->playedCards[g->playedCardCount - 1] != TEST_CARD){
		printf("\nLast played card: %d, Expected: %d", g->playedCards[g->playedCardCount - 1], TEST_CARD);
		failed = 1;		
	}
	//Check 1 treasure + extras removed from deck; other cards remain
	if (g->deckCount[whoseTurn(g)] != pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 1){
		printf("\nCurrent player's deck count: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 1);
		failed = 1;		
	}
	for (i = 0; i < g->deckCount[whoseTurn(g)]; i++){
		if (g->deck[whoseTurn(g)][i] != EXTRA_CARD){
			printf("\nCurrent player's deck[%d]: %d, Expected: %d", i, g->deck[whoseTurn(g)][i], EXTRA_CARD);
			failed = 1;		
		}	
	}
	//Check 1 treasure card added to hand, adventurer removed
	if (g->handCount[whoseTurn(g)] != pre->handCount[whoseTurn(g)]){
		printf("\nCurrent player's hand count: %d, Expected: %d", g->handCount[whoseTurn(g)], pre->handCount[whoseTurn(g)]);
		failed = 1;		
	}
	if (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1] != TREASURE){
		printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 1, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1], TREASURE);
		failed = 1;		
	}
	//Check extra cards added to discard
	if (g->discardCount[whoseTurn(g)] != pre->discardCount[whoseTurn(g)] + EXTRA_COUNT){
		printf("\nCurrent player's discard count: %d, Expected: %d", g->discardCount[whoseTurn(g)], pre->discardCount[whoseTurn(g)] + EXTRA_COUNT);
		failed = 1;		
	}
	for (i = 1; i <= EXTRA_COUNT; i++){
		if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i] != EXTRA_CARD){
			printf("\nCurrent player's discard[%d]: %d, Expected: %d", g->discardCount[whoseTurn(g)] - i, g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i], EXTRA_CARD);
			failed = 1;		
		}
	}
	//Check no bonus coins added
	if (coin_bonus != 0){
		printf("\nCoin bonus after adventurer: %d, Expected: %d", coin_bonus, 0);
		failed = 1;		
	}	
	//Final check
	if (failed){
		printf("\nResult: FAIL\n");
	} else {
		printf("none");
		printf("\nResult: PASS\n");
	}
	*/

	return 0;
}
Esempio n. 4
0
int main () {
	int i, j;			//loop controls
	int result;			//return value for function calls
	int failed;			//flags for tests
	
	struct gameState *g = malloc(sizeof(struct gameState));		//working game state
	struct gameState *pre = malloc(sizeof(struct gameState));	//reference game state; stored before functions run
	int selectedCards[10] = {adventurer, council_room, feast, gardens, mine, smithy, village, tribute, salvager, sea_hag};	
	int seed = 10;
	
	int choice1, choice2, choice3;	//choices for card effect
	int coin_bonus;				//coins added by card
	
	
//---Test smithy (all choices = -1, no bonus)
/*---Expected result: 
	- Game and turn settings are unchanged
	- Other player's cards (hand, deck, discard) are unchanged
	- Current player's discard is unchanged
	- Played card count increased by 1
	- Smithy card added to played pile (in last position)
	- Smithy card removed from hand
	- Last 3 cards of current player's deck moved to hand
	- Current player's deckCount is decreased by 3
	- Current player's handCount is increased by 2 (+3 new cards, -1 smithy)
	- No bonus coins
*/
	printf("*** Testing valid smithy ***\n");
	printf("Errors: ");
	//Setup card options
	choice1 = -1;
	choice2 = -1;
	choice3 = -1;
	coin_bonus = 0;
	//Create clean game
	if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){
		printf("\nCould not initialize game. Testing aborted.\n");
		return -1;
	}
	//Set deck to 5 copper cards
	g->deckCount[whoseTurn(g)] = 5;
	for (i = 0; i < 5; i++){
		g->deck[whoseTurn(g)][i] = copper;
	}
	//Set test position in hand to test card
	g->hand[whoseTurn(g)][TEST_POS] = TEST_CARD;
	//Save current state
	memcpy(pre, g, sizeof(struct gameState));
	//Attempt to execute card
	result = cardEffect(TEST_CARD, choice1, choice2, choice3, g, TEST_POS, &coin_bonus);
	failed = 0;
	if (result != 0){
		printf("\nReturn value: %d, Expected: %d\n", result, 0);
		failed = 1;
	}
	//Check game/turn settings
	if (checkNumPlayers(pre, g) < 0){
		printf("\nNumPlayers: %d, Expected: %d\n", g->numPlayers, pre->numPlayers);
		failed = 1;
	}
	result = checkSupply(pre, g);
	if (result != 0){
		printf("\nSupply count for card %d: %d, Expected: %d\n", result, g->supplyCount[result], pre->supplyCount[result]);
		failed = 1;
	}
	result = checkEmbargo(pre, g);
	if (result != 0){
		printf("\nEmbargo for card %d: %d, Expected: %d\n", result, g->embargoTokens[result], pre->embargoTokens[result]);
		failed = 1;
	}
	if (checkOutpost(pre, g) < 0){
		printf("\noutpostPlayed: %d, Expected: %d\n", g->outpostPlayed, pre->outpostPlayed);
		printf("\noutpostTurn: %d, Expected: %d\n", g->outpostTurn, pre->outpostTurn);
		failed = 1;
	}	
	if (checkTurn(pre, g) < 0){
		printf("\nwhoseTurn: %d, Expected: %d\n", g->whoseTurn, pre->whoseTurn);
		failed = 1;
	}
	if (checkPhase(pre, g) < 0){
		printf("\nphase: %d, Expected: %d\n", g->phase, pre->phase);
		failed = 1;
	}	
	if (checkNumActions(pre, g) < 0){
		printf("\nnumActions: %d, Expected: %d\n", g->numActions, pre->numActions);
		failed = 1;
	}	
	if (checkCoins(pre, g) < 0){
		printf("\ncoins: %d, Expected: %d\n", g->coins, pre->coins);
		failed = 1;
	}
	if (checkNumBuys(pre, g) < 0){
		printf("\nnumBuys: %d, Expected: %d\n", g->numBuys, pre->numBuys);
		failed = 1;
	}
	//Check all player's discard unchanged
	if (checkDiscards(pre, g) < 0){
		printf("\nDiscards changed after smithy\n");
		//Print expected and actual discards for each player
		for (i = 0; i < NUM_PLAYERS; i++){
			printf("    Discard pile for player %d:\n", i);
			printf("      Count: %d, Expected: %d\n", g->discardCount[i], pre->discardCount[i]);
			if (g->discardCount[i] > 0){
				printf("      Actual Cards: ");
				for (j = 0; j < g->discardCount[i]; j++){
					printf("%d ", g->discard[i][j]);
				}
				printf("\n      Expected Cards: ");
				for (j = 0; j < pre->discardCount[i]; j++){
					printf("%d ", pre->discard[i][j]);
				}
			}
		}
		failed = 1;
	}
	//Check deck unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->deckCount[i] != g->deckCount[i]){
			printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->deckCount[i]; j++){
				if (pre->deck[i][j] != g->deck[i][j]){
					printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check hand unchanged for other players
	for (i = 0; i < g->numPlayers; i++){
		//skip if current player
		if (i == whoseTurn(g)){
			continue;
		}
		if (pre->handCount[i] != g->handCount[i]){
			printf("\nPlayer %d's handCount: %d, Expected: %d", i, g->handCount[i], pre->handCount[i]);
			failed = 1;
		} else {   //check each card
			for (j = 0; j < g->handCount[i]; j++){
				if (pre->hand[i][j] != g->hand[i][j]){
					printf("\nPlayer %d's hand[%d]: %d, Expected: %d", i, j, g->hand[i][j], pre->hand[i][j]);
					failed = 1;
				}
			}
		}
	}
	//Check smithy added to played pile
	if (g->playedCardCount != pre->playedCardCount + 1){
		printf("\nPlayed card count: %d, Expected: %d", g->playedCardCount, pre->playedCardCount + 1);
		failed = 1;
	} else if (g->playedCards[g->playedCardCount - 1] != TEST_CARD){
		printf("\nLast played card: %d, Expected: %d", g->playedCards[g->playedCardCount - 1], TEST_CARD);
		failed = 1;		
	}
	//Check 3 cards added to hand and smithy removed
	if (g->handCount[whoseTurn(g)] != pre->handCount[whoseTurn(g)] + 2){
		printf("\nCurrent player's hand count: %d, Expected: %d", g->handCount[whoseTurn(g)], pre->handCount[whoseTurn(g)] + 2);
		failed = 1;		
	}
	//Check 3 cards removed from deck
	if (g->deckCount[whoseTurn(g)] != pre->deckCount[whoseTurn(g)] - 3){
		printf("\nCurrent player's deck count: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)] - 3);
		failed = 1;		
	}
	//Check cards removed from deck = cards added to hand (last 2 cards, plus position 0...last card replaces test card when discarded)
	if (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1] != pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 1]){
		printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 1, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1], pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 1]);
		failed = 1;		
	}
	if (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2] != pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 2]){
		printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 2, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2], pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 2]);
		failed = 1;		
	}
	if (g->hand[whoseTurn(g)][0] != pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 3]){
		printf("\nCurrent player's hand[0]: %d, Expected: %d", g->hand[whoseTurn(g)][0], pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 3]);
		failed = 1;		
	}
	
	//Check no bonus coins added
	if (coin_bonus != 0){
		printf("\nCoin bonus after smithy: %d, Expected: %d", coin_bonus, 0);
		failed = 1;		
	}	
	//Final check
	if (failed){
		printf("\nResult: FAIL\n");
	} else {
		printf("none");
		printf("\nResult: PASS\n");
	}

	
	return 0;
}
Esempio n. 5
0
void ServerController::processClient(sf::Packet &packet, sf::TcpSocket &client)
{
	std::string protocol;
		
	packet >> protocol;
		
	std::cout << "Interpreting Packet Protocol: " << protocol << std::endl;
		
	if(protocol=="LOGIN"){
		loginAccount(packet, client);
	}
	else if(protocol=="REGISTER"){
		registerAccount(packet, client);
	}
	else if(protocol=="CONFERENCE_LIST"){
		getConferences(packet, client);
	}
	else if(protocol=="CONFERENCE_ACCESS"){
		getAccess(packet, client);
	}
	else if(protocol=="VIEW_SUBMISSIONS"){
		getSubmissions(packet, client);
	}
	else if(protocol=="SUBMIT_PAPER"){
		paperSubmission(packet, client);
	}
	else if (protocol=="ADMIN_STATUS"){
		getAdminStatus(packet, client);
	}
	else if (protocol=="CREATE_CONFERENCE"){
		createConference(packet, client);
	}
	else if (protocol=="GET_NOTIFICATIONS"){
		getNotifications(packet, client);
	}
	else if (protocol=="CHECK_PHASE"){
		checkPhase(packet, client);
	}
	else if (protocol=="BID_LIST"){
		bidList(packet, client);
	}
	else if (protocol=="BID_PAPER"){
		bidPaper(packet, client);
	}
	else if (protocol=="ADVANCE_PHASE"){
		advancePhase(packet, client);
	}
	else if(protocol=="BYE"){
		logoutUser(packet, client);
	}
	else if(protocol=="GET_ALLOCATIONS"){
		getAllocations(packet, client);
	}
	else if(protocol=="CONFERENCE_SUBMISSIONS"){
		getConferenceSubs(packet, client);
	}
	else if(protocol=="REVIEW_LIST"){
		getReviewList(packet, client, true);
	}
	else if (protocol=="SUB_DETAIL"){
		sendSubDetail(packet, client);
	}
	else if (protocol=="SUBMIT_REVIEW"){
		submitReview(packet, client);
	}
	else if (protocol=="GET_COMMENTS"){
		getComments(packet, client);
	}
	else if (protocol=="SEND_COMMENT"){
		sendComments(packet, client);
	}
	else if (protocol=="ADD_REVIEWER"){
		addMember(packet, client, Account::Access_Reviewer);
	}
	else if (protocol=="ADD_AUTHOR"){
		addMember(packet, client, Account::Access_Author);
	}
	else if (protocol=="CHANGE_MAX_ALLOCATED_CONF"){
		changeLimit(packet, client, "ALLOCATED");
	}
	else if (protocol=="CHANGE_MAX_PAPERREVIEWERS_CONF"){
		changeLimit(packet, client, "PAPERREV");
	}
	else if (protocol=="GET_MAX_ALLOCATED_CONF"){
		getLimit(packet, client, "ALLOCATED");
	}
	else if (protocol=="GET_MAX_PAPERREVIEWERS_CONF"){
		getLimit(packet, client, "PAPERREV");
	}
	else if (protocol=="GET_FULLNAME"){
		getAccountName(packet, client);
	}
	else if (protocol=="VIEW_REVIEW"){
		getReview(packet, client);
	}
	else if (protocol=="NOTIFY_COUNT"){
		checkNotifyCount(packet, client);
	}
	else if (protocol=="APPROVE_PAPER"){
		decidePaper(packet, client, true);
	}
	else if (protocol=="REJECT_PAPER"){
		decidePaper(packet, client, false);
	}
	else if (protocol=="MY_REVIEWS"){
		getReviewList(packet, client, false);
	}
	else if (protocol=="DID_REVIEW"){
		checkReviewed(packet, client);
	}
	else if (protocol=="FINAL_REVIEW"){
		getFinalReview(packet, client);
	}
	else if (protocol=="CONF_REVIEWERS"){
		getReviewers(packet, client);
	}
	else if (protocol=="CONF_SUBMISSIONS"){
		getConfSubmissions(packet, client);
	}
	else if (protocol=="FILLED_ALLOCATION"){
		checkPaperAlloc(packet, client);
	}
	else if (protocol=="GET_FREE_REVIEWERS"){
		getFreeReviewers(packet, client);
	}
	else if (protocol=="ASSIGN_REVIEWER"){
		assignReviewer(packet, client);
	}
	else if (protocol=="CHANGE_PASSWORD"){
		changePassword(packet, client);
	}
	else {
		std::cout << "Unrecognised protocol" << std::endl;
	}
}