コード例 #1
0
ファイル: main.c プロジェクト: ichitakasan/emulGB
/************************************************************************************
 *                                MAIN FUNCTION
 ************************************************************************************/
int main(int argc, char *argv[]) {

	// Initialisation ...
	int out = initialiseScreen();
	if (out)
		return out;
	initialiseCPU();

	// Load ROM file ...
	loadROM("roms/Tetris (W) (V1.0) [!].gb");

	// Print game info ...
	printGameInfo();

	// program main loop
	int done = 0;
	while (!done) {

		updateCPU();
//		drawScreen();
		done = listen();
		manageKeys();
	}

	printf("Exited cleanly\n");
	exitProgram();
	return 0;
}
コード例 #2
0
int main() {
	int k[10] = {0,0,0,0,0,0,0,0,0,0};
	time_t t;
	srand((unsigned) time(&t));	
	int i, j, players, seed;
	struct gameState state;
        int card = 0;
	FILE *fp;
	char name[100];
	//Set number of players between two and four	
	players = rand() % 3 + 2;
	state.numPlayers = players;	
	  
	  //set random seed 
	seed = rand();		
	
	 //intialize kingdom cards and supply
	int same = 0;
	for(i = 0; i < 10; i++){
		card = rand() % 20 + adventurer;
		for(j = 0; j < 10; j++){
			if(card == k[j]){
				same = 1;
				break;
			}
			else{
			 same = 0;	
			}	
		}
		if(same){
			i--;	
		} 	
		else{
			k[i] = card;
		}
	}
		
	initializeGame(players, k, seed,&state);
	fp = fopen("gameResults.out", "w");
	fprintf(fp,"After Initalization\n");
	printf("After Initalization\n");
	fclose(fp);


	int hc = 0;
	struct trackers track; 

	int cardToBuy = 0;
	int choice1, choice2, choice3;
	int coinBonus;	
	while(!isGameOver(&state)){
		coinBonus = 0;	
		fp = fopen("gameResults.out", "a");
		printf("--------TURN %d--------\n",track.turns);	
		fprintf(fp, "--------TURN %d--------\n",track.turns);
//		print_Supply(&state);	
		fclose(fp);

		track.hasAction = 0;
		track.ableToPlay = -1;
		track.cardPlace = 0;
		card = 0;
	
		i = state.whoseTurn;
		track.hasAction = 0;
		printPlayerInfo(i,&state);
		printPlayerInfoGR(i,&state);
		printGameInfo(i,&state);
		
		//Determine if they have an action
		for(j = 0; j < state.handCount[i]; j++){
			card = state.hand[i][j];
			if(card >= adventurer && card <= treasure_map){
				track.hasAction = 1;
				track.cardPlace = j;
				cardNumToName(card,name);
//				printf("%s is >= %d and <= %d\n",name, adventurer, treasure_map);
				break;
			}
	//		printf("Looking at card %d\n",card);
		}
		
		if(track.hasAction){
			printf("Player has at least one action card to start\n");
			fp = fopen("gameResults.out", "a");
			fprintf(fp,"Player has at least one action card to start\n");
			fclose(fp);
		}	
		//play Actions
		while (state.numActions > 0 && track.hasAction){
			choice1 = rand() % state.handCount[i];
			choice2 = rand() % 20 + adventurer;
			choice3 = rand() % 20 + adventurer;
					

			printf("Card to Play %s\n",name);
			fp = fopen("gameResults.out", "a");
			fprintf(fp,"Card to play: %s\n",name);
			fclose(fp);

			//protection against the feast infinite loop
	//		if(card == feast){
	//			printf("You are trying to play a feast. There is an infinite loop in most dominion implementations\n");
	//			discardCard(track.cardPlace,i, &state,0); 
	//		}
			//try to play the card
	//		else{	
				track.ableToPlay = playCard(track.cardPlace,choice1,choice2,choice3,&state);
	//		}
			//the card will return a -1 if their is an error
			//trying to play the card  
			if(track.ableToPlay == -1){
				printf("You cannot play that card\n");
				fp = fopen("gameResults.out", "a");
				fprintf(fp,"You cannot play that card: %d\n",state.numActions);
				fclose(fp);
				discardCard(track.cardPlace,i, &state,0); 
			}

			printf("Actions after playing card %d\n",state.numActions);	
			fp = fopen("gameResults.out", "a");
			fprintf(fp,"Game after playing card: %d\n",state.numActions);
			fclose(fp);

			printf("Hand after: ");
			for(hc = 0; hc < state.handCount[i]; hc++){
				printf("%d, ",state.hand[i][hc]);	
			}
			printf("\n");
			//don't keep looking for actions if their used up	
			if (state.numActions <= 0){
				break;
			}
			//otherwise, try to look for another action to play
			card = lookForAction(i,&state, &track);
			cardNumToName(card,name);	
			if(track.hasAction){
				printf("Player has at least one action card\n");
			}	
		}

		coinBonus = state.coins;
		fp = fopen("gameResults.out", "a");
		fprintf(fp,"Player %d has %d coin now\n",i+1,state.coins);
		fclose(fp);
		tryBuyCard(&state);
		fp = fopen("gameResults.out", "a");
		fprintf(fp,"Player %d has %d coin now after buy\n",i+1,state.coins);
		fclose(fp);
		//Entering the Buy Phase
		//pick a card to try to buy
	
		//Game info after the play 
		printPlayerInfoGR(i,&state);
		printGameInfo(i,&state);
		fp = fopen("gameResults.out", "a");
		for(i = 0; i < state.numPlayers; i ++){
			fprintf(fp,"score for player %d: %d\n",i+1, scoreFor(i, &state));
			track.estateScore = track.duchyScore = track.provinceScore = 0;
			for(j = 0; j < state.handCount[i]; j++){
				card  = state.hand[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}	
			} 	
			for(j = 0; j < state.deckCount[i]; j++){
				card  = state.deck[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}
			}	
			for(j = 0; j < state.discardCount[i]; j++){
				card  = state.discard[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}	
			}
			fprintf(fp,"estate %d, duchy %d, province %d \n",track.estateScore, track.duchyScore, track.provinceScore);
		}
		fclose(fp);		
	  


		//turn is over
		endTurn(&state);
		track.turns ++;
	}
	//when the Game is Over, print out the scores		
	for(i = 0; i < state.numPlayers; i ++){
		printf("score for player %d: %d\n",i+1, scoreFor(i, &state));	
	}		
	  
	printf("Tests Complete\n");
	return 0;
}