class creature { String name="randomcreature"; float fitness; genome genotype; int minGenes=25; int maxGenes=30; int maxRepeat=3; int maxNodes=500; // int amount=int(random(minGenes,maxGenes)); int amount=16; position rootNode; lattice phenotype; int nodeAmount=0; float cohesionDistance=30; float minDistance=15; float collisionDistance=12; position lastP; position p; float distanceTravelled=0; boolean allTypes=false; float avgSpeed=0; creature(position startPos) { rootNode=new position(startPos); genotype=new genome(amount,this); phenotype=new lattice(nodeAmount,this); buildCreature(rootNode,phenotype,genotype,maxNodes); phenotype.update(); p=new position(phenotype.averagePos); lastP=new position(p); distanceTravelled=0; allTypes=checkCompletion(); tagGenome(); genotype.buildKey(); } creature(creature c) { fitness=0; rootNode=new position(c.rootNode); minGenes=c.minGenes; maxGenes=c.maxGenes; maxNodes=c.maxNodes; maxRepeat=c.maxRepeat; amount=c.amount; nodeAmount=c.nodeAmount; cohesionDistance=c.cohesionDistance; collisionDistance=c.collisionDistance; minDistance=c.minDistance; genotype=new genome(c.genotype,this); phenotype=new lattice(nodeAmount,this); //rebuild(); //phenotype=new lattice(c.nodeAmount,this); buildCreature(rootNode,phenotype,genotype,maxNodes); phenotype.update(); p=new position(phenotype.averagePos); lastP=new position(p); distanceTravelled=0; allTypes=checkCompletion(); tagGenome(); genotype.buildKey(); } creature(position startPos,genome g) { rootNode=new position(startPos); genotype=new genome(g,this); phenotype=new lattice(nodeAmount,this); buildCreature(rootNode,phenotype,genotype,maxNodes); phenotype.update(); p=new position(phenotype.averagePos); lastP=new position(p); distanceTravelled=0; allTypes=checkCompletion(); tagGenome(); genotype.buildKey(); } void update(position l) { lastP=new position(p); phenotype.update(l); p=new position(phenotype.averagePos); distanceTravelled+=dist(lastP,p); } boolean checkCompletion() { return phenotype.allTypes(); } boolean checkStability() { return phenotype.stable; } float currentSize() { return phenotype.mostDistant; } void export(String filename) { println("Exporting creature..."); println(genotype.strainKey); String list[]=split(genotype.strainKey,'@'); saveStrings(filename,list); } void importGen(String filename) { String lines[] = loadStrings(filename); // println("there are " + lines.length + " lines"); name=lines[0]; String creatureStrainData[]=split(lines[1]); amount=int(Float.parseFloat(creatureStrainData[0])); cohesionDistance=Float.parseFloat(creatureStrainData[1]); minDistance=Float.parseFloat(creatureStrainData[2]); collisionDistance=Float.parseFloat(creatureStrainData[3]); /* println("amount: "+amount); println("cohesion distance: "+cohesionDistance); println("min distance: "+minDistance); println("collision distance: "+collisionDistance);*/ genotype=new genome(filename,this); rebuild(); } void rebuild() { genotype.clearTags(); phenotype=new lattice(nodeAmount,this); buildCreature(rootNode,phenotype,genotype,maxNodes); phenotype.update(); p=phenotype.averagePos; lastP=new position(p); distanceTravelled=0; tagGenome(); genotype.buildKey(); } void mutate() { for(int m=0;m<4;m++) genotype.mutateMorph(); for(int m=0;m<4;m++) genotype.mutateNS(); } void tagGenome() { for(int p=0;p