示例#1
0
int main(int argc, char *argv[]) {
	srandom(100);
	if(argc<2) return 0;
	Net myNet;
	//printf("add_movement started with file %s port %s\n", argv[0], argv[1]);
	char * genome_file = argv[0];
	int port = atoi(argv[1]);

	int num_attack_outputs = 3;
	int num_attack_geneneurons = 2;
	int num_eat_outputs = 3;
	int num_eat_geneneurons = 2;

	stringstream net_file;  net_file<<genome_file<<"."<<port<<".net";
	myNet.loadFromFile(net_file.str().c_str());

	/*
	for(int i = 0 ; i < 4; i++) {
		myNet.addNeuron(INPUT, "hunger");
	}
	myNet.connectSubnets("hunger", "eat", -0.1, 1.5);
	*/

	for(int o = 0 ; o < num_attack_outputs; o++) {
		myNet.addNeuron(OUTPUT, "attack");
	}
	for(int o = 0 ; o < num_attack_geneneurons; o++) {
		myNet.addNeuron(OUTPUT, "//attack");
	}
	for(int o = 0 ; o < num_eat_outputs; o++) {
		myNet.addNeuron(OUTPUT, "eat");
	}
	for(int o = 0 ; o < num_eat_geneneurons; o++) {
		myNet.addNeuron(OUTPUT, "//eat");
	}
	myNet.connectSubnets("visual_cortex", "attack", -0.25, 1.5);
	myNet.connectSubnets("visual_cortex", "//attack", -0.2, 1.2);
	myNet.connectSubnets("visual_cortex", "eat", -0.25, 1.5);
	myNet.connectSubnets("visual_cortex", "//eat", -0.2, 1.2);

	myNet.saveToFile(net_file.str().c_str());
}
示例#2
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;
}