Skip to content

Commit 4a2bb96

Browse files
committed
Change training dataset
1 parent 70d1983 commit 4a2bb96

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/apps/nnm.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import { CANVAS_WIDTH, CANVAS_HEIGHT } from '../game/constants';
44
import { Runner } from '../game';
55
import NNModel from '../ai/models/nn/NNModel';
66

7+
const T_REX_COUNT = 3;
8+
79
let runner = null;
810

11+
const training = {
12+
inputs: [],
13+
labels: []
14+
};
15+
916
function 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

7982
function convertStateToVector(state) {

0 commit comments

Comments
 (0)