JSFiddle - React, Tailwind, and code Playground
by a_bertrand
HTML
<div id="status"></div>
Live world:<br />
<canvas width="500" height="300" style="border: black 1px solid; background-color: black;" id="worldCanvas"></canvas>
<pre id="result"></pre>
Weights: <input type="text" id="weights" />
JavaScript
var Goal = (function () {
function Goal(world) {
this.X = Math.round(Math.random() * 400) + 50;
this.Y = Math.round(Math.random() * 100) + 50;
this.Life = 0;
this.World = world;
}
Goal.prototype.Render = function (ctx) {
ctx.fillStyle = "#FF0000";
ctx.beginPath();
ctx.arc(Math.round(this.X), Math.round(this.Y), 7, 0, Math.PI * 2);
ctx.fill();
};
Goal.prototype.Handle = function () {
this.Life++;
if (this.Life > 400) {
for (var i = 0; i < this.World.Goals.length; i++) {
if (this.World.Goals[i] == this) {
this.World.Goals.splice(i, 1);
return;
}
}
}
};
Goal.prototype.Remove = function () {
for (var i = 0; i < this.World.Goals.length; i++) {
if (this.World.Goals[i] == this) {
this.World.Goals.splice(i, 1);
return;
}
}
};
return Goal;
}());
var Neuron = (function () {
function Neuron(net) {
this.Connections = [];
this.ReverseConnections = [];
this.value = 0;
this.Net = net;
}
Object.defineProperty(Neuron.prototype, "Value", {
get: function () {
return this.value;
},
set: function (newValue) {
this.value = newValue;
for (var i = 0; i < this.Connections.length; i++)
this.Connections[i].To.RecalcValue();
},
enumerable: true,
configurable: true
});
Neuron.prototype.RecalcValue = function () {
var v = 0;
for (var i = 0; i < this.ReverseConnections.length; i++) {
v += this.ReverseConnections[i].From.value * this.ReverseConnections[i].Weight;
}
this.value = v;
for (var i = 0; i < this.Connections.length; i++)
this.Connections[i].To.RecalcValue();
};
return...