Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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;
        }