User prompt
Make some tweaks to how often food spawns. Make it a little bit rares.
User prompt
Make it so the sharing system also includes the field of view
User prompt
Make it so the sharing system also uses the field of view function. Display on each ai what generation it belongs too.
User prompt
Fix the ais dying too fast. Make it so that it shows the generation number right.
User prompt
Something changed that made the ais die to quick. Fix that
User prompt
Make the AIs smarter.
User prompt
Make it so there are more random traits, such as speed, food needed to survive (that should be between 1 and 2), food needed to breed(between 2 and 3), and other trais. Don't forget to make all those inheritable and mutatable.
User prompt
Make it so each ai can only spawn one child at a time.
User prompt
Make it so food doesn't spawn that often or whatever you think would make it more balanced.
User prompt
Fix Bug: 'TypeError: self.generation is undefined' in this line: 'self.generationText = new Text2(self.generation.toString(), {' Line Number: 27
User prompt
Make it so on each ai it is displayed what generation it belongs to.
User prompt
Add field of view to the sharing method too.
User prompt
Continue tweaking with the filed of view.
User prompt
Make the game look more enjoyable.
User prompt
Continue tweaking the field of view systems. Make it so the sharing method uses the field of view too.
User prompt
Fix Bug: 'TypeError: self.generation is undefined' in this line: 'var generationText = new Text2(self.generation.toString(), {' Line Number: 27
User prompt
Fix Bug: 'TypeError: self.generation is undefined' in this line: 'var generationText = new Text2(self.generation.toString(), {' Line Number: 27
User prompt
Make it so on each ai, there is written it's generation number.
User prompt
Make it so the game has quite a more enjoyable ui.
User prompt
Continue tweaking with the field of view systems.
User prompt
Make so the field of view applies to ai sharing too
User prompt
Fix Bug: 'TypeError: Graphics is not a constructor' in this line: 'self.viewRayLeft = new Graphics();' Line Number: 90
User prompt
Fix Bug: 'TypeError: self.viewRayLeft.lineStyle is not a function' in this line: 'self.viewRayLeft.lineStyle(1, 0xFF0000, 1);' Line Number: 91
User prompt
Fix Bug: 'TypeError: Graphics is not a constructor' in this line: 'self.viewRayLeft = new Graphics();' Line Number: 90
User prompt
Fix Bug: 'TypeError: self.viewRayLeft.lineStyle is not a function' in this line: 'self.viewRayLeft.lineStyle(1, 0xFF0000, 1);' Line Number: 91
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); self.inheritTraits = function (parent) { this.food = parent.food * 0.5; }; var ais = []; self.foods = []; self.aiGraphics = self.createAsset('ai', 'AI character', .5, .5); self.generation = 1; self.generationText = new Text2(self.generation.toString(), { size: 50, fill: '#ffffff' }); self.addChild(self.generationText); self.food = 10; self.eat = function (food) { if (food.amount > 0) { this.food += food.consume(1); } }; self.share = function (otherAI) { var dx = otherAI.x - this.x; var dy = otherAI.y - this.y; var distance = Math.sqrt(dx * dx + dy * dy); var angle = Math.atan2(dy, dx); var deltaAngle = Math.abs(this.direction - angle); if (distance < this.viewDistance && deltaAngle < this.fieldOfView / 2) { 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.generation = 1; self.direction = Math.random() * 2 * Math.PI; self.fieldOfView = Math.random() * Math.PI; self.viewDistance = Math.random() * 500; self.move = function () { var nearestFood = null; var nearestFoodDistance = Infinity; for (var i = 0; i < this.foods.length; i++) { var dx = this.foods[i].x - this.x; var dy = this.foods[i].y - this.y; var distance = Math.sqrt(dx * dx + dy * dy); var angle = Math.atan2(dy, dx); var deltaAngle = Math.abs(this.direction - angle); if (distance < this.viewDistance && deltaAngle < this.fieldOfView / 2 && distance < nearestFoodDistance) { nearestFood = this.foods[i]; nearestFoodDistance = distance; } } var decision = nearestFood ? this.neuralNetwork.feedForward([this.food, nearestFood.amount, nearestFoodDistance]) : 0; if (decision > 0) { if (Math.random() < 0.05) { self.direction += Math.random() * 0.2 - 0.1; } } else { if (nearestFood) { var dx = nearestFood.x - this.x; var dy = nearestFood.y - this.y; self.direction = Math.atan2(dy, dx); } } var speed = 5; var newX = self.x + Math.cos(self.direction) * speed; var newY = self.y + Math.sin(self.direction) * speed; if (newX < 0) { newX = 0; self.direction = Math.PI - self.direction; } else if (newX > 2048) { newX = 2048; self.direction = Math.PI - self.direction; } if (newY < 0) { newY = 0; self.direction = -self.direction; } else if (newY > 2732) { newY = 2732; self.direction = -self.direction; } self.x = newX; self.y = newY; }; self.childSpawned = false; self.reproduce = function () { if (this.food > 10 && !this.childSpawned) { var child = new AI(); child.neuralNetwork = this.neuralNetwork.clone(); child.generation = this.generation + 1; 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; } if (Math.random() < 0.2) { child.fieldOfView += Math.random() * 0.4 - 0.2; } if (Math.random() < 0.1) { child.viewDistance += Math.random() * 100 - 50; } child.inheritTraits(this); child.generationText.setText(child.generation.toString()); this.food -= 10; ais.push(child); child.direction = Math.random() * 2 * Math.PI; this.childSpawned = true; 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.move(); 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); ais.push(child); } } } if (LK.ticks % 120 == 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
@@ -113,10 +113,11 @@
}
self.x = newX;
self.y = newY;
};
+ self.childSpawned = false;
self.reproduce = function () {
- if (this.food > 10) {
+ if (this.food > 10 && !this.childSpawned) {
var child = new AI();
child.neuralNetwork = this.neuralNetwork.clone();
child.generation = this.generation + 1;
for (var i = 0; i < child.neuralNetwork.weights.length; i++) {
@@ -137,8 +138,9 @@
child.generationText.setText(child.generation.toString());
this.food -= 10;
ais.push(child);
child.direction = Math.random() * 2 * Math.PI;
+ this.childSpawned = true;
return child;
}
return null;
};