class genome { creature parent=null; gene strain[]; int strainLength; String strainKey; genome(String filename,creature p) { parent=p; String lines[] = loadStrings(filename); strainLength=parent.amount; strain=new gene[strainLength]; for(int i=0;i50) neuronWeight=1; else neuronWeight=-1; float neuronPower=random(0,2); boolean bidirectional=false; if(random(100)>50) bidirectional=true; float heading=random(-360,360); float distance=random(p.minDistance,p.cohesionDistance); strain[i]=new gene(i,repeat,int(heading),distance,neuronWeight,neuronPower,bidirectional,int(rkey)); if(random(100)>30&&!strain[i].isLightSensor) { strain[i].isNeuron=false; } } int maxConnections=int(strainLength*.8); for(int s=0;s0&&idparent.cohesionDistance); g.distance=parent.cohesionDistance-.1; } void mutateRepeat(gene g) { g.repeat=int(random(parent.maxRepeat)); } void mutateKey(gene g) { g.rkey=int(random(4)); } void mutateNeurons(gene g) { int rm=int(random(4)); switch(rm) { case 0: if(random(100)>50) g.neuronWeight=1; else g.neuronWeight=-1; break; case 1: if(random(100)>50) g.bidirectional=false; else g.bidirectional=true; break; case 2: g.neuronPower=random(0,2); break; } } void mutateChild(gene g) { if(random(100)>50&&g!=strain[0]) { g.child=null; g.childID=-1; } else { int rc=int(random(strainLength)); if(strain[rc].child==null) { g.child=strain[rc]; g.childID=rc; } } } void deleteChild(gene g) { if(g.child==null||g==strain[0]) return; else { } } void addGene() { strainLength++; gene temp[]=new gene[strainLength]; System.arraycopy(strain,0,temp,0,strain.length); float rkey=random(4); int repeat=int(random(parent.maxRepeat)); float neuronWeight; if(random(100)>50) neuronWeight=1; else neuronWeight=-1; float neuronPower=random(0,2); boolean bidirectional=false; if(random(100)>50) bidirectional=true; float heading=random(-360,360); float distance=random(parent.minDistance,parent.cohesionDistance); temp[strainLength-1]=new gene(strainLength-1,repeat,int(heading),distance,neuronWeight,neuronPower,bidirectional,int(rkey)); if(random(100)>30&&!temp[strainLength-1].isLightSensor) { temp[strainLength-1].isNeuron=false; } strain=temp; } void garbageCollect() { // for } void mutateMorph() { int rg=int(random(strainLength)); while(strain[rg].usedInPhenotype==false) { rg=int(random(strainLength)); } gene cg=strain[rg]; int rm=int(random(5)); switch(rm) { case 0: mutateAngle(cg); break; case 1: mutateDistance(cg); break; case 2: mutateRepeat(cg); break; case 3: mutateKey(cg); break; case 4: for(int m=0;m<5;m++) mutateChild(cg); break; } // if(random(100)>60) // addGene(); // buildKey(); } void mutateNS() { int rg=int(random(strainLength)); gene cg=strain[rg]; while(strain[rg].usedInPhenotype==false&&strain[rg].isNeuron==false) { rg=int(random(strainLength)); cg=strain[rg]; } mutateNeurons(cg); } void clearTags() { for(int r=0;r