xxxxxxxxxx
155
function Dna(team){
this.team = team;
this.fitness = 0;
}
Dna.prototype.generate = function(){
this.seperateMult = round(random(1.5,2.5),2); //2
//align
this.alignRange = round(random(30,70),2); //50
this.alignMult = round(random(0.5,1.5),2); //1
//cohesion
this.cohesionRange = round(random(1,20),2); //10
this.cohesionMult = round(random(0.5,1.5),2); //1
this.runRange = 0; //240
this.runMult = 0; //2
this.foodRange = 0; //200
this.foodMult = 0; //1.2
this.chaseRange = 0;
this.chaseMult = 0;
//this.maxForce = 0.2;//random(random(0.1,0.3),3);
if(this.team == 0){
//speed;
this.speed = round(random(4,7),2);
//run
this.runRange = round(random(200,300),2); //240
this.runMult = round(random(0.5,1.5),2); //2
//seperate
this.seperateRange = round(random(10,30),2); //24
//food
this.foodRange = round(random(100,300),2); //200
this.foodMult = round(random(0.5,1.5),2); //1.2
}
if(this.team == 1){
//speed;
this.speed = round(random(4,6),2);
//chase
this.chaseRange = round(random(250,450),2); //300
this.chaseMult = round(random(0.5,2),2); //1.6
//seperate
this.seperateRange = round(random(20,50),2); //36
}
console.log(this);
}
Dna.prototype.copy = function(other){
let chance = 20;
let mutation = round(random(1,chance),1);
if(mutation == 1){
this.seperateMult = round(random(1.5,2.5),2);
}else{
this.seperateMult = other.seperateMult; //2
}
mutation = round(random(1,chance),1);
if(mutation == 1){
this.seperateRange = round(random(10,40),2);
}else{
this.seperateRange = other.seprateRange;
}
mutation = round(random(1,chance),1);
if(mutation == 1){
this.alignRange = round(random(40,60),2);
}else{
this.alignRange = other.alignRange; //50
}
mutation = round(random(1,chance),1);
if(mutation == 1){
this.alignMult = round(random(0.5,1.5),2);
}else{
this.alignMult = other.alignMult; //1
}
mutation = round(random(1,chance),1);
if(mutation == 1){
this.cohesionRange = round(random(5,25),2);
}else{
this.cohesionRange = other.cohesionRange; //10
}
mutation = round(random(1,chance),1);
if(mutation == 1){
this.cohesionMult = round(random(0.5,1.5),2);
}else{
this.cohesionMult = other.cohesionMult;
}
mutation = round(random(1,chance),1);
if((mutation == 1) && (this.team == 0)){
this.runRange = round(random(100,300),2); //240
}else{
this.runRange = other.runRange; //240
}
mutation = round(random(1,chance),1);
if((mutation == 1) && (this.team == 0)){
this.runMult = round(random(1,3),2);
}else{
this.runMult = other.runMult;
}
mutation = round(random(1,chance),1);
if((mutation == 1) && (this.team == 0)){
this.foodRange = round(random(100,300),2); //240
}else{
this.foodRange = other.foodRange; //200; //240
}
mutation = round(random(1,chance),1);
if((mutation == 1) && (this.team == 0)){
this.foodMult = round(random(1,2),2);
}else{
this.foodMult = other.foodMult; //1.2
}
mutation = round(random(1,chance),1);
if((mutation == 1) && (this.team == 1)){
this.chaseRange = round(random(200,400),2); //240
}else{
this.chaseRange = other.chaseRange; //200; //240
}
mutation = round(random(1,chance),1);
if((mutation == 1) && (this.team == 1)){
this.chaseMult = round(random(1,2),2);
}else{
this.chaseMult = other.foodMult; //1.2
}
mutation = round(random(1,chance),1);
if(mutation ==1){
this.speed = round(random(4,7),2);
}else{
this.speed = other.speed;
}
}
Dna.prototype.fitness = function(lifeTime,score){
this.fitness = lifeTime*0.5 + score*0.5;
}