public void Run() { CreatureElement creature = new CreatureElement(); double[][][] weights = new double[][][] { new double[][]{ new double[]{ 1, 2, 3, 4 }, new double[]{ -1, 2, -3, 4 }, new double[]{ 4, 3, 2, 1 } }, }; creature.Brain = new NeuralNetwork(weights); Universe.Elements.Add(creature); while (true) { foreach (CreatureElement c in Universe.Elements) { c.Run(); } Universe.NotifyChanges(); } }
public override double Sense(Universe universe, CreatureElement parent) { Vector orientation = parent.Orientation + DirectionFromParent; Vector displacement; double foodSense = 0; foreach (FoodElement food in universe.Elements.OfType <FoodElement>()) { displacement = food.Position - parent.Position; if (Vector.AngleBetween(orientation, displacement) < Range) { foodSense += (1 / displacement.LengthSquared) * food.GetSize(); } } return(foodSense); }
public override double Sense(Universe universe, CreatureElement parent) { Vector orientation = parent.Orientation + DirectionFromParent; Vector displacement; double foodSense = 0; foreach (FoodElement food in universe.Elements.OfType<FoodElement>()) { displacement = food.Position - parent.Position; if (Vector.AngleBetween(orientation, displacement) < Range) { foodSense += (1 / displacement.LengthSquared) * food.GetSize(); } } return foodSense; }