From d9f3730b4d4b7ce047fa1cb0baa09198cd07f540 Mon Sep 17 00:00:00 2001 From: "Martin M. S. Pedersen" Date: Mon, 10 Jun 2019 19:38:25 +0200 Subject: [PATCH 1/3] Add pipe's width when bird is looking for closest pipe --- examples/neuroevolution-flappybird/bird.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/neuroevolution-flappybird/bird.js b/examples/neuroevolution-flappybird/bird.js index 2cccc5b..2cfa5db 100644 --- a/examples/neuroevolution-flappybird/bird.js +++ b/examples/neuroevolution-flappybird/bird.js @@ -62,7 +62,7 @@ class Bird { let closest = null; let record = Infinity; for (let i = 0; i < pipes.length; i++) { - let diff = pipes[i].x - this.x; + let diff = pipes[i].x - this.x + pipes[i].w; if (diff > 0 && diff < record) { record = diff; closest = pipes[i]; @@ -111,4 +111,4 @@ class Bird { // Every frame it is alive increases the score this.score++; } -} \ No newline at end of file +} From a86257cdd392f3522afcbf239723cb6e16431ff5 Mon Sep 17 00:00:00 2001 From: "Martin M. S. Pedersen" Date: Mon, 10 Jun 2019 19:52:35 +0200 Subject: [PATCH 2/3] Add birdsalives and generation info to webpage --- examples/neuroevolution-flappybird/index.html | 2 ++ examples/neuroevolution-flappybird/sketch.js | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/neuroevolution-flappybird/index.html b/examples/neuroevolution-flappybird/index.html index e540f29..7933238 100755 --- a/examples/neuroevolution-flappybird/index.html +++ b/examples/neuroevolution-flappybird/index.html @@ -19,6 +19,8 @@ speed: 1
high score: 0
all time high score: 0 +
generation: 0 +
birds alive: 0

diff --git a/examples/neuroevolution-flappybird/sketch.js b/examples/neuroevolution-flappybird/sketch.js index 58fe6f0..dc4ee32 100644 --- a/examples/neuroevolution-flappybird/sketch.js +++ b/examples/neuroevolution-flappybird/sketch.js @@ -25,6 +25,9 @@ let allTimeHighScoreSpan; // All time high score let highScore = 0; +// Count generations +let generations = 1 + // Training or just showing the current best let runBest = false; let runBestButton; @@ -34,6 +37,8 @@ function setup() { canvas.parent('canvascontainer'); // Access the interface elements + generationText = select('#gens'); + birdsAlive = select('#birdsalive'); speedSlider = select('#speedSlider'); speedSpan = select('#speed'); highScoreSpan = select('#hs'); @@ -159,6 +164,8 @@ function draw() { // Update DOM Elements highScoreSpan.html(tempHighScore); allTimeHighScoreSpan.html(highScore); + generationText.html(generations); + birdsAlive.html(activeBirds.length); // Draw everything! for (let i = 0; i < pipes.length; i++) { @@ -173,7 +180,8 @@ function draw() { } // If we're out of birds go to the next generation if (activeBirds.length == 0) { + generations++; nextGeneration(); } } -} \ No newline at end of file +} From e1e13fcc21c126e4434cbdbc1ca979e5f35ea5dd Mon Sep 17 00:00:00 2001 From: "Martin M. S. Pedersen" Date: Mon, 10 Jun 2019 19:57:07 +0200 Subject: [PATCH 3/3] Add relu activation function --- lib/nn.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/nn.js b/lib/nn.js index 0cb4527..4e61c92 100644 --- a/lib/nn.js +++ b/lib/nn.js @@ -17,6 +17,11 @@ let tanh = new ActivationFunction( y => 1 - (y * y) ); +let tanh = new ActivationFunction( + x => (x<0)?0:x, + y => (x<0)?0:1 +); + class NeuralNetwork { /*