Ejemplo n.º 1
0
int main(int argc, char **argv){
#ifdef PAPI_MEASUREMENT
	Papi papi;
	PapiInstance *instance = papi.create();
	instance->addEvent(PAPI_TOT_INS);
	instance->addEvent(PAPI_BR_MSP);
	instance->start();
#endif

	OpenMPGameOfLife gof(500, 500);
	gof.init();
//	gof.print(std::cout);
	for(int i = 0; i < 100; ++i){
		gof.tick();
	}
//	gof.print(std::cout);

#ifdef PAPI_MEASUREMENT
	instance->stop();
	std::cout << "\nThe measured total instructions were: " << instance->getEventValue(PAPI_TOT_INS) << "\n";
	std::cout << "The measured mispredicted branches were: " << instance->getEventValue(PAPI_BR_MSP) << std::endl;
#endif

	return 0;
}
Ejemplo n.º 2
0
void tloop(int history)
{
	using_history();
	stifle_history(history);

	lookf(self.next);

	while(1){
		int fail = 0;
		struct tobj *prev = NULL;
		struct tobj *noun = NULL;
		char *input = readline(">> ");
		char *verbstr = input;
		char *nounstr = verbstr;
		add_history(verbstr);

		/* Blank out spaces and punctuation and set the noun as the last word */
		while(*input){
			if(!isalpha(*input)){
				*input = '\0';
				if(isalpha(*(input + 1))){
					nounstr = input + 1;
				}
			}
			++input;
		}
		input = verbstr; /* Restore input back to where it was */

		/* Do basic substition for shortcut commands */
		if(tstrequals(verbstr, 2, "n", "north")){
			verbstr = "go";
			nounstr = "north";
		}
		else if(tstrequals(verbstr, 2, "ne", "northeast")){
			verbstr = "go";
			nounstr = "northeast";
		}
		else if(tstrequals(verbstr, 2, "e", "east")){
			verbstr = "go";
			nounstr = "east";
		}
		else if(tstrequals(verbstr, 2, "se", "southeast")){
			verbstr = "go";
			nounstr = "southeast";
		}
		else if(tstrequals(verbstr, 2, "s", "south")){
			verbstr = "go";
			nounstr = "south";
		}
		else if(tstrequals(verbstr, 2, "sw", "southwest")){
			verbstr = "go";
			nounstr = "southwest";
		}
		else if(tstrequals(verbstr, 2, "w", "west")){
			verbstr = "go";
			nounstr = "west";
		}
		else if(tstrequals(verbstr, 2, "nw", "northwest")){
			verbstr = "go";
			nounstr = "northwest";
		}
		else if(tstrequals(verbstr, 1, "out")){
			verbstr = "go";
			nounstr = "out";
		}

		noun = tfind(&self, &prev, nounstr);
		if(noun == NULL){
			if(verbstr != nounstr){
				if(tstrequals(verbstr, 2, "go", "travel")){
					printf("You can't go ``%s'' here.\n", nounstr);
				}
				else{
					printf("You don't see ``%s'' here.\n", nounstr);
				}
				fail = 1;
			}
			else{
				prev = NULL;
				noun = self.next;
			}
		}
		if(!fail){
			if(tstrcmp(verbstr, "look") == 0){
				lookf(noun);
			}
			else if(tstrequals(verbstr, 2, "i", "inventory")){
				lookf(&self);
			}
			else if(tstrequals(verbstr, 3, "eat", "consume", "ingest")){
				eatf(prev, noun);
			}
			else if(tstrequals(verbstr, 2, "go", "travel")){
				gof(noun);
			}
			else if(tstrequals(verbstr, 3, "drop", "leave", "abandon")){
				dropf(prev, noun);
			}
			else if(tstrequals(verbstr, 3, "talk", "say", "speak")){
				talkf(noun);
			}
			else if(tstrequals(verbstr, 6, "break", "smash", "kick", "punch", "headbutt", "kill")){
				breakf(noun);
			}
			else if(tstrcmp(verbstr, "unlock") == 0){
				unlockf(noun);
			}
			else if(tstrequals(verbstr, 2, "lock", "bar")){
				lockf(noun);
			}
			else if(tstrequals(verbstr, 5, "pick", "get", "take", "steal", "pack")){
				pickf(prev, noun);
			}
			else{
				printf("Don't know how to ``%s.''\n", verbstr);
				fail = 1;
			}
		}
		free(input);
	}
}