Esempio n. 1
0
Agent * add_agent(char * filename, Agent *mother) {
	Genome * myGenome;
	myGenome = new Genome(filename);
	Agent * newAgent;
	char portNum[256]; sprintf(portNum, "%i", curPort); 
	int pid = myGenome->buildOrganismFromGenome(portNum);
	newAgent = new Agent(myGenome, pid, curPort++);
	agents.push_back(newAgent);
	printf("loaded %s on port %i (%p)\n", filename, newAgent->get_port(), newAgent);
	return newAgent;
}
Esempio n. 2
0
Agent * add_agent(const char * filename) {
	static int curPort=49153;

	QFileInfo file_info(filename);
	if(!file_info.exists()) return (Agent*)0;

	ifstream validateStream(filename, ios::in);
	char magic[8];
	validateStream.getline(magic, 8);
	if(strcmp(magic, "//body")) return (Agent*)0;

	Genome * myGenome;
	myGenome = new Genome(filename);
	Agent * newAgent;
	char portNum[256]; sprintf(portNum, "%i", curPort); 
	pid_t pid = myGenome->buildOrganismFromGenome(portNum);
	if(pid<0 || waitpid(pid, (int*)0, WNOHANG)>0) return (Agent*)0;
 
	newAgent = new Agent(myGenome, pid, curPort++);
	agents.push_back(newAgent);
	printf("loaded %s on port %i (%p)\n", filename, newAgent->get_port(), newAgent);
	return newAgent;
}