Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xviniette committed Jul 25, 2016
1 parent f691044 commit 64629d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
26 changes: 20 additions & 6 deletions Neuroevolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ var Neuroevolution = function(options){
mutationRange:0.5,
network:[1, [1], 1],
historic:0,
scoreSort:-1
lowHistoric:false,
scoreSort:-1,
nbChild:1
}

self.set = function(options){
Expand Down Expand Up @@ -210,10 +212,12 @@ var Neuroevolution = function(options){
var max = 0;
while(true){
for(var i = 0; i < max; i++){
var childs = this.breed(this.genomes[i], this.genomes[max], 1);
nexts.push(childs[0].network);
if(nexts.length >= self.options.population){
return nexts;
var childs = this.breed(this.genomes[i], this.genomes[max], (self.options.nbChild > 0 ? self.options.nbChild : 1) );
for(var c in childs){
nexts.push(childs[c].network);
if(nexts.length >= self.options.population){
return nexts;
}
}
}
max++;
Expand Down Expand Up @@ -279,6 +283,16 @@ var Neuroevolution = function(options){
nn.setSave(networks[i]);
nns.push(nn);
}

if(self.options.lowHistoric){
if(self.generations.generations.length >= 2){
var genomes = self.generations.generations[self.generations.generations.length - 2].genomes;
for(var i in genomes){
delete genomes[i].network;
}
}
}

if(self.options.historic != -1){
if(self.generations.generations.length > self.options.historic + 1){
self.generations.generations.splice(0, self.generations.generations.length - (self.options.historic + 1));
Expand All @@ -287,7 +301,7 @@ var Neuroevolution = function(options){
return nns;
}

self.addNetwork = function(network, score){
self.networkScore = function(network, score){
self.generations.addGenome(new Genome(score, network.getSave()));
}
}
Binary file added doc/flappy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Game.prototype.update = function(){
this.birds[i].alive = false;
this.alives--;
//console.log(this.alives);
Neuvol.addNetwork(this.gen[i], this.score);
Neuvol.networkScore(this.gen[i], this.score);
if(this.isItEnd()){
this.start();
}
Expand Down Expand Up @@ -262,7 +262,7 @@ window.onload = function(){
var start = function(){
Neuvol = new Neuroevolution({
population:50,
network:[2, [2], 1]
network:[2, [2], 1],
});
game = new Game();
game.start();
Expand Down

0 comments on commit 64629d8

Please sign in to comment.