Exemplo n.º 1
0
    public override float GetFitness()
    {
        sw.Stop();
        print(String.Format("It took {0}ms from activation to fitness evaluation.", sw.ElapsedMilliseconds));

        PhysicsTester.BallDropResults bdResults = PhysicsTester.MeassureBallDropExperiment(_ballDropExperiment);

        print("Balldrop: " + bdResults);
        //pot function of rotation, scaled to two times the possible value of ChildCount
        rotationTerm = bdResults.objRotation / 180.0f * Height * Width * Length * 3.2f;
        //print("rot angle: " + bdResults.objRotation);
        //print("rotation term: " + rotationTerm);

        //exponential function of ball travel distance
        ballTravelTerm = Mathf.Min(1000, Mathf.Pow(3, 2 * bdResults.ballTravelled));
        //print("ball travel term: " + ballTravelTerm);

        float deltaMiddle = bdResults.ballRestHeight - ((TestExperiment.Height + 2f) / 2);

        ballRestTerm = Mathf.Pow(2, -(deltaMiddle * 2));
        print("ball rest term: " + ballRestTerm);

        float headHeightTerm = -((bdResults.headOverHips + 6.75f) / 13.5f - 0.7f) * 2000;

        //print("material cost term: " + ChildCount);

        //Less is better
        fitnessCost = ChildCount + rotationTerm + ballTravelTerm + ballRestTerm + headHeightTerm;
        print("fitnesscost: " + fitnessCost);

        float maxRotation   = Height * Length * Width * 3.2f;
        float maxBallTravel = 1000;
        float maxBallRest   = Mathf.Pow(2, (TestExperiment.Height + 2f));
        float maxChildCount = Height * Length * Width;
        float maxHead       = 600;

        if (rotationTerm > maxRotation)
        {
            throw new SystemException("rotation term above assumed max");
        }
        if (ballTravelTerm > maxBallTravel)
        {
            throw new SystemException("ball travel term above assumed max");
        }
        if (ballRestTerm > maxBallRest)
        {
            throw new SystemException("ball rest term above assumed max");
        }
        if (ChildCount > maxChildCount)
        {
            throw new SystemException("child count term above assumed max");
        }
        if (headHeightTerm > maxHead)
        {
            throw new SystemException("head height term above assumed max");
        }

        return((ChildCount == 0) ? 0 : (maxChildCount + maxRotation + maxBallTravel + maxBallRest + maxHead) - fitnessCost);
    }
Exemplo n.º 2
0
    public override void Activate(IBlackBox box)
    {
        Box = box;
        sw.Start();
        _numVoxels = 0;
        for (int x = 0; x < Width; x++)
        {
            for (int y = 0; y < Height; y++)
            {
                for (int z = 0; z < Length; z++)
                {
                    box.ResetState();
                    box.InputSignalArray[0] = x;
                    box.InputSignalArray[1] = y;
                    box.InputSignalArray[2] = z;
                    box.Activate();
                    _voxels[x, y, z] = (float)box.OutputSignalArray[0];
                    if (_voxels[x, y, z] > _threshold)
                    {
                        _numVoxels++;
                    }
                }
            }
        }
        print(String.Format("Time taken to generate voxels: {0}ms", sw.ElapsedMilliseconds));

        var stopWatch = new Stopwatch();

        stopWatch.Start();
        Geometry.FindLargestComponent(_voxels, _threshold, gameObject);
        stopWatch.Stop();
        ChildCount = transform.childCount;
        gameObject.GetComponent <Rigidbody>().mass = ChildCount * childMass;
        _ballDropExperiment = PhysicsTester.StartBallDropExperiment(gameObject);
        print(String.Format("It took {0}ms to find largest component.", stopWatch.ElapsedMilliseconds));
    }
Exemplo n.º 3
0
        public MainGame() : base("Dungeon")
        {
            sb     = new SpriteBatch();
            camera = new Camera3D();
            camera.IsOrthographic = true;
            camera.Orientation   *= quat.FromAxisAngle(0, vec3.UnitX);
            camera.Position       = new vec3(0, 0, 1) * camera.Orientation;

            mainTarget = new RenderTarget(Resolution.RenderWidth, Resolution.RenderHeight,
                                          RenderTargetFlags.Color | RenderTargetFlags.Depth);
            mainSprite      = new Sprite(mainTarget, null, Alignments.Left | Alignments.Top);
            mainSprite.Mods = SpriteModifiers.FlipVertical;

            Player player = new Player();

            player.UnlockSkill(PlayerSkills.Jump);

            scene        = new Scene();
            scene.Camera = camera;
            scene.Add(player);
            scene.ModelBatch.LightDirection = Utilities.Normalize(new vec3(1, -0.2f, 0));

            renderTargetUsers = new List <IRenderTargetUser>();
            renderTargetUsers.Add(scene.ModelBatch);

            physicsTester = new PhysicsTester();

            MessageSystem.Subscribe(this, CoreMessageTypes.ResizeWindow, (messageType, data, dt) =>
            {
                mainSprite.ScaleTo(Resolution.WindowWidth, Resolution.WindowHeight);
            });

            MessageSystem.ProcessChanges();
            MessageSystem.Send(CoreMessageTypes.ResizeRender, Resolution.RenderDimensions);
            MessageSystem.Send(CoreMessageTypes.ResizeWindow, Resolution.WindowDimensions);
        }