Esempio n. 1
0
void WorldWindow::set_port(int port_no) {
	if(sock>=0) ::close(sock);
	myPort = port_no;

	sock = UDP_bind(myPort);
	if(sock == -1) return ;
	printf("world started on port %i\n", myPort);

}
Esempio n. 2
0
int main(int argc, char *argv[]){
	int listenfd;
//	daemon_init(argv[0], 0);

	g_GroupTable = tableCreate(D2MCED_GROUP_NUMBER, sizeof(struct group));

	if(read_config()<0){
        perror("Error: read_config()");
		return -1;
	}
	//UDP_init(unsigned int ip,unsigned short int port,struct sockaddr_in * sockaddr)
	listenfd = UDP_bind(INADDR_ANY, g_system_conf.demon_port);
    demon_receiver(listenfd);
	tableDestroy(g_GroupTable);
//	closelog();
    return 1;
}
Esempio n. 3
0
int main (int argc, char * argv[]) {
	worldportstr << worldPort;
	if(argc<2) return 1;
	genome_file = argv[1];  if(!genome_file) return 1;
	myGenome.attachFile(genome_file);
	if(argc>2) myPort=atoi(argv[2]); 
	portstr << myPort;
	int sock = UDP_bind(myPort);
	//printf("my file is %s waiting on port %i\n", genome_file, myPort);

	myGenome.transcribeGene("//green_appearance", 1, portstr.str().c_str());

	srandom(100);
	stringstream net_file;  net_file<<genome_file<<"."<<myPort<<".net";
	myNet.name = net_file.str();
	myNet.saveToFile(net_file.str().c_str());
	myGenome.transcribeGene("//add_eye", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_eye", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_auditory", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_reproduction", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_movement", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_turn", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//connect_subnets", 2, genome_file, portstr.str().c_str());
	myNet.loadFromFile(net_file.str().c_str());
	myNet.printStats();

	//printf("body\n");

	stringstream child_file;  child_file<<genome_file<<n_children;
	//myGenome.transcribeGene("//asexual_reproduction", 4, portstr.str().c_str(), genome_file, child_file.str().c_str(), worldportstr.str().c_str());
	
	int n=4;
	while(1) {
		try {
			int status; while (waitpid(-1, &status, WNOHANG)>0);

			int nMessages=0; do {
				nMessages = check_for_message(sock);
			} while (nMessages>0);

			myNet.addClick();

			map<string,int>output_length; map<string,unsigned char*>output_data;
			myNet.getOutput(output_length, output_data);

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "talk", 0.25, "//say", 1, portstr.str().c_str()) ;

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "move", 0.2, "//move", 1, portstr.str().c_str()) ;

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "turn", 0.1, "//turn", 1, portstr.str().c_str()) ;

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "attack", 0.1, "//attack", 1, portstr.str().c_str()) ;

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "eat", 0.2, "//eat", 1, portstr.str().c_str()) ;

			stringstream child_file;  child_file<<genome_file<<n_children;
			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "reproduction", 0.33, "//asexual_reproduction", 4, portstr.str().c_str(), genome_file, child_file.str().c_str(), worldportstr.str().c_str()) ;
	
			usleep(1000);
			//sleep(2);
		} 
		catch (...) {
			printf("organism %i error\n", myPort);
		}
	}
	close (sock);
	
	return 1;
}