Skip to content

Commit 86549c0

Browse files
committed
return the brain rather than full bird object
1 parent b1285ef commit 86549c0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

examples/NeuroEvolution-flappy-bird/bird.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class Bird {
22
constructor(brain) {
3-
// A bird's brain receives 5 inputs and classifies them into one of two labels
43
if (brain) {
54
this.brain = brain;
65
} else {
6+
// A bird's brain receives 4 inputs and classifies them into one of two labels
77
this.brain = ml5.neuralNetwork({
88
inputs: 4,
99
outputs: ["flap", "no flap"],

examples/NeuroEvolution-flappy-bird/sketch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function setup() {
77
birds[i] = new Bird();
88
}
99
pipes.push(new Pipe());
10-
1110
ml5.tf.setBackend("cpu");
1211
}
1312

@@ -59,7 +58,7 @@ function reproduction() {
5958
for (let i = 0; i < birds.length; i++) {
6059
let parentA = weightedSelection();
6160
let parentB = weightedSelection();
62-
let child = parentA.brain.crossover(parentB.brain);
61+
let child = parentA.crossover(parentB);
6362
child.mutate(0.01);
6463
nextBirds[i] = new Bird(child);
6564
}
@@ -91,5 +90,6 @@ function weightedSelection() {
9190
}
9291
// Undo moving to the next element since the finish has been reached
9392
index--;
94-
return birds[index];
93+
// Instead of returning the entire Bird object, just the brain is returned
94+
return birds[index].brain;
9595
}

0 commit comments

Comments
 (0)