function population(game){ this.max = 50; this.top = 4; this.game = game; if (this.max < this.top){ this.top = this.max; } this.Population = []; this.scale = 200; this.reset = function(){ this.iteration = 1; this.mutateRate = 1; this.best_population = 0; this.best_fitness = 0; this.best_score = 0; } this.create_population = function(){ this.Population = []; for (var i=0; i= 0){ unit.y -= 1; } else if (max == 2 && unit.y <= 500){ unit.y += 1; } else if (max == 1 && unit.x <= 500){ unit.x += 1; } else if (max == 3 && unit.x >= 0){ unit.x -= 1; } //unit.round++; //this.game.draw(unit.x,unit.y); unit.fitness = dist(unit.x,unit.y,0,0); //console.log(max+"evolving"+outputs); } this.evolve = function(){ var Winners = this.select(); if (this.mutateRate == 1 && Winners[0].fitness < 0){ this.create_population(); } else{ this.mutateRate = 0.2; } for (var i=this.top; i