Beispiel #1
0
//-----------------------------------------------------------------------------
void Game::PlayGame()
{
    printw("\nPress any key to start the game.\n");
    refresh();
    getch();

    ClearScreen();
    int numLosers = 0;

    while (numLosers < (int)m_players.size() - 1) {
        numLosers = 0;
        for (int i=0;i<(int)m_players.size();i++) {
            m_currentPlayer = i;
            printw("%s has £%d\n", m_players[i]->getName().c_str(), m_players[i]->getBalance());
            refresh();
            if (m_players[i]->getBalance() > 0) {
                TakeTurn(m_players[i]);
            }
            else {
                printw("%s has no money.\n", m_players[i]->getName().c_str());
                refresh();
                numLosers++;
            }

        }
    }

    printw("Final scores:\n");

    for (int i=0;i<(int)m_players.size(); i++) {
        printw("%s: %d", m_players[i]->getName().c_str(), m_players[i]->getBalance()); 

    }
}
Beispiel #2
0
main()
{
	Dudes *Board[8][8];
	CreateBoard(Board);
	SetupBoard(Board);
	while (1)
	{
		TakeTurn(Board);
	}
}
int main(int argc, char* argv[]){
	//deal with the commandline
	if(argc != 3)
	{
		printf("\nUSAGE: testdominion [seed][num_games]\n-1 IN EITHER FIELD USES DEFAULTS [TIME][50]\n");
		return 1;
	}
	
	int seed = atoi(argv[1]); 
	int num_games = atoi(argv[2]);
	
	
	if(seed == -1)
	{
		srand(time(0));
	}
	else
	{
		srand(seed);
	}
	
	if(num_games == -1)
	{
		num_games = 50;
	}
	//now move on to basic setup stuff	
	cardnames[0] = "curse";
	cardnames[1] = "estate";
	cardnames[2] = "duchy";
	cardnames[3] = "province";
	cardnames[4] = "copper";
	cardnames[5] = "silver";
	cardnames[6] = "gold";
	cardnames[7] = "adventurer";
	cardnames[8] = "council_room";
	cardnames[9] = "feast";
	cardnames[10] = "gardens";
	cardnames[11] = "mine";
	cardnames[12] = "remodel";
	cardnames[13] = "smithy";
	cardnames[14] = "village";
	cardnames[15] = "baron";
	cardnames[16] = "great_hall";
	cardnames[17] = "minion";
	cardnames[18] = "steward";
	cardnames[19] = "tribute";
	cardnames[20] = "ambassador";
	cardnames[21] = "cutpurse";
	cardnames[22] = "embargo";
	cardnames[23] = "outpost";
	cardnames[24] = "salvager";
	cardnames[25] = "sea_hag";
	cardnames[26] = "treasure_map";
	
	
	struct gameState* pre;
	struct gameState* post;
	
	int p;
	int f;
	int* pass = &p;
	int* fail = &f;
	
	//Try to allocate memory for the gamestates
	pre = malloc(sizeof(struct gameState));
	post = malloc(sizeof(struct gameState));
	if(!pre || !post){printf("\nFAILED TO MALLOC ONE OR BOTH GAMESTATES\n");return 1;}
	//if successful, carry on
	
	//Try to open Logfile
	FILE *fp;
	fp = fopen("gameResults.out", "w");
	if(!fp){printf("\nFAILED TO OPEN OUTPUT FILE gameResults.out FOR WRITE\n"); return 1;}
	//If successful, carry on
	printf("ALL FURTHER TESTING OUTPUT IS REDIRECTED TO gameResults.out\n");
	
	//set the file output version of fassert to point to the file we just setup.
	setfassert(fp);
	
	//Main Testing Loop
	for(int i = 0; i < num_games; i++)
	{
		int err = 0;
		int numPlayers = (rand() % 3) + 2; //2,3,4 players
		int *randomSupplyCards = randSupplyCards();
		
		fprintf(fp, "Trying to start game with %d players\n", numPlayers);
		fprintf(fp, "Using supply cards...\n");
		for(int j = 0; j < 10; j ++)
		{
			fprintf(fp, "%s\n",cardnames[randomSupplyCards[j]]);
		}
		fprintf(fp,"\n");
		err += fassert(initializeGame(numPlayers, randomSupplyCards, rand(), pre) == 0, pass, fail, "initializeGame returned good");
		free(randomSupplyCards);
		
		//now we make two copies of the gamestate for comparison
		memcpy(post,pre,sizeof(struct gameState));
		
		
		while(!isGameOver(pre))
		{
			err = TakeTurn(fp, pre->whoseTurn, pre,post, pass, fail);
			if(err)
			{
				fprintf(fp,"\nGame #%d Failed one or more tests. Ending run and moving to next Game\n",i);
				break;
			}
		}
		
		if(isGameOver(pre))
		{
			int winners[MAX_PLAYERS];
			getWinners(winners, pre);
			for(int j = 0; j < numPlayers; j++)
			{
				if(winners[j])
				{
					fprintf(fp, "\nplayer %d Won!",j);
				}
				else
				{
					fprintf(fp, "\nPlayer %d Lost",j);
				}
			}
		}
		
		fprintf(fp,"\n%d Errors on Game #%d\n",err,i);
		fprintf(fp,"=============================================================================================");
		
		
		
	}

}