User prompt
Add the next features you think the game needs.
User prompt
Make it so once the ai children spawn they start moving and behaiving like the initial ai, using the same movement system you created for the ai.
User prompt
The ai children are still not moving after being spawned.
User prompt
Add the same movements system the ai uses to the children.
User prompt
Work on the ai child inheriting traits system.
User prompt
The ai child is not moving after being spawned. Fix this.
User prompt
Continue improving the ai movement so it doesn't get stuck on the corners of the screen, add collisions. Continue developing the other ai functions after.
User prompt
The ai is almost not moving at all. It looks like it is shaking. Fix that by making it not change directions so randomly, and by keeping a sense of the axis for a longer time.
User prompt
Improve the AI movement. Make it more fluid and actually effective.
User prompt
Make it so the AI entities can move
User prompt
Using what was said above, try fixing the ai not showing/spawning when the game starts.
User prompt
Continue developing the game.
User prompt
The ai are not showing/spawning. Fix that problem and continue updating the ai.
User prompt
Make it so when the game starts there are 3 ais spawning
User prompt
Fix Bug: 'ReferenceError: ais is not defined' in this line: 'var index = ais.indexOf(this);' Line Number: 37
User prompt
Review the code and do the debugging. Improve the functions and methods.
User prompt
Continue developing the neural network. Update the game logic to reflect the new additions.
User prompt
Fix Bug: 'ReferenceError: NeuralNetwork is not defined' in this line: 'self.neuralNetwork = new NeuralNetwork();' Line Number: 5
User prompt
Look at numer 2. in your previous answer. Implement all the methods listed there. Also develop and add the neural network.
Initial prompt
Machine learning example
var NeuralNetwork = function () { var self = this; self.weights = []; self.bias = 0; self.clone = function () { var clone = new NeuralNetwork(); clone.weights = this.weights.slice(); clone.bias = this.bias; return clone; }; self.feedForward = function (inputs) { var sum = 0; for (var i = 0; i < inputs.length; i++) { sum += inputs[i] * this.weights[i]; } return sum + this.bias; }; }; var AI = Container.expand(function () { var self = Container.call(this); var ais = []; self.aiGraphics = self.createAsset('ai', 'AI character', .5, .5); self.food = 10; self.eat = function (food) { if (food.amount > 0) { this.food += food.consume(1); } }; self.share = function (otherAI) { var decision = this.neuralNetwork.feedForward([this.food, otherAI.food]); if (decision > 0) { var shareAmount = this.food * 0.1; this.food -= shareAmount; otherAI.food += shareAmount; } }; self.survive = function () { this.food -= 0.01; if (this.food < 0) { this.destroy(); var index = ais.indexOf(this); if (index > -1) { ais.splice(index, 1); } } }; self.neuralNetwork = new NeuralNetwork(); self.neuralNetwork.weights = [Math.random(), Math.random()]; self.neuralNetwork.bias = Math.random(); self.reproduce = function () { if (this.food > 10) { var child = new AI(); child.neuralNetwork = this.neuralNetwork.clone(); for (var i = 0; i < child.neuralNetwork.weights.length; i++) { if (Math.random() < 0.1) { child.neuralNetwork.weights[i] += Math.random() * 0.2 - 0.1; } } if (Math.random() < 0.1) { child.neuralNetwork.bias += Math.random() * 0.2 - 0.1; } this.food -= 10; ais.push(child); return child; } return null; }; }); var Food = Container.expand(function () { var self = Container.call(this); var foodGraphics = self.createAsset('food', 'Food', .5, .5); self.amount = 10; self.consume = function (amount) { this.amount -= amount; return amount; }; }); var Game = Container.expand(function () { var self = Container.call(this); var ais = []; var foods = []; for (var i = 0; i < 3; i++) { var ai = new AI(); ai.x = Math.random() * 2048; ai.y = Math.random() * 2732; ais.push(ai); self.addChild(ai); var food = new Food(); food.x = Math.random() * 2048; food.y = Math.random() * 2732; foods.push(food); self.addChild(food); } LK.on('tick', function () { for (var i = 0; i < ais.length; i++) { var ai = ais[i]; ai.survive(); for (var j = 0; j < foods.length; j++) { var food = foods[j]; if (ai.intersects(food)) { ai.eat(food); food.consume(1); if (food.amount <= 0) { food.destroy(); foods.splice(j, 1); j--; } } } for (var j = i + 1; j < ais.length; j++) { var otherAI = ais[j]; if (ai.intersects(otherAI)) { var decision = ai.neuralNetwork.feedForward([ai.food, otherAI.food]); if (decision > 0) { ai.share(otherAI); } } } if (ai.food <= 0) { var index = ais.indexOf(ai); if (index > -1) { ais.splice(index, 1); } ai.destroy(); i--; } } if (LK.ticks % 600 == 0) { for (var i = 0; i < ais.length; i++) { var ai = ais[i]; var child = ai.reproduce(); if (child) { child.x = ai.x; child.y = ai.y; self.addChild(child); } } } if (LK.ticks % 60 == 0) { var food = new Food(); food.x = Math.random() * 2048; food.y = Math.random() * 2732; foods.push(food); self.addChild(food); } }); });
===================================================================
--- original.js
+++ change.js
@@ -19,9 +19,9 @@
var AI = Container.expand(function () {
var self = Container.call(this);
var ais = [];
self.aiGraphics = self.createAsset('ai', 'AI character', .5, .5);
- self.food = 0;
+ self.food = 10;
self.eat = function (food) {
if (food.amount > 0) {
this.food += food.consume(1);
}
@@ -35,9 +35,9 @@
}
};
self.survive = function () {
this.food -= 0.01;
- if (this.food <= 0) {
+ if (this.food < 0) {
this.destroy();
var index = ais.indexOf(this);
if (index > -1) {
ais.splice(index, 1);
@@ -68,9 +68,9 @@
});
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.createAsset('food', 'Food', .5, .5);
- self.amount = 0;
+ self.amount = 10;
self.consume = function (amount) {
this.amount -= amount;
return amount;
};
@@ -84,9 +84,8 @@
ai.x = Math.random() * 2048;
ai.y = Math.random() * 2732;
ais.push(ai);
self.addChild(ai);
- self.addChild(ai);
var food = new Food();
food.x = Math.random() * 2048;
food.y = Math.random() * 2732;
foods.push(food);