Ejemplo n.º 1
0
    private float calcScore(FlockControl.UnityState us, BirdControl me)
    {
        float score = 0;

        float gd = (us.goal.transform.position - transform.position).magnitude;

        score += GOAL_CONST * Mathf.Min(ASYMPTOTE, 1 / Mathf.Sqrt(gd));

        if (!me.Moving)
        {
            return(score);
        }

        foreach (BirdControl b in us.birds)
        {
            if (b.Equals(me) || !b.Moving)
            {
                continue;
            }

            float d = me.GetDistance(b).dist;
            score += BIRD_CONST * Mathf.Min(ASYMPTOTE, 1 / Mathf.Sqrt(d));
        }

        for (int i = 0; i < us.walls.Length; i++)
        {
            float d = me.WallDistance(i).dist;
            score += WALL_CONST * Mathf.Min(ASYMPTOTE, 1 / Mathf.Sqrt(d));
        }

        return(score);
    }
    private Vector2 obstacle(GameObject[] walls, BirdControl me)
    {
        Vector2 force = Vector2.zero;

        for (int i = 0; i < walls.Length; i++)
        {
            BirdControl.CachedDelta cd = me.WallDistance(i);
            if (cd.dist > genome.Obstacle.Distance)
            {
                continue;
            }
            force += calcForce(-1 * cd.norm, cd.dist, genome.Cohesion);
        }
        return(force);
    }