File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,19 @@ import { CANVAS_WIDTH, CANVAS_HEIGHT } from '../game/constants';
44import { Runner } from '../game' ;
55import NNModel from '../ai/models/nn/NNModel' ;
66
7+ const T_REX_COUNT = 3 ;
8+
79let runner = null ;
810
11+ const training = {
12+ inputs : [ ] ,
13+ labels : [ ]
14+ } ;
15+
916function setup ( ) {
1017 // Initialize the game Runner.
1118 runner = new Runner ( '.game' , {
12- T_REX_COUNT : 3 ,
19+ T_REX_COUNT ,
1320 onReset : handleReset ,
1421 onCrash : handleCrash ,
1522 onRunning : handleRunning
@@ -28,16 +35,12 @@ function handleReset({ tRexes }) {
2835 tRexes . forEach ( ( tRex ) => {
2936 tRex . model = new NNModel ( ) ;
3037 tRex . model . init ( ) ;
31- tRex . training = {
32- inputs : [ ] ,
33- labels : [ ]
34- } ;
3538 } ) ;
3639 } else {
3740 // Train the model before restarting.
3841 console . info ( 'Training' ) ;
3942 tRexes . forEach ( ( tRex ) => {
40- tRex . model . train ( tRex . training . inputs , tRex . training . labels ) ;
43+ tRex . model . train ( training . inputs , training . labels ) ;
4144 } ) ;
4245 }
4346}
@@ -72,8 +75,8 @@ function handleCrash({ tRex }) {
7275 input = convertStateToVector ( tRex . lastRunningState ) ;
7376 label = [ 0 , 1 ] ;
7477 }
75- tRex . training . inputs . push ( input ) ;
76- tRex . training . labels . push ( label ) ;
78+ training . inputs . push ( input ) ;
79+ training . labels . push ( label ) ;
7780}
7881
7982function convertStateToVector ( state ) {
You can’t perform that action at this time.
0 commit comments