예제 #1
0
    public float DetermineFitness(CarState state)
    {
        //return UnityEngine.Random.value * 1000;

        //state.AngleToGoal         Drehung           0     0.6       0.1
        //state.CurrentVelocity     Geschwindiket     0     0.8       0.3
        //state.DistanceFromGoal    Entfernung        0     0.9       0.2
        //state.NumberOfCollisions  Unfall            0       9         1


        float angle      = state.AngleToGoal();
        float velocity   = state.CurrentVelocity();
        float distance   = state.DistanceFromGoal();
        int   collisions = state.NumberOfCollisions();

        if (angle < 0.1)
        {
            fAngle = 0.1F;
        }
        if (angle >= 0.1)
        {
            fAngle = 0.9F;
        }

        if (velocity < 0.1)
        {
            fVelocity = 0.1F;
        }
        if (velocity > 0.5)
        {
            fVelocity = 0.9F;
        }

        if (distance < 0.5)
        {
            fDistance = 0.1F;
        }
        if (distance >= 0.5)
        {
            fDistance = 0.9F;
        }


        if (collisions == 0)
        {
            fCollision = 0.1F;
        }
        if (collisions > 0 && collisions <= 3)
        {
            fCollision = 0.5F;
        }
        if (collisions > 3)
        {
            fCollision = 0.99F;
        }

        float fitness = 1 - (fAngle * fVelocity * fDistance * fCollision);

        return((distance / 100) - 5);
    }
예제 #2
0
        //Should be beteween 0..1
        public float DetermineFitness(CarState state)
        {
            //Debug.Log(state.DistanceFromGoal() + " -- " + state.AngleToGoal());
            int maxDistance = 40;

            float angle    = state.AngleToGoal(); //transform:  angle = 1 --> Optimal; angle = 0 --> so bad
            float distance = state.DistanceFromGoal();

            float weightDistance  = 0.50f;
            float weightAngle     = 0.30f;
            float weightCollision = 0.1f;
            float weightSpeed     = 0.1f;

            // 0 ... car ... max    --> lerp
            Debug.Log("the angle is: " + angle);
            float partDistance  = weightDistance * (float)Math.Pow((1f - Math.Min(distance, maxDistance) / maxDistance), 2);
            float partCollision = weightCollision * (float)Math.Pow((1f - Math.Min(state.NumberOfCollisions(), 4) / 4), 2);
            float partSpeed     = weightSpeed * (float)Math.Pow((1f - Math.Min(state.CurrentVelocity(), 1)), 2);
            float partAngle     = weightAngle * (float)Math.Pow((1f - (Math.Abs(angle / 4))), 2);                                // why
            //float partAngle = weightAngle           * ((float)Math.Pow(1f - Math.Min(angle, (4 - angle)) / 2f, 2f));
            //float partAngle = weightAngle           * (float)Math.Pow((1 - (Math.Abs ( 2 - angle) / 2)),1f);
            //Debug.Log("Angle: " + angle + "  rel: " + relAngle + " with faktor:" + partAngle);

            float sum = partDistance + partAngle + partCollision + partSpeed;

            return(sum);
            //else return sum;
        }
예제 #3
0
    public float DetermineFitness(CarState state)
    {
        var angle      = state.AngleToGoal();
        var velocity   = state.CurrentVelocity();
        var distance   = state.DistanceFromGoal();
        var collisions = state.NumberOfCollisions();

        var goalTransform = GameObject.Find("GoalPosition").transform;
        var spawnPoint    = GameObject.Find("SpawnPoint").transform;

        var relAngle      = angle * WEIGHT_ANGLE;
        var relVelocity   = velocity * WEIGHT_VELOCITY;
        var relDistance   = distance * WEIGHT_DISTANCE;
        var relCollisions = collisions * WEIGHT_COLLISION;

        var fitness = relAngle + relVelocity + relDistance + relCollisions;

        return(1 / fitness);
    }
예제 #4
0
    public float DetermineFitness(CarState state)
    {
        int maxDistance = 40;

        float angle    = state.AngleToGoal();
        float distance = state.DistanceFromGoal();

        float weightDistance  = 0.3f;
        float weightAngle     = 0.1f;
        float weightCollision = 0.5f;
        float weightSpeed     = 0.1f;

        float partDistance  = weightDistance * (float)Math.Pow((1f - Math.Min(distance, maxDistance) / maxDistance), 2);
        float partCollision = weightCollision * (float)Math.Pow((1f - Math.Min(state.NumberOfCollisions(), 4) / 4), 2);
        float partSpeed     = weightSpeed * (float)Math.Pow((1f - Math.Min(state.CurrentVelocity(), 1)), 2);
        float partAngle     = weightAngle * (float)Math.Pow((1f - (Math.Abs(angle / 4))), 2);
        float sum           = partDistance + partAngle + partCollision + partSpeed * 100;

        return(sum);
    }
예제 #5
0
    public float DetermineFitness(CarState state)
    {
        float angle      = state.AngleToGoal() / 4;
        float distance   = state.DistanceFromGoal();
        float speed      = state.CurrentVelocity();
        float collisions = state.NumberOfCollisions();

//        Debug.Log("angle: " + angle);
//        Debug.Log("distance: " + distance);
//        Debug.Log("speed: " + speed);
//        Debug.Log("collisions: " + collisions);

        float scaledAngle;

        if (angle >= maxAngle)
        {
            scaledAngle = 100;
        }
        else
        {
            scaledAngle = angle * 100;
        }
//        Debug.Log("scaledAngle: " + scaledAngle);
        float weightedAngle = scaledAngle * wheightAngle;


        float scaledDistance;

        if (distance >= maxDist)
        {
            scaledDistance = 100;
        }
        else
        {
            scaledDistance = distance / maxDist * 100;
        }
//        Debug.Log("scaledDistance: " + scaledDistance);
        float wheightedDistance = scaledDistance * wheightDistance;


        float scaledSpeed;

        if (speed >= maxSpeed)
        {
            scaledSpeed = 100;
        }
        else
        {
            scaledSpeed = speed / maxSpeed * 100;
        }
//        Debug.Log("scaledSpeed: " + scaledSpeed);
        float wheightedSpeed = scaledSpeed * wheightSpeed;


        float scaledCollisions;

        if (collisions >= maxCollisions)
        {
            scaledCollisions = 100;
        }
        else
        {
            scaledCollisions = collisions / maxCollisions * 100;
        }
//        Debug.Log("scaledCollisions: " + scaledCollisions);
        float wheightedCollisions = scaledCollisions * wheightCollisions;


//        float sum = 100 - ((scaledAngle + scaledDistance + scaledSpeed + scaledCollisions)/4);
        float sum = 100 - (weightedAngle + wheightedDistance + wheightedSpeed + wheightedCollisions);

        if (sum > 99)
        {
            Debug.Log("angle: " + angle);
            Debug.Log("distance: " + distance);
            Debug.Log("speed: " + speed);
            Debug.Log("collisions: " + collisions);
            Debug.Log("weightedAngle: " + weightedAngle);
            Debug.Log("wheightedDistance: " + wheightedDistance);
            Debug.Log("wheightedSpeed: " + wheightedSpeed);
            Debug.Log("wheightedCollisions: " + wheightedCollisions);
            Debug.Log("sum: " + sum);
        }

        return(sum);
    }
예제 #6
0
 public float DetermineFitness(CarState state)
 {
     return(state.DistanceFromGoal() + state.AngleToGoal() * 10 + state.CurrentVelocity() * 10 + state.NumberOfCollisions() * 1000);
 }
예제 #7
0
 public float DetermineFitness(CarState state)
 {
     return(100 - state.DistanceFromGoal() * 4 - state.AngleToGoal() * 2 - (state.NumberOfCollisions() * 20) - Mathf.Abs(state.CurrentVelocity()) * 10);
 }