-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
33 lines (30 loc) · 898 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const TOTAL = 50;
let neat;
let config = {
model: [
{nodeCount: 6, type: "input"},
{nodeCount: 3, type: "output", activationfunc: activation.SOFTMAX}
],
mutationRate: 0.2,
crossoverMethod: crossover.RANDOM,
mutationMethod: mutate.RANDOM,
populationSize: TOTAL
};
neat = new NEAT(config);
function updateNeuralNet(state) {
for (let i = 0; i < TOTAL; i++) {
neat.setInputs(state.dinos[i].inputs(state), i);
}
neat.feedForward();
let decisions = neat.getDecisions();
// console.log(decisions);
for (let i = 0; i < TOTAL; i++) {
if (decisions[i] === 1) {
state.dinos[i].jump();
} else if (decisions[i] === 2) {
state.dinos[i].duck(true);
}
}
document.getElementById("genNum").innerText = neat.getGen()+1;
document.getElementById("aliveNum").innerText = state.alive;
}