File tree Expand file tree Collapse file tree 2 files changed +4
-4
lines changed
examples/NeuroEvolution-flappy-bird Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Original file line number Diff line number Diff line change 1
1
class Bird {
2
2
constructor ( brain ) {
3
- // A bird's brain receives 5 inputs and classifies them into one of two labels
4
3
if ( brain ) {
5
4
this . brain = brain ;
6
5
} else {
6
+ // A bird's brain receives 4 inputs and classifies them into one of two labels
7
7
this . brain = ml5 . neuralNetwork ( {
8
8
inputs : 4 ,
9
9
outputs : [ "flap" , "no flap" ] ,
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ function setup() {
7
7
birds [ i ] = new Bird ( ) ;
8
8
}
9
9
pipes . push ( new Pipe ( ) ) ;
10
-
11
10
ml5 . tf . setBackend ( "cpu" ) ;
12
11
}
13
12
@@ -59,7 +58,7 @@ function reproduction() {
59
58
for ( let i = 0 ; i < birds . length ; i ++ ) {
60
59
let parentA = weightedSelection ( ) ;
61
60
let parentB = weightedSelection ( ) ;
62
- let child = parentA . brain . crossover ( parentB . brain ) ;
61
+ let child = parentA . crossover ( parentB ) ;
63
62
child . mutate ( 0.01 ) ;
64
63
nextBirds [ i ] = new Bird ( child ) ;
65
64
}
@@ -91,5 +90,6 @@ function weightedSelection() {
91
90
}
92
91
// Undo moving to the next element since the finish has been reached
93
92
index -- ;
94
- return birds [ index ] ;
93
+ // Instead of returning the entire Bird object, just the brain is returned
94
+ return birds [ index ] . brain ;
95
95
}
You can’t perform that action at this time.
0 commit comments