예제 #1
0
    void CheckPerimeter()
    {
        if (!perimeter.upToDate)
        {
            perimeter.upToDate = ResetPerimeter();
        }

        // determine enemy heading range etc i.e disposition
        List <GameObject> bogieGOs = new List <GameObject>(bogies.Count);

        for (int i = 0; i < bogies.Count; i++)
        {
            bogieGOs[i] = bogies[i].bogieObject;
        }

        NTools.Slice enemyDisposition = NTools.AnalyseGroupDisposition(
            perimeter.center,
            perimeter.headingFloat,
            bogieGOs
            );

        // Adjust perimeter heading based on enemy positions center of weight

        // Determine green and nongreen population of sectors

        // Compare population to sector importance, compute importanceMet value
        // if needed, add problem of type perimeter
        // if there exists a problem with said sector, but is not relevant anymore, remove problem
    }
예제 #2
0
파일: NTools.cs 프로젝트: ancronym/LaserFox
    // Used to determine for example in which direction the enemy lies and how widespread they are.
    // works in CCW mode
    public static NTools.Slice AnalyseGroupDisposition(Vector3 originPos, float originHeading, List <GameObject> objects)
    {
        NTools.Slice slice = new NTools.Slice(originPos, originHeading, 0, 0, 0, 0, new Vector3(0, 0, 0));

        // sanity check, no objects means return of 000000 !!!
        if (objects.Count == 0)
        {
            return(slice);
        }

        float tempBear, leftBear = 0, rightBear = 0;

        // statistical analysis floats:
        float meanbearing = 0f, sumDiffFromMean = 0f;

        float[] bearings = new float[objects.Count];

        slice.centerOfMass = NTools.GetCenterOfObjects3D(objects);

        for (int i = 0; i < objects.Count; i++)
        {
            // left bearing is positive, right bearing is negative, clamped between -180 to 180

            tempBear = Mathf.Clamp(
                NTools.GetBearingFromHeadings(
                    originHeading,
                    NTools.HeadingFromVector(objects[i].transform.position - originPos)
                    ), -180f, 180f);

            // storing for later analysis
            bearings[i] = tempBear;

            // with the first heading set both left and right bearings
            if (i == 0)
            {
                leftBear = tempBear; rightBear = tempBear;
            }
            else
            {
                if (tempBear > leftBear)
                {
                    leftBear = tempBear;
                }
                else if (tempBear < rightBear)
                {
                    rightBear = tempBear;
                }
            }
        }


        // disperison computation
        for (int i = 0; i < bearings.Length; i++)
        {
            meanbearing += bearings[i];
        }
        meanbearing = meanbearing / bearings.Length;

        for (int i = 0; i < bearings.Length; i++)
        {
            sumDiffFromMean += bearings[i] - meanbearing;
        }


        // Filling the slice !!!
        slice.leftmostBearing  = leftBear;
        slice.rightmostBearing = rightBear;
        slice.bearingRange     = leftBear - rightBear;
        slice.stdDeviation     = Mathf.Sqrt(Mathf.Pow(sumDiffFromMean, 2f) / (bearings.Length - 1));

        return(slice);
    }