/*****************************************************************************/ /* File: predator.c */ /* Version: 1.0 */ /* Date: 07-Oct-98 */ /* Description: Predator in the prey - predator experiment. */ /* This program was adapted from Dario Floreano's program */ /* Author: Olivier.Michel@cyberbotics.com */ /* */ /* Copyright (c) 1998 Cyberbotics - www.cyberbotics.com */ /*****************************************************************************/ #include #include #include #include #include #define SYNAPSE_LENGTH 5 /* binary length for one synapse */ #define PROXIMITY 8 #define CAMERA 5 /* 5 photo-sensors on a linear camera */ #define HIDDEN 2 #define INPUT ((PROXIMITY)+(CAMERA)+(HIDDEN)) #define N_SYNAPSES ((INPUT)*(HIDDEN)+(HIDDEN)) #define CHROMOSOME_SIZE ((SYNAPSE_LENGTH)*(N_SYNAPSES)) #define SENSCALE 1024.0 #define MOTSCALE 20.0 int chromosome[CHROMOSOME_SIZE]; int w1sign[(INPUT)*(HIDDEN)]; float w1[(INPUT)*(HIDDEN)]; int bhsign[HIDDEN]; float bh[HIDDEN]; float inp[INPUT]; float hid[HIDDEN]; int distance[PROXIMITY]; uint8 *camera; int left_speed; int right_speed; bool braiten=false; int generation = 0; int seed = 1; gui_window window=NULL; gui_textfield file_number_tf=NULL; gui_textfield gen_number_tf=NULL; gui_button reload=NULL; /* load a chromosome from a file */ void load() { char filename[256]; int i,j; FILE *file; sprintf(filename,"best_P.%d",seed); file = fopen(filename,"r"); if (file==NULL) fprintf(stderr,"predator: %s file not found\n",filename); for(i=0;i<=generation;i++) { fscanf(file,"%s",filename); // skip the generation number for(j=0;j 128 ms } }